mNo edit summary Tag: sourceedit |
m (undid test) Tag: sourceedit |
||
Line 1: | Line 1: | ||
local objects = require("Module:Data/Objects"); |
local objects = require("Module:Data/Objects"); |
||
− | local utils = require("Module:TemplateUtils"); |
||
local function GetObjectById(self,id) |
local function GetObjectById(self,id) |
||
Line 36: | Line 35: | ||
local objects = createObjectManager(class):GetAll(); |
local objects = createObjectManager(class):GetAll(); |
||
objects = objects:Sort(sort,sortdesc=="desc"); |
objects = objects:Sort(sort,sortdesc=="desc"); |
||
− | return |
+ | return require("Module:TemplateUtils").PreProcess(frame,table.concat(objects:Format(format))) |
end |
end |
||
Latest revision as of 19:34, 30 October 2016
Documentation for this module may be created at Module:Data/Civ6/Base/Objects/doc
local objects = require("Module:Data/Objects");
local function GetObjectById(self,id)
local class = self.ClassDefinition
local data = require(class.DataPath)
return objects.CreateObject(id,data[class.KeysModule][id],class)
end
local function GetAllObjects(self)
local class = self.ClassDefinition
local data = require(class.DataPath)
local ol = objects.CreateObjectList(class);
objects.FillObjectList(ol,data[class.KeysModule],class)
return ol;
end
local function createObjectManager(key)
return {ClassDefinition=require("Module:Data/Civ6/Base/Objects/"..key);
GetById = GetObjectById;
GetAll = GetAllObjects;};
end
local function objectManagerLoader(t,key)
t[key]=createObjectManager(key);
return t[key];
end
--Todo, make sorting better, add filters
local function FormatObjects(frame)--(class,format,sort,sortdesc,filters)
local class = frame.args.Class
local format = frame.args.Format
local sort = frame.args.Sort or "Name"
local sortdesc = frame.args.SortDesc or "Asc"
local objects = createObjectManager(class):GetAll();
objects = objects:Sort(sort,sortdesc=="desc");
return require("Module:TemplateUtils").PreProcess(frame,table.concat(objects:Format(format)))
end
return setmetatable({FormatObjects=FormatObjects},{__index = objectManagerLoader});
--Usage:
-- objects = require("Module:Data/Civ6/Base/Objects")
-- Buildings = objects.Buildings
-- ListOfBuildings = Buildings:GetAll()
-- Monument = Buildings:GetById("BUILDING_MONUMENT")
-- To see all the functions of the objects see their class definitions under Project:Lua/Data/Civ6/Base/Objects. See also the base object manager at Module:Data/Objects