Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
Trying to add links to pages
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 stat_links = mw.loadJsonData("Data:Sandbox.json")
local stat_links = mw.loadJsonData("Data:StatLinks.json")
 
local LANG_CODE = lang.get_lang_code()
local IS_EN = (LANG_CODE == "en")
 
local MOVE_SPEED_RATES = mw.loadJsonData("Data:LocalizedUnits.json")
 
local function has_rate_unit(str)
    if type(str) ~= "string" then return false end
    return str:find("/") ~= nil
end
 
local function get_movespeed_rate_suffix()
    return MOVE_SPEED_RATES[LANG_CODE]
end
 
local function get_missing_rate_warning()
    return '<sup style="white-space:nowrap; font-size: smaller;"><span title="Missing translated m/s. Please add an entry for this language to Data:Lang_MoveSpeedRates.json" style="color:red; cursor:help;">!?</span></sup>'
end


-- Get raw value, CSS class, and LocTokenOverride for a property
-- Get raw value, CSS class, and LocTokenOverride for a property
Line 23: Line 41:
     end
     end
end
end
-- Strip embedded unit postfix when not EN (e.g. "3.0m" -> "3.0")
local function strip_embedded_postfix(val)
    if IS_EN then return val end
    if type(val) ~= "string" then return val end
    return val:match("^%-?%d+%.?%d*") or val
end


-- Check if property exists in language data
-- Check if property exists in language data
Line 66: Line 92:


-- Enhanced stat wrapper - prefix and value get enhanced styling, postfix/label don't
-- Enhanced stat wrapper - prefix and value get enhanced styling, postfix/label don't
local function format_stat_enhanced(item_name, prop, skip_label)
local function format_stat_enhanced(item_name, prop, skip_label, allow_conditional)
skip_label = skip_label or false
skip_label = skip_label or false
if allow_conditional == nil then allow_conditional = true end
local value, css, loc_key = get_raw_value(item_name, prop)
local value, css, loc_key = get_raw_value(item_name, prop)
if value == nil or value == 0 or value == "" then
if value == nil or value == 0 or value == "" then
Line 110: Line 137:
local val_str
local val_str
local suffix = postfix
local suffix = postfix
if css == "move_speed" or css == "sprint_speed" then
 
if not postfix:find("%%") then
        -- Special spacing rule for HP/s
suffix = postfix .. "/s"
    if postfix == "HP/s" then
end
        suffix = "&#32;" .. postfix
end
    end
   
    if (css == "move_speed" or css == "sprint_speed")
    and postfix ~= "%"
    and not has_rate_unit(postfix)
    then
        local override = get_movespeed_rate_suffix()
 
        if override then
            suffix = override
        else
            suffix = "m/s"
            suffix = suffix .. get_missing_rate_warning()
        end
    end


if prefix ~= "" then
if prefix ~= "" then
Line 188: Line 229:
-- Conditional marker
-- Conditional marker
--------------------------------------------------
--------------------------------------------------
local item = get_json_item(item_name)
    if allow_conditional then
local raw_prop = item[prop]
        local item = get_json_item(item_name)
 
        local raw = item and item[prop]
if type(raw_prop) == "table"
        if type(raw) == "table"
and (raw_prop.UsageFlags == "ConditionallyApplied"
          and (raw.UsageFlags == "ConditionallyApplied"
or raw_prop.UsageFlags == "ConditionallyEnemyApplied")
            or raw.UsageFlags == "ConditionallyEnemyApplied")
then
        then
local conditional_text = lang.get_string("Citadel_Shop_ConditionalAttribute")
            val_str = val_str .. string.format(
val_str = val_str .. string.format(
                ' <span style="color:#C0C0C0">(%s)</span>',
' <span style="color:#C0C0C0">(%s)</span>',
                lang.get_string("Citadel_Shop_ConditionalAttribute")
conditional_text
            )
)
        end
end
    end


return val_str
return val_str
Line 254: Line 295:
-- Format stat value for Infobox, handling prefix/postfix, CSS, scaling, and conditional
-- Format stat value for Infobox, handling prefix/postfix, CSS, scaling, and conditional
-- allow_conditional should be true for ImportantProperties, false for regular Properties
-- allow_conditional should be true for ImportantProperties, false for regular Properties
local function format_stat(item_name, prop, skip_label, debug, allow_conditional, enhanced)
local function format_stat(item_name, prop, skip_label, debug, allow_conditional)
if allow_conditional == nil then allow_conditional = true end
    skip_label = skip_label or false
    if allow_conditional == nil then allow_conditional = true end


if prop == "AbilityCooldown" and not skip_label then
    local value, css, loc_key = get_raw_value(item_name, prop)
return nil
    if value == nil or value == 0 or value == "" then return nil end
end


