Module:Quest Chapter Act

local p = {} local lib = require('Module:Feature') local ne = lib.isNotEmpty local link_label = require('Module:Link Label')._main

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {		parentFirst = true,		wrappers = { 'Template:Quest Chapter Act' }	}) return p._main(args) end

function p._main(args) local out, cat = mw.html.create, mw.html.create local AQ1_AQ7 = false local AQ	local questType = args['type'] or '' local ch = args['chapter'] or '' local act = args['act'] or '' local part = args['part'] or 0 local event = args['event_name'] or '' local event_label = args['event_label'] or '' if questType == 'Archon' then if p.isRoman(ch) then AQ1_AQ7 = true AQ = true elseif ch == 'Prologue' or ch == 'Interlude Chapter' then AQ = true end end if ne(event) then out:wikitext(, (ne(event_label) and event_label or event), ) if ne(ch) then if questType == 'World' then out:wikitext(' Series ') else out:wikitext(' Chapter ') end end end --create output if ne(ch) and (AQ1_AQ7 or p.isRoman(ch)) then out:wikitext('Chapter ', ch, '') elseif ne(ch) then out:wikitext(link_label({ch})) end if args['actNum'] then if args['actNum'] == 'Prologue' then out:wikitext(': Prologue') else local actT = args['actType'] or 'Act' if (actT == 'None') then out:wikitext(': ', args['actNum']) else out:wikitext(': ', actT, ' ', args['actNum']) end end end if ne(act) then out:wikitext(' - ', link_label({act})) end if args['actName'] then out:wikitext(': ', args['actName']) end if args['actSuffix'] then out:wikitext(args['actSuffix']) end

--figure out categories and their sortkeys if AQ then pad_part = string.format('%02d', part) pad_act = string.format('%02d', p.RtN(args['actNum'])) pad_ch = string.format('%03d', p.RtN(ch)) if AQ1_AQ7 then ch = 'Chapter ' .. ch		elseif ch == 'Prologue' then pad_ch = '000' elseif ch == 'Interlude Chapter' then pad_ch = '00I' else pad_ch = 'ZZZ' end --tracking categories cat:wikitext('') cat:wikitext('') cat:wikitext('') cat:wikitext('' ) cat:wikitext('') cat:wikitext('') else if ne(event) then cat:wikitext('') end if ne(ch) and ch:find('Chapter') then cat:wikitext('') elseif ne(ch) and p.isRoman(ch) then cat:wikitext('') elseif ne(ch) then cat:wikitext('') end if ne(act) then cat:wikitext('') end local questPrefix = p.getQuestPrefix(args['type']) if questPrefix ~= '' then cat:wikitext('') else cat:wikitext('') end end

out:node(require('Module:Namespace detect').main{['main']=cat})

return out end

function p.RtN(num) if num == 'Prologue' then return 0 elseif num == 'Interlude Chapter' then return 99 else local roman_numerals = { I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000 }		if type(num) ~= 'string' then return -1, 'roman numeral not a string' end local rev = num:reverse local raising = true local last = 0 local result = 0 for i = 1, #rev do			local c = rev:sub(i, i)			local next = roman_numerals[c] if next == nil then return -1, 'roman numeral contains illegal character ' .. c end if next > last then result = result + next raising = true elseif next < last then result = result - next raising = false elseif raising then result = result + next else result = result - next end last = next end return tostring(result) end end

-- Very basic is roman numeral check without order validation function p.isRoman(text) if (lib.isEmpty(text)) then return false end local numerals = { 'M', 'D', 'C', 'L', 'X', 'V', 'I' } for _, i in pairs(lib.split(text, '')) do		local valid = false for _, j in pairs(numerals) do			if i:upper == j then valid = true end end if not valid then return false end end return true end

function p.getQuestPrefix(questType) if		questType == 'Archon' then return 'AQ' elseif	questType == 'Story' then return 'SQ' elseif	questType == 'World' then return 'WQ' else   return '' end end

return p