feat: multiple components per entity support

This commit is contained in:
MihailRis
2024-07-04 19:47:52 +03:00
parent a6aa42a521
commit 8f379f2ee7
8 changed files with 120 additions and 65 deletions
+3
View File
@@ -1,4 +1,7 @@
{
"components": [
"drop"
],
"hitbox": [0.2, 0.125, 0.2],
"triggers": [
["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2],
+9 -6
View File
@@ -53,6 +53,7 @@ return {
entity.rigidbody = new_Rigidbody(eid)
entity.modeltree = new_Modeltree(eid)
entity.data = {}
entity.components = {}
entities[eid] = entity;
return entity
end,
@@ -62,17 +63,19 @@ return {
remove_Entity = function(eid)
local entity = entities[eid]
if entity then
entity.env = nil
entity.components = nil
entities[eid] = nil;
end
end,
update = function()
for id,entity in pairs(entities) do
local callback = entity.env.on_update
if callback then
local result, err = pcall(callback)
if err then
print(err)
for _, component in pairs(entity.components) do
local callback = component.on_update
if callback then
local result, err = pcall(callback)
if err then
print(err)
end
end
end
end