Module:Data

local utils = require("Module:TemplateUtils")

--To get a simple text value function GetValue(path,entry,field) local data = mw.loadData("Module:Data/"..path) local value = data[entry][field] if type(value) == "table" then return table.concat(value, ", ") else return tostring(value) end end

function GetSubValue(path,t,entry,field) local data = mw.loadData("Module:Data/"..path) local value = data[t][entry][field] if type(value) == "table" then return table.concat(value, ", ") else return tostring(value) end end

--To get all of the keys of a game's datatype function GetKeys(path,separator) local data = mw.loadData("Module:Data/"..path) local t = {} for k,v in pairs(data) do		table.insert(t,k) end table.sort(t) return table.concat(t, separator) end

--To get all of the keys of a game's datatype function ModuleToJSON(path) local JSON = require("Module:JSON") local data = mw.loadData("Module:Data/"..path) return JSON:encode(utils.RecreateTable(data)) end

local p = {} function p.GetValue(frame) return GetValue(frame.args[1],frame.args[2],frame.args[3]) end function p.GetSubValue(frame) return GetSubValue(frame.args[1],frame.args[2],frame.args[3],frame.args[4]) end function p.GetKeys(frame) return GetKeys(frame.args[1],frame.args[2] or " ") end function p.ModuleToJSON(frame) return ModuleToJSON(frame.args[1]) end

function p.SelectFromWhere(from,whereName,whereValue) for key,value in pairs(from) do		if value[whereName] and value[whereName] == whereValue then return value end end return nil end

function p.SelectAllFromWhere(from,whereName,whereValue) local result = {} for key,value in pairs(from) do		if value[whereName] and value[whereName] == whereValue then table.insert(result, value) end end return result end

function p.SelectAllKeysFromWhere(from,whereName,whereValue) local result = {} for key,value in pairs(from) do		if value[whereName] and value[whereName] == whereValue then table.insert(result, key) end end return result end

return p