Module:Activity-2

--[=[

Temporary Lua Module for Character Activities Templates Functions

--]=]

local p = {} local util = require("Module:Utility")

local EC = require("Module:EC").getEC local LTE = require("Module:LTEvent").getLTE local TOK = require("Module:CharacterToken").getToken local ICON = require("Module:CharacterAvatar").getAvatar local COLL = require("Module:ItemCollection").getCollection local TASK = require("Module:Tasks").getData local NPC = require("Module:NPC").getNPC

local function unavailable(tokens, type, pagename, event) if not tokens or tokens == "" then return "" end local tOut = {} for _, k in ipairs(tokens) do		if pagename == TOK({k, "T"}) then if type == "S" then return 'style="border: 3px solid #595358; border-style: dashed;'			elseif type == "T" then				return " * Unavailable during the " .. LTE({event, nil, "A", "Event"}) .. " "			end		end	end	return "" end

local function eventchanges(afterevent, duringevent) if afterevent == duringevent then return nil end if not (type(afterevent) == "table" and type(duringevent) == "table") then return {from = afterevent, to = duringevent} end

local result = {} for k, v in pairs(afterevent) do		result[k] = eventchanges(v, duringevent[k]) end for k, v in pairs(duringevent) do		if afterevent[k] == nil then result[k] = eventchanges(nil, v)		end end

return next(result) and result end

function p.getconflicts(tokens, event) if type(tokens) ~= "table" then return "" end local allcharacters = – local tOut = {'{| class="article-table" style="text-align: center; line-height: 1.0; width: fit-content;"'} local i = 6

for _, data in ipairs(tokens) do		if type(TOK({data, "X"})) == "table" then for _, v in ipairs(TOK({data, "X"})) do				if not allcharacters[v] then if v:match("^IP-") then table.insert(allcharacters[1], 'AAAA-' .. v)					elseif v:match("^Fabric ") then table.insert(allcharacters[1], 'ZZZZ-' .. v)					else table.insert(allcharacters[1], v)					end allcharacters[v] = v				end end end end

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

for k, name in pairs(allcharacters[1]) do		if i == 6 then i = 0 table.insert(tOut, '\n|-') end if name:match("^AAAA-") then table.insert(tOut, ('\n| style="width: 15%; padding: 5px;"|' .. COLL({mw.ustring.lower(name):match("^aaaa%-ip%-(.+)$"), "P"}))) i = i + 1 elseif name:match("^ZZZZ-") then table.insert(tOut, ('\n| style="width: 15%; padding: 5px;"|' .. TOK({name:match("^ZZZZ%-(.+)$"), "50"}) .. ' ' .. TOK({name:match("^ZZZZ%-(.+)$"), "L"}) .. ' '))			i = i + 1 elseif name ~= "" then table.insert(tOut, ('\n| style="width: 15%; padding: 5px;"|' .. ICON({name, (event or '')}) .. ' ' .. name .. ' ')) i = i + 1 end end

table.insert(tOut, "\n|}\n Note: if the collection icon is displayed, it means that this token conflicts with the whole collection") return table.concat(tOut) end

function p.main(frame) local tArgs = util.getArgs(frame) local today = os.date("%Y/%m/%d %H:%M:%S") local fullpagename = tArgs["F"] or mw.title.getCurrentTitle.prefixedText or "" local pagename = tArgs["P"] or mw.title.getCurrentTitle.text or ""

local char1 = tArgs["ch1"] or "? #0" local ch1name, ch1lvl = mw.ustring.match(char1, "^([^#]-)%s*#*%s*([%d%,]*)$") if not ch1name then ch1name = char1 ch1lvl = "?" end if ch1lvl == "0" then ch1lvl = "?" end

local char2 = tArgs["ch2"] local ch2name = nil local ch2lvl = nil if char2 then ch2name, ch2lvl = mw.ustring.match(char2, "^([^#]-)%s*#*%s*([%d%,]*)$") if not ch2name then ch2name = char2 ch2lvl = "?" end if ch2lvl == "0" then ch2lvl = "?" end end

local actanim = tArgs["anim"] local actname = tArgs["name"] or "?" local actaltname = tArgs["altname"] or actname local actreq = tArgs["req"] local acttime = tArgs["time"] or "?h"

local wish = tArgs["wish"] local trophy = tArgs["trophy"] local notokens = tArgs["notok"] local tokens = tArgs["tok"] or ""

local event = tArgs["event"] local noec = tArgs["noec"] --	if event and LTE({event, nil, "SD"}) > today then event = nil end local eventtokens = tArgs["eventtok"] or ""

local tOut = {	'|-', "", '\n| style="text-align: center;"|', "", '\n|', (actanim and " " or ""), actname, "", "", '\n| nowrap|', (wish and EC({"Happiness"}) or ""), '\n', TASK({acttime, (ch2name and "J" or ""), event}), "", '\n| nowrap style="text-align: center;"|', TOK({tokens, nil, "B"}), ("\n"), "" }

if ch2name then tOut[11] = ICON({ch2name, nil, 30}) .. ' ' .. " ''Lvl " .. ch2lvl .. "'' "		tOut[18] = "" end

if noec and event and noec == event then tOut[13] = TASK({acttime, (ch2name and "J" or "")}) end

if not fullpagename:match("^Template") then tOut[17] = "" tOut[18] = "" end

if pagename == ch1name then tOut[4] = ch1lvl elseif ch2name and pagename == ch2name then tOut[4] = ch2lvl tOut[7] = actaltname tOut[11] = ICON({ch1name, nil, 30}) .. ' ' .. " ''Lvl " .. ch1lvl .. "'' "	else tOut[4] = ICON({ch1name, event}) .. " ''Level " .. ch1lvl .. "'' "	end if actreq then local sep = "" local rOut = "" local requirements = mw.text.split(actreq, "%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 tOut[8] = " ''*" .. rOut .. "'' "	end if trophy and not event then tOut[14] = ", " .. NPC({"Gold Trophies", "G"}) end if not notokens then if event and eventtokens ~= tokens then --			if LTE({event, nil, "SD"}) < today and today < LTE({event, nil, "ED"}) then if today < LTE({event, nil, "ED"}) then local alltokens = {} alltokens["After"] = mw.text.split(tokens, "%s*%$%s*") alltokens["During"] = mw.text.split(eventtokens, "%s*%$%s*") local unavtokens = {}

for _, data in pairs(eventchanges(alltokens["After"], alltokens["During"])) do					for y, v in pairs(data) do						if y == "from" then table.insert(unavtokens, v) end end end

tOut[2] = unavailable(unavtokens, "S", pagename, event) tOut[9] = unavailable(unavtokens, "T", pagename, event)

tOut[16] = TOK({eventtokens, nil, "B"}) end end else tOut[15] = "" tOut[16] = "" end return table.concat(tOut) end

return p