Module:Sandbox/Vergir: Difference between revisionsGive feedback
Test draft: generic StatScaling builder, base + scaling cells (with help from vergir-bot LLM) |
Final test draft of StatScaling before publishing (with help from vergir-bot LLM) |
||
| Line 4: | Line 4: | ||
-- Each public function below renders one table. The shared work lives in | -- Each public function below renders one table. The shared work lives in | ||
-- build_scaling_table(), so adding a table for another scaling type (Boons, | -- build_scaling_table(), so adding a table for another scaling type (Boons, | ||
-- for instance) only takes a new wrapper naming its | -- for instance) only takes a new wrapper naming its scaling type. | ||
-- | -- | ||
-- {{#invoke:Sandbox/Vergir|write_spirit_scaling_table}} | -- {{#invoke:Sandbox/Vergir|write_spirit_scaling_table}} | ||
| Line 15: | 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') | ||
-- Never listed: both are derived from the weapon stats that are already | |||
-- listed in their own right, so they only ever duplicate a row. | |||
local EXCLUDED_STATS = { | |||
DPS = true, | |||
SustainedDPS = true, | |||
} | |||
-- Per stat handling of the base value shown before the scaling. | |||
-- text: printed verbatim, for stats the data holds no base value for | |||
-- sig_figs: rounds an over-precise base value | |||
local BASE_DISPLAY = { | |||
BulletResist = {text = "0%"}, | |||
TechResist = {text = "0%"}, | |||
RoundsPerSecond = {sig_figs = 3}, | |||
} | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 28: | Line 44: | ||
table.sort(keys) | table.sort(keys) | ||
return keys | return keys | ||
end | end | ||
| Line 70: | Line 78: | ||
end | end | ||
-- "6.3 + x0.0084", or | -- Base value as displayed, or nil when the stat has none to show. | ||
local function base_value(hero_data, stat) | |||
local display = BASE_DISPLAY[stat] | |||
if (display ~= nil and display.text ~= nil) then return display.text end | |||
local base = hero_data_module.get_stat(hero_data, stat) | |||
if (type(base) ~= "number") then return nil end | |||
if (display ~= nil and display.sig_figs ~= nil) then | |||
base = util_module.round_to_sig_fig(base, display.sig_figs) | |||
end | |||
return tostring(base) | |||
end | |||
-- "6.3 + x0.0084", or the scaling alone when there is no base value to show. | |||
local function scaling_cell(hero_data, stat, value, scaling_type) | local function scaling_cell(hero_data, stat, value, scaling_type) | ||
local scaling_str = hero_data_module.write_scalar_str(value, scaling_type) | local scaling_str = hero_data_module.write_scalar_str(value, scaling_type) | ||
local base = | local base = base_value(hero_data, stat) | ||
if | if (base == nil) then return scaling_str end | ||
return base .. ' + ' .. scaling_str | return base .. ' + ' .. scaling_str | ||
end | end | ||
| Line 82: | Line 102: | ||
-- zeroes, ordered by localized stat name: | -- zeroes, ordered by localized stat name: | ||
-- { { stat = , label = , value = }, ... } | -- { { stat = , label = , value = }, ... } | ||
local function hero_scalings(hero_data, scaling_key | local function hero_scalings(hero_data, scaling_key) | ||
local scalings = {} | local scalings = {} | ||
local hero_scaling_data = hero_data[scaling_key] | local hero_scaling_data = hero_data[scaling_key] | ||
for _, stat in ipairs(sorted_keys(hero_scaling_data)) do | for _, stat in ipairs(sorted_keys(hero_scaling_data)) do | ||
local value = hero_scaling_data[stat] | local value = hero_scaling_data[stat] | ||
if (not | 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}) | ||
end | end | ||
| Line 102: | Line 122: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- scaling_type: "Spirit" or "Level", picking both the <type>Scaling data key | ||
-- and the scaling template ({{Ss}} or {{PI}}). | |||
-- | local function build_scaling_table(scaling_type) | ||
local scaling_key = scaling_type .. "Scaling" | |||
local function build_scaling_table( | |||
local scaling_key = | |||
-- Collect the heroes that have anything | -- Collect the heroes that have anything to show | ||
local rows = {} | local rows = {} | ||
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 | if (not hero_data["InDevelopment"] and not hero_data["IsDisabled"]) then | ||
local scalings = hero_scalings(hero_data, scaling_key | local scalings = hero_scalings(hero_data, scaling_key) | ||
if (#scalings > 0) then | if (#scalings > 0) then | ||
table.insert(rows, { | table.insert(rows, { | ||
| Line 131: | Line 148: | ||
-- Build the table | -- Build the table | ||
local output = { | local output = { | ||
'{| class="wikitable"' | '{| class="wikitable sortable"', | ||
'! ' .. dictionary_module.translate("Hero"), | '! ' .. dictionary_module.translate("Hero"), | ||
'! ' .. dictionary_module.translate("Stats"), | '! ' .. dictionary_module.translate("Stats"), | ||
| Line 141: | Line 157: | ||
table.insert(output, '|-') | table.insert(output, '|-') | ||
if (index == 1) then | if (index == 1) then | ||
local | local attributes = 'data-sort-value="' .. row.sort_name .. '"' | ||
if (#row.scalings > 1) then | if (#row.scalings > 1) then | ||
table.insert(output, '|' .. | attributes = attributes .. ' rowspan="' .. #row.scalings .. '"' | ||
end | |||
table.insert(output, '| ' .. attributes .. ' | ' .. hero_icon(row.key, row.data)) | |||
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, scaling_type)) | ||
end | end | ||
end | end | ||
| Line 160: | Line 177: | ||
-- Hero base stats that scale with Spirit Power. | -- Hero base stats that scale with Spirit Power. | ||
--{{#invoke:Sandbox/Vergir|write_spirit_scaling_table | --{{#invoke:Sandbox/Vergir|write_spirit_scaling_table}} | ||
function p.write_spirit_scaling_table(frame) | function p.write_spirit_scaling_table(frame) | ||
return build_scaling_table("Spirit") | |||
return build_scaling_table | |||
end | end | ||
return p | return p | ||