Editing Module:Sandbox/Vergir

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
-- Audit: for every item stat that goes through Infobox item's append_label
-- with attribute styling enabled (Passive/Active Main stats), compute the
-- label link target under the CURRENT priority (attr link > StatLinks)
-- and the PROPOSED priority (StatLinks > attr link) and list the results.
local p = {}
local p = {}
local lang = require "Module:Lang"
local data = mw.loadJsonData("Data:ItemCards.json")
local stat_links = mw.loadJsonData("Data:StatLinks.json")
local ATTR = require("Module:Icon/attr")
local LABEL_KEY_REMAP = { DotDuration = "DOTDuration" }
local IGNORED = { BuildUpPerShot = true }
local function get_pair(base, s1, s2)
    local v = lang.get_string(base .. s1)
    if v and v ~= "" then return v end
    v = lang.get_string(base .. s2)
    if v and v ~= "" then return v end
    return ""
end
local function resolve_label_key(prop_key, loc_override)
    local base = (loc_override or prop_key):gsub("^#", "")
    return LABEL_KEY_REMAP[base] or base
end
local function esc(s)
    if s == nil or s == "" then return "''(none)''" end
    return "<nowiki>" .. tostring(s) .. "</nowiki>"
end
function p.audit(frame)
    local mode = frame.args[1] or "diff" -- "diff" | "all"
    local rows = {}
    local names = {}
    for key, item in pairs(data) do
        if not item.IsDisabled then
            table.insert(names, key)
        end
    end
    table.sort(names, function(a, b)
        return (data[a].Name or a) < (data[b].Name or b)
    end)
    local n_items, n_stats, n_diff = 0, 0, 0
    for _, key in ipairs(names) do
        local item = data[key]
        n_items = n_items + 1
        local i = 1
        while item["Info" .. i] do
            local sec = item["Info" .. i]
            if sec.Type ~= "Innate" then
                local seen = {}
                for _, obj in ipairs(sec.Main or {}) do
                    local pk = obj.Key
                    if not seen[pk] and not IGNORED[pk] and not pk:match("^StatusEffect") then
                        seen[pk] = true
                        local label_key = resolve_label_key(pk, obj.LocTokenOverride)
                        local label = get_pair(label_key, "_label", "_Label")
                        if label ~= "" then
                            n_stats = n_stats + 1
                            local attr = obj.Type and ATTR[obj.Type] or nil
                            local attr_link = attr and attr.link or nil
                            if attr_link == "" then attr_link = nil end
                            local sl = stat_links[label_key]
                            if sl == "" then sl = nil end
                            local cur = attr_link or sl
                            local new = sl or attr_link
                            local differs = (cur or "") ~= (new or "")
                            if differs then n_diff = n_diff + 1 end
                            if mode == "all" or differs then
                                table.insert(rows, string.format(
                                    "|-%s\n| [[%s]] || %s || %s || <nowiki>%s</nowiki> || %s || %s || %s",
                                    differs and ' style="background:#4a3a1a"' or "",
                                    item.Name or key, sec.Type, esc(label_key), tostring(obj.Type),
                                    esc(label), esc(cur), esc(new)))
                            end
                        end
                    end
                end
            end
            i = i + 1
        end
    end
    local out = {}
    table.insert(out, string.format("Items scanned: %d. Passive/Active main stats with a label: %d. Rows whose link changes: %d.\n",
        n_items, n_stats, n_diff))
    table.insert(out, '{| class="wikitable sortable"\n! Item !! Section !! Stat key !! Type !! Label !! Current link !! Proposed link')
    for _, r in ipairs(rows) do table.insert(out, r) end
    table.insert(out, "|}")
    return table.concat(out, "\n")
end
return p
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: