Module:Storyline

--[=[

Lua Module for Stroylines Function

--]=]

local p = {}

local util = require("Module:Utility") local collectionData = mw.loadData( 'Module:ItemCollection/data' )

---[==[ 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 EC = require("Module:EC").getEC 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; background: radial-gradient(circle, #', "36d0ff", ' 5%, #', "1ca1fc", ' 100%); border-radius: 15px; font-weight: normal; box-shadow: 0 0 5px #666666; border: ', "none", '; color: #', "000000", ';">', "", "", "", "", "", "", "", "", "", "", ""} 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[11] = table.concat({""})

tOut[11] = tOut[11] .. ' ' .. COLL({qLink, 30}) .. ' '

tOut[11] = ' ' .. tOut[11] .. ' '		tOut[16] = qLink		tOut[17] = "  " end

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

if storylineData["Colors"][qType] then local eData = storylineData["Colors"][qType]

if eData[3] then tOut[2] = eData[3] end

if eData[2] then tOut[4] = eData[2] end

if eData[5] then tOut[6] = "4px solid #" .. eData[5] end

if eData[1] == true then tOut[8] = "f5f3f5" end

if eData[4] and qLink ~= "" then tOut[14] = eData[4] end end

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

local function oneCell(tIn, qType, qLink, qTime, qText, Mobile) local tOut = {} local mOut = {}

if storylineData["Arrows"][qType] and Mobile then return "" elseif 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: 1px; background: radial-gradient(circle, #', "36d0ff", ' 5%, #', "1ca1fc", ' 100%); border-radius: 15px; font-weight: normal; box-shadow: 0 0 5px #666666; border: ', "none", '; color: #', "000000", ';">', "", "", "", "", "", "", "", "", "", "", ""} mOut = {"\n* ", "", " ", "", "", "", "", "", "", ""} end

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

if iType and iType == "main" then tOut[10] = "" mOut[2] = "" qType = iName elseif iType and iType == "side" then tOut[10] = "" mOut[2] = "" qType = iName else tOut[10] = "" mOut[2] = "" end end

if qLink ~= "" then tOut[11] = " %{%}]", "")		mOut[4 ] = mw.ustring.gsub(qLink, "[%<%>%[%]%|%{%}]", "")		tOut[13] = '|'		if qLink:match("-" .. qType:upper .. "$") then			qLink = mw.ustring.gsub(qLink, "-" .. qType:upper .. "$", "")		elseif qLink:match("^.+ %(%d%)$") then			qLink = qLink:match("(.+) %(%d%)$")		elseif qLink:match("^.+ %(%d%d%)$") then			qLink = qLink:match("(.+) %(%d%d%)$")		end		tOut[16] = mw.text.encode(qLink, '%[%]')		mOut[6 ] = mw.text.encode(qLink, '%[%]')		if qLink:match("^.+%#Part %d$") then      			local qName, qAnch = qLink:match("^(.+)%#Part (%d+)$")			tOut[16] = qName .. ", Pt. " .. qAnch 			mOut[6 ] = qName .. ", Pt. " .. qAnch 		elseif qLink:match("^.+%#Part %d%d$") then       			local qName, qAnch = qLink:match("^(.+)%#Part (%d+)$")			tOut[16] = qName .. ", Pt. " .. qAnch 			mOut[6 ] = qName .. ", Pt. " .. qAnch 		end		tOut[17] = " " end

if storylineData["Colors"][qType] then local eData = storylineData["Colors"][qType]

if eData[3] then tOut[2] = eData[3] end

if eData[2] then tOut[4] = eData[2] end

if eData[5] then tOut[6] = "4px solid #" .. eData[5] end

if eData[1] == true then tOut[8] = "f5f3f5" end

if eData[4] and qLink ~= "" then tOut[14] = eData[4] end end

if qTime ~= "" then local qReq = mw.text.split(qTime, "%) %(") table.insert(tOut, " ") table.insert(mOut, " ") for idx = 1, #qReq do			table.insert(tOut, " (")			table.insert(tOut, qReq[idx])			table.insert(tOut, ")")

table.insert(mOut, " (")			table.insert(mOut, qReq[idx])			table.insert(mOut, ")") end table.insert(tOut, " ") table.insert(mOut, " ") end

if qText ~= "" then table.insert(tOut, " ''") table.insert(mOut, " ''") for idx = 4, #tIn do			table.insert(tOut, " - ") table.insert(tOut, tIn[idx])

table.insert(mOut, " - ") table.insert(mOut, tIn[idx]) end table.insert(tOut, "'' ") table.insert(mOut, "'' ") end if Mobile then return table.concat(mOut) else return table.concat(tOut) .. " "	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<td style="width: 1%;"> ', '\n<td style="width: 10%;"> '} 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 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 "")) elseif pagename == "Main Storyline Walkthrough/Milestones" then tOut[i] = tTh[i] .. oneMilestone(tIn[1], (tIn[2] or ""), (tIn[3] 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 ' .. mOut else return ' ' .. table.concat(tOut) .. '\n ' 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