Module:Sandbox/MoonOverMira/class attributes and Module:Sandbox/MoonOverMira/class attributes/sandbox: Difference between pages
(Difference between pages)
m (Vinifera7 moved page Module:Class attributes to Module:Sandbox/MoonOverMira/class attributes without leaving a redirect) |
m (Vinifera7 moved page Module:Class attributes/sandbox to Module:Sandbox/MoonOverMira/class attributes/sandbox without leaving a redirect) |
||
Line 13: | Line 13: | ||
errors = { | errors = { | ||
invalid_cols = 'Invalid columns. Only str, dex, and int are allowed.', | invalid_cols = 'Invalid columns. Only str, dex, and int are allowed.', | ||
}, | }, | ||
messages = {}, | messages = {}, | ||
char_class = { | char_class = { | ||
class = 'Class', | attr = 'Attribute →', | ||
class = 'Class ↓', | |||
total = 'Total', | total = 'Total', | ||
}, | }, | ||
Line 34: | Line 34: | ||
int = 'intelligence', | int = 'intelligence', | ||
} | } | ||
function h.link(page_name) | function h.link(page_name) | ||
-- Returns a wikitext internal link for the specified page name. | -- Returns a wikitext internal link for the specified page name. | ||
return string.format('[[%s]]', page_name) | return string.format('[[%s]]', page_name) | ||
end | end | ||
Line 61: | Line 45: | ||
function p._shared.class_tbl_head(cols, show_total) | function p._shared.class_tbl_head(cols, show_total) | ||
--[[ | --[[ | ||
Creates a table with a header for | Creates a table with a header for each specified attribute and the total, | ||
if desired. | |||
]] | ]] | ||
Line 70: | Line 54: | ||
tr:tag('th') | tr:tag('th') | ||
:wikitext(i18n.char_class. | :wikitext(i18n.char_class.attr) | ||
for _, col in ipairs(cols) do | for _, col in ipairs(cols) do | ||
tr:tag('th') | tr:tag('th') | ||
:wikitext(h. | :attr('rowspan', 2) | ||
:wikitext(h.link(h.col_to_attr[col])) | |||
end | end | ||
if show_total then | if show_total then | ||
tr:tag('th') | tr:tag('th') | ||
:attr('rowspan', 2) | |||
:wikitext(i18n.char_class.total) | :wikitext(i18n.char_class.total) | ||
end | end | ||
tbl | |||
:tag('tr') | |||
:tag('th') | |||
:wikitext(i18n.char_class.class) | |||
return tbl | return tbl | ||
end | end | ||
Line 104: | Line 93: | ||
end | end | ||
function p. | function p.character_class_table(frame) | ||
--[[ | --[[ | ||
Displays a table of character classes and their attributes. | Displays a table of all character classes and their attributes. | ||
cols is a comma-separated list of attributes to include as columns in the | cols is a comma-separated list of attributes to include as columns in the | ||
table. | table. | ||
Line 112: | Line 101: | ||
Examples | Examples | ||
-------- | -------- | ||
= p. | = p.character_class_table{cols='str,dex,int', show_total=True} | ||
]] | ]] | ||
Line 120: | Line 109: | ||
}) | }) | ||
frame = mw.getCurrentFrame() | frame = mw.getCurrentFrame() | ||
local | local show_table = tpl_args.show_table | ||
-- Validate cols arg | -- Validate cols arg | ||
local cols = mw.text.split(tpl_args.cols, ",") | |||
if #cols == 0 then | |||
error(i18n.errors.invalid_cols, tpl_args.cols) | error(i18n.errors.invalid_cols, tpl_args.cols) | ||
end | end | ||
for _, col in ipairs(cols) do | for _, col in ipairs(cols) do | ||
if h. | if h.col_to_attrs[col] == nil then | ||
error(i18n.errors.invalid_cols, tpl_args.cols) | error(i18n.errors.invalid_cols, tpl_args.cols) | ||
end | end | ||
end | end | ||
Line 143: | Line 125: | ||
-- Build output table | -- Build output table | ||
-- ------------------------------------------------------------------------ | -- ------------------------------------------------------------------------ | ||
local tbl = p._shared.class_tbl_head( | local tbl = p._shared.class_tbl_head() | ||
-- Each class gets a row | -- Each class gets a row | ||
for _, class in ipairs( | for _, class in ipairs(m_game.constants.characters_order) do | ||
local tr = tbl:tag('tr') | local tr = tbl:tag('tr') | ||
p._shared.class_row(tr | p._shared.class_row(tr, cols) | ||
end | end | ||
Line 178: | Line 141: | ||
return p | return p | ||