fix(kæde): kæden tager aldrig spillerens traktorer, respekterer slukkede produktioner og handler ikke på delvise data

This commit is contained in:
2026-09-30 13:52:15 +02:00
parent 32f2886a55
commit b389fa3564
3 changed files with 107 additions and 28 deletions
+13 -5
View File
@@ -30,6 +30,13 @@ function ADChainData.warnOnce(key, fmt, ...)
if Logging ~= nil and Logging.warning ~= nil then Logging.warning(ADChainData.LOG_PREFIX .. fmt, ...) end
end
-- En læsefejl i dette kald: data.partial = true (også når advarslen allerede er logget), så kæden ikke
-- slukker eller stopper noget på et ufuldstændigt billede af gården.
local function failed(data, key, fmt, ...)
data.partial = true
ADChainData.warnOnce(key, fmt, ...)
end
-- ---- hjælpere ----
-- Navn for et fillType-indeks; husker indeks og titel til GUI og vognvalg.
@@ -128,7 +135,7 @@ local function readPlaceables(data, farmId, byChain, nameOf)
end)
if not ok then
local key = tostring(placeable ~= nil and placeable.uniqueId or index)
ADChainData.warnOnce("placeable:" .. key, "bygning %s kunne ikke læses: %s", key, tostring(err))
failed(data, "placeable:" .. key, "bygning %s kunne ikke læses: %s", key, tostring(err))
end
end
table.sort(data.recipes, function(a, b) return a.key < b.key end)
@@ -147,7 +154,7 @@ local function readCrops(data, nameOf)
local quote = fruit.fillType.index ~= nil and ADSources.getMarketQuote(fruit.fillType.index) or nil
data.prices[fruit.name] = quote ~= nil and quote.price or 0
end)
if not ok then ADChainData.warnOnce("fruit:" .. tostring(fruit.name), "afgrøde %s kunne ikke læses: %s", tostring(fruit.name), tostring(err)) end
if not ok then failed(data, "fruit:" .. tostring(fruit.name), "afgrøde %s kunne ikke læses: %s", tostring(fruit.name), tostring(err)) end
end
end
end
@@ -159,7 +166,7 @@ local function readStock(data, adEnv, farmId, nameOf)
if fruit ~= nil then data.stock[fruit] = (data.stock[fruit] or 0) + liters end
end
end)
if not ok then ADChainData.warnOnce("stock", "lager kunne ikke læses: %s", tostring(err)) end
if not ok then failed(data, "stock", "lager kunne ikke læses: %s", tostring(err)) end
end
-- Afgrøder gården selv bruger: input i en tændt produktion eller foder/halm i en stald.
@@ -177,7 +184,7 @@ local function readUsedFruits(data, adEnv, farmId, nameOf)
if fruit ~= nil and (rate.consumption or 0) > 0 then data.usedFruits[fruit] = true end
end
end)
if not ok then ADChainData.warnOnce("rates", "staldforbrug kunne ikke læses: %s", tostring(err)) end
if not ok then failed(data, "rates", "staldforbrug kunne ikke læses: %s", tostring(err)) end
end
local function readFields(data)
@@ -193,7 +200,7 @@ local function readFields(data)
if ok then
table.insert(data.fields, entry)
else
ADChainData.warnOnce("field:" .. tostring(info.id), "mark %s kunne ikke læses: %s", tostring(info.id), tostring(entry))
failed(data, "field:" .. tostring(info.id), "mark %s kunne ikke læses: %s", tostring(info.id), tostring(entry))
end
end
end
@@ -201,6 +208,7 @@ end
-- ---- samlet ----
-- byChain = {[recipeKey] = true} for produktioner kæden selv har tændt (ikke rødder).
-- data.partial = true når noget ikke kunne læses i dette kald.
function ADChainData.collect(adEnv, farmId, byChain)
local data = {recipes = {}, husbandry = {}, crops = {}, stock = {}, fields = {}, yields = {}, prices = {},
usedFruits = {}, points = {}, fillTitles = {}, fillIndex = {}}