-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.lua
More file actions
98 lines (84 loc) · 2.4 KB
/
Copy pathsystem.lua
File metadata and controls
98 lines (84 loc) · 2.4 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
function getsystem()
local system = {}
system.__index = system
setmetatable(system, {
__call = function (klass, ...)
local self = setmetatable({}, klass)
self:_init(...)
return self
end,
})
function system:_init(type)
self.type = type
self.world = nil
self.entitys = {}
end
function system:set_type(newval)
self.type = newval
end
function system:get_type()
return self.type
end
function system:get_entity(entity_id)
if self.world == nil then
error("system not registered in world")
end
local entity = self.world:get_entity(entity_id)
return entity
end
function system:register_world(world)
self.world = world
end
function system:register_entity(entity)
if self.world == nil then
error("system not registered in world")
end
if entity == nil then
error("Cant register a nil entity")
end
if debug then
logger:debug("Registring some entity "..entity:get_id().." to system ")
end
local entity_type = entity:get_type()
local tmp = self:get_entity(entity_type)
--debug
if debug and tmp ~= nil then
logger:debug("type is "..tmp:get_type())
end
if tmp ~= nil then
--debug
if debug then
logger:debug("Aready added "..entity_type.." to system ")
end
else
if self.world:has_entity(entity:get_id()) then
add(self.entitys, entity)
else
error("Can register an entity that is not on the world")
end
--debug
if debug then
logger:debug("added "..entity:get_id().." to system ")
end
end
end
function system:unregister_entity(entity)
for i,e in ipairs(self.entitys) do
if e:get_id() == entity:get_id() then
del(self.entitys,e)
if debug then
logger:debug("unregistered "..entity:get_id().." from system ")
end
break
end
end
end
function system:update(dt)
end
function system:render()
end
return system
end