-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_sequence.lua
More file actions
50 lines (38 loc) · 1.09 KB
/
vector_sequence.lua
File metadata and controls
50 lines (38 loc) · 1.09 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
local vector_sequence = {
_class = "vector_sequence",
is_in = function(self, vector)
vector = vector or {}
for _, value in pairs(self.list) do
if (value.x == (vector.x or 0)) and (value.y == (vector.y or 0)) then return true end
end
return false
end,
is_list_match = function(self, list)
for _, value in pairs(list ) do
if not self:is_in(value) then return false end
end
return true
end,
add = function(self, vector)
if not self:is_in(vector) then
return table.insert(self.list, vector)
end
return false
end,
push = function(self, list)
if type(list) ~= "table" then return false end
for _, value in pairs(list) do self:add(value) end
end,
}
setmetatable(vector_sequence, {
__call = function(self, list)
list = list or {}
local object = {
list = {}
}
setmetatable(object, { __index = vector_sequence })
object:push(list)
return object
end
})
return vector_sequence