Module:LoRData

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

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 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

return p -- --