[checked revision] | [checked revision] |
No edit summary |
No edit summary |
||
Line 12: | Line 12: | ||
trainee = { |
trainee = { |
||
long = 'trainee ', |
long = 'trainee ', |
||
− | short = ' |
+ | short = 'Trn/' |
}, |
}, |
||
[''] = { |
[''] = { |
||
Line 24: | Line 24: | ||
function h.getInfo(str, settings) |
function h.getInfo(str, settings) |
||
if str == '' then str = nil end |
if str == '' then str = nil end |
||
+ | h.parseRoleModifier(settings) |
||
settings.namelength = 'role' |
settings.namelength = 'role' |
||
if settings.sub then |
if settings.sub then |
||
Line 65: | Line 66: | ||
sortnumber = 70 |
sortnumber = 70 |
||
} |
} |
||
+ | if settings.staff then |
||
+ | settings.skipdefault = true |
||
+ | default = util_args.lookupVars('default_staff', LOOKUP) |
||
+ | end |
||
settings.vars = util_args.lookupVars(str, LOOKUP, settings.skipdefault) or settings.default or default |
settings.vars = util_args.lookupVars(str, LOOKUP, settings.skipdefault) or settings.default or default |
||
settings.name = settings.vars[settings.namelength] |
settings.name = settings.vars[settings.namelength] |
||
return |
return |
||
+ | end |
||
+ | |||
+ | function h.parseRoleModifier(settings) |
||
⚫ | |||
+ | if settings.modifier:lower() == 'sub' then |
||
+ | settings.sub = true |
||
+ | elseif settings.modifier:lower() == 'trainee' then |
||
+ | settings.trainee = true |
||
+ | end |
||
end |
end |
||
Line 78: | Line 92: | ||
local img = tbl:tag('div') |
local img = tbl:tag('div') |
||
:addClass('role-icon-sub-image') |
:addClass('role-icon-sub-image') |
||
− | h.printIcon(img, settings |
+ | h.printIcon(img, settings) |
h.printLetter(tbl, 'S') |
h.printLetter(tbl, 'S') |
||
elseif settings.trainee then |
elseif settings.trainee then |
||
local img = tbl:tag('div') |
local img = tbl:tag('div') |
||
:addClass('role-icon-sub-image') |
:addClass('role-icon-sub-image') |
||
− | h.printIcon(img, settings |
+ | h.printIcon(img, settings) |
h.printLetter(tbl, 'T') |
h.printLetter(tbl, 'T') |
||
else |
else |
||
− | h.printIcon(tbl, settings |
+ | h.printIcon(tbl, settings) |
end |
end |
||
return tbl |
return tbl |
||
end |
end |
||
− | function h.printIcon(tbl, |
+ | function h.printIcon(tbl, settings) |
− | tbl:wikitext(h.iconText( |
+ | tbl:wikitext(h.iconText(settings)) |
end |
end |
||
− | function h.iconText( |
+ | function h.iconText(settings) |
− | return ('[[File:%srole icon.png|%s|link=]]'):format( |
+ | return ('[[File:%srole icon.png|%s|%s|link=]]'):format( |
+ | settings.vars.store and settings.vars.role or 'Manager', |
||
+ | settings.vars.role, |
||
+ | settings.size or '15px' |
||
+ | ) |
||
end |
end |
||
Line 213: | Line 231: | ||
function p.medium(str, settings) |
function p.medium(str, settings) |
||
⚫ | |||
if not settings then settings = {} end |
if not settings then settings = {} end |
||
h.getInfo(str, settings) |
h.getInfo(str, settings) |
||
Line 227: | Line 244: | ||
local tbl = mw.html.create() |
local tbl = mw.html.create() |
||
tbl:wikitext(('%s%s'):format(PREPEND[settings.prepend].short, settings.name)) |
tbl:wikitext(('%s%s'):format(PREPEND[settings.prepend].short, settings.name)) |
||
+ | return tostring(tbl) |
||
+ | end |
||
+ | |||
+ | function p.rolenameright(str, settings) |
||
+ | if not settings then settings = {} end |
||
+ | h.getInfo(str, settings) |
||
+ | local tbl = mw.html.create() |
||
+ | h.addImage(tbl, settings) |
||
+ | tbl:wikitext((' %s%s'):format(PREPEND[settings.prepend].short, settings.name)) |
||
return tostring(tbl) |
return tostring(tbl) |
||
end |
end |
Revision as of 23:42, 17 February 2020
To edit the documentation or categories for this module, click here.
local util_args = require('Module:ArgsUtil')
local util_math = require('Module:MathUtil')
local util_table = require('Module:TableUtil')
local LOOKUP = mw.loadData('Module:Rolenames')
local PREPEND = {
sub = {
long = 'substitute ',
short = 'Sub/'
},
trainee = {
long = 'trainee ',
short = 'Trn/'
},
[''] = {
long = '',
short = ''
}
}
local h = {}
function h.getInfo(str, settings)
if str == '' then str = nil end
h.parseRoleModifier(settings)
settings.namelength = 'role'
if settings.sub then
settings.div = true
if str then
settings.sortnumber = 20
settings.prepend = 'sub'
settings.namelength = 'short'
else
settings.sortnumber = 10
settings.prepend = ''
str = 'substitute'
end
elseif settings.trainee then
settings.div = true
if str then
settings.sortnumber = 40
settings.prepend = 'trainee'
settings.namelength = 'short'
else
settings.sortnumber = 30
settings.prepend = ''
str = 'trainee'
end
else
if str then
settings.sortnumber = 10
settings.prepend = ''
else
str = ''
settings.prepend = ''
end
end
local default = {
adjective = str,
short = str,
role = str,
rolelc = string.lower(str or ''),
sentence = (str or '') .. ' for',
article = 'a',
sortnumber = 70
}
if settings.staff then
settings.skipdefault = true
default = util_args.lookupVars('default_staff', LOOKUP)
end
settings.vars = util_args.lookupVars(str, LOOKUP, settings.skipdefault) or settings.default or default
settings.name = settings.vars[settings.namelength]
return
end
function h.parseRoleModifier(settings)
if not settings.modifier then return end
if settings.modifier:lower() == 'sub' then
settings.sub = true
elseif settings.modifier:lower() == 'trainee' then
settings.trainee = true
end
end
function h.addImage(tbl, settings)
tbl:attr('title', settings.title or settings.vars.role)
:addClass('role-icon')
if settings.sub then
local img = tbl:tag('div')
:addClass('role-icon-sub-image')
h.printIcon(img, settings)
h.printLetter(tbl, 'S')
elseif settings.trainee then
local img = tbl:tag('div')
:addClass('role-icon-sub-image')
h.printIcon(img, settings)
h.printLetter(tbl, 'T')
else
h.printIcon(tbl, settings)
end
return tbl
end
function h.printIcon(tbl, settings)
tbl:wikitext(h.iconText(settings))
end
function h.iconText(settings)
return ('[[File:%srole icon.png|%s|%s|link=]]'):format(
settings.vars.store and settings.vars.role or 'Manager',
settings.vars.role,
settings.size or '15px'
)
end
function h.printLetter(tbl, letter)
if not letter then return end
tbl:tag('div'):addClass('role-icon-sub-s'):wikitext(letter)
end
local p = {}
function p.main(frame)
-- this should NEVER be called from Lua, only invoked from MW
local args = util_args.merge(true)
if not args[1] and not args.sub then
return ''
end
local style = args[2] or 'rolename'
return p[style](args[1], args)
end
function p.isplayer(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
return not settings.vars.notaplayer
end
function p.onlyimage(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = mw.html.create('div')
return tostring(h.addImage(tbl, settings))
end
function p.onlyimagestaff(str, settings)
if not settings then settings = {} end
settings.skipdefault = true
h.getInfo(str, settings)
local tbl = mw.html.create('div')
return tostring(h.addImage(tbl, settings))
end
function p.sentencemultiple(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = {
settings.vars.article,
PREPEND[settings.prepend].long,
settings.vars.sentence
}
return util_table.concat(tbl, ' ')
end
function p.rolelc(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
return settings.vars.rolelc
end
function p.article(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
return settings.vars.article
end
function p.sentence(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = {
PREPEND[settings.prepend].long,
settings.vars.sentence
}
return util_table.concat(tbl, ' ')
end
function p.sortnumber(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
return util_math.padleft((settings.vars.sortnumber) + (settings.sortnumber or 0), 2)
end
function p.roleonly(str, settings)
-- Ignores whether it's a sub or not
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = mw.html.create()
tbl:wikitext(settings.vars.role)
return tostring(tbl)
end
function p.shortname(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = mw.html.create()
tbl:wikitext(settings.vars.short)
return tostring(tbl)
end
function p.mediumname(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = mw.html.create()
tbl:wikitext(settings.vars.medium)
return tostring(tbl)
end
function p.portalname(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = mw.html.create()
tbl:wikitext(settings.vars.portal)
return tostring(tbl)
end
function p.medium(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
if settings.vars.notaplayer then return settings.vars.medium or str end
local tbl = mw.html.create()
tbl:wikitext(PREPEND[settings.prepend].short .. (settings.vars.medium or str))
return tostring(tbl)
end
function p.rolename(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = mw.html.create()
tbl:wikitext(('%s%s'):format(PREPEND[settings.prepend].short, settings.name))
return tostring(tbl)
end
function p.rolenameright(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
local tbl = mw.html.create()
h.addImage(tbl, settings)
tbl:wikitext((' %s%s'):format(PREPEND[settings.prepend].short, settings.name))
return tostring(tbl)
end
function p.storename(str, settings)
if not settings then settings = {} end
h.getInfo(str, settings)
return settings.vars.store
end
function p.default(str, settings)
-- deprecated, do not use pls ty
return p.rolename(str, settings)
end
return p