Module:ActivityList

--[==[-- -- Temporary Lua script to get Activity Lists -- --]==]

local p = {}

local util = require("Module:Utility") local COLL = require("Module:ItemCollection") local ACT = require("Module:Activity-2").OtherSource local actData = mw.loadData( 'Module:ActivityList/data' ) local actDataEC = mw.loadData( 'Module:ActivityList/dataEC' )

function p.getList(frame) local tArgs = util.getArgs(frame)

local GoTo = {["S"] = ""} local tOut = {	'{| class="article-table sortable" style="text-align: center; width: 100%; line-height: 1.5;"\n', '! style="text-align: center; width: 10%;"|Collection\n', '! style="text-align: center; width: 10%;"|Character\n', '! class="unsortable"|Activity\n', '! style="text-align: center; width: 10%;"|+\n', '! style="text-align: center; width: 1%;" class="unsortable"|Time\n', '! style="text-align: center; width: ', (tArgs[1]=="ANIM" and '5%;"|Location\n' or '1%;"|Wished?\n'),			(tArgs[1] and "" or "|- class=\"sorttop\" style=\"border: 3px #3f51b5 dotted;padding: 5px;\"|\n| colspan=\"7\"|Select the duration of the activities you want to see: 60m · 2h · 4h · 6h · 8h · 10h · 12h · 16h · 18h · 24h  "),		}	for item, data in pairs(actData) do		if tArgs[1] and tArgs[1] == "ANIM" and data[9] then			local collname = COLL.getCollection({data[1], "N"})

if not GoTo[collname] then GoTo["S"] = GoTo["S"] .. collname .. "$"               		GoTo[collname] = true end

