Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Trying to add links to pages |
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: | 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 | ||
-- Special spacing rule for HP/s | |||
if postfix == "HP/s" then | |||
suffix = " " .. 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" | |||
suffix = suffix .. get_missing_rate_warning() | |||
end | |||
end | |||
if prefix ~= "" then | if prefix ~= "" then | ||
| Line 188: | Line 229: | ||
-- Conditional marker | -- Conditional marker | ||
-------------------------------------------------- | -------------------------------------------------- | ||
if allow_conditional then | |||
local item = get_json_item(item_name) | |||
local raw = item and item[prop] | |||
if type(raw) == "table" | |||
and (raw.UsageFlags == "ConditionallyApplied" | |||
or raw.UsageFlags == "ConditionallyEnemyApplied") | |||
then | |||
val_str = val_str .. string.format( | |||
' <span style="color:#C0C0C0">(%s)</span>', | |||
lang.get_string("Citadel_Shop_ConditionalAttribute") | |||
) | |||
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 | local function format_stat(item_name, prop, skip_label, debug, allow_conditional) | ||
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) | |||
if value == nil or value == 0 or value == "" then return nil end | |||
local numeric_val = tonumber(tostring(value):match("^-?%d+%.?%d*")) or 0 | |||
if numeric_val == 0 then return nil end | |||
local label_key = loc_key:gsub("^#", "") | |||
if prop == "BuildUpPerShot" then label_key = "BuildupPerShot" | |||
elseif prop == "DotDuration" then label_key = "DOTDuration" 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") | |||
local postfix = get_lang_with_fallback(label_key, "_postfix", "_Postfix") | |||
if prefix == "" and postfix == "" and label == "" then return nil end | |||
-------------------------------------------------- | |||
-- Prefix logic | |||
-------------------------------------------------- | |||
if prefix == "{s:sign}" then | |||
if numeric_val >= 0 then | |||
prefix = "+" | |||
else | |||
prefix = "" | |||
end | |||
end | |||
-------------------------------------------------- | |||
-- Postfix / move speed handling | |||
-------------------------------------------------- | |||
local suffix = postfix | |||
if postfix == "HP/s" then suffix = " " .. 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 | |||
-------------------------------------------------- | |||
-- Compose main value string | |||
-------------------------------------------------- | |||
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 | |||
-------------------------------------------------- | |||
-- Scale handling (Boon / Ss) | |||
-------------------------------------------------- | |||
local item = get_json_item(item_name) | |||
local raw_prop = item and 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 | |||
val_str = val_str .. string.format( | |||
' <span style="color:#C0C0C0">(%s)</span>', | |||
lang.get_string("Citadel_Shop_ConditionalAttribute") | |||
) | |||
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, "| | 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, "| | if cu then table.insert(lines, "| passive1_chargeup = " .. cu) end | ||
end | end | ||