-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntity.lua
More file actions
44 lines (40 loc) · 1.07 KB
/
Entity.lua
File metadata and controls
44 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'utils'
local function AddComponent(entity, component)
-- Component MUST have a name property
local name = component.name
entity.components[name] = component
return entity
end
local function RemoveComponent(entity, componentName)
entity.components[componentName] = nil
return entity
end
local function PrintEntity(entity)
local components = entity.components
print('Entity{id: '..entity.id..', #components: '..#keys(components)..', components: {'..dump(components)..'}}')
return entity
end
-- Create an Entity
local function Entity()
local id = generateId()
local components = {}
local entity = {
id = id,
components = components
}
-- Update global entity count
count = count + 1
function entity:addComponent(component)
-- components[component.name] = component
-- entity.components = components
return AddComponent(self, component)
end
function entity:removeComponent(component)
return RemoveComponent(self, component)
end
function entity:print()
return PrintEntity(self)
end
return entity
end
return Entity