Module:Sandbox/Vergir: Difference between revisionsGive feedback
Test draft of the Spirit scaling table module (with help from vergir-bot LLM) |
Test draft: generic StatScaling builder, base + scaling cells (with help from vergir-bot LLM) |
||
| Line 1: | Line 1: | ||
-- | -- Builds tables of hero base stats that scale with a given scaling type, | ||
-- | -- 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') | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| 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 | 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) .. | 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) | ||
return mw.getCurrentFrame():expandTemplate{ | |||
[1] = hero_data["Name"] or hero_key, | title = "HeroIcon", | ||
args = {[1] = hero_data["Name"] or hero_key, l1 = lang_module.get_string(hero_key)}, | |||
} | } | ||
end | end | ||
-- Every | -- "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( | local hero_scaling_data = hero_data[scaling_key] | ||
local value = | 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: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- Shared table builder | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- options: | ||
-- | -- scaling_type: "Spirit" or "Level", picks both the <type>Scaling data key | ||
-- | -- and the scaling template ({{Ss}} or {{PI}}) | ||
-- | -- caption_key: [[Data:Dictionary]] key for the table caption | ||
function | -- excluded_stats: set of stat keys to leave out | ||
local | local function build_scaling_table(options) | ||
local scaling_key = options.scaling_type .. "Scaling" | |||
-- 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] | ||
if (not hero_data["InDevelopment"] and not hero_data["IsDisabled"]) 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( | '|+ ' .. 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, '| ' .. | 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 | ||