Module:System Data

-- -- Module for object and turf related system data for quick reference systems. --

local util = require('Module:Util') local p = {} local getArgs = require('Module:Arguments').getArgs

-- -- Utility / Helper functions --

local h = {}

-- Validate single value properties and set them

h.validate = {}

function h.validate.not_nil (args) return function (arg) if g_args[arg] == nil then error(string.format('%s must not be nil', arg)) end end end

function h.validate.number (args) return function (arg) g_args[arg] = util.cast.number(g_args[arg], args) return g_args[arg] end end

function h.handle_mapped_property_args (map) local properties = {} for _, data in ipairs(map) do       if data.func ~= nil then data.func(data.name) end if data.property ~= nil then properties[data.property] = g_args[data.name] end end g_frame:callParserFunction('#set:', properties) end

function h.create_header(row) local stat = mw.html.create('span') local text, nsub = mw.ustring.gsub(row['Has stat text'], '%d+', '?') stat :attr('class', 'system-table-header-stat') :wikitext(text) :done local mgroup = mw.html.create('span') mgroup :attr('class', 'system-table-header-systemgroup') :wikitext(row['Has mod group']) :done local tbl = mw.html.create('table') tbl :attr('class', 'wikitable mw-collapsible mw-collapsed system-table') :tag('tr') :tag('th') :attr('class', 'system-table-header') :attr('colspan', g_args.colspan) :tag('span') :attr('class', 'system-table-header-container') :wikitext(tostring(stat) .. tostring(mgroup)) :done :done return tbl end

function h.format_system(tbl, row, tags) local tr = tbl:tag('tr') tr       :tag('td') :wikitext(string.format('%s', row[1], row['Has name'])) :attr('class', 'system-table-cell-name') :done :tag('td') :wikitext(row['Has level requirement']) :attr('class', 'system-table-cell-level') :done :tag('td') :wikitext(row['Has stat text']) :attr('class', 'system-table-cell-stat') :done end

-- -- Templates --

-- -- Template: Data --

function p.data(frame) -- Get args g_args = getArgs(frame, {       parentFirst = true    }) g_frame = util.misc.get_frame(frame) --   -- Validation & semantic properties --   -- Validate single value properties and set them local map = { {           name = 'name', property = 'Has name', wikitext = 'Name', },       {            name = 'path', property = 'Has path', wikitext = 'Path', },       {            name = 'description', property = 'Has description', wikitext = 'Desc', },       {            name = 'description_fluff', property = 'Has fluff text', wikitext = 'Desc_fluff', },       {            name = 'description_antag', property = 'Has antag text', wikitext = 'Desc_antag', },   }    --    -- Display for stats --   local container = mw.html.create('div') container :attr('class', 'modbox') -- core stats local tbl = container:tag('table') tbl :attr('class', 'wikitable') for _, data in ipairs(map) do       local text if data.display == nil then text = g_args[data.name] else text = data.display(g_args[data.name]) end tbl :tag('tr') :tag('th') :wikitext(string.format('%s', data.property, data.wikitext)) :done :tag('td') :wikitext(text) :done :done :done end tbl :tag('tr') :tag('th') :wikitext('Tags') :done :done :done -- stat table tbl = container:tag('table') tbl :attr('class', 'wikitable sortable') :tag('tr') :tag('th') :attr('colspan', 4) :wikitext('Resistances') :done :done :tag('tr') :tag('th') :wikitext('Type') :done :tag('th') :wikitext('Resistance value') :done :done :done for i=1, 5 do       local value = { id = g_args['stat' .. i .. '_id'], min = g_args['stat' .. i .. '_min'], max = g_args['stat' .. i .. '_max'], }       if value.id then tbl :tag('tr') :tag('td') :wikitext(i) :done :tag('td') :wikitext(value.id) :done :tag('td') :wikitext(value.min) :done :tag('td') :wikitext(value.max) :done :done :done end end -- Categories cats = {'Objects'} -- Done -> output return tostring(container) .. util.misc.add_category(cats) .. '\n' end

return p