fix(flows): traktorer der ikke findes længere fjernes fra flowet 2 min efter indlæsning (ikke hvis alle mangler); resuméet viser aldrig rå køretøjs-id (v1.59.6.0)

This commit is contained in:
2026-09-29 18:13:30 +02:00
parent 3d11ee9748
commit 45f58abcf0
7 changed files with 60 additions and 2 deletions
+7 -1
View File
@@ -429,7 +429,13 @@ local SUMMARY = {
local ids = guide.draft.vehicleIds
if #ids == 0 then return {L("spu_guide_flow_sumNoTractors")} end
if #ids > ADFlowGuide.MAX_NAMED_TRACTORS then return {L("spu_guide_flow_sumTractors", {#ids})} end
return {T(table.concat(namesFor(ids, guide.context.vehicles, "label"), ", "))}
-- traktorer der ikke findes (solgt, eller ikke indlæst endnu) vises ikke som rå id
local known = {}
for _, vehicle in ipairs(guide.context.vehicles or {}) do known[vehicle.id] = true end
local present = {}
for _, id in ipairs(ids) do if known[id] then table.insert(present, id) end end
if #present == 0 then return {L("spu_guide_flow_sumNoTractors")} end
return {T(table.concat(namesFor(present, guide.context.vehicles, "label"), ", "))}
end,
}
+2
View File
@@ -626,6 +626,8 @@ function ADFlowWagons.tick(adEnv, dt)
cleanedUp = true
local ok, err = pcall(cleanupAfterLoad, adEnv)
if not ok then Logging.warning(ADFlowWagons.LOG_PREFIX .. "oprydning efter indlæsning: %s", tostring(err)) end
local okPrune, errPrune = pcall(ADRunsController.pruneMissingVehicles, adEnv)
if not okPrune then Logging.warning(ADFlowWagons.LOG_PREFIX .. "oprydning af solgte traktorer: %s", tostring(errPrune)) end
end
end
rememberTimer = rememberTimer + dt
+17
View File
@@ -344,6 +344,23 @@ function ADRuns.unassignVehicle(store, vehicleId)
return new
end
-- Traktorer der ikke findes længere (solgt/byttet) fjernes fra deres flow. exists(vehicleId) -> bool.
-- Mangler ALLE flowenes traktorer, er indlæsningen nok ikke færdig/gået galt: intet fjernes.
-- -> ny store, {{runName, vehicleId}} over de fjernede
function ADRuns.pruneMissingVehicles(store, exists)
local missing, total = {}, 0
for _, run in ipairs(store.runs) do
for _, id in ipairs(run.vehicleIds) do
total = total + 1
if not exists(id) then table.insert(missing, {runName = run.name, vehicleId = id}) end
end
end
if #missing == 0 or #missing == total then return store, {} end
local new = store
for _, entry in ipairs(missing) do new = ADRuns.unassignVehicle(new, entry.vehicleId) end
return new, missing
end
-- En traktor er kun i ét run. Returnerer ny store + id på det run den blev flyttet FRA (nil = ingen).
function ADRuns.assignVehicle(store, runId, vehicleId)
local previous = ADRuns.findRunByVehicle(store, vehicleId)
+13
View File
@@ -1502,6 +1502,19 @@ function ADRunsController.load(adEnv)
end
end
-- Én gang efter indlæsning (køretøjerne er klar): traktorer der ikke findes længere fjernes fra flowene.
function ADRunsController.pruneMissingVehicles(adEnv)
local vehiclesById = getFarmVehiclesById(adEnv)
if next(vehiclesById) == nil then return end
local store, removed = ADRuns.pruneMissingVehicles(ADRunsController.store, function(id) return vehiclesById[id] ~= nil end)
if #removed == 0 then return end
ADRunsController.store = store
for _, entry in ipairs(removed) do
Logging.info(ADRunsController.LOG_PREFIX .. "run '%s': køretøj %s findes ikke længere — fjernet fra flowet", tostring(entry.runName), tostring(entry.vehicleId))
end
ADRunsController.save()
end
function ADRunsController.installSaveHook()
if ItemSystem == nil or ItemSystem.save == nil or Utils == nil then
return
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.59.5.0</version>
<version>1.59.6.0</version>
<title>
<en>AD Smart Pickup</en>
</title>
+5
View File
@@ -203,6 +203,11 @@ check("FL10 regler", partText(lineFor(sumIn, "rules")), "spu_guide_flow_sumLoops
check("FL10 vent", partText(lineFor(sumIn, "wait")), "spu_waitPool_all")
check("FL10 traktorer", partText(lineFor(sumIn, "tractors")), "=Traktor 1")
check("FL10 intet lager-trin", lineFor(sumIn, "store"), nil)
-- traktor der ikke findes længere (solgt): aldrig rå id i resuméet (in-game 29/9)
local withGhost = FG.choose(FG.choose(withTarget, "vehicleIds", {item = "t1", on = true}), "vehicleIds", {item = "vehicleGONE", on = true})
check("FL10b resumé springer manglende over", partText(lineFor(FG.summary(withGhost), "tractors")), "=Traktor 1")
local onlyGhost = FG.choose(withTarget, "vehicleIds", {item = "vehicleGONE", on = true})
check("FL10b kun manglende -> ingen traktorer", partText(lineFor(FG.summary(onlyGhost), "tractors")), "spu_guide_flow_sumNoTractors")
local sumOut = FG.summary(FG.choose(FG.choose(policy, "collectRound", true), "sellAtPercent", 95))
check("FL11 retning ud", partText(lineFor(sumOut, "direction")), "spu_direction_out")
check("FL11 fra tom", partText(lineFor(sumOut, "buildings")), "spu_guide_flow_none")
+15
View File
@@ -345,5 +345,20 @@ local ps3 = ADRuns.assignVehicle(ps2, prunB.id, "trac")
check("R4 gammel flow glemmer vognen", ADRuns.getRun(ps3, prunA.id).wagons.trac, nil)
local ps4 = ADRuns.unassignVehicle(ps2, "trac")
check("R4 fjernet traktor: vogn glemt", ADRuns.getRun(ps4, prunA.id).wagons.trac, nil)
-- oprydning: traktorer der ikke findes længere (solgt) fjernes fra deres flow — men ikke hvis ALLE mangler
do
local st, r1 = ADRuns.createRun(ADRuns.newStore(), "A", "supply")
st = ADRuns.assignVehicle(st, r1.id, "keep")
st = ADRuns.assignVehicle(st, r1.id, "gone")
local exists = function(id) return id == "keep" end
local pruned, removed = ADRuns.pruneMissingVehicles(st, exists)
check("prune: fjernet", #removed, 1)
check("prune: den rigtige", removed[1].vehicleId, "gone")
check("prune: flowets navn med", removed[1].runName, "A")
check("prune: tilbage", #ADRuns.getRun(pruned, r1.id).vehicleIds, 1)
check("prune: original urørt", #ADRuns.getRun(st, r1.id).vehicleIds, 2)
local _, none = ADRuns.pruneMissingVehicles(st, function() return false end)
check("prune: alle mangler -> intet fjernes", #none, 0)
end
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1)