local tAct = {	'\n|- id="', collname, '"|', '\n| data-sort-value="', COLL.getCollection({data[1], "D"}), '"|', "', COLL.getCollection({data[1], "D"}), "", '\n| id="', data[1], "-", data[5], '"|', data[1], " Level ", data[2], " ", '\n| style="text-align: left;"|', data[5], " ", data[9], " ", '\n|', (data[3]~="" and (" " .. data[3] .. " ''Lvl " .. data[4] .. "'' ") or ""), '\n| data-sort-value="', (data[6]=="60m" and "1h" or data[6]), '"|', data[6], '\n| ', data[10], ' ', }

table.insert(tOut, table.concat(tAct)) elseif (tArgs[1] and data[6] == tArgs[1]) or (tArgs[1] and data[8] == tArgs[1]) then local collname = COLL.getCollection({data[1], "N"})

if not GoTo[collname] then GoTo["S"] = GoTo["S"] .. collname .. "$"               		GoTo[collname] = true end

local tAct = {	'\n|- id="', collname, '"|', '\n| data-sort-value="', COLL.getCollection({data[1], "D"}), '"|', "', COLL.getCollection({data[1], "D"}), "", '\n|', data[1], " Level ", data[2], " ", '\n| style="text-align: left;"|', data[5], '', '\n|', (data[3]~="" and (" " .. data[3] .. " ''Lvl " .. data[4] .. "'' ") or ""), '\n| data-sort-value="', (data[6]=="60m" and "1h" or data[6]), '"|', data[6], '\n|', data[8], }

if data[7] ~= "" then local sep = "" local rOut = "" local requirements = mw.text.split(data[7], "%s*%$%s*") for idx = #requirements, 1, -1 do					local reqname, reqlvl = mw.ustring.match(requirements[idx], "^(.-)%s*#%s*([%d%,]*)$") if not reqname then reqname = requirements[idx] reqlvl = nil end if reqlvl and reqlvl == "" then reqlvl = nil end rOut = " " .. reqname .. "" .. (reqlvl and (" (Ench. Lvl. " .. reqlvl .. ")") or "") .. sep .. rOut if sep == "" then sep = " &" else sep = "," end end tAct[19] = " ''*" .. rOut .. "'' "			end

table.insert(tOut, table.concat(tAct)) elseif not tArgs[1] then local collname = COLL.getCollection({data[1], "N"})

if not GoTo[collname] then GoTo["S"] = GoTo["S"] .. collname .. "$"               		GoTo[collname] = true end

local tAct = {	'\n|- class="mw-collapsible mw-collapsed" id="mw-customcollapsible-', data[6], '"|', "\n|', COLL.getCollection({data[1], "D"}), "", '\n|', data[1], " Level ", data[2], " ", '\n| style="text-align: left;"|', data[5], '', '\n|', (data[3]~="" and (" " .. data[3] .. " ''Lvl " .. data[4] .. "'' ") or ""), '\n| data-sort-value="', (data[6]=="60m" and "1h" or data[6]), '"|', data[6], '\n|', data[8], }

if data[7] ~= "" then local sep = "" local rOut = "" local requirements = mw.text.split(data[7], "%s*%$%s*") for idx = #requirements, 1, -1 do					local reqname, reqlvl = mw.ustring.match(requirements[idx], "^(.-)%s*#%s*([%d%,]*)$") if not reqname then reqname = requirements[idx] reqlvl = nil end if reqlvl and reqlvl == "" then reqlvl = nil end rOut = " " .. reqname .. "" .. (reqlvl and (" (Ench. Lvl. " .. reqlvl .. ")") or "") .. sep .. rOut if sep == "" then sep = " &" else sep = "," end end tAct[16] = " ''*" .. rOut .. "'' "			end

table.insert(tOut, table.concat(tAct)) end end return (tArgs[1] and COLL.getCollection({GoTo["S"], "A"}) or "") .. "\n" .. table.concat(tOut) .. "\n|}" end

local actHeader = { '\n|-| Activities=', '{| class="article-table act2 sortable" style="width: 100%; text-align: center;"', '! style="text-align: center;" width="1"|Lvl', '! width="100%" class="unsortable"|Activity', '! style="text-align: center;" width="1" class="unsortable"|+', '! width="5%" data-sort-type="number"|Time', '! width="20%" class="unsortable"|Rewards', '! width="20%"|Tokens' }

function p.getCharacterActivities(pagename) if not pagename or pagename == "" then return "" end local character = pagename local costume = 'ZZZZ' if character:match("^([^%(]-)%/([^%(]-)$") then character = mw.ustring.gsub(pagename, "^([^%(]-)%/([^%(]-)$", "%1") costume = mw.ustring.gsub(pagename, "^([^%(]-)%/([^%(]-)$", "%2") costume = mw.ustring.gsub(costume, "-", "%-") end

local ActOut = {table.concat(actHeader, "\n")}

local activities = {} local Xactivities = {}

for _, data in pairs(actData) do		if (data[1] == character or data[3] == character) and (data["X"] and not data["X"]:match(costume .."%$") or true) then local durNumb, durHMS = string.match(data[6], "^([%d%?]+)([hms])$") local durNumb = tonumber(durNumb) if durNumb then if durHMS == "h" then durNumb = durNumb * 3600 elseif durHMS == "m" then durNumb = durNumb * 60 end else durNumb = 99900 end

if data[7] ~= "" then durNumb = durNumb + 1 end

if data["X"] and data["X"]:match(costume .."%$") then if data[3] ~= "" then table.insert(Xactivities, {durNumb + 2, ("")}) else table.insert(Xactivities, {durNumb, ("")}) end elseif data[3] ~= "" then table.insert(activities, {durNumb + 2, ("")}) elseif (data["X"] and not data["X"]:match(costume .."%$")) or not data["X"] then table.insert(activities, {durNumb, ("")}) end end end

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

for _, template in pairs(activities) do		table.insert(ActOut, template[2]) end

if costume~="ZZZZ" then table.insert(ActOut, '|-') table.insert(ActOut, '! colspan="7"|Activities that cannot be done with the costume') for _, template in pairs(Xactivities) do			table.insert(ActOut, template[2]) end table.insert(ActOut, "|}") else table.insert(ActOut, "|}") local EventActOut = {}

for _, ecdata in pairs(actDataEC) do			for item in mw.text.gsplit(ecdata[2], "%s*%$%s*") do				if item == character then table.insert(EventActOut, ("")) end end end

if table.concat(EventActOut) ~= "" then actHeader[1] = '\n|-| Event Activities=' actHeader[8] = '' table.insert(EventActOut, 1, table.concat(actHeader, "\n")) table.insert(EventActOut, "|}") table.insert(ActOut, table.concat(EventActOut, "\n")) end end return table.concat(ActOut, "\n") end

function p.getAttractionActivities(pagename) if not pagename or pagename == "" then return "" end pagename = mw.ustring.gsub(pagename, "-", "%-")

actHeader[1] = '\n|-| Character Activities='

local tOut = {table.concat(actHeader, "\n")}

local activities = {}

for _, data in pairs(actData) do if data[7]:match("^" .. pagename) then local durNumb, durHMS = string.match(data[6], "^([%d%?]+)([hms])$") local durNumb = tonumber(durNumb) if durNumb then if durHMS == "h" then durNumb = durNumb * 3600 elseif durHMS == "m" then durNumb = durNumb * 60 end else durNumb = 99900 end

if data[7] ~= "" then durNumb = durNumb + 1 end

if data[3] ~= "" then table.insert(activities, {durNumb + 2, ("")}) else table.insert(activities, {durNumb, ("")}) end end end

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

for _, template in pairs(activities) do		table.insert(tOut, template[2]) end

table.insert(tOut, "|}") return table.concat(tOut, "\n") end

function p.getECActivities(frame) local tArgs = util.getArgs(frame) if not tArgs["event"] then return "" end

local tOut = {'==Character Helping==', '{| class="article-table" style="text-align: center; line-height: 1.0; width: fit-content;"'} local i = 6 actHeader[1] = '\n==How to obtain==' actHeader[8] = '' local ActOut = {table.concat(actHeader, "\n")}

for _, data in pairs(actDataEC) do		if data[1]:lower == tArgs["event"]:lower then for _, character in pairs(mw.text.split(data[2], "%s*%$%s*")) do				if i == 6 then i = 0 table.insert(tOut, '|-') end local file = character:lower :gsub("^%s*(.-)%s*$", "%1") :gsub("[%.',]", "") :gsub("^([^%(]-) *%(([^%(]-)%)$", "%1_%2") :gsub(" ", "_") :gsub("\"", "")

table.insert(tOut, table.concat({'| style="width: 15%; padding: 5px;"| ', character, ' '})) table.insert(ActOut, ("")) i = i + 1 end for _, character in pairs(mw.text.split(data[3], "%s*%$%s*")) do				local file = character:lower :gsub("^%s*(.-)%s*$", "%1") :gsub("[%.',]", "") :gsub("^([^%(]-) *%(([^%(]-)%)$", "%1_%2") :gsub(" ", "_") :gsub("\"", "")

table.insert(ActOut, table.concat({'|-\n|\n| style="text-align: left;"|', character, ': All activities\n| nowrap|\n|Various\n| nowrap|'})) end break end end

table.insert(tOut, "|}") table.insert(tOut, "

")	table.insert(tOut, table.concat(ActOut, "\n"))	table.insert(tOut, ACT({event=(tArgs["event"] .. "$EC"), ec=tArgs["ec"]}))

return frame:preprocess(table.concat(tOut, "\n")) end

return p