feat: kørsler følger markørnavne efter AD-omnummerering (v1.62.135)
This commit is contained in:
@@ -483,6 +483,21 @@ function ADRunsController.resolveMarkers(adEnv, run)
|
||||
local role = run.kind == "outbound" and "load" or "unload"
|
||||
local buildingIds = run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds
|
||||
local existing = run.kind == "outbound" and run.sourceWayPointIds or ADRunsController.getRunTargets(run)
|
||||
-- gemte markørnavne følges, når AutoDrive har omnummereret vejpunkterne (spilleren sletter/flytter punkter live)
|
||||
local graph = adEnv.ADGraphManager
|
||||
local storedNames = run.kind == "outbound" and run.sourceNames or run.targetNames
|
||||
if storedNames ~= nil and #storedNames > 0 and graph ~= nil and graph.getMapMarkerByWayPointId ~= nil then
|
||||
local byName = {}
|
||||
for _, marker in pairs(graph:getMapMarkers() or {}) do
|
||||
if marker.name ~= nil and byName[marker.name] == nil then byName[marker.name] = marker.id end
|
||||
end
|
||||
local moves
|
||||
existing, moves = ADRuns.remapByName(existing, storedNames, function(name) return byName[name] end,
|
||||
function(id) local marker = graph:getMapMarkerByWayPointId(id) return marker ~= nil and marker.name or nil end)
|
||||
for _, move in ipairs(moves) do
|
||||
Logging.info(ADRunsController.LOG_PREFIX .. "run '%s': markøren '%s' er flyttet (vejpunkt %d -> %d) — fulgt", tostring(run.name), tostring(move.name), move.from, move.to)
|
||||
end
|
||||
end
|
||||
local resolved, seen = {}, {}
|
||||
for _, buildingId in ipairs(buildingIds or {}) do
|
||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||
@@ -533,12 +548,20 @@ function ADRunsController.resolveMarkers(adEnv, run)
|
||||
if #pruned > 0 then
|
||||
Logging.info(ADRunsController.LOG_PREFIX .. "run '%s': gamle markører fjernet (ingen kilde eller dublet af valgt bygning): %s", tostring(run.name), table.concat(pruned, " "))
|
||||
end
|
||||
if not listEquals(resolved, existing or {}) then
|
||||
local changes = run.kind == "outbound" and {sourceWayPointIds = resolved} or {targetWayPointIds = resolved}
|
||||
-- navnene gemmes sammen med id'erne, så de kan følges efter en omnummerering
|
||||
local names = {}
|
||||
for _, wayPointId in ipairs(resolved) do
|
||||
local marker = graph ~= nil and graph.getMapMarkerByWayPointId ~= nil and graph:getMapMarkerByWayPointId(wayPointId) or nil
|
||||
table.insert(names, marker ~= nil and tostring(marker.name) or "")
|
||||
end
|
||||
local current = run.kind == "outbound" and run.sourceWayPointIds or ADRunsController.getRunTargets(run)
|
||||
if not listEquals(resolved, current or {}) or not listEquals(names, storedNames or {}) then
|
||||
local changes = run.kind == "outbound" and {sourceWayPointIds = resolved, sourceNames = names} or {targetWayPointIds = resolved, targetNames = names}
|
||||
ADRunsController.store = ADRuns.updateRun(ADRunsController.store, run.id, changes)
|
||||
local updated = ADRuns.getRun(ADRunsController.store, run.id)
|
||||
if updated ~= nil then
|
||||
run.sourceWayPointIds, run.targetWayPointIds, run.targetWayPointId = updated.sourceWayPointIds, updated.targetWayPointIds, updated.targetWayPointId
|
||||
run.sourceNames, run.targetNames = updated.sourceNames, updated.targetNames
|
||||
end
|
||||
end
|
||||
return {missing = missing}
|
||||
|
||||
Reference in New Issue
Block a user