-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBranchLenghtNodeRule.gd
More file actions
35 lines (24 loc) · 809 Bytes
/
BranchLenghtNodeRule.gd
File metadata and controls
35 lines (24 loc) · 809 Bytes
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
extends NodeRule
class_name BranchLengthNodeRule
@export var required_length := 3
func _init():
resource_local_to_scene = true
func check_correctness(local_node: PuzzleNode) -> bool:
var branch :Array[PuzzleNode] = local_node.get_branch()
var collective_required_length := required_length
var endpoints : Array[PuzzleNode] = []
for node in branch:
if node.connections.size() != 2:
endpoints.append(node)
if node == local_node:
continue
if node.node_rule is BranchLengthNodeRule:
if node.node_rule.color == color:
collective_required_length += node.node_rule.required_length
else:
return false
if branch.size() < 2:
return false
if endpoints.size() != 2:
return branch.size() == collective_required_length
return branch.size() - 1 == collective_required_length