local value, css, loc_key = get_raw_value(item_name, prop)
    local numeric_val = tonumber(tostring(value):match("^-?%d+%.?%d*")) or 0
if value == nil or value == 0 or value == "" then
    if numeric_val == 0 then return nil end
return nil
end


local numeric_val = tonumber(tostring(value):match("^-?%d+%.?%d*")) or 0
    local label_key = loc_key:gsub("^#", "")
if numeric_val == 0 then
    if prop == "BuildUpPerShot" then label_key = "BuildupPerShot"
return nil
    elseif prop == "DotDuration" then label_key = "DOTDuration" end
end


local label_key = loc_key:gsub("^#", "")
    local label = skip_label and "" or get_lang_with_fallback(label_key, "_label", "_Label")
    local prefix = get_lang_with_fallback(label_key, "_prefix", "_Prefix")
    local postfix = get_lang_with_fallback(label_key, "_postfix", "_Postfix")


if not (
    if prefix == "" and postfix == "" and label == "" then return nil end
lang.get_string(label_key.."_label") or
lang.get_string(label_key.."_Label") or
lang.get_string(label_key.."_prefix") or
lang.get_string(label_key.."_Prefix") or
lang.get_string(label_key.."_postfix") or
lang.get_string(label_key.."_Postfix") or
lang.get_string(label_key.."_postvalue_label") or
lang.get_string(label_key.."_Postvalue_Label")
) then
return nil
end


if prop == "BuildUpPerShot" then label_key = "BuildupPerShot"
    --------------------------------------------------
elseif prop == "DotDuration" then label_key = "DOTDuration"
    -- Prefix logic
end
    --------------------------------------------------
    if prefix == "{s:sign}" then
        if numeric_val >= 0 then
            prefix = "+"
        else
            prefix = ""
        end
    end


local label = skip_label and "" or get_lang_with_fallback(label_key, "_label", "_Label")
    --------------------------------------------------
local prefix = get_lang_with_fallback(label_key, "_prefix", "_Prefix")
    -- Postfix / move speed handling
local postfix = get_lang_with_fallback(label_key, "_postfix", "_Postfix")
    --------------------------------------------------
    local suffix = postfix
    if postfix == "HP/s" then suffix = "&#32;" .. postfix end
    if (css == "move_speed" or css == "sprint_speed") and postfix ~= "%" and not has_rate_unit(postfix) then
        local override = get_movespeed_rate_suffix()
        if override then
            suffix = override
        else
            suffix = "m/s" .. get_missing_rate_warning()
        end
    end


if prefix == "" and postfix == "" and label == "" then
    --------------------------------------------------
return nil
    -- Compose main value string
end
    --------------------------------------------------
    local val_str = tostring(numeric_val)
    if prefix ~= "" then val_str = prefix .. val_str end
    if suffix ~= "" and not val_str:find(suffix, 1, true) then val_str = val_str .. suffix end


--------------------------------------------------
    --------------------------------------------------
-- VALUE (normal or enhanced)
    -- Scale handling (Boon / Ss)
--------------------------------------------------
    --------------------------------------------------
local val_str
    local item = get_json_item(item_name)
if enhanced then
    local raw_prop = item and item[prop]
val_str = string.format(
    if type(raw_prop) == "table" and raw_prop.Scale and raw_prop.Scale.Value ~= 0 then
"{{#invoke:Enhanced|render|%s|%s}}",
        local scale_val = util_module.round_to_sig_fig(raw_prop.Scale.Value, 2)
item_name,
        local template_name = (raw_prop.Scale.Type == "power_increase") and "Boon" or "Ss"
prop
        val_str = val_str .. " " .. mw.getCurrentFrame():expandTemplate{ title = template_name, args = { scale_val } }
)
    end
else
val_str = tostring(value)
end


--------------------------------------------------
    --------------------------------------------------
-- Prefix (UNSTYLED - skipped when enhanced, handled internally by Enhanced module)
    -- Label (unstyled)
--------------------------------------------------
    --------------------------------------------------
if not enhanced then
    if label ~= "" then
if prefix ~= "" then
        local link_page = stat_links[prop]
if prefix == "{s:sign}" then
        if link_page then
local num = tonumber(val_str:match("^-?%d+%.?%d*"))
            if link_page == label then
if num and num >= 0 and not val_str:find("^%+") then
                val_str = val_str .. " [[" .. label .. "]]"
val_str = "+" .. val_str
            else
end
                val_str = val_str .. " [[" .. link_page .. "|" .. label .. "]]"
else
            end
val_str = prefix .. val_str
        else
end
            val_str = val_str .. " " .. label
end
        end
end
    end


--------------------------------------------------
    --------------------------------------------------
-- Postfix (UNSTYLED - skipped when enhanced, handled internally by Enhanced module)
    -- Conditional marker
--------------------------------------------------
    --------------------------------------------------
if not enhanced then
    if allow_conditional and type(raw_prop) == "table" and
