Module:Npcstat

--- l10n info -- local l10n_info = mw.loadData('Module:Npcstat/l10n')

--- The following is not related to l10n. -- local trim = mw.text.trim

local currentFrame local args_table local lang local l10n_table

local l10n = function(key) return l10n_table[key] or l10n_info['en'][key] end

local getArg = function(key) local value = args_table[key] if not value then return nil end value = trim(value) if value == '' then return nil end return value end

local function modestat(prefix, postfix, content, mode) local span = mw.html.create('span') if prefix then span.tag('span'):addClass('prefix'):wikitext(l10n('prefix_'..mode)) end span.wikitext(content) if postfix then span.tag('span'):addClass('postfix'):wikitext(l10n('postfix_'..mode)) end return span end

local function mode(output, mode, ph, hm, pp, hardmode_only, prefix, postfix, class) local span = mw.html.create('span'):addClass(class):addClass(mode) if not hardmodeonly then local s = modestat(prefix, postfix, ph, 'ph') if hm then s:attr('title', l10n('title_ph')) end span.node(s) end if hm then if sep2 then span:tag('span'):addClass('sep'):wikitext(sep2) end span.node(modestat(prefix, postifx, hm, 'hm'):attr('title', l10n('title_hm'))) end if pp then if sep2 then span:tag('span'):addClass('sep'):wikitext(sep2) end span.node(modestat(prefix, postifx, pp, 'pp'):attr('title', l10n('title_pp'))) end return span end

return {

format = function(frame, args) --cache something currentFrame = frame args_table = args or frame.args lang = getArg('lang') or 'en' l10n_table = l10n_info[lang] or l10n_info['en']

-- exclusive local expert_only = getArg('expertonly') local hardmode_only = getArg('hardmodeonly')

local normal = getArg(1) local expert, expert_hm, expert_pp = getArg(2), getArg(3), getArg(4) local master, master_hm, master_pp = getArg(5), getArg(6), getArg(7) if master_hm == master_pp then master_pp = nil end if not master_pp then if not hardmodeonly and master == master_hm then master_hm = nil end end if expert_hm == expert_pp then expert_pp = nil end if not expert_pp then if not hardmodeonly and expert == expert_hm then expert_hm = nil end end if expert == master and expert_hm == master_hm and expert_pp == master_pp then master, master_hm, master_pp = nil, nil, nil end if not expert_hm and not master then if normal == expert then expert = nil end end

--output: local needsep = false local prefix = getArg('prefix') local postfix = getArg('postfix') local sep, sep2 = getArg('sep'), arg_table['sep2'] if not sep2 and not prefix and not postfix then sep2 = '›' end

local output = mw.html.create('span'):addClass('npcstat') if not expertonly then output:tag('span'):addClass(expert and 'm-normal' or 'm-all'):wikitext(normal) needsep = true end if expert then if needsep and sep then output:tag('span'):addClass('ssep'):wikitext(sep) end output:node(mode('expert', ph, hm, pp, hardmode_only, prefix, postfix, (master and 'm-expert' or 'm-expert-master'))) needsep = true end if master then if needsep and sep then output:tag('span'):addClass('ssep'):wikitext(sep) end output:node(mode('master', ph, hm, pp, hardmode_only, prefix, postfix, 'm-master')) end end, -- end mode.stats

} -- end return p