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 oneCell(tIn, eType, qLink, qTime, qText, Mobile) local tOut = {} local mOut = {}

if storylineData["Arrows"][eType] and Mobile then return "" elseif storylineData["Arrows"][eType] 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 10px #666666; border: ', "none", '; color: #', "3a3a3a", ';">', "", "", "", "", "", "", "", "", "", "", ""} mOut = {"\n*", "", " ", "", "", "", "", "", "", ""} end

if eType == "main" then tOut[10] = "" mOut[2] = "" elseif eType == "side" then tOut[10] = "" mOut[2] = "" else tOut[10] = "" mOut[2] = "" end

if qLink ~= "" then tOut[11] = " '		if qLink:match("^.+ %(%d%)$") then			qLink = qLink:match("(.+) %(%d%)$")		elseif qLink:match("^.+ %(%d%d%)$") then			qLink = qLink:match("(.+) %(%d%d%)$")		end		tOut[16] = qLink		if qLink:match("^.+%#Part %d$") then      			local qName, qAnch = qLink:match("^(.+)%#Part (%d+)$")			tOut[16] = qName .. ", Pt. " .. qAnch 		elseif qLink:match("^.+%#Part %d%d$") then       			local qName, qAnch = qLink:match("^(.+)%#Part (%d+)$")			tOut[16] = qName .. ", Pt. " .. qAnch 		end		tOut[17] = " "

mOut[4 ] = qLink if qLink:match("^.+ %(%d%)$") then qLink = qLink:match("(.+) %(%d%)$") elseif qLink:match("^.+ %(%d%d%)$") then qLink = qLink:match("(.+) %(%d%d%)$") end mOut[6 ] = qLink if qLink:match("^.+%#Part %d$") then local qName, qAnch = qLink:match("^(.+)%#Part (%d+)$") mOut[6 ] = qName .. ", Pt. " .. qAnch elseif qLink:match("^.+%#Part %d%d$") then local qName, qAnch = qLink:match("^(.+)%#Part (%d+)$") mOut[6 ] = qName .. ", Pt. " .. qAnch end end

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

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

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

if eData[5] then tOut[6] = "3.5px 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 tOut[18] = " ("		tOut[19] = qTime		tOut[21] = ")"

mOut[ 8] = " ("		mOut[ 9] = qTime		mOut[10] = ")" 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(mOut, ' ') --		table.insert(tOut, ' ') 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 tOut = { '\n ', '\n ', '\n ', '\n ', '\n ', '\n ', '\n ', '\n ', '\n '} local mOut = "" local tTh = { '\n<th style="width: 15%;', '\n<th style="width: 6%;', '\n<th style="width: 15%;', '\n<th style="width: 6%;', '\n<th style="width: 15%;', '\n<th style="width: 6%;', '\n<th style="width: 15%;', '\n<th style="width: 6%;', '\n<th style="width: 15%;'}

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

if i == 3 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 ' .. 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;"|  ', collNumb[1], '  \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] = name[2]:lower:gsub("[%.']", ""):gsub("^(.-)%s*%((.+)%)%s*$", "%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 storylines = "" local space = ""

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

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

for _, coll in pairs(collections) do       storylines = storylines .. space .. findCharacter(coll[2], coll[1])

space = "\n\n" end

return frame:preprocess(storylines) end

return p