feat: kørsler følger markørnavne efter AD-omnummerering (v1.62.135)

This commit is contained in:
2026-10-10 01:36:54 +02:00
parent 10cc8c12a5
commit f3f3bdb80b
5 changed files with 72 additions and 3 deletions
+40
View File
@@ -92,6 +92,7 @@ local function copyRun(run)
name = run.name,
kind = run.kind,
sourceWayPointIds = copyList(run.sourceWayPointIds),
sourceNames = copyList(run.sourceNames),
sourceBuildingIds = copyList(run.sourceBuildingIds),
targetBuildingIds = copyList(run.targetBuildingIds),
storeBuildingIds = copyList(run.storeBuildingIds),
@@ -103,6 +104,7 @@ local function copyRun(run)
collectRound = run.collectRound,
targetWayPointId = run.targetWayPointId,
targetWayPointIds = copyList(run.targetWayPointIds),
targetNames = copyList(run.targetNames),
ingredientMode = run.ingredientMode,
ingredients = copyList(run.ingredients),
waitPoolGroup = run.waitPoolGroup,
@@ -145,6 +147,7 @@ function ADRuns.createRun(store, name, kind)
name = name,
kind = ADRuns.KINDS[kind] and kind or "supply",
sourceWayPointIds = {},
sourceNames = {},
sourceBuildingIds = {},
targetBuildingIds = {},
storeBuildingIds = {},
@@ -156,6 +159,7 @@ function ADRuns.createRun(store, name, kind)
collectRound = false,
targetWayPointId = nil,
targetWayPointIds = {},
targetNames = {},
ingredientMode = "auto",
ingredients = {},
waitPoolGroup = "",
@@ -207,6 +211,10 @@ function ADRuns.updateRun(store, runId, changes)
run.targetWayPointIds = {changes.targetWayPointId}
end
run.targetWayPointId = run.targetWayPointIds[1]
if changes.targetNames ~= nil then run.targetNames = copyList(changes.targetNames)
elseif changes.targetWayPointIds ~= nil or changes.targetWayPointId ~= nil then run.targetNames = {} end
if changes.sourceNames ~= nil then run.sourceNames = copyList(changes.sourceNames)
elseif changes.sourceWayPointIds ~= nil then run.sourceNames = {} end
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
@@ -435,6 +443,34 @@ function ADRuns.parseIngredients(text)
end
-- Flade poster (kun strenge/tal) til XML-laget, i store'ens rækkefølge.
-- Markørnavne gemt ved siden af vejpunkt-id'erne ("a|b|c" -> liste). AutoDrive omnummererer alle senere vejpunkter,
-- når spilleren sletter et, så et gemt id kan pege på et tilfældigt punkt (in-game 10/10: æg-runden mistede alle
-- 7 kilder, mælk 2, græs-til-hø sit mål, mens spilleren rettede vejnettet).
function ADRuns.splitNames(text)
local names = {}
for token in string.gmatch(tostring(text or ""), "[^|]+") do table.insert(names, token) end
return names
end
-- ids + names (parallelle lister) -> nye ids: står markøren med det gemte navn ikke længere på id'et, følges navnet.
-- idOfName(name) -> id | nil; nameOfId(id) -> navn | nil. -> nye ids, flytninger {{name, from, to}}
function ADRuns.remapByName(ids, names, idOfName, nameOfId)
local result, moves = {}, {}
for index, id in ipairs(ids or {}) do
local wanted = names ~= nil and names[index] or nil
local newId = id
if wanted ~= nil and wanted ~= "" and nameOfId(id) ~= wanted then
local found = idOfName(wanted)
if found ~= nil and found ~= id then
newId = found
table.insert(moves, {name = wanted, from = id, to = found})
end
end
table.insert(result, newId)
end
return result, moves
end
function ADRuns.toRecords(store)
local records = {}
for index, run in ipairs(store.runs) do
@@ -451,6 +487,8 @@ function ADRuns.toRecords(store)
vehicleIds = copyList(run.vehicleIds),
kind = run.kind,
sources = table.concat(run.sourceWayPointIds or {}, " "),
sourceNames = table.concat(run.sourceNames or {}, "|"),
targetNames = table.concat(run.targetNames or {}, "|"),
sourceBuildings = table.concat(run.sourceBuildingIds or {}, " "),
targetBuildings = table.concat(run.targetBuildingIds or {}, " "),
storeBuildings = table.concat(run.storeBuildingIds or {}, " "),
@@ -500,6 +538,8 @@ function ADRuns.fromRecords(records)
name = record.name,
kind = ADRuns.KINDS[record.kind] and record.kind or "supply",
sourceWayPointIds = sources,
sourceNames = ADRuns.splitNames(record.sourceNames),
targetNames = ADRuns.splitNames(record.targetNames),
sourceBuildingIds = parseIds(record.sourceBuildings),
targetBuildingIds = parseIds(record.targetBuildings),
storeBuildingIds = parseIds(record.storeBuildings),