Notice something wrong, missing, or inadequate? Feel free to edit pages yourself and make use of discussion pages.
Wiki content is created, maintained, and administrated by players. Learn how you can help!
Wiki content is created, maintained, and administrated by players. Learn how you can help!
Module:ItemstatsCheckbox: Difference between revisions
From Dalaya Wiki
Jump to navigationJump to search
(Itemstats checkbox Phase 1 Task 6: Lua bridge) |
m (Phase 2 Task 1: generic core= + flag=) |
||
| Line 1: | Line 1: | ||
-- Itemstats checkbox->numbered bridge. | -- Itemstats checkbox->numbered bridge. Reconstructs class/race/slot numbered params | ||
-- | -- from checkboxes and expands a verbatim core template (default Itemstats/core2). | ||
-- | -- Reused by the main template AND every view surrogate via |core=. | ||
local p = {} | local p = {} | ||
local CLASSES = {"WAR","CLR","PAL","RNG","SHD","DRU","MNK","BRD","ROG","SHM","NEC","WIZ","MAG","ENC","BST"} | local CLASSES = {"WAR","CLR","PAL","RNG","SHD","DRU","MNK","BRD","ROG","SHM","NEC","WIZ","MAG","ENC","BST"} | ||
| Line 9: | Line 9: | ||
local function set(v) return v ~= nil and v ~= "" end | local function set(v) return v ~= nil and v ~= "" end | ||
local function build(a, list, maxn, prefix, allkey, out) | local function build(a, list, maxn, prefix, allkey, out) | ||
local anybool = allkey ~= nil and set(a[allkey]) or false | local anybool = allkey ~= nil and set(a[allkey]) or false | ||
| Line 28: | Line 25: | ||
function p.render(frame) | function p.render(frame) | ||
local core = frame.args.core or "Itemstats/core2" | |||
local a = frame:getParent().args | local a = frame:getParent().args | ||
local out = {} | local out = {} | ||
| Line 41: | Line 39: | ||
build(a, RACES, 15, "race", "AllRaces", out) | build(a, RACES, 15, "race", "AllRaces", out) | ||
build(a, SLOTS, 18, "slot", nil, out) | build(a, SLOTS, 18, "slot", nil, out) | ||
local res = frame:expandTemplate{ title = | local res = frame:expandTemplate{ title = core, args = out } | ||
if a["class1"] ~= nil or a["race1"] ~= nil or a["slot1"] ~= nil then | -- self-flag legacy (numbered) ITEM pages only (main template passes flag=1; surrogates do not) | ||
if frame.args.flag and (a["class1"] ~= nil or a["race1"] ~= nil or a["slot1"] ~= nil) then | |||
res = res .. "[[Category:Items pending checkbox conversion]]" | res = res .. "[[Category:Items pending checkbox conversion]]" | ||
end | end | ||
Revision as of 19:19, 5 July 2026
Documentation for this module may be created at Module:ItemstatsCheckbox/doc
-- Itemstats checkbox->numbered bridge. Reconstructs class/race/slot numbered params
-- from checkboxes and expands a verbatim core template (default Itemstats/core2).
-- Reused by the main template AND every view surrogate via |core=.
local p = {}
local CLASSES = {"WAR","CLR","PAL","RNG","SHD","DRU","MNK","BRD","ROG","SHM","NEC","WIZ","MAG","ENC","BST"}
local RACES = {"HUM","BAR","ERU","ELF","HIE","DEF","HFL","DWF","TRL","OGR","HEF","GNM","IKS","VAH","FRG"}
local SLOTS = {"Primary","Secondary","Range","Ammo","Head","Face","Ear","Neck","Shoulders","Back","Arms","Wrist","Hands","Fingers","Chest","Waist","Legs","Feet","Charm"}
local function set(v) return v ~= nil and v ~= "" end
local function build(a, list, maxn, prefix, allkey, out)
local anybool = allkey ~= nil and set(a[allkey]) or false
for _, n in ipairs(list) do if set(a[n]) then anybool = true end end
if anybool then
if allkey ~= nil and set(a[allkey]) then
for i, n in ipairs(list) do out[prefix .. i] = n end
else
local k = 0
for _, n in ipairs(list) do if set(a[n]) then k = k + 1; out[prefix .. k] = n end end
end
else
for i = 1, maxn do if a[prefix .. i] ~= nil then out[prefix .. i] = a[prefix .. i] end end
end
end
function p.render(frame)
local core = frame.args.core or "Itemstats/core2"
local a = frame:getParent().args
local out = {}
local skip = {}
for i = 1, 15 do skip["class" .. i] = true; skip["race" .. i] = true end
for i = 1, 18 do skip["slot" .. i] = true end
local bool = { AllClasses = true, AllRaces = true }
for _, t in ipairs({ CLASSES, RACES, SLOTS }) do for _, n in ipairs(t) do bool[n] = true end end
for k, v in pairs(a) do
if not skip[k] and not bool[k] then out[k] = v end
end
build(a, CLASSES, 15, "class", "AllClasses", out)
build(a, RACES, 15, "race", "AllRaces", out)
build(a, SLOTS, 18, "slot", nil, out)
local res = frame:expandTemplate{ title = core, args = out }
-- self-flag legacy (numbered) ITEM pages only (main template passes flag=1; surrogates do not)
if frame.args.flag and (a["class1"] ~= nil or a["race1"] ~= nil or a["slot1"] ~= nil) then
res = res .. "[[Category:Items pending checkbox conversion]]"
end
return res
end
return p