Module:InfoboxHero: Difference between revisionsGive feedback
add tooltips (the fancy template style) |
Gammaton32 (talk | contribs) round health regen to 3 figs |
||
| (9 intermediate revisions by 4 users not shown) | |||
| 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') | |||
local get_stat | -- Shared hero-data lookups, see [[Module:HeroData]]. | ||
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 184: | Line 190: | ||
link = 'Health Regen', | link = 'Health Regen', | ||
icon = 'Health regen.png', | icon = 'Health regen.png', | ||
sig_figs = | sig_figs = 3, | ||
}, | }, | ||
{ | { | ||
| Line 314: | Line 320: | ||
-- 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 = 'pronouns', label_dict = 'Pronouns' }, | |||
{ param = 'voice_actor', label_dict = 'VoiceActor', link = 'Voice actors' }, | |||
{ param = 'release_date', label_dict = 'ReleaseDate', link = 'Heroes by release' }, | { param = 'release_date', label_dict = 'ReleaseDate', link = 'Heroes by release' }, | ||
{ param = 'codenames', label_dict = 'Codenames', tooltip = 'Codenames used for this hero in the game files' }, | { param = 'codenames', label_dict = 'Codenames', tooltip = 'Codenames used for this hero in the game files' }, | ||
} | } | ||
| Line 322: | Line 328: | ||
-- 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 = function(ctx) return ctx.is_disabled and 'Unused Heroes' or 'Heroes' end, | |||
always = true, | |||
}, | |||
{ | { | ||
name = function(ctx) return ctx.hero_en end, | name = function(ctx) return (ctx.args.name ~= '' and ctx.args.name) or 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 431: | Line 441: | ||
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 437: | Line 451: | ||
-- Data access | -- Data access | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
has_override_or_stat = function(ctx, param, stat) | has_override_or_stat = function(ctx, param, stat) | ||
| Line 542: | Line 523: | ||
if row.stat and row.scaling ~= false then | if row.stat and row.scaling ~= false then | ||
local parts = {} | local parts = {} | ||
for _, scaling in ipairs( | for _, scaling in ipairs(get_scalings(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 560: | Line 541: | ||
end | end | ||
if row.link then | if row.link then | ||
label_cell:wikitext(string.format('[[%s|<span>%s</span>]]:', | label_cell:wikitext(string.format('[[%s|<span class="infobox-h-stat-label">%s</span>]]:', | ||
page_link(ctx, row.link), label_of(row))) | page_link(ctx, row.link), label_of(row))) | ||
else | else | ||
| Line 620: | Line 601: | ||
end | end | ||
if row.link then | if row.link then | ||
tr:tag('td'):wikitext(string.format('[[%s|<span>%s</span>]]:', | tr:tag('td'):wikitext(string.format('[[%s|<span class="infobox-h-stat-label">%s</span>]]:', | ||
page_link(ctx, row.link), label)) | page_link(ctx, row.link), label)) | ||
else | else | ||
| Line 679: | Line 660: | ||
local tags = {} | local tags = {} | ||
for i = 1, 3 do | for i = 1, 3 do | ||
local tag = hero_module. | local tag = hero_module.hero_tag(ctx.hero_en, i) | ||
if | if tag ~= '' then | ||
tags[#tags + 1] = tag | tags[#tags + 1] = tag | ||
end | end | ||
| Line 699: | Line 680: | ||
return '' | return '' | ||
end | 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 | |||
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 715: | Line 699: | ||
-- Entry point | -- Entry point | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
function p.render(frame) | function p.render(frame) | ||
| Line 740: | Line 712: | ||
end }) | end }) | ||
local hero_key = | -- |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 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] | ||