Module:UniverseData

-- local p = {}

local loreData = mw.loadData('Module:UniverseData/data') local lib      = require('Module:Feature') local FN       = require('Module:Filename')

function banner( piece ) local s = "" --image s = s .. " [[File:"        if piece.artwork == nil then            s = s .. "MSI 2018 Promo 01.jpg|link=]]" else s = s .. piece.artwork .. "|" .. piece .. "]]"       end s = s .. "]] "   --/image --description s = s .. " "        s = s .. "" if piece.loretype ~= nil then if piece.loretype == "Short Story" then s = s .. "Short Story • " if piece.duration == nil then s = s .. "N/A" else s = s .. piece.duration .. " Minute Read" end end else s = s .. piece.loretype end s = s .. " "       s = s .. ""        if piece.loretype == "Biography" then s = s .. piece.starring else s = s .. piece end        s = s .. " " if piece.description ~= nil then s = s .. "" .. piece.description .. " "        else s = s .. " " end if piece.starring ~= nil then s = s .. "Starring: " .. piece.starring .. " "       end if piece.mentioned ~= nil then s = s .. "Mentioned: " .. piece.mentioned .. " "       end s = s .. " "    --/description s = s " "

return s end

function p.getChampionlore (frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local loreList = "" local lore = {} local result = false for x in pairs(loreData) do       table.insert(lore, x)    end table.sort(lore) for _, piece in pairs(lore) do       local hit = false local t = loreData[piece] if (t.starring ~= nil) then if type(t.starring) == "table" then for _, substarring in pairs(t.starring) do                   if substarring == args[1] then hit = true result = true end end else if t.starring == args[1] then hit = true result = true end end end if hit == true then loreList = loreList .. banner(piece) end end if result == false then loreList = "No match found for " .. args[1] .. "."   end return loreList end

function p.getTest(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return "" end

function p.getArtwork(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return loreData[args[1]].artwork end function p.checkStarring(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end if loreData[args[1]].starring == nil then return "" else return "true" end end function p.checkMentioned(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end if loreData[args[1]].mentioned == nil then return "" else return "true" end end

function p.getStarring(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return getChampions( loreData[args[1]].starring ) end

function p.getMentioned(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return getChampions( loreData[args[1]].mentioned ) end

function getChampions ( t ) local s = "" local championtable = {} for i, champion in pairs(t) do       table.insert(championtable, champion) end table.sort(championtable) for i, champion in pairs(championtable) do       if i ~= 1 then s = s .. ", " .. champion .. " " else s = s .. " " .. champion .. " " end end return s end

function p.getRegion(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return loreData[args[1]].region end

function p.getLoretype(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return loreData[args[1]].loretype end

function p.getDuration(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return loreData[args[1]].duration end

function p.getDescription(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

return loreData[args[1]].description end

-- helper functions function table.val_to_str ( v ) if "string" == type( v ) then v = string.gsub( v, "\n", "\\n" ) if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then return "'" .. v .. "'"   end return '"' .. string.gsub(v,'"', '\\"' ) .. '"' else return "table" == type( v ) and table.tostring( v ) or     tostring( v ) end end function table.key_to_str ( k ) if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then return k else return "[" .. table.val_to_str( k ) .. "]" end end function table.tostring( tbl ) local result, done = {}, {} for k, v in ipairs( tbl ) do   table.insert( result, table.val_to_str( v ) ) done[ k ] = true end for k, v in pairs( tbl ) do   if not done[ k ] then table.insert( result,       table.key_to_str( k ) .. "=" .. table.val_to_str( v ) ) end end return "{" .. table.concat( result, "," ) .. "}" end

return p

-- --