Module:Storyline

--[=[

Lua Module for Stroylines Function

--]=]

local p = {}

local util = require("Module:Utility") local collectionData = mw.loadData( 'Module:ItemCollection/data' ) local ICON = require("Module:CharacterAvatar").getAvatar local EC = require("Module:EC").getEC

---[==[ local storylineData = mw.loadData( 'Module:Storyline/data' ) --[===[]==] local storylineData = { ["Colors"] = { ["main"] = {nil, "ffc823", "ffff6b", "cc6600"}, ["side"] = {nil, "18e8ca", "36ffbe", "005555"}, ["ttc"] = {true, "450a6c", "930eb9", "dc86ee", "31ac2a"}, },   ["Arrows"] = { ["R"] = "right", ["r"] = "right-", } } --]===]

local function oneMilestone(qType, qLink, qCost) local COLL = require("Module:ItemCollection").getCollection local tOut = {}

if storylineData["Arrows"][qType] then tOut = {'">'}		if qLink ~= "" and storylineData["Arrows"][qLink] then			table.insert(tOut, ' [[File:m-arrow-')			table.insert(tOut, storylineData["Arrows"][qLink])			table.insert(tOut, '.png|x35px]]')		end		return table.concat(tOut) .. " "	else		tOut = {' padding: 5px; color: #', "000000", '; background: radial-gradient(circle, #', "36d0ff", ' 5%, #', "1ca1fc", ' 100%); border-radius: 15px; font-weight: normal; box-shadow: 0 0 5px #666666; border: 4px ridge #', "ffffff00", ';">', "", " ', qLink, "  (", qCost, ") "} end

if qLink ~= "" then local fname = qLink:lower:gsub("[':\"%,%.]", ""):gsub(" ", "_")		fname = fname:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2")		fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")

local iType = "C" if collectionData["Items"][qLink] and collectionData["Items"][qLink][2] and collectionData["Items"][qLink][2] == "ba" then iType = "Ba" end tOut[10] = table.concat({""}) tOut[10] = tOut[10] .. ' ' .. COLL({qLink, 30}) .. ' '		tOut[10] = ' ' .. tOut[10] .. ' '	end

if qCost:match("^EC") then tOut[18] = EC({qCost, nil, nil, nil, 25}) end

if storylineData["Colors"][qType] then local eData = storylineData["Colors"][qType] tOut[4] = eData[3] or "1ca1fc" tOut[6] = eData[2] or "36d0ff" tOut[14] = eData[4] or "08598e" end

return table.concat(tOut) .. " " end

local function oneCell(qAct, qType, qLink, qRequirement, qActivity, noTable) local bgName = qType local qTable = {} local qText = {}

if storylineData["Arrows"][qType] and noTable then return "" elseif storylineData["Arrows"][qType] then qTable = {'">'}		if qLink ~= "" and storylineData["Arrows"][qLink] then			table.insert(qTable, ' [[File:m-arrow-')			table.insert(qTable, storylineData["Arrows"][qLink])			table.insert(qTable, '.png|x35px]]')		end		return table.concat(qTable) .. " "	else		qTable = {' padding: 1px; color: #', "000000", '; background: radial-gradient(circle, #', "36d0ff", ' 5%, #', "1ca1fc", ' 100%); border-radius: 15px; font-weight: normal; box-shadow: 0 0 5px #666666; border: 4px ridge #', "ffffff00", ';">', "", " %{%}]", ""), '|', mw.text.encode(qLink, '%[%]'), "", " ", " ", "", " ", " ", "", " "} qText = {" ", "%{%}]", ""), "|", mw.text.encode(qLink, '%[%]'), "", "", " ", "", " ", " ", "", " "} end

if qType == "main" then qTable[10] = "" qText[1] = " " elseif qType == "side" then qTable[10] = "" qText[1] = " " qText[2] = " "		qText[7] = " " else local iName, iType = mw.ustring.match(qType, 			"^([^,]-)%s*-%s*(.-)$")

if iType and iType == "main" then qTable[10] = "" qText[1] = " " bgName = iName elseif iType and iType == "side" then qTable[10] = "" qText[1] = " " qText[2] = " "			qText[7] = " " bgName = iName else qTable[10] = "" qText[1] = " " end end

