Module:Sandbox/LVL: Difference between revisionsGive feedback
No edit summary |
No edit summary |
||
| Line 62: | Line 62: | ||
lang.get_string(base_key .. suffix2) | lang.get_string(base_key .. suffix2) | ||
) | ) | ||
end | |||
-- Enhanced stat wrapper - prefix and value get enhanced styling, postfix/label don't | |||
local function format_stat_enhanced(item_name, prop, skip_label) | |||
skip_label = skip_label or false | |||
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 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 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 | |||
-------------------------------------------------- | |||
-- VALUE (Enhanced) with PREFIX and POSTFIX/SUFFIX | |||
-------------------------------------------------- | |||
local val_str | |||
local suffix = postfix | |||
if css == "move_speed" or css == "sprint_speed" then | |||
if not postfix:find("%%") then | |||
suffix = postfix .. "/s" | |||
end | |||
end | |||
if prefix ~= "" then | |||
if prefix == "{s:sign}" then | |||
local num = tonumber(tostring(value):match("^-?%d+%.?%d*")) | |||
if num and num >= 0 then | |||
prefix = "+" | |||
else | |||
prefix = "" | |||
end | |||
end | |||
if suffix ~= "" and suffix ~= "%" then | |||
val_str = string.format( | |||
"{{#invoke:Enhanced|render|%s|%s|prefix=%s|suffix=%s|noicon=true}}", | |||
item_name, | |||
prop, | |||
prefix, | |||
suffix | |||
) | |||
else | |||
val_str = string.format( | |||
"{{#invoke:Enhanced|render|%s|%s|prefix=%s|noicon=true}}", | |||
item_name, | |||
prop, | |||
prefix | |||
) | |||
end | |||
else | |||
if suffix ~= "" and suffix ~= "%" then | |||
val_str = string.format( | |||
"{{#invoke:Enhanced|render|%s|%s|suffix=%s|noicon=true}}", | |||
item_name, | |||
prop, | |||
suffix | |||
) | |||
else | |||
val_str = string.format( | |||
"{{#invoke:Enhanced|render|%s|%s|noicon=true}}", | |||
item_name, | |||
prop | |||
) | |||
end | |||
end | |||
-------------------------------------------------- | |||
-- Postfix (UNSTYLED) | |||
-------------------------------------------------- | |||
if postfix ~= "" 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 | |||
-------------------------------------------------- | |||
-- Label (UNSTYLED - only if not skipped) | |||
-------------------------------------------------- | |||
if label ~= "" then | |||
val_str = val_str .. " " .. label | |||
end | |||
-------------------------------------------------- | |||
-- Conditional marker | |||
-------------------------------------------------- | |||
local item = get_json_item(item_name) | |||
local raw_prop = item[prop] | |||
if 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 | |||
-- Special formatting for StatusEffect properties (enhanced variant) | |||
local function format_property_for_infobox_enhanced(item_name, prop) | |||
if prop:match("^StatusEffect") then | |||
return string.format( | |||
"[[{{#invoke:Lang|get_string|Citadel_%s}}]] [[{{#invoke:Lang|get_string|Citadel_StatusEffect}}]]", | |||
prop | |||
) | |||
else | |||
return format_stat_enhanced(item_name, prop) | |||
end | |||
end | end | ||
| Line 101: | Line 244: | ||
-- 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, enhanced) | ||
if allow_conditional == nil then allow_conditional = true end | |||
if prop == "AbilityCooldown" and not skip_label then | |||
return nil | |||
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 not ( | 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 | ) then | ||
return nil | |||
end | end | ||
if | 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 | |||
-------------------------------------------------- | |||
-- VALUE (normal or enhanced) | |||
-------------------------------------------------- | |||
local val_str | |||
if enhanced then | |||
val_str = string.format( | |||
"{{#invoke:Enhanced|render|%s|%s}}", | |||
item_name, | |||
prop | |||
) | |||
else | |||
val_str = tostring(value) | |||
end | |||
-------------------------------------------------- | |||
-- Prefix (UNSTYLED - skipped when enhanced, handled internally by Enhanced module) | |||
-------------------------------------------------- | |||
if not enhanced then | |||
if prefix ~= "" then | |||
if prefix == "{s:sign}" then | |||
local num = tonumber(val_str:match("^-?%d+%.?%d*")) | |||
if num and num >= 0 and not val_str:find("^%+") then | |||
val_str = "+" .. val_str | |||
end | |||
else | |||
val_str = prefix .. val_str | |||
end | |||
end | |||
end | end | ||
-------------------------------------------------- | |||
-- Postfix (UNSTYLED - skipped when enhanced, handled internally by Enhanced module) | |||
-------------------------------------------------- | |||
if not enhanced then | |||
if 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 | |||
end | |||
-------------------------------------------------- | |||
-- 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 | end | ||
-------------------------------------------------- | |||
-- Label (UNSTYLED) | |||
-------------------------------------------------- | |||
if label ~= "" then | |||
val_str = val_str .. " " .. label | |||
if | |||
end | end | ||
-------------------------------------------------- | |||
-- Conditional marker | |||
-------------------------------------------------- | |||
if allow_conditional | if allow_conditional | ||
and type(raw_prop) == "table" | |||
and (raw_prop.UsageFlags == "ConditionallyApplied" | |||
or raw_prop.UsageFlags == "ConditionallyEnemyApplied") | |||
then | 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 | end | ||
return val_str | |||
end | end | ||
| Line 265: | Line 394: | ||
end | end | ||
function | -- Build raw wikitext for the default tooltip infobox (no preprocess) | ||
local function build_tooltip(frame) | |||
local item_name = frame.args[1] | local item_name = frame.args[1] | ||
if not item_name then return "Item name missing" end | if not item_name then return "Item name missing", 0 end | ||
local debug = tonumber(frame.args.debug) or 0 | local debug = tonumber(frame.args.debug) or 0 | ||
local item = get_json_item(item_name) | local item = get_json_item(item_name) | ||
if not item then return "Item not found" end | if not item then return "Item not found", debug end | ||
local ItemData = require("Module:ItemData") | local ItemData = require("Module:ItemData") | ||
| Line 342: | Line 472: | ||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | ||
and is_property_in_lang_data(prop) and not seen_props[prop] then | and is_property_in_lang_data(prop) and not seen_props[prop] then | ||
local val = | local val = format_stat(item_name, prop, false, debug, true) | ||
if val then | if val then | ||
table.insert(lines, string.format("| passive%d_stat%d = %s", passive_counter, stat_index, val)) | table.insert(lines, string.format("| passive%d_stat%d = %s", passive_counter, stat_index, val)) | ||
| Line 401: | Line 531: | ||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | ||
and is_property_in_lang_data(prop) and not seen_props[prop] then | and is_property_in_lang_data(prop) and not seen_props[prop] then | ||
local val = | local val = format_stat(item_name, prop, false, debug, true) | ||
if val then | if val then | ||
table.insert(lines, string.format("| active%d_stat%d = %s", active_index, stat_index, val)) | table.insert(lines, string.format("| active%d_stat%d = %s", active_index, stat_index, val)) | ||
| Line 497: | Line 627: | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
table.insert(lines, "}}") | table.insert(lines, "}}") | ||
local | return table.concat(lines, "\n"), debug | ||
end | |||
-- Build raw wikitext for the enhanced tooltip infobox (no preprocess) | |||
local function build_tooltip_enhanced(frame) | |||
local item_name = frame.args[1] | |||
if not item_name then return "Item name missing" end | |||
local item = get_json_item(item_name) | |||
if not item then return "Item not found" end | |||
local ItemData = require("Module:ItemData") | |||
local lines = { | |||
"{{Infobox item", | |||
"| item_name = " .. item_name | |||
} | |||
if item.StreetBrawl == true then | |||
table.insert(lines, "| street_brawl = true") | |||
end | |||
---------------------------------------------------------------------- | |||
-- Check if AbilityCooldown or AbilityChargeUpTime exists in sections | |||
---------------------------------------------------------------------- | |||
local cooldown_found_in_sections = false | |||
local chargeup_found_in_sections = false | |||
for _, section in ipairs(item.TooltipSections or {}) do | |||
for _, entry in ipairs(section.Entries or {}) do | |||
for _, prop in ipairs(entry.Properties or {}) do | |||
if prop == "AbilityCooldown" then cooldown_found_in_sections = true end | |||
if prop == "AbilityChargeUpTime" then chargeup_found_in_sections = true end | |||
end | |||
for _, prop in ipairs(entry.ImportantProperties or {}) do | |||
if prop == "AbilityCooldown" then cooldown_found_in_sections = true end | |||
if prop == "AbilityChargeUpTime" then chargeup_found_in_sections = true end | |||
end | |||
end | |||
end | |||
---------------------------------------------------------------------- | |||
-- Innate stats (Enhanced) | |||
---------------------------------------------------------------------- | |||
local innate_index = 1 | |||
for _, section in ipairs(item.TooltipSections or {}) do | |||
if section.Type == "EArea_Innate" then | |||
for _, entry in ipairs(section.Entries or {}) do | |||
for _, prop in ipairs(entry.Properties or {}) do | |||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | |||
and is_property_in_lang_data(prop) then | |||
local val = format_stat_enhanced(item_name, prop) | |||
if val then | |||
table.insert( | |||
lines, | |||
string.format( | |||
"| item_stat%d = %s", | |||
innate_index, | |||
val | |||
) | |||
) | |||
innate_index = innate_index + 1 | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end | |||
---------------------------------------------------------------------- | |||
-- Passive stats (Enhanced) | |||
---------------------------------------------------------------------- | |||
local passive_counter = 1 | |||
for _, section in ipairs(item.TooltipSections or {}) do | |||
if section.Type ~= "EArea_Innate" and section.Type ~= "EArea_Active" then | |||
for _, entry in ipairs(section.Entries or {}) do | |||
if entry.LocString then | |||
table.insert(lines, string.format( | |||
"| passive%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}", | |||
passive_counter, | |||
entry.LocString:gsub("#",""), | |||
item_name | |||
)) | |||
end | |||
local stat_index = 1 | |||
local seen = {} | |||
for _, prop in ipairs(entry.ImportantProperties or {}) do | |||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | |||
and is_property_in_lang_data(prop) and not seen[prop] then | |||
local val = format_property_for_infobox_enhanced(item_name, prop) | |||
if val then | |||
table.insert( | |||
lines, | |||
string.format( | |||
"| passive%d_stat%d = %s", | |||
passive_counter, | |||
stat_index, | |||
val | |||
) | |||
) | |||
stat_index = stat_index + 1 | |||
seen[prop] = true | |||
end | |||
end | |||
end | |||
for _, prop in ipairs(entry.Properties or {}) do | |||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | |||
and is_property_in_lang_data(prop) and not seen[prop] then | |||
local val = format_stat_enhanced(item_name, prop) | |||
if val then | |||
table.insert( | |||
lines, | |||
string.format( | |||
"| passive%d_stat%d = %s", | |||
passive_counter, | |||
stat_index, | |||
val | |||
) | |||
) | |||
stat_index = stat_index + 1 | |||
seen[prop] = true | |||
end | |||
end | |||
end | |||
for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do | |||
for _, prop in ipairs(prop_list) do | |||
if prop == "AbilityCooldown" then | |||
local cd = format_stat_enhanced(item_name, prop, true) | |||
if cd then | |||
table.insert(lines, string.format("| passive%d_cooldown = %s", passive_counter, cd)) | |||
end | |||
end | |||
if prop == "AbilityChargeUpTime" then | |||
local cu = format_stat_enhanced(item_name, prop, true) | |||
if cu then | |||
table.insert(lines, string.format("| passive%d_chargeup = %s", passive_counter, cu)) | |||
end | |||
end | |||
end | |||
end | |||
passive_counter = passive_counter + 1 | |||
end | |||
end | |||
end | |||
---------------------------------------------------------------------- | |||
-- Active stats (Enhanced) | |||
---------------------------------------------------------------------- | |||
local active_index = 1 | |||
for _, section in ipairs(item.TooltipSections or {}) do | |||
if section.Type == "EArea_Active" then | |||
for _, entry in ipairs(section.Entries or {}) do | |||
if entry.LocString then | |||
table.insert(lines, string.format( | |||
"| active%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}", | |||
active_index, | |||
entry.LocString:gsub("#",""), | |||
item_name | |||
)) | |||
end | |||
local stat_index = 1 | |||
local seen = {} | |||
for _, prop in ipairs(entry.ImportantProperties or {}) do | |||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | |||
and is_property_in_lang_data(prop) and not seen[prop] then | |||
local val = format_property_for_infobox_enhanced(item_name, prop) | |||
if val then | |||
table.insert( | |||
lines, | |||
string.format( | |||
"| active%d_stat%d = %s", | |||
active_index, | |||
stat_index, | |||
val | |||
) | |||
) | |||
stat_index = stat_index + 1 | |||
seen[prop] = true | |||
end | |||
end | |||
end | |||
for _, prop in ipairs(entry.Properties or {}) do | |||
if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" | |||
and is_property_in_lang_data(prop) and not seen[prop] then | |||
local val = format_stat_enhanced(item_name, prop) | |||
if val then | |||
table.insert( | |||
lines, | |||
string.format( | |||
"| active%d_stat%d = %s", | |||
active_index, | |||
stat_index, | |||
val | |||
) | |||
) | |||
stat_index = stat_index + 1 | |||
seen[prop] = true | |||
end | |||
end | |||
end | |||
for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do | |||
for _, prop in ipairs(prop_list) do | |||
if prop == "AbilityCooldown" then | |||
local cd = format_stat_enhanced(item_name, prop, true) | |||
if cd then | |||
table.insert(lines, string.format("| active%d_cooldown = %s", active_index, cd)) | |||
end | |||
end | |||
if prop == "AbilityChargeUpTime" then | |||
local cu = format_stat_enhanced(item_name, prop, true) | |||
if cu then | |||
table.insert(lines, string.format("| active%d_chargeup = %s", active_index, cu)) | |||
end | |||
end | |||
end | |||
end | |||
active_index = active_index + 1 | |||
end | |||
end | |||
end | |||
---------------------------------------------------------------------- | |||
-- 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 | |||
local cd = format_stat_enhanced(item_name, "AbilityCooldown", true) | |||
if cd then | |||
local has_active = false | |||
for _, section in ipairs(item.TooltipSections or {}) do | |||
if section.Type == "EArea_Active" then has_active = true; break end | |||
end | |||
if has_active then | |||
table.insert(lines, "| active1_cooldown = " .. cd) | |||
else | |||
table.insert(lines, "| item_stat_cooldown = " .. cd) | |||
end | |||
end | |||
end | |||
if not chargeup_found_in_sections and item.AbilityChargeUpTime then | |||
local cu = format_stat_enhanced(item_name, "AbilityChargeUpTime", true) | |||
if cu then table.insert(lines, "| item_stat_chargeup = " .. cu) end | |||
end | |||
---------------------------------------------------------------------- | |||
-- Components | |||
---------------------------------------------------------------------- | |||
for i = 1, 2 do | |||
local comp = ItemData.get_component_name { args = { item_name, i } } | |||
if comp and comp ~= "" then | |||
table.insert(lines, string.format("| component%d_name = %s", i, comp)) | |||
end | |||
end | |||
---------------------------------------------------------------------- | |||
-- Is Component Of (sorted by tier) | |||
---------------------------------------------------------------------- | |||
local parents = get_component_of_sorted(item_name) | |||
for i, key in ipairs(parents) do | |||
local parent_name = data[key] and data[key]["Name"] or "" | |||
if parent_name ~= "" then | |||
table.insert(lines, string.format("| iscomponentof%d_name = %s", i, parent_name)) | |||
end | |||
end | |||
---------------------------------------------------------------------- | |||
-- Sounds | |||
---------------------------------------------------------------------- | |||
for key, value in pairs(frame.args) do | |||
local index = tostring(key):match("^sound(%d+)$") | |||
if index and value ~= "" then | |||
table.insert(lines, string.format("| sound%s = %s", index, value)) | |||
end | |||
end | |||
---------------------------------------------------------------------- | |||
table.insert(lines, "}}") | |||
return table.concat(lines, "\n") | |||
end | |||
function p.fill_tooltip(frame) | |||
local output, debug = build_tooltip(frame) | |||
if debug == 1 or debug == 2 then | if debug == 1 or debug == 2 then | ||
return output | return output | ||
end | end | ||
return mw.getCurrentFrame():preprocess(output) | |||
end | |||
function p.fill_tooltip_enhanced(frame) | |||
return mw.getCurrentFrame():preprocess(build_tooltip_enhanced(frame)) | |||
end | |||
return mw.getCurrentFrame():preprocess( | function p.render(frame) | ||
local output_lines = { "<tabber>" } | |||
table.insert(output_lines, "Default=") | |||
local tooltip, _ = build_tooltip(frame) | |||
table.insert(output_lines, tooltip) | |||
table.insert(output_lines, "|-|") | |||
table.insert(output_lines, "Enhanced=") | |||
table.insert(output_lines, build_tooltip_enhanced(frame)) | |||
table.insert(output_lines, "</tabber>") | |||
return mw.getCurrentFrame():preprocess(table.concat(output_lines, "\n")) | |||
end | end | ||
return p | return p | ||