Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ function Task:readStream(streamId, connection)
self.shouldRecur = streamReadBool(streamId)
self.recurMode = streamReadInt32(streamId)
self.nextN = streamReadInt32(streamId)
if self.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS and self.nextN ~= 0 then
self.nextN = TaskListUtils.normalizePeriod(self.nextN)
end
self.n = streamReadInt32(streamId)
self.effort = streamReadInt32(streamId)
self.type = streamReadInt32(streamId)
Expand Down Expand Up @@ -265,6 +268,9 @@ function Task:loadFromXMLFile(xmlFile, key)
self.shouldRecur = getXMLBool(xmlFile, key .. "#shouldRecur")
self.nextN = getXMLInt(xmlFile, key .. "#nextN")
self.n = getXMLInt(xmlFile, key .. "#n")
if self.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS and self.nextN ~= 0 then
self.nextN = TaskListUtils.normalizePeriod(self.nextN)
end
self.effort = getXMLInt(xmlFile, key .. "#effort") or 1
self.type = getXMLInt(xmlFile, key .. "#type") or Task.TASK_TYPE.Standard
self.husbandryFood = getXMLString(xmlFile, key .. "#husbandryFood") or ""
Expand Down
15 changes: 15 additions & 0 deletions TaskListUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ function TaskListUtils.convertPeriodToMonthNumber(period)
return period
end

--- Folds a game period or month slot into 1..12 (e.g. after adding N-month intervals, including N > 12).
function TaskListUtils.normalizePeriod(period)
if period == nil then
return 1
end
local p = math.floor(tonumber(period) or 1)
while p > 12 do
p = p - 12
end
while p < 1 do
p = p + 12
end
return p
end

function TaskListUtils.formatPeriodFullMonthName(period)
if period == 1 then
return g_i18n:getText("ui_month3")
Expand Down
Loading