Module:Activity

--[==[-- -- Lua script to get Character Activities --

PLEASE DO NOT USE/EDIT YET, AS THE MODULE AND DATA STRUCTURE IS STILL CHANGING AND NOT FINALIZED.

Parameters: Numbered Parameters 1 .. n = Character Name + Activity (Format: Character$Activity) Named Parameters Boolean (true if present) collection = Numbered Parameters are Collection names icon = Include Owner-Character Icon notoken = do not include token drops trophy = Include trophy icon for trophy tasks wish = Include Wish icon for wishable tasks Text event = LTE short name me = Mini-Event short name/reference display = output type blank = normal output character = Character Page tasks list(s) attraction = Attraction Page token tasks list currency = event (EC) tasks (only for 'event' if specified) animated = Animated Tasks Page trophy = trophy tasks conflict = Current Token Name (for conflict check) --]==]

local p = {}

--[===[ structure of data file (data file not to be created yet, till module is almost finished,	because the structure might need to be fine-tuned if it can help	in simplifying/speed-up code) Table Key: owner character (short name) Key: activity	(activity name) data: Table with fields as below numbered fields 1	= owner level 2	= duration 3	= sidekick character (short name) 4	= sidekick level keyed fields (only present when needed) alias	= points to activity this is an alias of   						Other fields are ignored if 'alias' is present Table of Character, Activity-Name pair. 1	= Character (if nil, another activity of same character) 2	= Activity (if nil, same activity of another character) tok		= possible token drops (table) toknpc = possible NPC token drops (table) attr	= requires attraction (table) 1 = Attraction Name 2 = Enchantment Level (nil if not needed) cstm1	= requires Costume 1 cstm2	= requires Costume 2 act		= owner activity (if different from activity-key) act2	= sidekick activity (if differnet from activity-key/act) anim	= present if activity is animated text description of activity wish	= present if task is wishable trophy	= present if task currently drops a trophy ver		= table: activity versions with fields (Not finalized yet) 1 = From version (e.g. 4.1.0) 2 = To version  (e.g. 4.2.0) optional fields (override the current values if present) dur = duration act act2 wish trophy tok toknpc event	= table of LTEs where activity produced EC. other changes (if any) during the LTE will be reflected in the ver(sions) above. key: "eventid" (LTE ID) data: Table with fields as below numbered fields 1	= generates EC 2	= table of tokens during event. 3  = table of npc tokens during event. (optional) --]===]

local actData = { ---[==[	-- Sample content of data file Module:Activity/mandf ["MAF"] = { -- Mickey Mouse ["Mickey Mouse"] = { ["High Five!"] = { 3, 7200, "Goofy", 3, req = { {"Mickey Mouse/Classic", "N"}, },				anim = "", tok = {"Daisy Duck,2","Sebastian,2","Ralph,2","Aladdin,3"}, },			["Search for Friends"] = { 1, 3600,				req = { {"Mickey Mouse/Classic", "N"}, },				anim = "Mickey Searches around the Kingdom", },			["Dance"] = { alias = {nil, "Dance with Minnie"}, },			["Dance with Minnie"] = { 8, 7200, "Minnie Mouse", 1, act2 = "Dance with Mickey", req = { {"Mickey Mouse/Classic", "N"}, },				anim = "Mickey and Minnie dance together", },			["Review"] = { alias = {nil, "Review Pete's Complaints"}, },			["Review Pete's Complaints"] = { 3, 7200,				req = { {"Mickey's House"}, {"Mickey Mouse/Classic", "N"}, },				tok = {"Bo Peep,3","Pumbaa,3","Sneezy,3","Honey Lemon,2"}, event = { HP = {true,{"Bo Peep,3","Pumbaa,3","Sneezy,3","Honey Lemon,2"}}, },			},			["Mistletoe"] = { alias = {"Minnie Mouse"}, },		},		-- Minnie Mouse ["Minnie Mouse"] = { ["Dance"] = { alias = {"Mickey Mouse"}, },			["Mistletoe"] = { 1, 7200, "Mickey Mouse", 1, req = { {"Mickey Mouse/Holiday"}, {"Minnie Mouse/Holiday"}, },				anim = "Minnie and Mickey, in their Holiday costumes, share a tender moment under the mistletoe", tok = {"Hans,3"}, },		},		-- Goofy ["Goofy"] = { ["High Five!"] = { alias = {"Mickey Mouse"}, },			["Check the Fun Wheel"] = { 1, 3600,				req = { {"Mickey's Fun Wheel"}, },				tok = {"IP-MI"}, toknpc = {"Viruses,2"}, },			["Run in Panic"] = { 1, 3600,				anim = "Goofy runs in panic", },		},	},	-- end of sample content --]==] }

