Module:LoRData

-- local p        = {} local lib      = require('Module:Feature') local userError = require('Dev:User error') local json     = require('Module:JSON')

local regions  = { ["DE"]             = "Demacia", ["FR"]             = "Freljord", ["IO"]             = "Ionia", ["NX"]             = "Noxus", ["PZ"]             = "Piltover & Zaun", ["SI"]             = "Shadow Isles", ["Demacia"]        = "DE", ["Freljord"]       = "FR", ["Ionia"]          = "IO", ["Noxus"]          = "NX", ["Piltover & Zaun"] = "PZ", ["Shadow Isles"]   = "SI" }

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local get     = require ('Module:LoRData/getter') local cardcode = args['cardcode'] or args[1] local datatype = args['datatype'] or args[2] local output  = args['output']   or args[3] or nil local result = get[datatype](cardcode) if output ~= nil and type(result) == "table" then if output == "csv" then return table.concat(result, ",") elseif output == "tip" then table.sort(result) return frame:preprocess(" ") end elseif (datatype == "desc" or datatype == "lvldesc" or datatype == "flavor") and result ~= nil then return frame:preprocess(result) elseif result == nil then return "" else return result end end

function p.getRegion(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end return regions[args['region'] or args[1]] end

function p.getRegionFromCardcode(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local cardcode = args['cardcode'] or args[1] or nil return regions[mw.ustring.sub(cardcode, 3, 4)] end

function p.getSetFromCardcode(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local cardcode = args['cardcode'] or args[1] or nil return tonumber(mw.ustring.sub(cardcode, 0, 2)) end

function p.cardData local titleobject = mw.title.new('User:Ninjamask/Sandbox/LoR.json') local o          = json.decode(titleobject:getContent) local s          = "" local cardData   = {} for _, data in pairs(o) do       table.insert(cardData, data) end table.sort(cardData, function(a, b) return a.cardCode < b.cardCode end) -- ============================   -- = Generate lua data output = -- ============================   s = s .. '-- \n' s = s .. '-- Legends of Runeterra data \n' s = s .. '\n' s = s .. 'return {\n'

for i, card in pairs(cardData) do       -- StatTable data local sLoop = "" sLoop = sLoop .. '   ["' .. card.cardCode .. '"] = {\n' local sCardRefs = '{"'       sCardRefs = sCardRefs .. table.concat(card.associatedCardRefs, '", "') .. '"}' if sCardRefs ~= '{""}' then sLoop = sLoop .. '       ["cardRefs"]    = '  .. lib.tbl(card.associatedCardRefs)    .. ',\n' end sLoop = sLoop .. '       ["name"]        = "'     .. card.name                  .. '",\n' sLoop = sLoop .. '       ["type"]        = "'     .. card.type                  .. '",\n' sLoop = sLoop .. '       ["rarity"]      = "'     .. card.rarity                .. '",\n' if card.subtype ~= "" then sLoop = sLoop .. '       ["subtype"]     = "' .. card.subtype               .. '",\n' end if card.supertype ~= "" then sLoop = sLoop .. '       ["supertype"]   = "' .. card.supertype             .. '",\n' end -- if card.spellSpeed ~= "" then --    sLoop = sLoop .. '       ["spellSpeed"]     = "' .. card.spellSpeed            .. '",\n' -- end local sKeywords = '{"'       sKeywords = sKeywords .. table.concat(card.keywords, '", "') .. '"}' if sKeywords ~= '{""}' then sLoop = sLoop .. '       ["keywords"]    = '  .. lib.tbl(card.keywords)    .. ',\n' end sLoop = sLoop .. '       ["collectible"] = '      .. tostring(card.collectible) .. ',\n' sLoop = sLoop .. '       ["attack"]      = '      .. card.attack               .. ',\n' sLoop = sLoop .. '       ["cost"]        = '      .. card.cost                 .. ',\n' sLoop = sLoop .. '       ["health"]      = '      .. card.health               .. ',\n' if card.descriptionRaw ~= "" then sLoop = sLoop .. '       ["desc"]        = "' .. string.gsub(string.gsub(string.gsub(card.descriptionRaw, '\"', '\\"'), "\n", "\\n"), "\r\\n", "\\n") .. '",\n' end if card.levelupDescriptionRaw ~= "" then sLoop = sLoop .. '       ["lvldesc"]     = "' .. string.gsub(string.gsub(string.gsub(card.levelupDescriptionRaw, '\"', '\\"'), "\n", "\\n"), "\r\\n", "\\n") .. '",\n' end sLoop = sLoop .. '       ["flavor"]      = "'     .. string.gsub(string.gsub(string.gsub(card.flavorText, '\"', '\\"'), "\n", "\\n"), "\r\\n", "\\n") .. '",\n' sLoop = sLoop .. '       ["artist"]      = "'     .. card.artistName            .. '"\n' sLoop = sLoop .. '   },\n' s = s .. sLoop end s = s .. '}\n' s = s .. '-- \n' -- pre needs to be splitted with, because of Lua weirdness s = s .. '-- '   return ' ' .. mw.text.nowiki(s) .. ' ' end

function p.cardlist(frame) local lorData  = mw.loadData('Module:LoRData/data') local lang     = mw.language.new( "en" ) local tablenode = mw.html.create('table')

tablenode :addClass('sortable article-table nopadding sticky-header') :css('width','100%') :css('text-align','center') :newline :tag('tr') :tag('th') :done :newline :tag('th') :wikitext('Name') :done :newline :tag('th') :wikitext('Type') :done :newline :tag('th') :wikitext('Subtype') :done :newline :tag('th') :wikitext('Region') :done :newline :tag('th') :css('width','20px') :tag('span') :attr('title','Cost') :wikitext('') :done :done :newline :tag('th') :css('width','20px') :tag('span') :attr('title','Attack') :wikitext('') :done :done :newline :tag('th') :css('width','20px') :tag('span') :attr('title','Health') :wikitext('') :done :done :newline :tag('th') :wikitext('Rarity') :done :done :newline -- START local cardtable = {} for cardcode in pairs(lorData) do           table.insert(cardtable, cardcode) end table.sort(cardtable) for i, cardcode in pairs(cardtable) do           local t        = lorData[cardcode] local cardnode = mw.html.create('tr') local region  = p.getRegionFromCardcode{cardcode} -- Image cardnode :tag('td') :addClass('lor-tooltip') :attr('data-sort-value', cardcode) :attr('data-param', cardcode) :wikitext('') :done -- Cardname cardnode :tag('td') :css('text-align', 'left') :wikitext(t.name) :done -- Type cardnode :tag('td') :css('text-align', 'left') :wikitext(t.type) :done -- Subtype cardnode :tag('td') :css('text-align', 'left') :wikitext(t.subtype) :done -- Region cardnode :tag('td') :css('text-align', 'left') :wikitext(' ' .. region .. '') :done -- Cost cardnode :tag('td') :css('text-align', 'left') :wikitext(t.cost) :done -- Attack cardnode :tag('td') :css('text-align', 'left') :wikitext(t.attack) :done -- Health cardnode :tag('td') :css('text-align', 'left') :wikitext(t.health) :done -- Rarity cardnode :tag('td') :css('text-align', 'left') :wikitext(t.rarity) :done -- Add card row to the table tablenode :newline :node(cardnode) end -- END tablenode:allDone return tostring(tablenode) end

return p -- --