Module:Item table/weapon columns
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Item table/weapon columns/doc
local damage_display = require("Module:Damage display")
-- The default set and order of columns used unless otherwise specified.
local default_layout = {
"name_fancy",
"enchantment",
"damage",
"damage_type",
"weight",
"price",
"special"
}
-- The columns that can be displayed for the weapon table.
-- Each column must define the following information:
-- cargo_fields: The cargo fields that must be queried to fill out this column
-- name: The name of the column displayed in the the table header
-- formatter: A function that returns a <td> element ready to be inserted into the table
local columns = {
-- List of weapon properties like "Light", "Finesse", "Reach", etc.
properties = {
cargo_fields = {"category", "handedness", "finesse", "light", "reach", "thrown"},
name = "Properties",
formatter = function(weapon)
local wikitext = (weapon.category:gsub("^%l", string.upper))
.. "<br>" .. (weapon.handedness:gsub("^%l", string.upper))
if weapon.finesse == "1" then
wikitext = wikitext .. "<br>[[Finesse]]"
end
if weapon.light == "1" then
wikitext = wikitext .. "<br>[[Light (weapon property)|Light]]"
end
if weapon.reach == "1" then
wikitext = wikitext .. "<br>[[Extra Reach|Reach]]"
end
if weapon.thrown == "1" then
wikitext = wikitext .. "<br>[[Thrown]]"
end
return mw.html.create("td")
:wikitext(wikitext)
:css("text-align", "center")
end
},
type = {
cargo_fields = {"type"},
name = "Type",
formatter = function(weapon)
local wikitext = string.format("[[%s]]", weapon.type)
return mw.html.create("td")
:wikitext(wikitext)
:css("text-align", "center")
end
},
-- Simple damage display with color-coded damage text, but no fancy templates
-- If the weapon does multiple types of damage, each is displayed on a separate line
damage = {
cargo_fields = {
"damage", "damage_type",
"extra_damage", "extra_damage_type",
"extra_damage_2", "extra_damage_2_type"
},
name = "Damage",
formatter = function(weapon)
local elem = mw.html.create("td")
:css("text-align", "center")
elem:tag("span")
:addClass("bg3wiki-damage-type-" .. weapon.damage_type:lower())
:wikitext(weapon.damage)
if weapon.extra_damage_type then
elem:tag("span")
:addClass("bg3wiki-damage-type-" .. weapon.extra_damage_type:lower())
:wikitext("<br>" .. weapon.extra_damage)
end
if weapon.extra_damage_2_type then
elem:tag("span")
:addClass("bg3wiki-damage-type-" .. weapon.extra_damage_2_type:lower())
:wikitext("<br>" .. weapon.extra_damage_2)
end
return elem
end
},
-- Simple damage type display with color-coded damage text, but no fancy templates
-- If the weapon does multiple types of damage, each is displayed on a separate line
damage_type = {
cargo_fields = {
"damage_type",
"extra_damage_type",
"extra_damage_2_type"
},
name = "Damage<br>type",
formatter = function(weapon)
local elem = mw.html.create("td")
:css("text-align", "center")
elem:tag("span")
:addClass("bg3wiki-damage-type-" .. weapon.damage_type:lower())
:wikitext(weapon.damage_type)
if weapon.extra_damage_type then
elem:tag("span")
:addClass("bg3wiki-damage-type-" .. weapon.extra_damage_type:lower())
:wikitext("<br>" .. weapon.extra_damage_type)
end
if weapon.extra_damage_2_type then
elem:tag("span")
:addClass("bg3wiki-damage-type-" .. weapon.extra_damage_2_type:lower())
:wikitext("<br>" .. weapon.extra_damage_2_type)
end
return elem
end
},
-- Damage value/type combined field using the Damage display module.
damage_combined = {
cargo_fields = {
"damage", "damage_type",
"extra_damage", "extra_damage_type",
"extra_damage_2", "extra_damage_2_type"
},
name = "Damage",
formatter = function(weapon)
return mw.html.create("td")
:node(damage_display.main(mw.getCurrentFrame(), {
["damage 1"] = weapon.damage,
["damage 1 type"] = weapon.damage_type,
["damage 2"] = weapon.extra_damage,
["damage 2 type"] = weapon.extra_damage_type,
["damage 3"] = weapon.extra_damage_2,
["damage 3 type"] = weapon.extra_damage_2_type,
["dice size"] = 0,
["format"] = "nosummary"
}))
end
},
-- Fancy damage display using the Damage display module.
damage_fancy = {
cargo_fields = {
"damage", "damage_type",
"extra_damage", "extra_damage_type",
"extra_damage_2", "extra_damage_2_type"
},
name = "Damage",
formatter = function(weapon)
return mw.html.create("td")
:node(damage_display.main(mw.getCurrentFrame(), {
["damage 1"] = weapon.damage,
["damage 1 type"] = weapon.damage_type,
["damage 2"] = weapon.extra_damage,
["damage 2 type"] = weapon.extra_damage_type,
["damage 3"] = weapon.extra_damage_2,
["damage 3 type"] = weapon.extra_damage_2_type,
}))
end
},
-- Special properties including passives, unique weapon actions, etc.
special = {
cargo_fields = {
"weapon_passives",
"passives_main_hand",
"passives_off_hand",
"special",
"special_weapon_actions"
},
name = "Special",
formatter = function(weapon)
local frame = mw.getCurrentFrame()
local wikitext = ""
for passive in string.gmatch(weapon.weapon_passives or "", "[^,]+") do
wikitext = wikitext .. frame:expandTemplate{
title = "Passive",
args = { passive }
}
end
for passive in string.gmatch(weapon.passives_main_hand or "", "[^,]+") do
wikitext = wikitext .. "Main hand only:" .. frame:expandTemplate{
title = "Passive",
args = { passive }
}
end
for passive in string.gmatch(weapon.passives_off_hand or "", "[^,]+") do
wikitext = wikitext .. "Off-hand only:" .. frame:expandTemplate{
title = "Passive",
args = { passive }
}
end
if weapon.special then
wikitext = wikitext .. "\n" .. weapon.special .. "\n"
end
for weapon_action in string.gmatch(weapon.special_weapon_actions or "", "[^,]+") do
wikitext = wikitext .. frame:expandTemplate{
title = "Spell action",
args = { weapon_action }
}
end
return mw.html.create("td")
:tag("div")
:wikitext(wikitext)
:done()
end
},
}
-- Columns that apply to both weapons and equipment tables
local common_columns = require("Module:Item table/common columns")
for k, v in pairs(common_columns) do
columns[k] = v
end
return {
default = default_layout,
columns = columns
}