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!"] = { 2, 3600, "Goofy", 1, tok = {"Daisy Duck,2","Aladdin,3","Sebastian,2","Ralph,2"}, anim = "Goofy and Mickey high five", },			["Search for Friends"]	= { 1, 60,				tok = {"IP-MAF"}, wish = 1, anim = "Mickey Searches around the Kingdom", },			["Dance"] = { alias = {nil, "Dance with Minnie"}, },			["Dance with Minnie"] = { 8, 7200, "Minnie Mouse", 8, act2 = "Dance with Mickey", anim = "Mickey and Minnie dance together", },			["Review"] = { 3, 3600,				act = "Review Pete's Complaints", attr = {"Mickey's House"}, tok = {"Pumbaa,3"}, event = { nbc = {true,nil}, }			},			["Mistletoe"] = { alias = {"Minnie Mouse"}, },		},		-- Minnie Mouse ["Minnie Mouse"] = { ["Dance"] = { alias = {"Mickey Mouse"}, },			["Mistletoe"] = { 1, 7200, "Mickey Mouse", 1, cstm1 = "Mickey Mouse/Holiday", cstm2 = "Minnie Mouse/Holiday", tok  = {"Hans,3"}, anim = "Minnie and Mickey, in their Holiday costumes, share a tender moment under the mistletoe", },		},		-- Goofy ["Goofy"] = { ["High Five!"] = { alias = {"Mickey Mouse"}, },			["Check the Fun Wheel"] = { 1, 3600,				req = "[Mickey's Fun Wheel]", tok = {"IP-MI","Mickey Mouse,3","Woody,2"}, },			["Run in Panic"] = { 1, 60,				tok = {"IP-MAF"}, 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) "", -- blank (14) "", -- Requirements start (15) "", "", "", "", "", "", -- Attraction/level (16-21) "", "", "", "", -- Costume 1 (22-25) "", "", "", "", -- Costume 2 (26-29) "", -- Requirements end (30) "\n|", -- (31) "", "", "", "", "", -- Char2 (32-36) "\n", -- (37) "", -- Task (duration / rewards) (38) "", "", -- Trophy (39-40) "", "", -- Tokens / Trophy (41-42) "\n" -- (43) }

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

local hasReq = 0 if data.attr then tRow[16] = ""			tRow[17] = data.attr[1]			tRow[18] = "" if (data.attr[2]) then tRow[19] = " (Ench. Lvl "				tRow[20] = data.attr[2]				tRow[21] = ")" end hasReq = hasReq + 1 end if data.cstm1 then tRow[23] = ""			tRow[24] = data.cstm1			tRow[25] = "" hasReq = hasReq + 1 end if data.cstm2 then tRow[27] = ""			tRow[28] = data.cstm2			tRow[29] = "" hasReq = hasReq + 1 end if hasReq > 0 then tRow[15] = " ''" tRow[30] = "'' " if hasReq == 2 then if tRow[28] ~= "" then tRow[26] = " & " else tRow[22] = " & " end elseif hasReq == 3 then tRow[22] = ", " tRow[26] = " & " end end

if data[3] then tRow[32] = " align=\"center\" nowrap|" tRow[33] = icon({actChar2, nil, "25"}) tRow[34] = " ''Lvl " tRow[35] = data[4 - asChar2] tRow[36] = "'' " end

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

if showTokens then tRow[41] = "\n| nowrap|" tRow[42] = 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 --