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!

Module:ItemstatsCheckbox

From Dalaya Wiki
Revision as of 17:52, 5 July 2026 by DalayaRebrand (talk | contribs) (Itemstats checkbox Phase 1 Task 6: Lua bridge)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

-- Itemstats checkbox->numbered bridge. Expands Template:Itemstats/core2 (verbatim
-- copy of live Itemstats) with real numbered params, so all "was-it-passed" idioms
-- and category loops in the core work byte-identically.
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

-- Build numbered params for one group into out. If any checkbox (or the All key)
-- is set, pack checked values sequentially (All => full roster). Otherwise forward
-- the numbered params verbatim, preserving passed-vs-absent (incl. passed-empty).
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 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 = "Itemstats/core2", args = out }
  if 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