Module:Sandbox/LVL: Difference between revisionsGive feedback
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
local data = mw.loadJsonData("Data:Monster_Domosed/ItemData.json") | local data = mw.loadJsonData("Data:Monster_Domosed/ItemData.json") | ||
-- Helper function: get first non-nil string from variants | -- Get raw value, CSS class, and LocTokenOverride for a property | ||
local function get_raw_value(item_name, prop) | |||
local item = data[item_name] or nil | |||
if not item then | |||
for k,v in pairs(data) do | |||
if v.Name == item_name then item = v; break end | |||
end | |||
end | |||
if not item then return nil, nil, nil end | |||
local raw_prop = item[prop] | |||
if type(raw_prop) == "table" then | |||
local loc_override = raw_prop.LocTokenOverride or prop | |||
return raw_prop.Value, raw_prop.CSSClass, loc_override | |||
else | |||
return raw_prop, nil, prop | |||
end | |||
end | |||
-- Check if property exists in language data | |||
local function is_property_in_lang_data(prop) | |||
local suffixes = {"_label", "_Label", "_prefix", "_Prefix", "_postfix", "_Postfix", "_postvalue_label", "_Postvalue_Label"} | |||
for _, suffix in ipairs(suffixes) do | |||
if lang.get_string(prop .. suffix) then | |||
return true | |||
end | |||
end | |||
return false | |||
end | |||
-- Get item by name, ignoring disabled if possible | |||
local function get_json_item(name) | |||
for _, v in pairs(data) do | |||
if v.Name == name and (v.IsDisabled == false or v.IsDisabled == nil) then | |||
return v | |||
end | |||
end | |||
for _, v in pairs(data) do | |||
if v.Name == name then return v end | |||
end | |||
return nil | |||
end | |||
-- Helper function: get first non-nil string from variants | |||
local function first_non_nil(...) | local function first_non_nil(...) | ||
for i = 1, select("#", ...) do | for i = 1, select("#", ...) do | ||
| Line 13: | Line 56: | ||
end | end | ||
-- Helper: get lang string with case fallback | -- Helper: get lang string with case fallback | ||
local function get_lang_with_fallback(base_key, suffix1, suffix2) | local function get_lang_with_fallback(base_key, suffix1, suffix2) | ||
return first_non_nil( | return first_non_nil( | ||
| Line 21: | Line 64: | ||
end | end | ||
-- | -- Returns items that build from this item, sorted by tier | ||
local function get_component_of_sorted(item_input) | local function get_component_of_sorted(item_input) | ||
local target_key = nil | local target_key = nil | ||
| Line 47: | Line 90: | ||
end | end | ||
table.sort(parents, function(a, b) | table.sort(parents, function(a, b) | ||
local tier_a = tonumber(data[a] and data[a]["Tier"]) or 0 | local tier_a = tonumber(data[a] and data[a]["Tier"]) or 0 | ||
| Line 55: | Line 97: | ||
return parents | return parents | ||
end | end | ||
-- 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 | |||
local function format_stat(item_name, prop, skip_label, debug, allow_conditional) | local function format_stat(item_name, prop, skip_label, debug, allow_conditional) | ||
if allow_conditional == nil then allow_conditional = true end | if allow_conditional == nil then allow_conditional = true end | ||
| Line 110: | Line 110: | ||
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 | ||
return nil | |||
end | end | ||
local numeric_val = tonumber(tostring(value):match("^-?%d+%.?%d*")) or 0 | local numeric_val = tonumber(tostring(value):match("^-?%d+%.?%d*")) or 0 | ||
if numeric_val == 0 then | if numeric_val == 0 then | ||
| Line 119: | Line 118: | ||
end | end | ||
local label_key = loc_key:gsub("^#", "") | local label_key = loc_key:gsub("^#", "") | ||
if not ( | |||
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 debug == 2 then | |||
local label_val, prefix_val, postfix_val | |||
if lang.get_string(label_key.."_label") then | |||
label_val = label_key.."_label" | |||
elseif lang.get_string(label_key.."_Label") then | |||
label_val = label_key.."_Label" | |||
else | |||
label_val = "(none)" | |||
end | |||
if lang.get_string(label_key.."_prefix") then | |||
prefix_val = label_key.."_prefix" | |||
elseif lang.get_string(label_key.."_Prefix") then | |||
prefix_val = label_key.."_Prefix" | |||
else | |||
prefix_val = "(none)" | |||
end | |||
if lang.get_string(label_key.."_postfix") then | |||
postfix_val = label_key.."_postfix" | |||
elseif lang.get_string(label_key.."_Postfix") then | |||
postfix_val = label_key.."_Postfix" | |||
else | |||
postfix_val = "(none)" | |||
end | |||
return string.format( | |||
"raw invoke key: %s | raw value: %s | label key used: %s | prefix key used: %s | postfix key used: %s", | |||
loc_key, | |||
tostring(value), | |||
label_val, | |||
prefix_val, | |||
postfix_val | |||
) | |||
end | |||
if prop == "BuildUpPerShot" then label_key = "BuildupPerShot" | if prop == "BuildUpPerShot" then label_key = "BuildupPerShot" | ||
| Line 154: | Line 173: | ||
end | end | ||
local label = skip_label and "" or get_lang_with_fallback(label_key, "_label", "_Label") | 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 prefix = get_lang_with_fallback(label_key, "_prefix", "_Prefix") | ||
| Line 160: | Line 178: | ||
if prefix == "" and postfix == "" and label == "" then | if prefix == "" and postfix == "" and label == "" then | ||
return nil | |||
end | |||
local val_str = tostring(value) | local val_str = tostring(value) | ||
| Line 180: | Line 198: | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
-- CSS-specific formatting (after prefix to avoid double +) | -- CSS-specific formatting (must run after prefix to avoid double +) | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
if css == "move_speed" or css == "sprint_speed" then | if css == "move_speed" or css == "sprint_speed" then | ||
| Line 195: | Line 213: | ||
-- Append postfix | -- Append postfix | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
if prop ~= "BuildUpPerShot" and postfix ~= "" and not val_str:find(postfix, 1, true) then | |||
if postfix == "HP/s" then | |||
val_str = val_str .. " " .. postfix | |||
else | |||
val_str = val_str .. postfix | |||
end | |||
end | |||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
| Line 222: | Line 240: | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
-- Append (Conditional) | -- Append (Conditional) — only shown for ImportantProperties | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
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 | return val_str | ||
end | end | ||
-- Special formatting for StatusEffect | -- Special formatting for StatusEffect properties | ||
local function format_property_for_infobox(item_name, prop, skip_label, debug) | local function format_property_for_infobox(item_name, prop, skip_label, debug) | ||
if prop:match("^StatusEffect") then | if prop:match("^StatusEffect") then | ||
| Line 243: | Line 261: | ||
) | ) | ||
else | else | ||
return format_stat(item_name, prop, skip_label, debug, true) | return format_stat(item_name, prop, skip_label, debug, true) | ||
end | end | ||
| Line 258: | Line 275: | ||
local ItemData = require("Module:ItemData") | local ItemData = require("Module:ItemData") | ||
local lines = { | local lines = { | ||
"{{Infobox item", | |||
"| item_name = " .. item_name | |||
} | |||
if item.StreetBrawl == true then | |||
table.insert(lines, "| street_brawl = true") | |||
end | |||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
| Line 293: | Line 310: | ||
for _, prop in ipairs(entry.Properties or {}) do | for _, prop in ipairs(entry.Properties or {}) do | ||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" then | if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" then | ||
local val = format_stat(item_name, prop, false, debug, false) | local val = format_stat(item_name, prop, false, debug, false) | ||
if val then | if val then | ||
| Line 323: | Line 339: | ||
local seen_props = {} | local seen_props = {} | ||
for _, prop in ipairs(entry.ImportantProperties or {}) do | for _, prop in ipairs(entry.ImportantProperties or {}) do | ||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | ||
| Line 336: | Line 351: | ||
end | end | ||
for _, prop in ipairs(entry.Properties or {}) do | for _, prop in ipairs(entry.Properties or {}) do | ||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | ||
| Line 349: | Line 363: | ||
end | end | ||
for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do | for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do | ||
for _, prop in ipairs(prop_list) do | for _, prop in ipairs(prop_list) do | ||
if prop == "AbilityCooldown" then | if prop == "AbilityCooldown" then | ||
local cd = format_stat(item_name, prop, true, debug) | local cd = format_stat(item_name, prop, true, debug) | ||
if cd then | if cd then table.insert(lines, string.format("| passive%d_cooldown = %s", passive_counter, cd)) end | ||
end | end | ||
if prop == "AbilityChargeUpTime" then | if prop == "AbilityChargeUpTime" then | ||
local cu = format_stat(item_name, prop, true, debug) | local cu = format_stat(item_name, prop, true, debug) | ||
if cu then | if cu then table.insert(lines, string.format("| passive%d_chargeup = %s", passive_counter, cu)) end | ||
end | end | ||
end | end | ||
| Line 395: | Line 398: | ||
local seen_props = {} | local seen_props = {} | ||
for _, prop in ipairs(entry.ImportantProperties or {}) do | for _, prop in ipairs(entry.ImportantProperties or {}) do | ||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | ||
| Line 408: | Line 410: | ||
end | end | ||
for _, prop in ipairs(entry.Properties or {}) do | for _, prop in ipairs(entry.Properties or {}) do | ||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | ||
| Line 421: | Line 422: | ||
end | end | ||
for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do | for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do | ||
for _, prop in ipairs(prop_list) do | for _, prop in ipairs(prop_list) do | ||
if prop == "AbilityCooldown" then | if prop == "AbilityCooldown" then | ||
local cd = format_stat(item_name, prop, true, debug) | local cd = format_stat(item_name, prop, true, debug) | ||
if cd then | if cd then table.insert(lines, string.format("| active%d_cooldown = %s", active_index, cd)) end | ||
end | end | ||
if prop == "AbilityChargeUpTime" then | if prop == "AbilityChargeUpTime" then | ||
local cu = format_stat(item_name, prop, true, debug) | local cu = format_stat(item_name, prop, true, debug) | ||
if cu then | if cu then table.insert(lines, string.format("| active%d_chargeup = %s", active_index, cu)) end | ||
end | end | ||
end | end | ||
| Line 451: | Line 441: | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
-- Global fallback for AbilityCooldown | -- Global fallback for AbilityCooldown and AbilityChargeUpTime | ||
-- Attaches to the active section if one exists, otherwise innate | |||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
if not cooldown_found_in_sections and not chargeup_found_in_sections and item.AbilityCooldown then | if not cooldown_found_in_sections and not chargeup_found_in_sections and item.AbilityCooldown then | ||
| Line 470: | Line 461: | ||
if not chargeup_found_in_sections and item.AbilityChargeUpTime then | if not chargeup_found_in_sections and item.AbilityChargeUpTime then | ||
local cu = format_stat(item_name, "AbilityChargeUpTime", true, debug) | local cu = format_stat(item_name, "AbilityChargeUpTime", true, debug) | ||
if cu then | if cu then table.insert(lines, "| item_stat_chargeup = " .. cu) end | ||
end | end | ||
| Line 479: | Line 468: | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
for i = 1, 2 do | for i = 1, 2 do | ||
local comp = ItemData.get_component_name { | local comp = ItemData.get_component_name { args = { item_name, i } } | ||
if comp and comp ~= "" then | if comp and comp ~= "" then | ||
table.insert(lines, string.format("| component%d_name = %s", i, comp)) | table.insert(lines, string.format("| component%d_name = %s", i, comp)) | ||
| Line 488: | Line 475: | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
-- Is Component Of ( | -- Is Component Of (sorted by tier) | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
local parents = get_component_of_sorted(item_name) | local parents = get_component_of_sorted(item_name) | ||
| Line 499: | Line 486: | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
-- Sounds | -- Sounds | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
for key, value in pairs(frame.args) do | for key, value in pairs(frame.args) do | ||