feat: flere mål pr. run (afkrydsning; den stald der mangler mest får turen, AD's mål skiftes ved turstart) + under-faner Overblik/Runs (v1.11.0.0)
This commit is contained in:
@@ -25,6 +25,7 @@ local function copyRun(run)
|
||||
id = run.id,
|
||||
name = run.name,
|
||||
targetWayPointId = run.targetWayPointId,
|
||||
targetWayPointIds = copyList(run.targetWayPointIds),
|
||||
ingredientMode = run.ingredientMode,
|
||||
ingredients = copyList(run.ingredients),
|
||||
waitPoolGroup = run.waitPoolGroup,
|
||||
@@ -62,6 +63,7 @@ function ADRuns.createRun(store, name)
|
||||
id = new.nextId,
|
||||
name = name,
|
||||
targetWayPointId = nil,
|
||||
targetWayPointIds = {},
|
||||
ingredientMode = "auto",
|
||||
ingredients = {},
|
||||
waitPoolGroup = "",
|
||||
@@ -102,12 +104,16 @@ function ADRuns.updateRun(store, runId, changes)
|
||||
return new
|
||||
end
|
||||
if changes.name ~= nil then run.name = changes.name end
|
||||
-- false = ryd målet (nil i changes betyder "rør ikke")
|
||||
if changes.targetWayPointId == false then
|
||||
run.targetWayPointId = nil
|
||||
-- Mål: liste (flere stalde pr. run); targetWayPointId = første = "primært" (bagudkompatibelt).
|
||||
-- false = ryd målene (nil i changes betyder "rør ikke")
|
||||
if changes.targetWayPointIds ~= nil then
|
||||
run.targetWayPointIds = copyList(changes.targetWayPointIds)
|
||||
elseif changes.targetWayPointId == false then
|
||||
run.targetWayPointIds = {}
|
||||
elseif changes.targetWayPointId ~= nil then
|
||||
run.targetWayPointId = changes.targetWayPointId
|
||||
run.targetWayPointIds = {changes.targetWayPointId}
|
||||
end
|
||||
run.targetWayPointId = run.targetWayPointIds[1]
|
||||
if ADRuns.INGREDIENT_MODES[changes.ingredientMode] then run.ingredientMode = changes.ingredientMode end
|
||||
if changes.ingredients ~= nil then run.ingredients = copyList(changes.ingredients) end
|
||||
if changes.waitPoolGroup ~= nil then run.waitPoolGroup = changes.waitPoolGroup end
|
||||
@@ -116,6 +122,27 @@ function ADRuns.updateRun(store, runId, changes)
|
||||
return new
|
||||
end
|
||||
|
||||
-- Tilføj/fjern et mål (afkrydsning i fanen).
|
||||
function ADRuns.toggleTarget(store, runId, wayPointId)
|
||||
local run = ADRuns.getRun(store, runId)
|
||||
if run == nil then
|
||||
return copyStore(store)
|
||||
end
|
||||
local targets = {}
|
||||
local found = false
|
||||
for _, id in ipairs(run.targetWayPointIds) do
|
||||
if id == wayPointId then
|
||||
found = true
|
||||
else
|
||||
table.insert(targets, id)
|
||||
end
|
||||
end
|
||||
if not found then
|
||||
table.insert(targets, wayPointId)
|
||||
end
|
||||
return ADRuns.updateRun(store, runId, {targetWayPointIds = targets})
|
||||
end
|
||||
|
||||
function ADRuns.findRunByVehicle(store, vehicleId)
|
||||
for _, run in ipairs(store.runs) do
|
||||
for _, id in ipairs(run.vehicleIds) do
|
||||
@@ -177,6 +204,7 @@ function ADRuns.toRecords(store)
|
||||
id = run.id,
|
||||
name = run.name,
|
||||
target = run.targetWayPointId or 0,
|
||||
targets = table.concat(run.targetWayPointIds, " "),
|
||||
ingredientMode = run.ingredientMode,
|
||||
ingredients = ADRuns.serializeIngredients(run.ingredients),
|
||||
waitPool = run.waitPoolGroup,
|
||||
@@ -196,10 +224,19 @@ function ADRuns.fromRecords(records)
|
||||
local isValid = id ~= nil and id >= 1 and record.name ~= nil and record.name ~= ""
|
||||
if isValid and ADRuns.getRun(store, id) == nil then
|
||||
local target = tonumber(record.target)
|
||||
local targets = {}
|
||||
for token in string.gmatch(tostring(record.targets or ""), "%S+") do
|
||||
local wayPointId = tonumber(token)
|
||||
if wayPointId ~= nil and wayPointId > 0 then table.insert(targets, wayPointId) end
|
||||
end
|
||||
if #targets == 0 and target ~= nil and target > 0 then
|
||||
targets = {target}
|
||||
end
|
||||
table.insert(store.runs, {
|
||||
id = id,
|
||||
name = record.name,
|
||||
targetWayPointId = target ~= nil and target > 0 and target or nil,
|
||||
targetWayPointId = targets[1],
|
||||
targetWayPointIds = targets,
|
||||
ingredientMode = ADRuns.INGREDIENT_MODES[record.ingredientMode] and record.ingredientMode or "auto",
|
||||
ingredients = ADRuns.parseIngredients(record.ingredients),
|
||||
waitPoolGroup = record.waitPool or "",
|
||||
|
||||
Reference in New Issue
Block a user