Jump to content

Module:OOOInfoBox

From Out of Ore Wiki
Revision as of 12:14, 6 October 2025 by T-Bone (talk | contribs) (Created page with "local p = {} local DOCS_TITLE = 'Data:Docs.json' -- Load the JSON docs file local function load_docs() local t = mw.title.new(DOCS_TITLE) if not t then return {} end local content = t:getContent() or '' if content == '' then return {} end local ok, data = pcall(mw.text.jsonDecode, content) return (ok and type(data) == 'table') and data or {} end local DOCS = load_docs() -- Small helper local function pick(args, data, key) local v = args[key...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:OOOInfoBox/doc

local p = {}
local DOCS_TITLE = 'Data:Docs.json'

-- Load the JSON docs file
local function load_docs()
    local t = mw.title.new(DOCS_TITLE)
    if not t then return {} end
    local content = t:getContent() or ''
    if content == '' then return {} end
    local ok, data = pcall(mw.text.jsonDecode, content)
    return (ok and type(data) == 'table') and data or {}
end

local DOCS = load_docs()

-- Small helper
local function pick(args, data, key)
    local v = args[key]
    if v and v ~= '' then return v end
    v = data[key]
    if v ~= nil and v ~= '' then return v end
end

function p.building(frame)
    local args = frame:getParent().args or {}
    local art = args.art or args.artNumber or args.id
    local data = art and DOCS[art]
    if not data then
        return '⚠️ Use |art=ART_NUMBER (e.g. 400113) and ensure Data:Docs.json has that key.'
    end

    local box = mw.html.create('table'):addClass('infobox')

    -- Title
    local title = pick(args, data, 'displayName') or ('Item ' .. art)
    box:tag('tr'):tag('th'):attr('colspan','2'):wikitext(title)

    local function row(label, key, fixed)
        local v = fixed or pick(args, data, key)
        if v ~= nil and tostring(v) ~= '' then
            local tr = box:tag('tr')
            tr:tag('th'):wikitext(label)
            tr:tag('td'):wikitext(v)
        end
    end

    row('Art Number', nil, art)
    row('Type', 'type')
    row('Throughput (m³/h)', 'throughput_m3h')
    row('Power (kW)', 'power_kw')
    row('Capacity', 'capacity')

    return tostring(box)
end

return p