local icon = require("Module:CharacterAvatar").getAvatar local token = require("Module:CharacterToken").getTokenDirect local task = require("Module:Tasks").getData local NPC = require("Module:NPC").getNPC local coll = require("Module:ItemCollection") local util = require("Module:Utility")

local tArgs = {} local tTasks = {} local badAct = {"?", "?h"} local showIcon  = false local showTokens = true local conflict  = nil local evtID     = nil

local function tableHdr(withTok, column1Hdr, banner, prevTable) local tHdr = { "", "", "", -- Table (1-3) "", "", "", "", -- Banner (4-7) "|-\n! style=\"text-align: center;\" width=\"1\"|", "", -- Col1 (8-9) "\n! width=\"100%\" class=\"unsortable\"|Activity\n", -- Col2 (10) "! style=\"text-align: center;\" width=\"1\" class=\"unsortable\"|+\n", -- Col3 (11) "! width=\"5%\" data-sort-type=\"number\"|Time\n", -- Col4 (12) "! width=\"20%\" class=\"unsortable\"|Rewards\n", -- Col5 (13) "", -- Col6 (14) }	if (not prevTable) then tHdr[1] = "{| class=\"article-table act"		tHdr[3] = "\" style=\"width: 100%;\"\n" if not column1Hdr then tHdr[2] = " sortable" end end tHdr[9] = column1Hdr or "Lvl" if withTok then tHdr[14] = "! width=\"20%\"|Tokens\n" end if banner then tHdr[4] = "|-\n! colspan=\""		tHdr[5] = withTok and "6" or "5"		tHdr[6] = "\" style=\"text-align: center;\"" local bannerColl = coll.getCollection({banner, "L"}) if (bannerColl ~= "") then tHdr[7] = bannerColl else tHdr[7] = banner end end return table.concat(tHdr) end

-- Generate the ouput list of tasks from data provided in a table. local function genOut(tActList, animPage) if type(tActList) ~= "table" then return "" end

table.sort(tActList, function(a, b)				if a[3][2] == b[3][2] then					if (a[3][3] and 2 or 1) == (b[3][3] and 2 or 1) then						if a[1] == b[1] then return a[3][1] < b[3][1]						else return a[1] < b[1] end					else return (a[3][3] and 2 or 1) < (b[3][3] and 2 or 1) end				else return a[3][2] < b[3][2] end			end)

local tRet = {} table.insert(tRet, tableHdr(showTokens)) for _, oneTask in ipairs(tActList) do       local data = oneTask[3] local actChar2 = data[3] or "" local asChar2 = 0 local actText = data.act or oneTask[2] if oneTask[4] and data[3] then asChar2 = 3 actChar2 = oneTask[4] actText = data.act2 or data.act or oneTask[2] end local evt, ECtype local tokens = data.tok local toknpc = data.toknpc if (data.event and data.event[evtID]) then evt = evtID ECtype = data.event[evtID][1] and evtID tokens = data.event[evtID][2] toknpc = data.event[evtID][3] end

local tRow = { "|-\n| style=\"text-align:center;\"|", "", "", "", "", -- Char1 (2-5) "\n|", -- (6) "", "", "", "", "", -- Animation (7-11) "", -- Happiness (12) actText, -- Activity (13) "", -- Requirements (14) "\n|", -- (15) "", "", "", "", "", -- Char2 (16-20) "\n", -- (21) "", -- Task (duration / rewards) (22) "", "", -- Trophy (23-24) "", "", -- Tokens / Trophy (25-26) "\n" -- (27) }

if showIcon then tRow[2] = icon({oneTask[1], evt}) tRow[3] = " ''Level " tRow[5] = "'' " end tRow[4] = data[1 + asChar2] or "?"

if data.anim then tRow[ 7] = " " end

if data["wish"] then tRow[12] = " " end

