Module:Sandbox/LVL: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 3: Line 3:
local util_module = require "Module:Utilities"
local util_module = require "Module:Utilities"
local data = mw.loadJsonData("Data:Monster_Domosed/ItemData.json")
local data = mw.loadJsonData("Data:Monster_Domosed/ItemData.json")
local function get_component_of_sorted(item_input)
    -- Find the item's key
    local target_key = nil
    if data[item_input] then
        target_key = item_input
    else
        for k, v in pairs(data) do
            if v.Name == item_input and (v.IsDisabled == false or v.IsDisabled == nil) then
                target_key = k; break
            end
        end
    end
    if not target_key then return {} end
    -- Find all items that have this item as a component
    local parents = {}
    for key, item in pairs(data) do
        if item.IsDisabled ~= true and item.Components and type(item.Components) == "table" then
            for _, comp in ipairs(item.Components) do
                if comp == target_key then
                    table.insert(parents, key)
                    break
                end
            end
        end
    end
    -- Sort by Tier instead of alphabetically
    table.sort(parents, function(a, b)
        local tier_a = tonumber(data[a] and data[a]["Tier"]) or 0
        local tier_b = tonumber(data[b] and data[b]["Tier"]) or 0
        return tier_a < tier_b
    end)
    return parents
end


-- Get raw value, CSS class, and LocTokenOverride for a property
-- Get raw value, CSS class, and LocTokenOverride for a property
Line 507: Line 544:
     -- Is Component Of
     -- Is Component Of
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     for i = 1, 3 do
    local parents = get_component_of_sorted(item_name)
         local parent = ItemData.get_builds_into_name {
     for i, key in ipairs(parents) do
            args = { item_name, i }
         local parent_name = data[key] and data[key]["Name"] or ""
        }
         if parent_name ~= "" then
         if parent and parent ~= "" then
             table.insert(lines, string.format("| iscomponentof%d_name = %s", i, parent_name))
             table.insert(lines, string.format("| iscomponentof%d_name = %s", i, parent))
         end
         end
     end
     end