Skip to content

Commit

Permalink
Use new opponent array
Browse files Browse the repository at this point in the history
  • Loading branch information
mbergen committed Sep 17, 2024
1 parent 1d04f7d commit b91df07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
14 changes: 5 additions & 9 deletions components/match2/wikis/ageofempires/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

local MatchLegacy = {}

local Array = require('Module:Array')
local Json = require('Module:Json')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
Expand All @@ -31,6 +32,7 @@ function MatchLegacy.storeGames(match, match2)
for gameIndex, game2 in ipairs(match2.match2games or {}) do
local game = Table.deepCopy(game2)
local participants = Json.parseIfString(game2.participants) or {}
local opponents = Json.parseIfString(game2.opponents) or {}

-- Extradata
game.extradata = {}
Expand All @@ -39,21 +41,15 @@ function MatchLegacy.storeGames(match, match2)
game.extradata.tournament = match.tournament
game.extradata.vodmatch = match.vod
if game.mode == 'team' then
local function processOpponent(opponentIndex)
local oppKey = opponentIndex .. '_'
Table.iter.forEachPair(participants, function (participantId, player)
if not String.startsWith(participantId, oppKey) then
return
end
Array.forEach(opponents, function(opponent, opponentIndex)
Array.forEach(opponent.players, function(player)
local prefix = 'o' .. opponentIndex .. 'p' .. player.index
game.extradata[prefix] = player.pageName
game.extradata[prefix .. 'faction'] = player.civ
game.extradata[prefix .. 'name'] = player.displayname
game.extradata[prefix .. 'flag'] = player.flag
end)
end
processOpponent(1)
processOpponent(2)
end)
elseif game.mode == '1v1' then
local player1 = participants['1_1'] or {}
local player2 = participants['2_1'] or {}
Expand Down
21 changes: 9 additions & 12 deletions components/match2/wikis/ageofempires/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Game = require('Module:Game')
local MapMode = require('Module:MapMode')
local Faction = require('Module:Faction')
local Game = require('Module:Game')
local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MapMode = require('Module:MapMode')
local Operator = require('Module:Operator')
local String = require('Module:StringUtils')
local Table = require('Module:Table')

Expand Down Expand Up @@ -161,8 +162,7 @@ function CustomMatchSummary._createGame(row, game, props)
faction1 = CustomMatchSummary._createFactionIcon(CustomMatchSummary._getPlayerData(game, '1_1').civ, normGame)
faction2 = CustomMatchSummary._createFactionIcon(CustomMatchSummary._getPlayerData(game, '2_1').civ, normGame)
else
local function createParticipant(participantId, flipped)
local player = CustomMatchSummary._getPlayerData(game, participantId)
local function createParticipant(player, flipped)
local playerNode = PlayerDisplay.BlockPlayer{player = player, flip = flipped}
local factionNode = CustomMatchSummary._createFactionIcon(player.civ, normGame)
return mw.html.create('div'):css('display', 'flex'):css('align-self', flipped and 'end' or 'start')
Expand All @@ -172,15 +172,12 @@ function CustomMatchSummary._createGame(row, game, props)
end
local function createOpponentDisplay(opponentId)
local display = mw.html.create('div'):css('display', 'flex'):css('flex-direction', 'column'):css('width', '35%')
local oppKey = opponentId .. '_'
for participantId, _ in Table.iter.spairs(
game.participants,
function(tbl, a, b) return tbl[a].index < tbl[b].index end
) do
if String.startsWith(participantId, oppKey) then
display:node(createParticipant(participantId, opponentId == 1))
Array.forEach(
Array.sortBy(game.opponents[opponentId], Operator.property('index')),
function(player)
display:node(createParticipant(player, opponentId == 1))
end
end
)
return display
end

Expand Down

0 comments on commit b91df07

Please sign in to comment.