mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 04:13:58 -04:00
Serializable component
You can remove the component to tell Concord an Entity shouldn't be serialized. It's given automatically on Entity creation, but this can be disabled by changing Entity.SERIALIZE_BY_DEFAULT to false.
This commit is contained in:
parent
892f4d4700
commit
cc0fd1614c
4 changed files with 32 additions and 4 deletions
5
concord/builtins/init.lua
Normal file
5
concord/builtins/init.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
local PATH = (...):gsub("(%.init)$", "")
|
||||
|
||||
return {
|
||||
serializable = require(PATH..".serializable"),
|
||||
}
|
12
concord/builtins/serializable.lua
Normal file
12
concord/builtins/serializable.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
local PATH = (...):gsub('%.builtins%.[^%.]+$', '')
|
||||
|
||||
local Component = require(PATH..".component")
|
||||
|
||||
local Serializable = Component("serializable")
|
||||
|
||||
function Serializable:serialize ()
|
||||
-- Don't serialize this Component
|
||||
return nil
|
||||
end
|
||||
|
||||
return Serializable
|
|
@ -8,7 +8,13 @@ local Components = require(PATH..".components")
|
|||
local Type = require(PATH..".type")
|
||||
local Utils = require(PATH..".utils")
|
||||
|
||||
local Entity = {}
|
||||
-- Initialize built-in Components (as soon as possible)
|
||||
local Builtins = require(PATH..".builtins")
|
||||
|
||||
local Entity = {
|
||||
SERIALIZE_BY_DEFAULT = true,
|
||||
}
|
||||
|
||||
Entity.__mt = {
|
||||
__index = Entity,
|
||||
}
|
||||
|
@ -31,6 +37,10 @@ function Entity.new(world)
|
|||
world:addEntity(e)
|
||||
end
|
||||
|
||||
if Entity.SERIALIZE_BY_DEFAULT then
|
||||
e:give("serializable")
|
||||
end
|
||||
|
||||
return e
|
||||
end
|
||||
|
||||
|
|
|
@ -323,9 +323,10 @@ function World:serialize()
|
|||
for i = 1, self.__entities.size do
|
||||
local entity = self.__entities[i]
|
||||
|
||||
local entityData = entity:serialize()
|
||||
|
||||
data[i] = entityData
|
||||
if entity.serializable then
|
||||
local entityData = entity:serialize()
|
||||
table.insert(data, entityData)
|
||||
end
|
||||
end
|
||||
|
||||
return data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue