Module:Sandbox/One Bar: Difference between revisionsGive feedback
capitalization |
m Mgpt moved page Module:One Bar/Sandbox to Module:Sandbox/One Bar: Deadlock:User pages |
||
| (33 intermediate revisions by one other user not shown) | |||
| Line 2: | Line 2: | ||
local item_data = mw.loadJsonData("Data:ItemData.json") | local item_data = mw.loadJsonData("Data:ItemData.json") | ||
local heroes_data = mw.loadJsonData("Data:HeroData.json") | local heroes_data = mw.loadJsonData("Data:HeroData.json") | ||
local | local ability_data = mw.loadJsonData("Data:AbilityCards.json") | ||
local function | local function format_spirit_scale(frame, key, base, scale) | ||
local spirit_scale = frame:expandTemplate{ title = "ss", args = {(scale or 0)}} | |||
return key ..": ".. (base or 0) .. "+" .. spirit_scale .. "\n" | |||
end | end | ||
local function | local function get_stats_spirit_scaling(frame, hero) | ||
local spirit_scaling = hero["SpiritScaling"] | |||
stats_text = "" | |||
if (spirit_scaling ~= nil) then | |||
for k, v in pairs(spirit_scaling) do | |||
stats_text = stats_text .. format_spirit_scale(frame, k, hero[k], v) | |||
end | |||
else | |||
stats_text = "-" | |||
end | |||
return stats_text | |||
end | end | ||
local | local function get_abilities_spirit_scaling(frame, hero_key, hero) | ||
local ret = {} | |||
for i=1,4 do | |||
local ability = ability_data[hero_key][i] | |||
local ability_text = "" | |||
if (ability ~= nil) then | |||
ret[i*2-1] = ability["Name"] | |||
if (ability["Info1"] ~= nil and ability["Info1"]["Main"] ~= nil | |||
and ability["Info1"]["Main"]["Props"] ~= nil) then | |||
for _, prop in ipairs(ability["Info1"]["Main"]["Props"]) do | |||
if (prop["Scale"] ~= nil and prop["Scale"]["Type"] == "spirit" and prop["Scale"]["Value"] ~= 0) then | |||
ability_text = ability_text .. format_spirit_scale(frame, prop["Name"], prop["Value"], prop["Scale"]["Value"]) | |||
end | |||
end | |||
end | |||
else | |||
ret[i*2-1] = "-" | |||
end | |||
if (ability_text == "") then | |||
ability_text = "-" | |||
end | end | ||
ret[i*2] = ability_text | |||
end | end | ||
return | return ret | ||
end | end | ||
-- Outputs a wikitable of heroes and their stats' and abilities' spirit scaling | |||
local | -- @function p.write_spirit_scaling_table | ||
for | -- @param {} | ||
if ( | -- @return {string} | ||
table.insert( | p.write_spirit_scaling_table = function(frame) | ||
local filtered_heroes = {} | |||
local hero_keys = {} | |||
for hero_key, hero in pairs(heroes_data) do | |||
if (not hero["IsDisabled"] and not hero["InDevelopment"]) then | |||
local hero_data = {["hero"] = hero; ["hero_key"] = hero_key} | |||
table.insert(filtered_heroes, hero_data) | |||
end | end | ||
end | end | ||
table.sort(filtered_heroes, function(a, b) return a.hero.Name:lower() < b.hero.Name:lower() end) | |||
local | local create_table = mw.html.create("table"):addClass("wikitable sortable"):done() | ||
local | local header = mw.html.create("tr") | ||
header | |||
:tag("th"):wikitext("Hero"):done() | |||
:tag("th"):attr("colspan", 2):wikitext("First Skill"):done() | |||
:tag("th"):attr("colspan", 2):wikitext("Second Skill"):done() | |||
:tag("th"):attr(" | :tag("th"):attr("colspan", 2):wikitext("Third Skill"):done() | ||
:tag("th"):attr(" | :tag("th"):attr("colspan", 2):wikitext("Ultimate"):done() | ||
:tag("th"):attr(" | create_table:node(header) | ||
:tag("th"):attr("colspan", | |||
for _, | for _, hero_data in ipairs(filtered_heroes) do | ||
local | local hero = hero_data.hero | ||
local hero_key = hero_data.hero_key | |||
local | local hero_row = mw.html.create("tr") | ||
local | local hero_icon = frame:expandTemplate{ title = "HeroIcon", args = {hero["Name"]}} | ||
hero_row:tag('td'):wikitext(hero_icon):done() | |||
local abilities = get_abilities_spirit_scaling(frame, hero_key, hero) | |||
for i=1,8 do | |||
hero_row:tag('td'):wikitext(abilities[i]):done() | |||
for i, | |||
end | end | ||
create_table:node(hero_row) | |||
end | end | ||
return tostring( | return tostring(create_table) | ||
end | end | ||