-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gd
62 lines (53 loc) · 1.36 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
extends Control
const TASK = preload("res://classes/task/task.tscn")
func load_tree(data: String):
var i = 0
var title = ""
var stack = [$"/root/Main/"]
while i < data.length():
var chr = data[i]
if chr == ":" or chr == ";":
if title != "":
var new_task = TASK.instance()
new_task.set_title(title)
title = ""
if stack[0].name == "Main":
stack[0].add_child(new_task)
else:
stack[0].get_node("ChildAnchor").add_child(new_task)
stack.push_front(new_task)
if chr == ";":
stack.pop_front()
else:
title += chr
i += 1
$"/root/Main/Task".arrange_children()
randomize()
_reminder()
func _reminder():
print(OS.get_name())
if OS.get_name() == "X11":
OS.execute("notify-send", [_get_leaf_text(), "-e"])
$Ding.play()
var timer = get_tree().create_timer(2 * 60)
timer.connect("timeout", self, "_reminder")
func _get_leaf_text():
var leaves = _get_leaves()
return leaves[rand_range(0, leaves.size())].get_task_path()
func _get_leaves():
var root = $"/root/Main/Task"
var queue = [root]
var visited = [root]
var leaves = []
var node
while queue.size() > 0:
node = queue.pop_front()
var neighbors: Array = node.get_child_tasks()
if neighbors.size() > 0:
for neighbor in neighbors:
if !visited.has(neighbor):
queue.append(neighbor)
visited.append(neighbor)
else:
leaves.append(node)
return leaves