fix(måned): visne-overgange læses fra afgrødens XML — høst der lukker vises (v1.62.261)

This commit is contained in:
2026-10-16 13:36:46 +02:00
parent 4618925521
commit 3581021b71
4 changed files with 75 additions and 3 deletions
+32 -1
View File
@@ -41,6 +41,35 @@ function SmartPickupFrame.monthCpProgress(fieldId)
return count > 0 and sum / count or nil
end
-- <growth><seasonal><period name><update startState endState> fra afgrødens XML (én gang pr. fil)
SmartPickupFrame.seasonalCache = {}
function SmartPickupFrame.readSeasonalPeriods(xmlFilename)
local cached = SmartPickupFrame.seasonalCache[xmlFilename]
if cached ~= nil then return cached or nil end
local periods = false
SmartPickupFrame.seasonalCache[xmlFilename] = false -- fejler indlæsningen, prøves den ikke igen
local xmlFile = XMLFile.loadIfExists("adspSeasonal", xmlFilename)
if xmlFile ~= nil then
periods = {}
xmlFile:iterate("foliageType.growth.seasonal.period", function(_, key)
local updates = {}
xmlFile:iterate(key .. ".update", function(_, updateKey)
table.insert(updates, {startState = xmlFile:getString(updateKey .. "#startState"),
endState = xmlFile:getString(updateKey .. "#endState")})
end)
table.insert(periods, {name = xmlFile:getString(key .. "#name"), updates = updates})
end)
xmlFile:delete()
end
local updates = 0
for _, entry in ipairs(periods or {}) do updates = updates + #entry.updates end
Logging.info(SmartPickupFrame.LOG_PREFIX .. "månedsfane: vækstdata '%s': %d perioder, %d overgange",
tostring(xmlFilename), periods and #periods or -1, updates)
SmartPickupFrame.seasonalCache[xmlFilename] = periods
return periods or nil
end
function SmartPickupFrame.monthContext(period)
return {
period = period,
@@ -50,7 +79,9 @@ function SmartPickupFrame.monthContext(period)
end,
withers = function(info, nextPeriod)
local fruit = info.fruitIndex ~= nil and g_fruitTypeManager:getFruitTypeByIndex(info.fruitIndex) or nil
local ok, result = pcall(ADMonthView.withersIn, fruit, nextPeriod, info.growthState)
local okXml, transitions = pcall(ADMonthView.xmlTransitions, fruit, SmartPickupFrame.readSeasonalPeriods)
local ok, result = pcall(ADMonthView.withersIn, fruit, nextPeriod, info.growthState,
okXml and transitions or nil)
return ok and result == true
end,
cpProgress = SmartPickupFrame.monthCpProgress,