-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtest31.lua
50 lines (37 loc) · 905 Bytes
/
test31.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
local ecs = require "ecs"
local w = ecs.world()
w:register {
name = "vector",
"x:float",
"y:float",
}
w:new {
vector = { x = 1, y = 2 }
}
-- vector_x is alias for vector.x
-- vector_y is alias for vector.y
for e in w:select "vector:in vector_x:in vector_y:out" do
assert(e.vector.x == e.vector_x)
print(e.vector_x)
e.vector_y = - e.vector_x
end
for e in w:select "vector:in vector_x:in vector_y:in" do
assert(e.vector.x == e.vector_x)
assert(e.vector.y == e.vector_y)
assert(e.vector_x == - e.vector_y)
print(e.vector_x, e.vector_y)
end
local t = w:template {
vector = { x = 100, y = 200 }
}
w:template_instance(w:new(), t, { vector_x = 42 })
print("Inc Vector.x")
for e in w:select "vector:in" do
w:extend(e, "vector_x:out")
print(e.vector.x, e.vector.y)
e.vector_x = e.vector.x + 1
end
print("Read Vector")
for e in w:select "vector:in" do
print(e.vector.x, e.vector.y)
end