Skip to content

Commit

Permalink
feat(infobox_extensions): create automated game appearances for playe…
Browse files Browse the repository at this point in the history
…rs (#4178)

* feat: add GameAppearances as Extension module

* 1st attempt at fixing

this is gonna take a while to figured it out

* 2nd attempt

* 3rd

* return string

* Update infobox_extension_game_appearances.lua

* Update infobox_extension_game_appearances.lua

* With the suggested changes

I still need a way for this extension to catch Underscores vs non-Underscores cases. That would be the last thing needed before this can go merged

* Update infobox_extension_game_appearances.lua
  • Loading branch information
Hesketh2 authored Apr 22, 2024
1 parent d8a7d1b commit 1797d51
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Infobox/Extension/GameApperances
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local Game = require('Module:Game')
local Table = require('Module:Table')

local DEFAULT_MAX_NUMBER_OF_PLAYERS_IN_PLACEMENT = 10

local Appearances = {}

----Provide a list of games compete by a player
---@param args {player: string?, numberOfPlayersInPlacement}?
---@return string[]?
function Appearances.player(args)
if not args or not args.player then return end
local numberOfPlayersInPlacement = args.numberOfPlayersInPlacement or DEFAULT_MAX_NUMBER_OF_PLAYERS_IN_PLACEMENT

local player = args.player:gsub(' ', '_')
local playerWithoutUnderscores = args.player:gsub('_', ' ')

local conditions = {
'[[opponentname::' .. player .. ']]',
'[[opponentname::' .. playerWithoutUnderscores .. ']]',
}

Array.forEach(Array.range(1, numberOfPlayersInPlacement), function(index)
Array.appenWith(conditions,
'[[opponentplayers_p' .. index .. '::' .. player .. ']]',
'[[opponentplayers_p' .. index .. '::' .. playerWithoutUnderscores .. ']]'
)
end)

local queriedGames = Table.map(mw.ext.LiquipediaDB.lpdb('placement', {
conditions = table.concat(conditions, ' OR '),
query = 'game',
groupby = 'game asc',
limit = 1000,
}), function(_, item) return Game.toIdentifier{game = item.game, useDefault = false}, true end)

local orderedGames = Array.filter(Game.listGames{ordered = true}, function(game)
return queriedGames[game]
end)

return Array.map(orderedGames, function(game)
return Game.name{game = game}
end)
end

return Appearances

0 comments on commit 1797d51

Please sign in to comment.