RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
achievement_notifier.gd
Go to the documentation of this file.
1extends RefCounted
2
3
6
7var layout_manager
8var settings_manager
9var queue := []
10var active := false
11var duration_seconds := 2.5
12var position := Vector2(18, 18)
13var _run_id := 0
14var _active_notifications := []
15
16
17func configure(layout, settings = null, options:Dictionary = {}) -> void:
18 layout_manager = layout
19 settings_manager = settings
20 duration_seconds = float(options.get("duration", duration_seconds))
21 position = options.get("position", position)
22
23
24
25func dispose() -> void:
26 _run_id += 1
27 queue.clear()
28 active = false
29 for notification in _active_notifications:
30 if is_instance_valid(notification):
31 notification.queue_free()
32 _active_notifications.clear()
33
34
35
36func show(parent:Node, stats_manager, ids:Array) -> void:
37 if parent == null or stats_manager == null or ids.is_empty():
38 return
39 var achievements = stats_manager.get_achievements()
40 for id in ids:
41 queue.append(achievements.get(id, {"id": id}))
42 if not active:
43 _process_queue(parent)
44
45
46func _process_queue(parent:Node) -> void:
47 if parent == null or layout_manager == null:
48 queue.clear()
49 active = false
50 return
51 active = true
52 var run_id := _run_id
53 while run_id == _run_id and not queue.is_empty() and is_instance_valid(parent):
54 var achievement = queue.pop_front()
55 var notification = layout_manager.create_achievement_notification(achievement)
56 notification.position = position
57 parent.add_child(notification)
58 _active_notifications.append(notification)
59 layout_manager.apply_theme(notification, str(_settings_value("theme", "dark")))
60 if settings_manager != null and settings_manager.has_method("apply_text_size"):
61 settings_manager.apply_text_size(notification)
62 var tree := parent.get_tree()
63 if tree == null:
64 break
65 await tree.create_timer(duration_seconds).timeout
66 if run_id != _run_id:
67 break
68 if is_instance_valid(notification):
69 notification.queue_free()
70 _active_notifications.erase(notification)
71 active = false
72
73
74func _settings_value(key:String, default_value):
75 if settings_manager != null and settings_manager.has_method("get_settings"):
76 return settings_manager.get_settings().get(key, default_value)
77 return default_value