User:Harimaron/Sandbox/Module:NewsDialogue

local p = { paramprefixes = { ['A'] = {['allowed'] = {'Splatoon', 'Splatoon 2', 'Splatoon 3'}, ['chr'] = 'A'}, ['B'] = {['allowed'] = {'Splatoon', 'Splatoon 2', 'Splatoon 3'}, ['chr'] = 'B'}, ['C'] = {['allowed'] = {'Splatoon'                            }, ['chr'] = 'A'}, ['M'] = {['allowed'] = {'Splatoon', 'Splatoon 2'              }, ['chr'] = 'B'}, ['P'] = {['allowed'] = {            'Splatoon 2'              }, ['chr'] = 'A'}, ['S'] = {['allowed'] = {                          'Splatoon 3'}, ['chr'] = 'A'}, ['F'] = {['allowed'] = {                          'Splatoon 3'}, ['chr'] = 'B'}, ['FR'] = {['allowed'] = {                         'Splatoon 3'}, ['chr'] = 'B'}, ['FL'] = {['allowed'] = {                         'Splatoon 3'}, ['chr'] = 'B'}, ['BML']= {['allowed'] = {                         'Splatoon 3'}, ['chr'] = 'C'}, ['BM'] = {['allowed'] = {                         'Splatoon 3'}, ['chr'] = 'C'} },   lpriority = { ['Splatoon'] =  {'C', 'A', 'P', 'S', 'FL'}, ['Splatoon 2'] = {'P', 'A', 'C', 'S', 'FL'}, ['Splatoon 3'] = {'S', 'FL', 'BML', 'A', 'C', 'P'} },   rpriority = { ['Splatoon'] =  {'M', 'B', 'BM', 'FR', 'F'}, ['Splatoon 2'] = {'M', 'B', 'BM', 'FR', 'F'}, ['Splatoon 3'] = {'BM', 'FR', 'F', 'B', 'M'} } }

function p:IsAllowed(prefix, game) local prefixdata = self.paramprefixes[prefix] if prefixdata then for _, v in pairs(prefixdata.allowed) do           if (game == v) then return true end -- if game == v       end -- for prefixdata.allowed end -- if prefixdata return false end -- p:IsAllowed

function p:FindMatchingEntry(parentframeargs, pri, i, var1, var2) for _, v in pairs(pri) do       if parentframeargs[v..i..var1] then return v, v..i..var1 end if parentframeargs[v..i..var2] then return v, v..i..var2 end end -- for end -- p:FindMatchingEntry

function p:HandleLforF_and_BM(parentframeargs, i, var1, var2) if parentframeargs['F'..i..var1] and parentframeargs['BM'..i..var1] then return 'F', 'F'..i..var1 end if parentframeargs['F'..i..var2] and parentframeargs['BM'..i..var2] then return 'F', 'F'..i..var2 end end -- p:HandleLforF_and_BM

function p:BuildRowArgs(parentframeargs, charargs, i, var1, var2, templateargs) local game = templateargs.game or 'Splatoon 3' local lpri = self.lpriority[game] local Lc, L = self:FindMatchingEntry(parentframeargs, lpri, i, var1, var2) local rightfirst='false' if 'Splatoon 3' == game and not L then Lc, L = self:HandleLforF_and_BM(parentframeargs, i, var1, var2) end -- if   local rpri = self.rpriority[game] local Rc, R = self:FindMatchingEntry(parentframeargs, rpri, i, var1, var2) if not R then Rc, R = self:FindMatchingEntry(parentframeargs, rpri, i, var1..'b', var2..'b') if R then rightfirst='true' end end -- if   local _, Reg = self:FindMatchingEntry(parentframeargs, {'R'}, i, var1, var2)

if not (L or R) then return false end

templateargs.rightfirst = rightfirst templateargs.Cquote = parentframeargs[L] or '' if L then local chrL = self.paramprefixes[Lc].chr templateargs.C=charargs[chrL] templateargs.CEng=charargs[chrL..'Eng'] templateargs.Ccolor=charargs[chrL..'color'] templateargs.Cface=parentframeargs[Lc..i..'face'] or '' templateargs.CquoteEng=parentframeargs[L..'eng'] or '' else templateargs.C='' templateargs.CEng='' templateargs.Ccolor='' templateargs.Cface='' templateargs.CquoteEng='' end -- L   templateargs.Mquote = parentframeargs[R] or '' if R then local chrR = self.paramprefixes[Rc].chr templateargs.M=charargs[chrR] templateargs.MEng=charargs[chrR..'Eng'] templateargs.Mcolor=charargs[chrR..'color'] templateargs.Mface = parentframeargs[Rc..i..'face'] or '' templateargs.MquoteEng = parentframeargs[R..'eng'] or '' else templateargs.M='' templateargs.MEng='' templateargs.Mcolor='' templateargs.Mface='' templateargs.MquoteEng='' end -- R   templateargs.R = parentframeargs[Reg] or ''

return true end -- p:BuildRowArgs

function p:ScanForMoreQuotes(parentframeargs, startindex) local suffixes = {'', 'A', 'b', 'Ab'} local i = startindex local trynext = true while trynext do       i = i + 1 trynext = false for k, _ in pairs(self.paramprefixes) do           if parentframeargs[k..i] or parentframeargs[k..i..'A'] or               parentframeargs[k..i..'b'] or parentframeargs[k..i..'Ab'] then trynext = true break end -- if       end -- for self.paramprefixes -- hard stop for extreme cases if i > 1000 then trynext = false end end -- while return i end -- p:ScanForMoreQuotes

