More actions
Created page with "local p = {} local function getImage(frame, baseName) local png = 'File:' .. baseName .. '.png' local gif = 'File:' .. baseName .. '.gif' local existsPng = frame:preprocess('{{#ifexist:' .. png .. '|yes|no}}') if existsPng == 'yes' then return png end local existsGif = frame:preprocess('{{#ifexist:' .. gif .. '|yes|no}}') if existsGif == 'yes' then return gif end return nil end function p.main(frame) local args = frame:getParent().args local title = mw.titl..." Â |
No edit summary  |
||
(5 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
local questbook = args.questbook or 'Unknown' | local questbook = args.questbook or 'Unknown' | ||
local version = args.version or 'Unknown' | local version = args.version or 'Unknown' | ||
-- Extract crafting table arguments | |||
local craftArgs = {} | |||
local hasInput = false | |||
local hasOutput = args.Output and args.Output ~= '' | |||
for k, v in pairs(args) do | |||
if type(k) == "string" and mw.ustring.match(k, '^[ABC][123]$') and v and v ~= '' then | |||
craftArgs[k] = v | |||
hasInput = true | |||
end | |||
end | |||
if hasOutput then | |||
craftArgs["Output"] = args.Output | |||
end | |||
local html = mw.html.create('table') | local html = mw.html.create('table') | ||
Line 28: | Line 44: | ||
:addClass('infobox') | :addClass('infobox') | ||
:addClass('infobox-workstation') | :addClass('infobox-workstation') | ||
    :addClass('floatright') | |||
    :css('width', '300px') | |||
:tag('tr') | :tag('tr') | ||
:tag('th') | :tag('th') | ||
:attr('colspan', '2') | :attr('colspan', '2') | ||
: | :addClass('infobox-header') | ||
:wikitext(name) | :wikitext(name) | ||
:done() | :done() | ||
:done() | :done() | ||
-- Main block image | |||
html | |||
:tag('tr') | :tag('tr') | ||
:tag('td') | :tag('td') | ||
Line 43: | Line 63: | ||
:done() | :done() | ||
:done() | :done() | ||
-- Inventory slot under image | |||
html | |||
:tag('tr') | :tag('tr') | ||
:tag('td'): | :tag('td') | ||
:attr('colspan', '2') | |||
:css('text-align', 'center') | |||
:wikitext(frame:expandTemplate{title = 'Inventory slot', args = {title}}) | |||
:done() | |||
:done() | :done() | ||
-- Crafting recipe header and grid | |||
if hasInput and hasOutput then | |||
html | |||
:tag('tr') | |||
:tag('td') | |||
:attr('colspan', '2') | |||
          :addClass('crafting-caption') | |||
:wikitext('Crafting Recipe') | |||
:done() | |||
:done() | |||
:tag('tr') | |||
:tag('td') | |||
:attr('colspan', '2') | |||
:css('text-align', 'center') | |||
:wikitext(frame:expandTemplate{title = 'Crafting table', args = craftArgs}) | |||
:done() | |||
:done() | |||
end | |||
-- Quest book and version | |||
html | |||
:tag('tr') | :tag('tr') | ||
:tag('td'):wikitext('Quest Book'):done() | :tag('td'):wikitext('Quest Book'):done() |
Latest revision as of 05:10, 7 July 2025
Documentation for this module may be created at Module:InfoboxWorkstation/doc
local p = {}
local function getImage(frame, baseName)
local png = 'File:' .. baseName .. '.png'
local gif = 'File:' .. baseName .. '.gif'
local existsPng = frame:preprocess('{{#ifexist:' .. png .. '|yes|no}}')
if existsPng == 'yes' then return png end
local existsGif = frame:preprocess('{{#ifexist:' .. gif .. '|yes|no}}')
if existsGif == 'yes' then return gif end
return nil
end
function p.main(frame)
local args = frame:getParent().args
local title = mw.title.getCurrentTitle().text
local name = args.name or title
local baseImageName = args.image or ('Invicon_' .. title)
local imageFile = getImage(frame, baseImageName)
local questbook = args.questbook or 'Unknown'
local version = args.version or 'Unknown'
-- Extract crafting table arguments
local craftArgs = {}
local hasInput = false
local hasOutput = args.Output and args.Output ~= ''
for k, v in pairs(args) do
if type(k) == "string" and mw.ustring.match(k, '^[ABC][123]$') and v and v ~= '' then
craftArgs[k] = v
hasInput = true
end
end
if hasOutput then
craftArgs["Output"] = args.Output
end
local html = mw.html.create('table')
html
:addClass('infobox')
:addClass('infobox-workstation')
:addClass('floatright')
:css('width', '300px')
:tag('tr')
:tag('th')
:attr('colspan', '2')
:addClass('infobox-header')
:wikitext(name)
:done()
:done()
-- Main block image
html
:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:wikitext(imageFile and ('[[' .. imageFile .. '|center|frameless|128px]]') or 'No image available')
:done()
:done()
-- Inventory slot under image
html
:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:wikitext(frame:expandTemplate{title = 'Inventory slot', args = {title}})
:done()
:done()
-- Crafting recipe header and grid
if hasInput and hasOutput then
html
:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('crafting-caption')
:wikitext('Crafting Recipe')
:done()
:done()
:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:wikitext(frame:expandTemplate{title = 'Crafting table', args = craftArgs})
:done()
:done()
end
-- Quest book and version
html
:tag('tr')
:tag('td'):wikitext('Quest Book'):done()
:tag('td'):wikitext(questbook):done()
:done()
:tag('tr')
:tag('td'):wikitext('Added in'):done()
:tag('td'):wikitext(version):done()
:done()
return tostring(html)
end
return p