Module:Item table/equipment columns
From bg3.wiki
More actions
Documentation for this module may be created at Module:Item table/equipment columns/doc
-- The default set and order of columns used unless otherwise specified.
local default_layout = {
"name_fancy",
"type",
"weight",
"price",
"special"
}
-- The columns specific to equipment tables.
-- 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 = {
-- Item type, e.g. Amulet, Ring, Cloak, etc.
-- Also specifies required proficiency if it is not obvious.
type = {
cargo_fields = {"type", "proficiency"},
name = "Type",
formatter = function(item)
local wikitext = string.format("[[%s]]", item.type)
if item.proficiency and item.proficiency ~= "" and item.proficiency ~= item.type then
wikitext = wikitext .. string.format("<br>(%s)", item.proficiency)
end
return mw.html.create("td")
:wikitext(wikitext)
:css("text-align", "center")
end
},
-- The item's armour class. This includes base AC from armours and also AC bonuses from other items like robes.
armour_class = {
cargo_fields = {"armour_class", "armour_class_bonus"},
name = "Armour<br>Class",
formatter = function(item)
local wikitext = ""
if item.armour_class ~= nil and item.armour_class ~= "" then
wikitext = item.armour_class
elseif item.armour_class_bonus ~= nil and item.armour_class_bonus ~= "" then
wikitext = item.armour_class_bonus
end
return mw.html.create("td")
:wikitext(wikitext)
:css("text-align", "center")
end
},
-- Stealth disadvantage property found on medium/heavy armours
stealth_disadvantage = {
cargo_fields = {"stealth_disadvantage"},
name = "Stealth<br>disadvantage",
formatter = function(item)
local wikitext = "No"
if item.stealth_disadvantage == "1" then
wikitext = "Yes"
end
return mw.html.create("td")
:wikitext(wikitext)
:css("text-align", "center")
end
},
-- Special properties such as passives
special = {
cargo_fields = {
"passives",
"special",
},
name = "Special",
formatter = function(item)
local frame = mw.getCurrentFrame()
local wikitext = ""
if item.special then
wikitext = wikitext .. "\n" .. item.special .. "\n"
end
for passive in string.gmatch(item.passives or "", "[^,]+") do
wikitext = wikitext .. frame:expandTemplate{
title = "Passive",
args = { passive }
}
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
}