if qLink:match("^.+%#Part %d+$") then local qName, qAnch = qLink:match("^(.+)%#Part (%d+)$") qTable[17] = ", Pt. " .. qAnch qText[6] = ", Pt. " .. qAnch qLink = qName end local i = 1 local tIn = mw.text.split(qLink, "%s*%-%s*") for idx = 0, #tIn do i = idx end if tIn[i] and storylineData["Colors"][tIn[i]:lower] then qLink = mw.ustring.gsub(qLink, "-" .. tIn[i]:upper .. "$", "") end if qLink:match("^.+%-%d+$") then qLink = qLink:match("(.+)%-%d+$") elseif qLink:match("^.+ %(%d+%)$") then qLink = qLink:match("(.+) %(%d+%)$") end qTable[16] = mw.text.encode(qLink, '%[%]') qText[5] = mw.text.encode(qLink, '%[%]')

if storylineData["Colors"][bgName] or storylineData["Colors"][qType] and not noTable then local eData = storylineData["Colors"][bgName] or storylineData["Colors"][qType] if eData[1] == true then qTable[2] = "f5f3f5" end qTable[4] = eData[3] or "1ca1fc" qTable[6] = eData[2] or "36d0ff" qTable[8] = eData[5] or "ffffff00" qTable[14] = eData[4] or "08598e" end

if qRequirement ~= "" then local qReq = mw.text.split(qRequirement, "%) %(") for idx = 1, #qReq do qTable[20] = qTable[20] .. " (" .. qReq[idx] .. ")" qText[9] = qText[9] .. " (" .. qReq[idx] .. ")" end end

if qActivity ~= "" then for idx = 4, #qAct do			local aa = mw.text.split(qAct[idx], "%s*^%s*") if aa[1] and aa[2] and aa[3] then if aa[1]:match(".+ %#%d+ %+ .+ %#%d+$") then local ch1name, ch1lvl, ch2name, ch2lvl = mw.ustring.match(aa[1], "^(.-)%s*#%s*([%d%,]*)%s*+%s*(.-)%s*#%s*([%d%,]*)$") if ch1lvl == "0" then ch1lvl = "?" end if ch2lvl == "0" then ch2lvl = "?" end aa[1] = ICON({(ch1name or "?"), nil, 25}) .. " Lvl " .. (ch1lvl or "?") .. " + " .. ICON({(ch2name or "?"), nil, 25}) .. " Lvl " .. (ch2lvl or "?") elseif aa[1]:match(".+ %#%d+$") then local chname, chlvl = mw.ustring.match(aa[1], "^(.-)%s*#%s*([%d%,]*)$") if chlvl == "0" then chlvl = "?" end aa[1] = ICON({(chname or "?"), nil, 25}) .. " Lvl " .. (chlvl or "?") else local iType = "default" if collectionData["Items"][aa[1]] then iType = collectionData["Items"][aa[1]][2] end local tAct = { ["ch"] = "Welcome", ["ba"] = "Build", ["cos"] = "Get", ["default"] = "Unlock", }					aa[1] = tAct[iType] .. " " .. aa[1] .. "" end if aa[2]:match("^EC%-") then aa[2] = EC({aa[2], nil, nil, nil, 20}) end qTable[22] = qTable[22] .. " - " .. aa[1] .. " - " .. aa[2] .. " - " .. aa[3] qText[11] = qText[11] .. " - " .. aa[1] .. " - " .. aa[2] .. " - " .. aa[3] else qTable[22] = qTable[22] .. " - " .. qAct[idx] qText[11] = qText[11] .. " - " .. qAct[idx] end end end if noTable then return table.concat(qText) else return table.concat(qTable) .. " "	end end

function p.getStoryline(frame) local tArgs = util.getArgs(frame) local pagename = mw.title.getCurrentTitle.text or ""

local tOut = { '\n ', '\n ', '\n ', '\n ', '\n ', , , , } local mOut = "" local tTd = { '\n ', '\n ', '\n ', '\n ', '\n ', '\n ', '\n ', '\n ', '\n '} local tTh = { '\n<th style="width: 15%;', '\n<th style="width: 1%;', '\n<th style="width: 15%;', '\n<th style="width: 1%;', '\n<th style="width: 15%;', '\n<th style="width: 1%;', '\n<th style="width: 15%;', '\n<th style="width: 1%;', '\n<th style="width: 15%;'}

local i = 1 local Args = {}

repeat if tArgs[i] == nil and (tArgs[i + 1] or tArgs[i + 2] or tArgs[i + 3] or tArgs[i + 4] or tArgs[i + 5] or tArgs[i + 6] or tArgs[i + 7] or tArgs[i + 8] or tArgs[i + 9]) then table.insert(Args, tArgs[i] or "X") else table.insert(Args, tArgs[i]) end i = i + 1 until i == 10

