Module:Float

--[==[-- -- Lua script to get Float Information -- float: get Float data based on input parameters 1 = Float Name 3 = Event Name / IP Short Name

Unknown is returned if float is not in data. --]==]

local p = {}

---[=[ For testing remove 1 '-' from start of line local floatData = mw.loadData('Module:Float/data') --[==[]=] local floatData = { ["The Little Mermaid"] = { ["A"] = "500", ["R"] = { ["magic"] = {5, 750}, ["tlm"] = {5, 450}, }   }, } --]==]

local EC = require("Module:EC").getEC local icon = require("Module:CharacterAvatar").getAvatar local lte = require("Module:LTEvent").getLTE local util = require("Module:Utility")

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

local floatName = tArgs[1] or "" local event = tArgs[2] or "" local outType = tArgs[3] or "D"

floatName = floatName:gsub("^%s*(.-)%s*$", "%1") or '' if floatName == "" then floatName = mw.title.getCurrentTitle.text else floatName = mw.text.decode(floatName, false) end floatName = floatName:gsub("%s*Float$", "")

event = event:lower:gsub("^%s*(.-)%s*$", "%1") or ''

if not outType:match("^[ARD]$") then outType = "" end

local data = {}

if floatData[floatName] then data = floatData[floatName] else data = { ["A"] = "?", ["R"] = { ["magic"] = {"?", "?"}, }		}	   floatName = "Unknown" end

local reward = ""

if event ~= "" and data["R"][event] then reward = event else reward = "magic" -- current event (no magic entry yet) -- pick the first reward key (should be for current event) if not data["R"]["magic"] then for k, v in pairs(data["R"]) do				reward = k				break end end end

local tFunc = { -- Assign Cost ["A"] = function return EC({"Magic"}) .. data["A"] end, -- Rewards only ["R"] = function local retText = "" local space = ""

if event ~= "" then for k, v in pairs(data["R"]) do							if k ~= "magic" then local tRow = { space, EC({"Gems"}), v[1], ", ", EC({k}), v[2], "", "",									" (", lte({k, nil, "K"}), " Event) " }								retText = retText .. table.concat(tRow) space = " " end end if space == "" then if data["R"][reward][1] ~= "" then local tRow = { "", EC({"Gems"}), data["R"][reward][1], ", ", EC({reward}), data["R"][reward][2], }								retText = retText .. table.concat(tRow) end end else if data["R"][reward][1] ~= "" then local tRow = { "", EC({"Gems"}), data["R"][reward][1], ", ", EC({reward}), data["R"][reward][2], "", "",							}							retText = retText .. table.concat(tRow) end end return retText end, -- Default (token rewards table row) ["D"] = function local tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "",									"", "", "", "", "", "", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "", "", ", ", "", "", ""					}					tRet[ 2] = icon({"Parade", event or ""}) tRet[ 6] = floatName tRet[ 7] = " Float" if data["R"][reward][1] ~= "" then tRet[13] = "2h" tRet[15] = EC({"Gems"}) tRet[16] = data["R"][reward][1] tRet[18] = EC({reward}) tRet[19] = data["R"][reward][2] else tRet[17] = "" end return table.concat(tRet) end, }	return tFunc[outType] end

return p