update entity script semantics
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
function on_spawn(eid)
|
||||
print("spawn", eid)
|
||||
function on_despawn()
|
||||
print("despawn")
|
||||
end
|
||||
|
||||
function on_despawn(eid)
|
||||
print("despawn", eid)
|
||||
end
|
||||
|
||||
function on_grounded(eid)
|
||||
local entity = stdcomp.new_Entity(eid) -- test
|
||||
function on_grounded()
|
||||
entity.transform:set_rot(mat4.rotate({0, 1, 0}, math.random()*360))
|
||||
end
|
||||
|
||||
@@ -25,11 +25,25 @@ end
|
||||
|
||||
-- Entity class
|
||||
|
||||
local Entity = {__index={}}
|
||||
local Entity = {__index={
|
||||
despawn=function(self) return entity.despawn(self.eid) end,
|
||||
}}
|
||||
|
||||
return {new_Entity = function(eid)
|
||||
local entity = setmetatable({eid=eid}, Entity)
|
||||
entity.transform = new_Transform(eid)
|
||||
entity.rigidbody = new_Rigidbody(eid)
|
||||
return entity
|
||||
end}
|
||||
local entities = {}
|
||||
|
||||
return {
|
||||
new_Entity = function(eid)
|
||||
local entity = setmetatable({eid=eid}, Entity)
|
||||
entity.transform = new_Transform(eid)
|
||||
entity.rigidbody = new_Rigidbody(eid)
|
||||
entities[eid] = entity;
|
||||
return entity
|
||||
end,
|
||||
remove_Entity = function(eid)
|
||||
local entity = entities[eid]
|
||||
if entity and entity.on_despawn then
|
||||
entity.on_despawn()
|
||||
end
|
||||
entities[eid] = nil;
|
||||
end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user