-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathShapes.gd
48 lines (40 loc) · 960 Bytes
/
Shapes.gd
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
extends GridContainer
var _shapes = []
var _index = 0
func get_shape() -> ShapeData:
if _index == 0:
_shapes.shuffle()
_index = _shapes.size()
_index -= 1
var s = ShapeData.new()
s.name = _shapes[_index].name
s.color = _shapes[_index].color
s.coors = _shapes[_index].coors
s.grid = _shapes[_index].grid
return s
func _ready():
for shape in get_children():
var data = ShapeData.new()
data.name = shape.name
data.color = shape.modulate
var size = shape.columns
var s2 = size / 2
data.coors = range(-s2, s2 + 1)
# Remove the zero coordinate for even-sized grids
if size % 2 == 0:
data.coors.remove(s2)
#print(data.coors) # For testing purposes
data.grid = _get_grid(size, shape.get_children())
_shapes.append(data)
func _get_grid(n, cells):
var grid = []
var row = []
var i = 0
for cell in cells:
row.append(cell.modulate.a > 0.1)
i += 1
if i == n:
grid.append(row)
i = 0
row = []
return grid