feat: run-indstilling 'Kør hjem fra Wait under X %' (10–90, standard 50) i model, XML, Wait-regel og fane (v1.10.2.0)

This commit is contained in:
2026-09-23 01:47:42 +02:00
parent ef69347c55
commit 231d6a41d6
12 changed files with 98 additions and 6 deletions
+13
View File
@@ -6,6 +6,9 @@
ADRuns = {}
ADRuns.MAX_LOOPS = 99
-- "Kør hjem fra Wait når målet er under X %": 10..90, standard 50 (= den gamle 50 %-regel).
ADRuns.DEFAULT_RETURN_BELOW_PERCENT = 50
ADRuns.MIN_RETURN_BELOW_PERCENT, ADRuns.MAX_RETURN_BELOW_PERCENT = 10, 90
ADRuns.XML_VERSION = 1
ADRuns.INGREDIENT_MODES = {auto = true, manual = true}
@@ -26,6 +29,7 @@ local function copyRun(run)
ingredients = copyList(run.ingredients),
waitPoolGroup = run.waitPoolGroup,
loops = run.loops,
returnBelowPercent = run.returnBelowPercent,
vehicleIds = copyList(run.vehicleIds),
}
end
@@ -38,6 +42,11 @@ local function copyStore(store)
return {nextId = store.nextId, runs = runs}
end
local function clampPercent(percent)
local value = tonumber(percent) or ADRuns.DEFAULT_RETURN_BELOW_PERCENT
return math.max(ADRuns.MIN_RETURN_BELOW_PERCENT, math.min(ADRuns.MAX_RETURN_BELOW_PERCENT, math.floor(value)))
end
local function clampLoops(loops)
local value = tonumber(loops) or 0
return math.max(0, math.min(ADRuns.MAX_LOOPS, math.floor(value)))
@@ -57,6 +66,7 @@ function ADRuns.createRun(store, name)
ingredients = {},
waitPoolGroup = "",
loops = 0,
returnBelowPercent = ADRuns.DEFAULT_RETURN_BELOW_PERCENT,
vehicleIds = {},
}
new.nextId = new.nextId + 1
@@ -102,6 +112,7 @@ function ADRuns.updateRun(store, runId, changes)
if changes.ingredients ~= nil then run.ingredients = copyList(changes.ingredients) end
if changes.waitPoolGroup ~= nil then run.waitPoolGroup = changes.waitPoolGroup end
if changes.loops ~= nil then run.loops = clampLoops(changes.loops) end
if changes.returnBelowPercent ~= nil then run.returnBelowPercent = clampPercent(changes.returnBelowPercent) end
return new
end
@@ -170,6 +181,7 @@ function ADRuns.toRecords(store)
ingredients = ADRuns.serializeIngredients(run.ingredients),
waitPool = run.waitPoolGroup,
loops = run.loops,
returnBelow = run.returnBelowPercent,
vehicleIds = copyList(run.vehicleIds),
}
end
@@ -192,6 +204,7 @@ function ADRuns.fromRecords(records)
ingredients = ADRuns.parseIngredients(record.ingredients),
waitPoolGroup = record.waitPool or "",
loops = clampLoops(record.loops),
returnBelowPercent = clampPercent(record.returnBelow),
vehicleIds = copyList(record.vehicleIds),
})
store.nextId = math.max(store.nextId, id + 1)