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

function p.getList(frame) local collectionData = mw.loadData( 'Module:ItemCollection/data' )

local floats = {} local tOut = {	'{| class="article-table sortable" style="width: 100%;"\n', '! rowspan="2" class="unsortable" width="1"|\n', '! rowspan="2" width="57%"|Name\n', '! rowspan="2" style="text-align: center;" width="1"|Premium\n', '! rowspan="2" style="text-align: center;" width="1"|Limited\n', '! rowspan="2" style="text-align: center;" width="10"|Assign cost\n', '! colspan="2" style="text-align: center;"|Rewards\n', '|-\n! width="10%"|Gems\n! width="10%"|Magic' }	local tAtt = {} for item, data in pairs(floatData) do	   if data["A"] and data["R"]["magic"] and data["R"]["magic"][1] ~= "" then table.insert(floats, {mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), (item .. " Float"), data})      	end	end	table.sort(floats, function(a,b) return a[1] < b[1] end)    for _, flt in pairs(floats) do		local premium = ""		if collectionData["Items"][flt[2]] and collectionData["Items"][flt[2]][3] and collectionData["Items"][flt[2]][3] == true then			premium = ""       	end		local limited = ""		if collectionData["Items"][flt[2]] and collectionData["Items"][flt[2]][4] and collectionData["Items"][flt[2]][4] == true then			limited = ""   		end		tFlt = {"\n|-\n| style=\"text-align: center;\"|", "",				"\n|", "", "",				"\n| style=\"text-align: center;\"|", premium,				"\n| style=\"text-align: center;\"|", limited,				"\n| nowrap data-sort-value=\"", "", "\"|", "",				"\n| nowrap data-sort-value=\"", "", "\"|", "",				"\n| nowrap data-sort-value=\"", "", "\"|", ""				}

tFlt[ 2] = "" tFlt[ 4] = flt[2] tFlt[11] = flt[3]["A"] tFlt[13] = EC({"Magic"}) .. tFlt[11] tFlt[15] = flt[3]["R"]["magic"][1] tFlt[17] = EC({"Gems"}) .. tFlt[15] tFlt[19] = flt[3]["R"]["magic"][2] tFlt[21] = EC({"Magic"}) .. tFlt[19] table.insert(tOut, table.concat(tFlt)) end return table.concat(tOut) end

return p