if postfix ~= "" and not val_str:find(postfix, 1, true) then
      (raw_prop.UsageFlags == "ConditionallyApplied" or raw_prop.UsageFlags == "ConditionallyEnemyApplied") then
if postfix == "HP/s" then
        val_str = val_str .. string.format(
val_str = val_str .. " " .. postfix
            ' <span style="color:#C0C0C0">(%s)</span>',
else
            lang.get_string("Citadel_Shop_ConditionalAttribute")
val_str = val_str .. postfix
        )
end
    end
end
end


--------------------------------------------------
    return val_str
-- Move speed/Sprint speed postfix (skipped when enhanced)
--------------------------------------------------
if not enhanced then
if css == "move_speed" or css == "sprint_speed" then
if postfix == "" or not postfix:find("%%") then
val_str = val_str:gsub("/s", "") .. "/s"
end
local num = tonumber(val_str:match("^-?%d+%.?%d*"))
if num and num > 0 and not val_str:find("^%+") then
val_str = "+" .. val_str
end
end
end
 
--------------------------------------------------
-- Append scaling template {{Boon}} or {{Ss}}
--------------------------------------------------
local item = get_json_item(item_name)
local raw_prop = item[prop]
if type(raw_prop) == "table" and raw_prop.Scale and raw_prop.Scale.Value ~= 0 then
local scale_val = util_module.round_to_sig_fig(raw_prop.Scale.Value, 2)
local template_name = (raw_prop.Scale.Type == "power_increase") and "Boon" or "Ss"
val_str = val_str .. " " .. mw.getCurrentFrame():expandTemplate{ title = template_name, args = { scale_val } }
end
 
--------------------------------------------------
-- Label (UNSTYLED)
--------------------------------------------------
if label ~= "" then
    local link_page = stat_links[prop]
    if link_page then
        if link_page == label then
            val_str = val_str .. " [[" .. label .. "]]"
        else
            val_str = val_str .. " [[" .. link_page .. "|" .. label .. "]]"
        end
    else
        val_str = val_str .. " " .. label
    end
end
 
--------------------------------------------------
-- Conditional marker
--------------------------------------------------
if allow_conditional
and type(raw_prop) == "table"
and (raw_prop.UsageFlags == "ConditionallyApplied"
or raw_prop.UsageFlags == "ConditionallyEnemyApplied")
then
local conditional_text = lang.get_string("Citadel_Shop_ConditionalAttribute")
val_str = val_str .. string.format(
' <span style="color:#C0C0C0">(%s)</span>',
conditional_text
)
end
 
return val_str
end
end


Line 660: Line 647:
     local lines = {
     local lines = {
         "{{Infobox item",
         "{{Infobox item",
        "| enhanced = true",
         "| item_name = " .. item_name
         "| item_name = " .. item_name
     }
     }
Line 695: Line 683:
                     if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                     if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                       and is_property_in_lang_data(prop) then
                       and is_property_in_lang_data(prop) then
                         local val = format_stat_enhanced(item_name, prop)
                         local val = format_stat_enhanced(item_name, prop, nil, false)
                         if val then
                         if val then
                             table.insert(
                             table.insert(
Line 755: Line 743:
                     if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                     if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                       and is_property_in_lang_data(prop) and not seen[prop] then
                       and is_property_in_lang_data(prop) and not seen[prop] then
                         local val = format_stat_enhanced(item_name, prop)
                         local val = format_stat_enhanced(item_name, prop, nil, false)
                         if val then
                         if val then
                             table.insert(
                             table.insert(
Line 836: Line 824:
                     if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                     if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                       and is_property_in_lang_data(prop) and not seen[prop] then
                       and is_property_in_lang_data(prop) and not seen[prop] then
                         local val = format_stat_enhanced(item_name, prop)
                         local val = format_stat_enhanced(item_name, prop, nil, false)
                         if val then
                         if val then
                             table.insert(
                             table.insert(
Line 889: Line 877:
                 table.insert(lines, "| active1_cooldown = " .. cd)
                 table.insert(lines, "| active1_cooldown = " .. cd)
             else
             else
                 table.insert(lines, "| item_stat_cooldown = " .. cd)
                 table.insert(lines, "| passive1_cooldown = " .. cd)
             end
             end
         end
         end
Line 896: Line 884:
     if not chargeup_found_in_sections and item.AbilityChargeUpTime then
     if not chargeup_found_in_sections and item.AbilityChargeUpTime then
         local cu = format_stat_enhanced(item_name, "AbilityChargeUpTime", true)
         local cu = format_stat_enhanced(item_name, "AbilityChargeUpTime", true)
         if cu then table.insert(lines, "| item_stat_chargeup = " .. cu) end
         if cu then table.insert(lines, "| passive1_chargeup = " .. cu) end
     end
     end