Module:CollectionLog: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
function p.render(frame) | function p.render(frame) | ||
local args = frame:getParent() | local args = frame:getParent():getArguments() | ||
local html = mw.html.create('div'):addClass('collection-log-wrapper') | local html = mw.html.create('div'):addClass('collection-log-wrapper') | ||
-- | -- Look for Killcount first (optional) | ||
local killcount | |||
for _, arg in ipairs(args) do | |||
if arg.name == "Killcount" then | |||
killcount = arg.value | |||
break | |||
end | |||
end | |||
if killcount then | |||
local killcountDiv = mw.html.create('div') | local killcountDiv = mw.html.create('div') | ||
:addClass('collection-log-killcount') | :addClass('collection-log-killcount') | ||
:wikitext('Killcount: ' .. | :wikitext('Killcount: ' .. killcount) | ||
html:node(killcountDiv) | html:node(killcountDiv) | ||
end | end | ||
local grid = mw.html.create('div'):addClass('collection-log-grid') | local grid = mw.html.create('div'):addClass('collection-log-grid') | ||
for | for _, arg in ipairs(args) do | ||
local name = arg.name | |||
if name ~= "Killcount" then | if name ~= "Killcount" then | ||
qty = tonumber( | local qty = tonumber(arg.value) or 0 | ||
local item = mw.html.create('div') | local item = mw.html.create('div') | ||
:addClass('collection-log-item') | :addClass('collection-log-item') | ||
:addClass(qty > 0 and 'obtained' or 'missing') | :addClass(qty > 0 and 'obtained' or 'missing') | ||
-- Call your custom template, for example plinkp3 | |||
item:wikitext(string.format( | item:wikitext(string.format( | ||
' | '{{plinkp3|name=%s|qty=%d|obtained=%s}}', | ||
name, | name, qty, qty > 0 and 'obtained' or 'missing' | ||
)) | )) | ||
grid:node(item) | grid:node(item) |
Revision as of 06:47, 19 May 2025
Documentation for this module may be created at Module:CollectionLog/doc
local p = {}
function p.render(frame)
local args = frame:getParent():getArguments()
local html = mw.html.create('div'):addClass('collection-log-wrapper')
-- Look for Killcount first (optional)
local killcount
for _, arg in ipairs(args) do
if arg.name == "Killcount" then
killcount = arg.value
break
end
end
if killcount then
local killcountDiv = mw.html.create('div')
:addClass('collection-log-killcount')
:wikitext('Killcount: ' .. killcount)
html:node(killcountDiv)
end
local grid = mw.html.create('div'):addClass('collection-log-grid')
for _, arg in ipairs(args) do
local name = arg.name
if name ~= "Killcount" then
local qty = tonumber(arg.value) or 0
local item = mw.html.create('div')
:addClass('collection-log-item')
:addClass(qty > 0 and 'obtained' or 'missing')
-- Call your custom template, for example plinkp3
item:wikitext(string.format(
'{{plinkp3|name=%s|qty=%d|obtained=%s}}',
name, qty, qty > 0 and 'obtained' or 'missing'
))
grid:node(item)
end
end
html:node(grid)
return tostring(html)
end
return p