Module:HeroStats2/Infobox
Jump to navigation
Jump to search
Documentation
[purge]
This module renders infoboxes for Heroes in Darkest Dungeon II.
There are two API functions, render
and query
, both with Lua and Wikitext variants. The primary point of access is the _query
function; other functions mostly exist for testing purposes.
render and _render
Renders the given hero data into an infobox. In addition to all the hero attributes (see Template:HeroStats2/Add), it also accepts the following parameters:
(stat)_cdf
: numeric, for each stat. E.g.hp_cdf
orupgraded_bleed_cdf
. This (optional) value determines the colour of the displayed stat._pageName
: string. This is used to generate an edit link for entries that are loaded from Cargo. (Click on the small "+" button to view it.)
default_name
and permanent_conditions
are both optional.
Examples
Test Custom Hero | ||
---|---|---|
Default Name | ||
Test Default Name | ||
Stats | ||
Base | Upgraded | |
HP | 1 | 1 |
Speed | 3 | 4 |
Resistances | ||
Bleed | 5% | 6% |
Blight | 7% | 8% |
Burn | 9% | 9% |
Disease | 17% | 18% |
Stun | 11% | 12% |
Move | 13% | 14% |
Debuff | 15% | 15% |
Deathblow | 19% | 19% |
Low ▪ Medium ▪ High ▪ Upgraded | ||
Movement | ||
21 forward, 22 backward | ||
Permanent Condition(s) | ||
No Optionals | |
---|---|
Stats | |
HP | 1 |
Speed | 3 |
Resistances | |
Bleed | 5% |
Blight | 7% |
Burn | 9% |
Disease | 17% |
Stun | 11% |
Move | 13% |
Debuff | 15% |
Deathblow | 19% |
Low ▪ Medium ▪ High |
query and _query
As above, but fetches the data from Cargo instead of using arguments.
Examples
Bounty Hunter | |
---|---|
Stats | |
HP | 48 |
Speed | 3 |
Resistances | |
Bleed | 30% |
Blight | 30% |
Burn | 30% |
Disease | 40% |
Stun | 40% |
Move | 30% |
Debuff | 40% |
Deathblow | 75% |
Low ▪ Medium ▪ High | |
Movement | |
2 forward, 2 backward | |
Permanent Condition(s) | |
Grave Robber | ||
---|---|---|
Default Name | ||
Audrey | ||
Stats | ||
Base | Upgraded | |
HP | 29 | 29 |
Speed | 5 | 7 |
Resistances | ||
Bleed | 30% | 30% |
Blight | 30% | 40% |
Burn | 30% | 30% |
Disease | 30% | 30% |
Stun | 20% | 20% |
Move | 20% | 20% |
Debuff | 30% | 30% |
Deathblow | 60% | 75% |
Low ▪ Medium ▪ High ▪ Upgraded | ||
Movement | ||
2 forward, 2 backward |
Leper | ||
---|---|---|
Default Name | ||
Baldwin | ||
Stats | ||
Base | Upgraded | |
HP | 44 | 52 |
Speed | 2 | 2 |
Resistances | ||
Bleed | 10% | 10% |
Blight | 10% | 10% |
Burn | 20% | 20% |
Disease | 30% | 30% |
Stun | 30% | 30% |
Move | 20% | 30% |
Debuff | 20% | 20% |
Deathblow | 60% | 75% |
Low ▪ Medium ▪ High ▪ Upgraded | ||
Movement | ||
1 forward | ||
Permanent Condition(s) | ||
local Cargo = mw.ext.cargo
local Histogram = require("Module:Histogram")
local Utils = require("Module:HeroStats2/Utils")
local UPGRADE_LINK = "[[Altar of Hope/The Living City#%s|Upgraded]]"
local COMPARE_LINK = "[[Heroes (Darkest Dungeon II)#Stats|[Compare Stats]]]"
local EDIT_LINK = "[[%s|[View/Edit Data]]]"
local function _render(hero)
local has_upgrade = false
for _, stat in ipairs(Utils.BASE_STATS) do
if hero[stat.name] ~= hero[stat.upgraded.name] then
has_upgrade = true
end
end
local colspan = has_upgrade and 3 or 2
local infobox = mw.html.create("table")
:addClass("char-box-2")
infobox:tag("tr"):tag("th"):attr("colspan", colspan)
:wikitext(hero.name)
infobox:tag("tr"):tag("td"):attr("colspan", colspan)
:addClass("ctr")
:wikitext(("[[File:%s|250px]]"):format(hero.image))
if hero.default_name then
infobox:tag("tr"):tag("th"):attr("colspan", colspan)
:wikitext("Default Name")
infobox:tag("tr"):tag("td"):attr("colspan", colspan)
:addClass("ctr")
:wikitext(("''%s''"):format(hero.default_name))
end
local stat_links = {COMPARE_LINK}
if hero._pageName ~= nil then
table.insert(stat_links, EDIT_LINK:format(hero._pageName))
end
infobox:tag("tr"):tag("th"):attr("colspan", colspan)
:addClass("mw-collapsible")
:addClass("mw-collapsed")
:attr("data-expandtext", "+")
:attr("data-collapsetext", "-")
:wikitext("Stats")
:tag("div")
:addClass("mw-collapsible-content")
:tag("small")
:wikitext(table.concat(stat_links, " "))
if has_upgrade then
local stats_header = infobox:tag("tr")
stats_header:tag("td")
:addClass("char-stat-label-2")
stats_header:tag("td")
:addClass("char-stat-label-2")
:wikitext("Base")
stats_header:tag("td")
:addClass("char-stat-label-2")
:wikitext(UPGRADE_LINK:format(hero.name))
end
for _, stat in ipairs(Utils.BASE_STATS) do
local row = infobox:tag("tr")
row:tag("td")
:addClass("char-stat-label-2")
:wikitext(stat:long_label())
row:node(stat:create_cell(hero))
if has_upgrade then
local upgraded_cell = stat.upgraded:create_cell(hero)
if hero[stat.name] ~= hero[stat.upgraded.name] then
upgraded_cell:addClass("char-stat-upgraded-2")
end
row:node(upgraded_cell)
end
if stat.name == "speed" then
infobox:tag("tr"):tag("th"):attr("colspan", colspan)
:wikitext("Resistances")
end
end
local color_daemon = Utils.STATS[1]
local key = infobox:tag("tr"):tag("td")
:attr("colspan", colspan)
:addClass("char-stat-key-2")
key:tag("span"):css("color", color_daemon:to_color(0))
:wikitext("Low")
key:wikitext(" ▪ ")
key:tag("span"):css("color", color_daemon:to_color(0.5))
:wikitext("Medium")
key:wikitext(" ▪ ")
key:tag("span"):css("color", color_daemon:to_color(1))
:wikitext("High")
if has_upgrade then
key:wikitext(" ▪ ")
key:tag("span"):addClass("char-stat-upgraded-2")
:wikitext("Upgraded")
end
local movement = {}
if hero.forward > 0 then
table.insert(movement, hero.forward .. " forward")
end
if hero.backward > 0 then
table.insert(movement, hero.backward .. " backward")
end
if #movement > 0 then
infobox:tag("tr"):tag("th")
:attr("colspan", colspan)
:wikitext("Movement")
infobox:tag("tr"):tag("td")
:attr("colspan", colspan)
:addClass("ctr")
:wikitext(table.concat(movement, ", "))
end
if hero.permanent_conditions then
local frame = mw.getCurrentFrame()
infobox:tag("tr"):tag("th")
:attr("colspan", colspan)
:addClass("ctr")
:wikitext("Permanent Condition(s)")
infobox:tag("tr"):tag("td")
:attr("colspan", colspan)
:tag("div")
:addClass("char-conditions-2")
:wikitext(frame:preprocess(hero.permanent_conditions))
end
return infobox
end
local function _query(name)
local fields = {
"_pageName", -- for edit links
"name",
"image",
"default_name",
"forward",
"backward",
"permanent_conditions"
}
for _, stat in ipairs(Utils.STATS) do
table.insert(fields, stat.name)
end
local data = Cargo.query(
"HeroStats2",
table.concat(fields, ","),
{where=("name='%s'"):format(name)}
)
if #data == 0 then
return ('Could not find data for hero "%s".'):format(name)
end
local hero = Utils._parse_hero(data[1])
local hs = Histogram._load_table("HeroStats2Histograms")
for _, stat in ipairs(Utils.STATS) do
hero[stat.name .. "_cdf"] = Histogram._interpolate_cdf(
hs[stat.name], hero[stat.name])
end
return _render(hero)
end
local function render(frame)
return _render(Utils._parse_hero(frame.args))
end
local function query(frame)
return _query(frame.args[1])
end
return {
render=render,
_render=_render,
query=query,
_query=_query
}