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
+41 -1
View File
@@ -29,11 +29,51 @@ local function findsTransition(data, fromState, toState, depth)
return false
end
-- Periodenavne i afgrødens <growth><seasonal> (FS25: periode 1 = EARLY_SPRING)
ADMonthView.PERIOD_NAMES = {EARLY_SPRING = 1, MID_SPRING = 2, LATE_SPRING = 3, EARLY_SUMMER = 4, MID_SUMMER = 5,
LATE_SUMMER = 6, EARLY_AUTUMN = 7, MID_AUTUMN = 8, LATE_AUTUMN = 9, EARLY_WINTER = 10, MID_WINTER = 11,
LATE_WINTER = 12}
-- Stadienavn/-tal fra XML -> growthState (nameToGrowthState har store bogstaver). nil = ukendt.
local function stateIndex(fruit, value)
if value == nil then return nil end
local number = tonumber(value)
if number ~= nil then return number end
local names = fruit.nameToGrowthState
return type(names) == "table" and names[string.upper(tostring(value))] or nil
end
-- Overgange pr. periode læst fra afgrødens XML: {[periode] = {{from, to}, ...}}.
-- readPeriods(xmlFilename) -> liste af {name = "LATE_AUTUMN", updates = {{startState, endState}, ...}} eller nil.
function ADMonthView.xmlTransitions(fruit, readPeriods)
if fruit == nil or readPeriods == nil or fruit.xmlFilename == nil then return nil end
local list = readPeriods(fruit.xmlFilename)
if type(list) ~= "table" then return nil end
local result = {}
for _, period in ipairs(list) do
local index = ADMonthView.PERIOD_NAMES[string.upper(tostring(period.name or ""))]
if index ~= nil then
local transitions = result[index] or {} -- samme periode to gange: overgangene lægges sammen
for _, update in ipairs(period.updates or {}) do
local from, to = stateIndex(fruit, update.startState), stateIndex(fruit, update.endState)
if from ~= nil and to ~= nil then table.insert(transitions, {from = from, to = to}) end
end
result[index] = transitions
end
end
return result
end
-- Visner afgrøden (stadie state) ved overgangen til periode nextPeriod?
function ADMonthView.withersIn(fruit, nextPeriod, state)
-- transitions = ADMonthView.xmlTransitions(...) (valgfri): growthDataSeasonal gemmer ikke overgangene i en
-- form vi kan finde (in-game 16/10: bomuld 35 % høstet i oktober viste "ok", visner i LATE_AUTUMN).
function ADMonthView.withersIn(fruit, nextPeriod, state, transitions)
if fruit == nil or type(state) ~= "number" or state <= 0 then return false end
local withered = fruit.witheredState
if type(withered) ~= "number" or withered <= 0 then return false end
for _, transition in ipairs(transitions ~= nil and transitions[nextPeriod] or {}) do
if transition.from == state and transition.to == withered then return true end
end
local periods = fruit.growthDataSeasonal ~= nil and fruit.growthDataSeasonal.periods or nil
local data = periods ~= nil and periods[nextPeriod] or nil
return findsTransition(data, state, withered, 0)