Editing Module:InfoboxHero

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 28: Line 28:
local dict_module = require('Module:Dictionary')
local dict_module = require('Module:Dictionary')
local hero_module = require('Module:HeroData')
local hero_module = require('Module:HeroData')
local sb_module  = require('Module:StreetBrawlAbilities')


-- Shared hero-data lookups, see [[Module:HeroData]].
local get_stat, has_stat, has_override_or_stat, stat_number
local get_stat     = hero_module.get_stat
local get_scalings = hero_module.get_scalings
local has_stat     = hero_module.has_stat
 
local has_override_or_stat, stat_number


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 190: Line 184:
link    = 'Health Regen',
link    = 'Health Regen',
icon    = 'Health regen.png',
icon    = 'Health regen.png',
sig_figs = 3,
sig_figs = 2,
},
},
{
{
Line 320: Line 314:
-- The "Information" block. Manual input only; hidden entirely when all are empty.
-- The "Information" block. Manual input only; hidden entirely when all are empty.
local INFO_ROWS = {
local INFO_ROWS = {
{ param = 'release_date', label_dict = 'ReleaseDate', link = 'Heroes by release' },
{ param = 'pronouns',    label_dict = 'Pronouns' },
{ param = 'pronouns',    label_dict = 'Pronouns' },
{ param = 'voice_actor',  label_dict = 'VoiceActor', link = 'Voice actors' },
{ param = 'voice_actor',  label_dict = 'VoiceActor' },
{ param = 'release_date', label_dict = 'ReleaseDate', link = 'Heroes by release' },
{ param = 'codenames',    label_dict = 'Codenames' },
{ param = 'codenames',    label_dict = 'Codenames', tooltip = 'Codenames used for this hero in the game files' },
}
}


-- name: literal, or function(ctx) -> string.  when: function(ctx) -> boolean.
-- name: literal, or function(ctx) -> string.  when: function(ctx) -> boolean.
local CATEGORIES = {
local CATEGORIES = {
    {
{ name = 'Heroes' },
        name = function(ctx) return ctx.is_disabled and 'Unused Heroes' or 'Heroes' end,
        always = true,
    },
{
{
name = function(ctx) return (ctx.args.name ~= '' and ctx.args.name) or ctx.hero_en end,
name = function(ctx) return ctx.hero_en end,
-- Silver (Transformed) is documented on Silver's page and shares her category.
-- Silver (Transformed) is documented on Silver's page and shares her category.
when = function(ctx) return ctx.hero_en ~= 'Silver (Transformed)' end,
when = function(ctx) return ctx.hero_en ~= 'Silver (Transformed)' end,
        always = true,
},
},
{
{
Line 441: Line 431:
return 'Heroes with medium dash speed'
return 'Heroes with medium dash speed'
end,
end,
},
{
name = 'Heroes with Street Brawl changes',
when = function(ctx) return sb_module.hero_has_changes(ctx.hero_key) end,
},
},
}
}
Line 451: Line 437:
-- Data access
-- Data access
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Stats live at the top level for vitality, and under .Weapon for weapon stats.
get_stat = function(hero, stat)
if hero == nil or stat == nil then return nil end
local value = hero[stat]
if value == nil and hero.Weapon then
value = hero.Weapon[stat]
if value == nil and hero.Weapon.AltFire then
value = hero.Weapon.AltFire[stat]
end
end
return value
end
-- The raw Boon (Level) and Spirit scaling values for a stat, if any.
local function get_scaling(hero, stat)
local out = {}
for _, scaling_type in ipairs({ 'Level', 'Spirit' }) do
local scaling = hero[scaling_type .. 'Scaling']
local value = scaling and stat and scaling[stat]
if value ~= nil and value ~= 0 then
out[#out + 1] = { type = scaling_type, value = value }
end
end
return out
end
-- True when the hero has a non-zero base value, or any scaling, for a stat.
has_stat = function(hero, stat)
local value = get_stat(hero, stat)
if value ~= nil and value ~= 0 then return true end
return #get_scaling(hero, stat) > 0
end


has_override_or_stat = function(ctx, param, stat)
has_override_or_stat = function(ctx, param, stat)
Line 523: Line 542:
if row.stat and row.scaling ~= false then
if row.stat and row.scaling ~= false then
local parts = {}
local parts = {}
for _, scaling in ipairs(get_scalings(ctx.hero, row.stat)) do
for _, scaling in ipairs(get_scaling(ctx.hero, row.stat)) do
parts[#parts + 1] = hero_module.write_scalar_str(scaling.value, scaling.type)
parts[#parts + 1] = hero_module.write_scalar_str(scaling.value, scaling.type)
end
end
Line 541: Line 560:
end
end
if row.link then
if row.link then
label_cell:wikitext(string.format('[[%s|<span class="infobox-h-stat-label">%s</span>]]:',
label_cell:wikitext(string.format('[[%s|<span>%s</span>]]:',
page_link(ctx, row.link), label_of(row)))
page_link(ctx, row.link), label_of(row)))
else
else
Line 597: Line 616:
local tr = tbl:tag('tr')
local tr = tbl:tag('tr')
local label = dict_module.translate(row.label_dict)
local label = dict_module.translate(row.label_dict)
if row.tooltip then
label = ctx.frame:expandTemplate{ title = 'Tooltip', args = { label, row.tooltip } }
end
if row.link then
if row.link then
tr:tag('td'):wikitext(string.format('[[%s|<span class="infobox-h-stat-label">%s</span>]]:',
tr:tag('td'):wikitext(string.format('[[%s|<span>%s</span>]]:',
page_link(ctx, row.link), label))
page_link(ctx, row.link), label))
else
else
Line 660: Line 676:
local tags = {}
local tags = {}
for i = 1, 3 do
for i = 1, 3 do
local tag = hero_module.hero_tag(ctx.hero_en, i)
local tag = hero_module.get_hero_tag({ args = { ctx.hero_en, tostring(i) } })
if tag ~= '' then
if tag and tag ~= '' and not tag:find('Error:', 1, true) then
tags[#tags + 1] = tag
tags[#tags + 1] = tag
end
end
Line 680: Line 696:
return ''
return ''
end
end
 
if get_stat(ctx.hero, 'IsDisabled') ~= false then return '' end
    local is_disabled = get_stat(ctx.hero, 'Name') == 'TargetDummy' or get_stat(ctx.hero, 'IsDisabled')
    ctx.is_disabled = is_disabled


local out = {}
local out = {}
for _, category in ipairs(CATEGORIES) do
for _, category in ipairs(CATEGORIES) do
        if is_disabled and not category.always then
if category.when == nil or category.when(ctx) then
elseif category.when == nil or category.when(ctx) then
local name = category.name
local name = category.name
if type(name) == 'function' then name = name(ctx) end
if type(name) == 'function' then name = name(ctx) end
Line 699: Line 712:
-- Entry point
-- Entry point
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- |key= accepts a hero_* key or the hero's English name; unknown values fall back
-- to the target dummy, the default character in Sandbox mode.
local function resolve_hero_key(provided)
if provided == nil or provided == '' then return DEFAULT_HERO_KEY end
if hero_data_all[provided] ~= nil then return provided end
local wanted = mw.ustring.lower(provided)
for key, hero in pairs(hero_data_all) do
if hero.Name and mw.ustring.lower(hero.Name) == wanted then return key end
end
return DEFAULT_HERO_KEY
end


function p.render(frame)
function p.render(frame)
Line 712: Line 737:
end })
end })


-- |key= accepts a hero_* key or the hero's English name; unknown values fall
local hero_key = resolve_hero_key(args.key)
-- back to the target dummy, the default character in Sandbox mode.
local hero_key = hero_module.find_hero_key(args.key) or DEFAULT_HERO_KEY
local hero = hero_data_all[hero_key]
local hero = hero_data_all[hero_key]


Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: