Module:Sandbox/Vergir: Difference between revisions

Vergir (talk | contribs)
Temporary probe: dump SpiritScaling entries from Data:HeroData.json (with help from vergir-bot LLM)
Vergir (talk | contribs)
Probe: avoid next() on mw.loadJsonData tables (with help from vergir-bot LLM)
Line 9: Line 9:
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')
-- next() ignores metamethods, and mw.loadJsonData tables are proxies, so
-- emptiness has to be tested through pairs().
local function sorted_keys(tbl)
local keys = {}
if tbl == nil then return keys end
for key in pairs(tbl) do table.insert(keys, key) end
table.sort(keys)
return keys
end


local function attr_label_key(stat)
local function attr_label_key(stat)
Line 20: Line 30:


function p.dump(frame)
function p.dump(frame)
local keys = {}
for hero_key, hero_data in pairs(heroes_data) do
local scaling = hero_data["SpiritScaling"]
if scaling ~= nil and next(scaling) ~= nil then
table.insert(keys, hero_key)
end
end
table.sort(keys)
local out = {}
local out = {}
local stats_seen = {}
local stats_seen = {}
for _, hero_key in ipairs(keys) 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 stat_keys = {}
local stat_keys = sorted_keys(hero_data["SpiritScaling"])
for stat in pairs(hero_data["SpiritScaling"]) do
if #stat_keys > 0 then
table.insert(stat_keys, stat)
local parts = {}
stats_seen[stat] = true
for _, stat in ipairs(stat_keys) do
stats_seen[stat] = true
local base = hero_data_module.get_stat(hero_data, stat)
table.insert(parts, stat .. '=' .. tostring(hero_data["SpiritScaling"][stat]) ..
' (base ' .. tostring(base) .. ')')
end
table.insert(out, '* <code>' .. hero_key .. '</code> ' .. tostring(hero_data["Name"]) ..
' [dev=' .. tostring(hero_data["InDevelopment"]) ..
' disabled=' .. tostring(hero_data["IsDisabled"]) ..
' labs=' .. tostring(hero_data["InHeroLabs"]) ..
' selectable=' .. tostring(hero_data["IsSelectable"]) .. ']: ' ..
table.concat(parts, ', '))
end
end
table.sort(stat_keys)
local parts = {}
for _, stat in ipairs(stat_keys) do
local base = hero_data_module.get_stat(hero_data, stat)
table.insert(parts, stat .. '=' .. tostring(hero_data["SpiritScaling"][stat]) ..
' (base ' .. tostring(base) .. ')')
end
table.insert(out, '* <code>' .. hero_key .. '</code> ' .. tostring(hero_data["Name"]) ..
' [dev=' .. tostring(hero_data["InDevelopment"]) ..
' disabled=' .. tostring(hero_data["IsDisabled"]) ..
' labs=' .. tostring(hero_data["InHeroLabs"]) ..
' selectable=' .. tostring(hero_data["IsSelectable"]) .. ']: ' ..
table.concat(parts, ', '))
end
end
local stat_list = {}
for stat in pairs(stats_seen) do table.insert(stat_list, stat) end
table.sort(stat_list)


table.insert(out, '')
table.insert(out, '')
table.insert(out, 'Label resolution per stat:')
table.insert(out, 'Label resolution per stat:')
for _, stat in ipairs(stat_list) do
for _, stat in ipairs(sorted_keys(stats_seen)) do
local label_key, postfix_key = attr_label_key(stat)
local label_key, postfix_key = attr_label_key(stat)
local lang_str = label_key and lang_module.get_string(label_key) or ''
local lang_str = label_key and lang_module.get_string(label_key) or ''