mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 04:13:58 -04:00
Add serialization and deserialization functions to component, entity, world
This commit is contained in:
parent
c217183cb9
commit
6cd66e6737
6 changed files with 214 additions and 33 deletions
|
@ -18,6 +18,7 @@ function Component.new(populate)
|
|||
local componentClass = setmetatable({
|
||||
__populate = populate,
|
||||
|
||||
__name = nil,
|
||||
__isComponentClass = true,
|
||||
}, Component.__mt)
|
||||
|
||||
|
@ -32,22 +33,44 @@ end
|
|||
function Component:__populate() -- luacheck: ignore
|
||||
end
|
||||
|
||||
function Component:serialize() -- luacheck: ignore
|
||||
end
|
||||
|
||||
function Component:deserialize(data) -- luacheck: ignore
|
||||
end
|
||||
|
||||
--- Internal: Creates a new Component.
|
||||
-- @return A new Component
|
||||
function Component:__new()
|
||||
local component = setmetatable({
|
||||
__componentClass = self,
|
||||
|
||||
__isComponent = true,
|
||||
__isComponentClass = false,
|
||||
}, self.__mt)
|
||||
|
||||
return component
|
||||
end
|
||||
|
||||
--- Internal: Creates and populates a new Component.
|
||||
-- @param ... Varargs passed to the populate function
|
||||
-- @return A new populated Component
|
||||
function Component:__initialize(...)
|
||||
local component = setmetatable({
|
||||
__componentClass = self,
|
||||
|
||||
__isComponent = true,
|
||||
__isComponentClass = false,
|
||||
}, self)
|
||||
local component = self:__new()
|
||||
|
||||
self.__populate(component, ...)
|
||||
|
||||
return component
|
||||
end
|
||||
|
||||
function Component:hasName()
|
||||
return self.__name and true or false
|
||||
end
|
||||
|
||||
function Component:getName()
|
||||
return self.__name
|
||||
end
|
||||
|
||||
return setmetatable(Component, {
|
||||
__call = function(_, ...)
|
||||
return Component.new(...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue