mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
- Now entity.key() is the same as entity.key.value - Entity:serialize only serializes component given correctly - Any other value inside the Entity is ignored - Disable some diagnostics used in Lua language server by sumneko
41 lines
769 B
Lua
41 lines
769 B
Lua
local PATH = (...):gsub('%.builtins%.[^%.]+$', '')
|
|
|
|
local Component = require(PATH..".component")
|
|
|
|
local getKey = function (self, key)
|
|
local entity = self.__entity
|
|
|
|
if not entity:inWorld() then
|
|
error("entity needs to belong to a world")
|
|
end
|
|
|
|
local world = entity:getWorld()
|
|
|
|
return world:__assignKey(entity, key)
|
|
end
|
|
|
|
local Key = Component("key", function (self, key)
|
|
self.value = getKey(self, key)
|
|
end)
|
|
|
|
function Key:deserialize (data)
|
|
self.value = getKey(self, data)
|
|
end
|
|
|
|
function Key.__mt:__call()
|
|
return self.value
|
|
end
|
|
|
|
function Key:removed (replaced)
|
|
if not replaced then
|
|
local entity = self.__entity
|
|
|
|
if entity:inWorld() then
|
|
local world = entity:getWorld()
|
|
|
|
return world:__clearKey(entity)
|
|
end
|
|
end
|
|
end
|
|
|
|
return Key
|