for i, item in pairs(Args) do		local tIn = mw.text.split(item, "%s*$%s*")

if tIn[1] == "X" then tOut[i] = tTd[i] elseif tIn[1] == "title" then tOut = {' <td colspan="9" style="text-align: left;"><h3 style="margin: 0px;">', (tIn[2] or "?"), ' ', ""} if pagename ~= "Main Storyline Walkthrough/Milestones" then tOut[4] = ' .. (tIn[2] or "?") .. ' end return table.concat(tOut) elseif pagename == "Main Storyline Walkthrough/Milestones" then tOut[i] = tTh[i] .. oneMilestone(tIn[1], (tIn[2] or "?"), (tIn[3] or "?")) elseif i == 3 and pagename ~= "Main Storyline Walkthrough/Milestones" then mOut = oneCell(tIn, tIn[1], (tIn[2] or "?"), (tIn[3] or ""), (tIn[4] or ""), true) tOut[i] = tTh[i] .. oneCell(tIn, tIn[1], (tIn[2] or "?"), (tIn[3] or ""), (tIn[4] or "")) else tOut[i] = tTh[i] .. oneCell(tIn, tIn[1], (tIn[2] or "?"), (tIn[3] or ""), (tIn[4] or "")) end end if mOut ~= "" then return ' ' .. table.concat(tOut) .. '\n \n* ' .. mOut else return ' ' .. table.concat(tOut) .. '\n ' end end

function p.getTextStoryline(frame) local tArgs = util.getArgs(frame) if not tArgs[1] then return "" end local pagename = mw.title.getCurrentTitle.text or ""

local tIn = mw.text.split(tArgs[1], "%s*$%s*")

if tIn[1] == "title" then tOut = {' <td colspan="9" style="text-align: left;"><h3 style="margin: 0px;">', (tIn[2] or "?"), ' ', ""} if pagename ~= "Main Storyline Walkthrough/Milestones" then tOut[4] = ' .. (tIn[2] or "?") .. ' end return table.concat(tOut) else return oneCell(tIn, tIn[1], (tIn[2] or "?"), (tIn[3] or ""), (tIn[4] or ""), true) end

end

local function findCharacter(collNumb, collNo) local tOut = { '{| class="mw-collapsible mw-collapsed article-table" style="width: 100%;"\n| style="height: 35px;"|<span id="',		(collNumb["D"] or collNumb[2]),		'">  ', collNumb[2], '  \n| style="text-align: right;"| [ Back to Top ] \n' }	local tChar = { '|-\n| style="border-bottom: none;height: 35px;"| \'\'\'\'\'', '', -- Character '\'\'\'\'\' \n| rowspan="2" style="text-align: center; width: 25%;"| Cp-',		'', -- Character file		'.png \n|-\n| style="width: 75%;"|\n', }   local tIndex = {} for coll, v in pairs(collectionData["Items"]) do   	if v[1] == collNo then table.insert(tIndex, {coll:lower:gsub(" ", "_"), coll}) end end

table.sort(tIndex, function (a,b) return a[1] < b[1] end)

for _, name in pairs(tIndex) do       name[1] = mw.ustring.gsub(mw.ustring.lower(name[2]), "[':\"%,%.]", "")	name[1] = name[1]:gsub(" ", "_")	name[1] = mw.ustring.gsub(name[1], "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")    	if collectionData["Items"][name[2]][2] and collectionData["Items"][name[2]][2] == "ch" then		tChar[2] = name[2]		tChar[4] = name[1]		tChar[6] = name[2]		tChar[8] = name[2]		table.insert(tOut, table.concat(tChar))        end    end

return table.concat(tOut) .. '\n|}' end

function p.getCharacterStorylines(frame) local collections = {} local allcollections = {} local storylines = "" local space = ""

for k, v in pairs(collectionData["Collections"]) do   	if k ~= 10 and k <= 9900 then table.insert(collections, {k, v}) end end

table.sort(collections, function(a,b) return a[1] < b[1] end)

for _, coll in pairs(collections) do	table.insert(allcollections, (coll[2]["D"] or coll[2][2]))

storylines = storylines .. space .. findCharacter(coll[2], coll[1])

space = "\n\n" end

local COLL = require("Module:ItemCollection").getCollection storylines = COLL({table.concat(allcollections, "$"), "A"}) .. "\n" .. storylines

return frame:preprocess(storylines) end

return p