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'):addClass('s') 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(mode, ph, hm, pp, hardmode_only, sep, prefix, postfix, class) local span = mw.html.create('span'):addClass(class):addClass(mode) local needsep = false if hardmode_only and not pp then prefix = false postfix = false end if not hardmode_only then local s = modestat(prefix, postfix, ph, 'ph') if hm then s:attr('title', l10n('title_ph')) end span:node(s) needsep = true end if hm then if needsep and sep then span:tag('span'):addClass('sep'):wikitext(sep) end span:node(modestat(prefix, postifx, hm, 'hm'):attr('title', l10n('title_hm'))) needsep = true end if pp then if needsep and sep then span:tag('span'):addClass('sep'):wikitext(sep) 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']

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 not(normal or expert or epxert_hm or expert_pp or master or master_hm or master_pp) then return end

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

if master_pp == master_hm then master_pp = nil end if not master_pp and master_hm == master then master_hm = nil end if expert_pp == expert_hm then expert_pp = nil end if not expert_pp and expert_hm == expert then expert_hm = nil end if hardmode_only then if not expert_hm then epxert_hm = expert end if not master_hm then master_hm = master 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 expert == normal then expert = nil end end

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

local output = mw.html.create('span'):addClass('npcstat') if prefix then output:addClass('prefix') end if postfix then output:addClass('postfix') end

if not expert_only 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', expert, expert_hm, expert_pp, hardmode_only, sep2, 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', master, master_hm, master_pp, hardmode_only, sep2, prefix, postfix, 'm-master')) end return output end, -- end mode.stats

} -- end return p