Module:Sandbox/Vergir: Difference between revisions

Vergir (talk | contribs)
Test draft of the Spirit scaling table module (with help from vergir-bot LLM)
Vergir (talk | contribs)
Test draft: generic StatScaling builder, base + scaling cells (with help from vergir-bot LLM)
Line 1: Line 1:
-- Renders a table of hero base stats that scale with Spirit Power, built from
-- Builds tables of hero base stats that scale with a given scaling type,
-- the SpiritScaling entries in [[Data:HeroData.json]].
-- read from [[Data:HeroData.json]].
--
-- Each public function below renders one table. The shared work lives in
-- build_scaling_table(), so adding a table for another scaling type (Boons,
-- for instance) only takes a new wrapper naming its data key and caption.
--
-- {{#invoke:Sandbox/Vergir|write_spirit_scaling_table}}
-- {{#invoke:Sandbox/Vergir|write_spirit_scaling_table}}
local p = {}
local p = {}
Line 10: Line 15:
local dictionary_module = require('Module:Dictionary')
local dictionary_module = require('Module:Dictionary')
local hero_data_module  = require('Module:HeroData')
local hero_data_module  = require('Module:HeroData')
-- Stats left out by default. Both are derived from stats that are already
-- listed in their own right, so including them would duplicate every row.
local DEFAULT_EXCLUDED_STATS = "DPS,SustainedDPS"


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 35: Line 36:
for entry in string.gmatch(list, "[^,%s]+") do set[entry] = true end
for entry in string.gmatch(list, "[^,%s]+") do set[entry] = true end
return set
return set
end
local function missing_translation_tooltip()
return mw.getCurrentFrame():expandTemplate{title = "MissingValveTranslationTooltip"}
end
end


Line 57: Line 54:
if (translated ~= nil and translated:sub(1, 5) ~= "Key '") then return translated end
if (translated ~= nil and translated:sub(1, 5) ~= "Key '") then return translated end


return util_module.add_space_before_cap(stat) .. missing_translation_tooltip()
return util_module.add_space_before_cap(stat) ..
mw.getCurrentFrame():expandTemplate{title = "MissingValveTranslationTooltip"}
end
end


Line 66: Line 64:


local function hero_icon(hero_key, hero_data)
local function hero_icon(hero_key, hero_data)
local template_args = {
return mw.getCurrentFrame():expandTemplate{
[1] = hero_data["Name"] or hero_key,
title = "HeroIcon",
l1 = lang_module.get_string(hero_key),
args = {[1] = hero_data["Name"] or hero_key, l1 = lang_module.get_string(hero_key)},
}
}
return mw.getCurrentFrame():expandTemplate{title = "HeroIcon", args = template_args}
end
end


-- Every Spirit scaling a hero has, minus the excluded stats and any zeroes,
-- "6.3 + x0.0084", or just the scaling for stats that have no base value
-- ordered by localized stat name: { { stat = , label = , value = }, ... }
-- (percentage stats such as Fire Rate and the resistances).
local function hero_scalings(hero_data, excluded_stats)
local function scaling_cell(hero_data, stat, value, scaling_type)
local scaling_str = hero_data_module.write_scalar_str(value, scaling_type)
local base = hero_data_module.get_stat(hero_data, stat)
if (type(base) ~= "number") then return scaling_str end
return base .. ' + ' .. scaling_str
end
 
-- Every scaling a hero has of one type, minus the excluded stats and any
-- zeroes, ordered by localized stat name:
--  { { stat = , label = , value = }, ... }
local function hero_scalings(hero_data, scaling_key, excluded_stats)
local scalings = {}
local scalings = {}
for _, stat in ipairs(sorted_keys(hero_data["SpiritScaling"])) do
local hero_scaling_data = hero_data[scaling_key]
local value = hero_data["SpiritScaling"][stat]
for _, stat in ipairs(sorted_keys(hero_scaling_data)) do
local value = hero_scaling_data[stat]
if (not excluded_stats[stat] and type(value) == "number" and value ~= 0) then
if (not excluded_stats[stat] and type(value) == "number" and value ~= 0) then
table.insert(scalings, {stat = stat, label = stat_label(stat), value = value})
table.insert(scalings, {stat = stat, label = stat_label(stat), value = value})
Line 91: Line 99:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Wikitext entry point
-- Shared table builder
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


--{{#invoke:Sandbox/Vergir|write_spirit_scaling_table|exclude=|include_unreleased=}}
-- options:
-- exclude:           comma separated stat keys to leave out, defaults to
--   scaling_type: "Spirit" or "Level", picks both the <type>Scaling data key
--                     "DPS,SustainedDPS". Pass an empty value to list every stat.
--                and the scaling template ({{Ss}} or {{PI}})
-- include_unreleased: "yes" to also list heroes flagged InDevelopment or IsDisabled.
--   caption_key:  [[Data:Dictionary]] key for the table caption
function p.write_spirit_scaling_table(frame)
--   excluded_stats: set of stat keys to leave out
local args = frame.args or {}
local function build_scaling_table(options)
local excluded_stats = to_set(args["exclude"] or DEFAULT_EXCLUDED_STATS)
local scaling_key = options.scaling_type .. "Scaling"
local include_unreleased = (args["include_unreleased"] == "yes" or args["include_unreleased"] == "true")


-- Collect the heroes that have anything left to show
-- Collect the heroes that have anything left to show
Line 107: Line 114:
for _, hero_key in ipairs(sorted_keys(heroes_data)) do
for _, hero_key in ipairs(sorted_keys(heroes_data)) do
local hero_data = heroes_data[hero_key]
local hero_data = heroes_data[hero_key]
local released = not hero_data["InDevelopment"] and not hero_data["IsDisabled"]
if (not hero_data["InDevelopment"] and not hero_data["IsDisabled"]) then
if (released or include_unreleased) then
local scalings = hero_scalings(hero_data, scaling_key, options.excluded_stats)
local scalings = hero_scalings(hero_data, excluded_stats)
if (#scalings > 0) then
if (#scalings > 0) then
table.insert(rows, {
table.insert(rows, {
Line 126: Line 132:
local output = {
local output = {
'{| class="wikitable"',
'{| class="wikitable"',
'|+ ' .. dictionary_module.translate("SpiritScalingTableCaption"),
'|+ ' .. dictionary_module.translate(options.caption_key),
'! ' .. dictionary_module.translate("Hero"),
'! ' .. dictionary_module.translate("Hero"),
'! ' .. dictionary_module.translate("Stats"),
'! ' .. dictionary_module.translate("Stats"),
Line 140: Line 146:
end
end
table.insert(output, '| ' .. scaling.label)
table.insert(output, '| ' .. scaling.label)
table.insert(output, '| ' .. hero_data_module.write_scalar_str(scaling.value, "Spirit"))
table.insert(output, '| ' ..
scaling_cell(row.data, scaling.stat, scaling.value, options.scaling_type))
end
end
end
end
Line 146: Line 153:


return table.concat(output, '\n')
return table.concat(output, '\n')
end
--------------------------------------------------------------------------------
-- Wikitext entry points
--------------------------------------------------------------------------------
-- Hero base stats that scale with Spirit Power.
--{{#invoke:Sandbox/Vergir|write_spirit_scaling_table|exclude=}}
-- exclude: comma separated stat keys to leave out. Defaults to DPS and
--          SustainedDPS, which are both derived from stats already listed.
--          Pass an empty value to list every stat.
function p.write_spirit_scaling_table(frame)
local args = frame.args or {}
return build_scaling_table{
scaling_type = "Spirit",
caption_key = "HeroSpiritScalingCaption",
excluded_stats = to_set(args["exclude"] or "DPS,SustainedDPS"),
}
end
end


return p
return p