Module:GameData

local p = {}

function firstToUpper(str) return (str:gsub("^%l", string.upper)) end

function createcarddatatable(cardname, ordertable, inclextrastats) local fulldatatable = mw.text.jsonDecode(mw.title.makeTitle('Template', 'JSONGameData'):getContent) local rawcarddatatable = {} local carddatatable = {} -- create rawcarddatatable for k, v in ipairs (fulldatatable) do		if fulldatatable[k]["isOverriddenVersion"] == nil then if fulldatatable[k]["name"] == cardname then rawcarddatatable = fulldatatable[k] break end else if fulldatatable[k]["name"] == cardname and fulldatatable[k]["isOverriddenVersion"] == "True" then rawcarddatatable = fulldatatable[k] break end end end -- return empty table if card data not found if next(rawcarddatatable) == nil then return {} end -- populate carddatatable in order: -- as defined by ordertable, then any "extraStats", ignore anything else for k2, v2 in ipairs (ordertable) do		if type(rawcarddatatable[v2]) ~= "nil" then table.insert(carddatatable, {identifier=firstToUpper(tostring(v2)), value=rawcarddatatable[v2]}) rawcarddatatable[v2] = nil end end if inclextrastats and type(rawcarddatatable["extraStats"]) ~= "nil" then for k3, v3 in ipairs (rawcarddatatable["extraStats"]) do			table.insert(carddatatable, {identifier=firstToUpper(tostring(rawcarddatatable["extraStats"][k3]["identifier"])), value=rawcarddatatable["extraStats"][k3]["value"]}) end rawcarddatatable["extraStats"] = nil end return carddatatable end

p.carddatatable = function(f) local args = f.args local carddatatable = {} local ordertable = {"name", "type", "rarity", "description", "manacost", "count", "unitToSummon", "health", "lifeTime", "attackspeed", "attackDelay", "damage", "delay", "duration", "radius", "travelSpeed", "range", "aOERange", "isRanged", "isAOE", "flying", "hitsFlying", "attackOnlyStationary", "speed", "dps"} carddatatable = createcarddatatable(args.cardname, ordertable, true) if next(carddatatable) == nil then return '' end local str = '{|class="wikitable" style="width:500px" \n!Key \n!width=70%|Value \n' for k2, v2 in ipairs (carddatatable) do str = str .. '|- \n|' .. tostring(v2["identifier"]) .. '||' .. tostring(v2["value"]) .. '\n' end str = str .. '|}'	return str end

p.semanticcarddata = function(f) local args = f.args local carddatatable = {} local ordertable = {"name", "type", "rarity", "description", "manacost", "count", "unitToSummon", "health", "lifeTime", "attackspeed", "attackDelay", "damage", "delay", "duration", "radius", "travelSpeed", "range", "aOERange", "isRanged", "isAOE", "flying", "hitsFlying", "attackOnlyStationary", "speed", "dps"} carddatatable = createcarddatatable(args.cardname, ordertable, true) if next(carddatatable) == nil then return '' end local str = '' return f:preprocess(str) end

return p