function p:GenerateNewsDialogue(frame) local templateargs ={ Qopen='"',       Qclose='"', [':']=':',       C='Callie', M='Marie', Ccolor='', Mcolor='', game='Splatoon', language='Eng' }   local parentframeargs = frame:getParent.args local lang = parentframeargs.language or templateargs.language --Get the character names and punctuation per language: local charnameseng = {'Callie', 'Marie', 'Pearl', 'Marina', 'Shiver', 'Frye', 'Big Man'} local charnames = charnameseng if lang == 'Jap' then charnames = {'アオリ', 'ホタル', 'ヒメ', 'イイダ', 'フウカ', 'ウツホ', 'マンタロー'} templateargs.Qopen='「' templateargs.Qclose='」' templateargs[':']='：' elseif lang == 'Dut' then charnames = {'Callie', 'Marie', 'Lorelei', 'Mariana', 'Haya', 'Muriël', 'Ray'} elseif lang == 'Fre' then charnames = {'Ayo', 'Oly', 'Perle', 'Coralie', 'Pasquale', 'Angie', 'Raimi'} templateargs.Qopen='« ' templateargs.Qclose=' »' templateargs[':']=' :' elseif lang == 'Ger' then charnames = {'Aioli', 'Limone', 'Perla', 'Marina', 'Mako', 'Muri', 'Mantaro'} templateargs.Qopen='„' templateargs.Qclose='"'   elseif lang == 'Ita' then        charnames = {'Stella', 'Marina', 'Alga', 'Nori', 'Pinnuccia', 'Morena', 'Mantaleo'}        templateargs.Qopen='«'        templateargs.Qclose='»'    elseif lang == 'Rus' then        charnames = {'Кэлли', 'Мари', 'Жемчик', 'Мариша', 'Кулла', 'Мурия', 'Биг Ман'}        templateargs.Qopen='«'        templateargs.Qclose='»'    elseif lang == 'Spa' or lang == 'SpaE' then        charnames = {'Mar', 'Tina', 'Perla', 'Marina', 'Megan', 'Angie', 'Rayan'}        templateargs.Qopen='«'        templateargs.Qclose='»'    elseif lang == 'SpaA' then        charnames = {'Mar', 'Tina', 'Perla', 'Marina', 'Megan', 'Angie', 'Rayan'}    elseif lang == 'ChiS' then        charnames = {'小拟', '小萤', 'Pearl', 'Marina', '莎莎', '曼曼', '鬼福'}        templateargs[':']='：'    elseif lang == 'ChiT' then        charnames = {'小擬', '小螢', 'Pearl', 'Marina', '莎莎', '曼曼', '鬼福'} templateargs.Qopen='「' templateargs.Qclose='」' templateargs[':']='：' elseif lang == 'Kor' then charnames = {'아오리', '호타루', 'Pearl', 'Marina', '후우카', '우츠호', '만타로'} end --'Eng' is handled by default --Game-specific settings: local game = parentframeargs.game or templateargs.game templateargs.game = game local idx1=5 local idx2=6 local idx3=7 if game == 'Splatoon' then idx1=1 idx2=2 idx3=0 elseif game == 'Splatoon 2' then idx1=3 idx2=4 idx3=0 end -- game local charargs = {} charargs.A=charnames[idx1] charargs.AEng=charnameseng[idx1] charargs.Acolor=frame:expandTemplate{ title='TextColor', args= { charargs.AEng } } charargs.B=charnames[idx2] charargs.BEng=charnameseng[idx2] charargs.Bcolor=frame:expandTemplate{ title='TextColor', args= { charargs.BEng } } if 0 < idx3 then charargs.C=charnames[idx3] charargs.CEng=charnameseng[idx3] charargs.Ccolor=frame:expandTemplate{ title='TextColor', args= { charargs.CEng } } end -- if idx3 --Use the default only for unspecified parameters: for k,v in pairs(templateargs) do       if parentframeargs[k] ~= nil then templateargs[k] = parentframeargs[k] end end local ret ='' local numquotes=16 if parentframeargs['numquotes'] then local nq = tonumber(parentframeargs['numquotes']) if nq then numquotes=nq end else numquotes = self:ScanForMoreQuotes(parentframeargs, numquotes) end for i=1,numquotes do       --Quote #A if self:BuildRowArgs(parentframeargs, charargs, i, '', 'A', templateargs) then ret = ret..'|- valign=top\n'..frame:expandTemplate{ title='StageQuote', args = templateargs }..'\n' end --Quote #B if self:BuildRowArgs(parentframeargs, charargs, i, 'B', 'E', templateargs) then ret = ret..'|- valign=top\n'..frame:expandTemplate{ title='StageQuote', args = templateargs }..'\n' end if parentframeargs['Notes'..i] then ret = ret..'|-\n|colspan=3 style="background-color:#EED"|Notes: '..parentframeargs['Notes'..i]..'\n' end end return ret end -- p:GenerateNewsDialogue

function p.Generate(frame) return p:GenerateNewsDialogue(frame) end -- p.Generate

return p