Skip to content

Commit 9aae949

Browse files
refactor(standings): use existing stash/retrieve functions for legacy ffa parsing (#8182)
use existing functions
1 parent eb5457f commit 9aae949

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

  • lua/wikis/commons/Standings/Table/Legacy

‎lua/wikis/commons/Standings/Table/Legacy/Ffa.lua‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ local Lua = require('Module:Lua')
99

1010
local Arguments = Lua.import('Module:Arguments')
1111
local Array = Lua.import('Module:Array')
12-
local Json = Lua.import('Module:Json')
1312
local Table = Lua.import('Module:Table')
14-
local Variables = Lua.import('Module:Variables')
13+
local Template = Lua.import('Module:Template')
1514

1615
local StandingTable = Lua.import('Module:Standings/Table')
1716

@@ -76,46 +75,45 @@ end
7675

7776
---Template:league standings start
7877
---@param frame Frame
78+
---@return string
7979
function StandingTableLegacyFfa.slotStart(frame)
8080
local args = Arguments.getArgs(frame)
81-
Variables.varDefine('standings_legacy_start', Json.stringify(args))
82-
Variables.varDefine('standings_legacy_count', 0)
81+
args.__source = 'legacy_start'
82+
return Template.stashReturnValue(args, 'standings_legacy')
8383
end
8484

8585
---Template:league standings slot & Template:league standings slot2
8686
---@param frame Frame
87+
---@return string
8788
function StandingTableLegacyFfa.slot(frame)
8889
local args = Arguments.getArgs(frame)
89-
local cnt = (tonumber(Variables.varDefault('standings_legacy_count')) or 0) + 1
90-
Variables.varDefine('standings_legacy_slot_' .. cnt, Json.stringify(args))
91-
Variables.varDefine('standings_legacy_count', cnt)
90+
args.__source = 'legacy_slot'
91+
return Template.stashReturnValue(args, 'standings_legacy')
9292
end
9393

9494
---Template:league standings end & Template:league standings end2
9595
---@param frame Frame
9696
---@return Renderable?
9797
function StandingTableLegacyFfa.templateEnd(frame)
98-
local cnt = tonumber(Variables.varDefault('standings_legacy_count'))
99-
if not cnt then
98+
local entries = Template.retrieveReturnValues('standings_legacy')
99+
100+
if #entries == 0 then
100101
return
101102
end
102-
local startArgs = Json.parseIfString(Variables.varDefault('standings_legacy_start'))
103-
if not startArgs then
104-
return
103+
104+
local startArgs = table.remove(entries, 1)
105+
106+
if startArgs.__source ~= 'legacy_start' then
107+
mw.ext.TeamLiquidIntegration.add_category('Pages with malformed Legacy FFA standings structure')
108+
error('Invalid legacy FFA Standings setup')
105109
end
106-
Variables.varDefine('standings_legacy_start', nil)
107-
local slots = Array.mapRange(1, cnt, function(index)
108-
local data = (Json.parseIfString(Variables.varDefault('standings_legacy_slot_' .. index)))
109-
Variables.varDefine('standings_legacy_slot_' .. index, nil)
110-
return data
111-
end)
112110

113111
local rounds = Table.map(Array.range(1, tonumber(startArgs.rounds) or 1), function(roundIndex)
114112
return 'round' .. roundIndex, StandingTableLegacyFfa.parseRoundInput(startArgs, roundIndex)
115113
end)
116114

117115
---@type StandingTableOpponentData[]
118-
local opponents = Array.map(slots, function(slot)
116+
local opponents = Array.map(entries, function(slot)
119117
return StandingTableLegacyFfa.parseTeamInputManualSlots(slot)
120118
end)
121119

0 commit comments

Comments
 (0)