if data.req then local tReq = {} for _, reqData in ipairs(data.req) do				local tOneReq = {"", -- 1 "", reqData[1], "", -- 2..4 "", "", "", -- 5..7								}				if string.match(reqData[1], "/Basic$") then tOneReq[2] = "" tOneReq[3] = "No Costume" tOneReq[4] = "" end if reqData[2] then if tonumber(reqData[2]) then tOneReq[5] = " (Ench. Lvl "						tOneReq[6] = tonumber(reqData[2])						tOneReq[7] = ")" elseif reqData[2] == "N" then tOneReq[1] = "No " end end table.insert(tReq, table.concat(tOneReq)) end tRow[14] = " ''" .. mw.text.listToText(tReq, ", ", " & ") .. "'' "		end

if data[3] then tRow[16] = " align=\"center\" nowrap|" tRow[17] = icon({actChar2, nil, "25"}) tRow[18] = " ''Lvl " tRow[19] = data[4 - asChar2] tRow[20] = "'' " end

tRow[22] = task({data[2], data[3] and "J" or nil, ECtype}) if data["trophy"] then tRow[23] = ", " tRow[24] = NPC({"Gold Trophies"}) end

if showTokens then tRow[25] = "\n| nowrap|" tRow[26] = token(tokens, nil, true, conflict) end

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

local function getDataFile(ch) local sName = coll.getCollection({ch, "S"}) if (sName ~= "" and not actData[sName]) then actData[sName] = mw.loadData( 'Module:Activity/' .. sName ) end return actData[sName] end

local function addAct(tList, tChk, in_ch, in_act, fixed) local ch = in_ch local act = in_act local tChActData = getDataFile(ch) local actData = nil

if tChActData and tChActData[ch] then actData = tChActData[ch][act]

while (actData and actData.alias) do			local aliasCh = actData.alias[1] or ch			local aliasAct = actData.alias[2] or act if (aliasCh == ch and aliasAct == act) then actData = nil else ch = aliasCh act = aliasAct tChActData = getDataFile(ch) if tChActData[ch] then actData = tChActData[ch][act] end end end end local tAct = {in_ch, in_act} if actData then if (not fixed) then tAct[1] = ch end tAct[2] = act tAct[3] = actData if fixed and (ch ~= in_ch) then tAct[4] = ch end else tAct[3] = badAct end if not tChk[tAct[1]..tAct[2]] then table.insert(tList, tAct) tChk[tAct[1]..tAct[2]] = 1 end return end

local function normalDisplay local tList = {} local tChk = {}

for _, act in ipairs(tTasks) do		addAct(tList, tChk, act[1], act[2]) end return genOut(tList, nil) end

local function characterPage local ch	local costume

if tTasks[1] then ch = tTasks[1][1] end if not ch then ch = mw.title.getCurrentTitle.rootText or "" if mw.title.getCurrentTitle.isSubpage then costume = mw.title.getCurrentTitle.subpageText or "" end end if coll.getItemType(ch) ~= "ch" then return "" end

local tActData = getDataFile(ch)

local tList = {} local tChk = {} local tOut = {}

if tActData and tActData[ch] then for key, data in pairs(tActData[ch]) do			addAct(tList, tChk, ch, key, true) end end return genOut(tList, nil) end

local function attractionPage return "Not Finished Yet\nAttraction Page Format\n" end

local function ECPage return "Not Finished Yet\nEvent Currency Page Format\n" end

local function animatedTasks return "Not Finished Yet\nAnimated Tasks Page Format\n" end

local function trophyTasks return "Not Finished Yet\nTrophy Tasks List\n" end

local function processArgs(frame) tArgs = util.getArgs(frame)

-- ensure blank table tTasks = {}

-- Loop over all numbered args to get Character/Activity Pairs for _, value in ipairs(tArgs) do		table.insert(tTasks, mw.text.split(value, "%s*%$%s*")) end if tArgs.icon then showIcon = true else showIcon = false end if tArgs.notoken then showTokens = false else showTokens = true end evtID = tArgs.event conflict = tArgs.conflict end

function p.main(frame) processArgs(frame)

local tFunc = { normal = normalDisplay, character = characterPage, attraction = attractionPage, currency = ECPage, animated = animatedTasks, trophy = trophyTasks, }

local display = string.lower(tArgs.display or "normal")

if tFunc[display] then return tFunc[display] else return normalDisplay end

--	return "Not Finished Yet\nStill finalising data table structure\n" end

return p --