-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.lua
80 lines (62 loc) · 1.83 KB
/
entity.lua
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
Entity = (function ()
local entity_id = 1
return function (x, y, w, h, z)
local read_only = {}
local read_write = { }
local p = Point(x, y)
read_only["id"] = entity_id
entity_id = entity_id + 1
local get = function (key)
local value = read_only[key]
if not value then
value = read_write[key]
end
return value
end
local set = function (key, value)
read_write[key] = value
end
local getFilterFor = function(key)
return function(other)
if other.get then return other.get(key) end
end
end
local getBoundingBox = function()
return p.getX(), p.getY(), w, h
end
local getWidth = function ()
return w
end
local getHeight = function ()
return h
end
local getZOrder = function ()
return z
end
local getId = function ()
return read_only['id']
end
local getName = function ()
return name
end
local tic = function () end
local cleanup = function () end
return {
get = get,
set = set,
tic = tic,
cleanup = cleanup,
getWidth = getWidth,
getHeight = getHeight,
getZOrder = getZOrder,
getId = getId,
getName = getName,
getX = p.getX,
getY = p.getY,
setX = p.setX,
setY = p.setY,
getFilterFor = getFilterFor,
getBoundingBox = getBoundingBox
}
end
end)()