Module:Senate faction
From MicrasWiki
Jump to navigationJump to search
Documentation for this module may be created at Module:Senate faction/doc
local p = {}
local white = 'white'
local black = 'black'
local factions = {
['traditionalist'] = { a = 'T', n = 'Traditionalist', l = 'Traditionalist faction', f = '#3279a8', t = white },
['t'] = { a = 'T', n = 'Traditionalist', l = 'Traditionalist faction', f = '#3279a8', t = white },
['humanist'] = { a = 'H', n = 'Humanist', l = 'Humanist faction', f = '#B59410', t = black },
['h'] = { a = 'H', n = 'Humanist', l = 'Humanist faction', f = '#B59410', t = black },
['conservative'] = { a = 'C', n = 'Conservative', l = 'Conservative faction', f = '#00008B', t = white },
['c'] = { a = 'C', n = 'Conservative', l = 'Conservative faction', f = '#00008B', t = white },
['phineonesian'] = { a = 'P', n = 'Phineonesian', l = 'Phineonesian faction', f = '#ff5c39', t = black },
['p'] = { a = 'P', n = 'Phineonesian', l = 'Phineonesian faction', f = '#ff5c39', t = black },
['verionist'] = { a = 'V', n = 'Verionist', l = 'Verionist faction', f = '#000000', t = white },
['v'] = { a = 'V', n = 'Verionist', l = 'Verionist faction', f = '#000000', t = white },
['draconic humanist'] = { a = 'D', n = 'Draconic Humanist', l = 'Draconic Humanist faction', f = '#6AB023', t = black },
['d'] = { a = 'D', n = 'Draconic Humanist', l = 'Draconic Humanist faction', f = '#6AB023', t = black },
['no faction'] = { a = 'X', n = 'No faction', l = 'No faction', f = '#D3D3D3', t = black },
['x'] = { a = 'X', n = 'No faction', l = 'No faction', f = '#D3D3D3', t = black },
['ayreonist'] = { a = 'A', n = 'Ayreonist', l = 'Ayreonist faction', f = '#8B1A1A', t = white },
['a'] = { a = 'A', n = 'Ayreonist', l = 'Ayreonist faction', f = '#8B1A1A', t = white },
['united ayreonist–traditionalist'] = { a = 'U', n = 'United Ayreonist–Traditionalist', l = 'United Ayreonist–Traditionalist faction', f = '#5B3A8E', t = white },
['united ayreonist-traditionalist'] = { a = 'U', n = 'United Ayreonist–Traditionalist', l = 'United Ayreonist–Traditionalist faction', f = '#5B3A8E', t = white },
['u'] = { a = 'U', n = 'United Ayreonist–Traditionalist', l = 'United Ayreonist–Traditionalist faction', f = '#5B3A8E', t = white },
['einhornist'] = { a = 'E', n = 'Einhornist', l = 'Einhornist faction', f = '#30B7A4', t = black },
['e'] = { a = 'E', n = 'Einhornist', l = 'Einhornist faction', f = '#30B7A4', t = black },
}
function p.getFaction(frame)
local faction = mw.text.trim(frame.args[1] or '')
faction = mw.ustring.lower(faction)
if faction == 'demo' or faction == 'demonstration' then
return factions
end
if factions[faction] then
return factions[faction]
end
return { a = '?', n = 'Unknown faction', l = 'Faction', f = '#eeeeee', t = black }
end
function p.value(frame)
local faction = frame.args[1]
local field = frame.args[2]
if not faction or not field then
return ''
end
local data = p.getFaction{ args = { faction } }
if type(data) == 'table' then
return data[field] or ''
end
return ''
end
function p.demo(frame)
local rows = ''
local keys = {}
for key in pairs(factions) do
table.insert(keys, key)
end
table.sort(keys)
rows = rows .. mw.text.tag('tr', {},
mw.text.tag('th', {}, 'Code') ..
mw.text.tag('th', {}, 'Abbrev.') ..
mw.text.tag('th', {}, 'Faction') ..
mw.text.tag('th', {}, 'Link') ..
mw.text.tag('th', {}, 'Background') ..
mw.text.tag('th', {}, 'Text') ..
mw.text.tag('th', {}, 'Example')
)
for _, key in ipairs(keys) do
local f = factions[key]
local example = mw.text.tag(
'div',
{
style = 'background:' .. f.f .. '; color:' .. f.t .. '; text-align:center; padding:0.2em;'
},
f.a
)
rows = rows .. mw.text.tag('tr', {},
mw.text.tag('td', {}, key) ..
mw.text.tag('td', {}, f.a) ..
mw.text.tag('td', {}, f.n) ..
mw.text.tag('td', {}, '[[' .. f.l .. ']]') ..
mw.text.tag('td', {}, f.f) ..
mw.text.tag('td', {}, f.t) ..
mw.text.tag('td', {}, example)
)
end
return mw.text.tag('table', { class = 'wikitable sortable' }, rows)
end
return p