7,038
edits
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
function p.main(frame) | function p.main(frame) | ||
local args = p.getArgs(frame) | local args = p.getArgs(frame) | ||
local title = mw.title.new(args | local title = mw.title.new(args[1]) | ||
local text = title:getContent() | local text = title:getContent() | ||
local games = p.extractGames(text) | local games = p.extractGames(text) | ||
return | local text = {} | ||
local games2 = { "iii", "vc", "sa", "iv" } | |||
for i,game in ipairs(games2) do | |||
if p.inArray(games, game) then | |||
table.insert(text, "{{icon-"..game.."}}") | |||
else | |||
table.insert(text, "{{icon-placeholder}}") | |||
end | |||
end | |||
return table.concat(text, " ") | |||
end | end | ||
| Line 21: | Line 30: | ||
function p.extractGames(text) | function p.extractGames(text) | ||
local games = text:match("|%s*games%s*=%s*([^|]+)") | local games = text:match("|%s*games%s*=%s*([^|]+)") | ||
if games then | if not games then | ||
games = games:match("^%s*(.-)%s*$") -- trim | return nil | ||
end | |||
games = games:match("^%s*(.-)%s*$") -- trim | |||
local result = {} | |||
for game in games:gmatch("%S+") do | |||
table.insert(result, game) | |||
end | |||
return result | |||
end | |||
function p.inArray(array, value) | |||
for i,v in ipairs(array) do | |||
if v == value then | |||
return true | |||
end | |||
end | end | ||
return | return false | ||
end | end | ||
return p | return p | ||
edits