RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
tutorial_manager.gd
Go to the documentation of this file.
1extends RefCounted
2
3
6
7const ConditionEvaluator = preload("res://scripts/systems/conditionEvaluator/condition_evaluator.gd")
8const DataCacheManager = preload("res://scripts/systems/dataCacheManager/data_cache_manager.gd")
9
10var steps := []
11var completed := {}
12var condition_evaluator = ConditionEvaluator.new()
13var data_cache_manager = DataCacheManager.new()
14
15
16
17func load_steps(file_path:String) -> void:
18 steps.clear()
19 var data = data_cache_manager.load_json(file_path)
20 if not data is Dictionary:
21 return
22 configure(data.get("steps", []))
23
24
25
26func get_cache_stats() -> Dictionary:
27 return data_cache_manager.get_cache_stats()
28
29
30
31func configure(next_steps:Array, state:Dictionary = {}) -> void:
32 steps.clear()
33 completed = state.get("completed", {}).duplicate(true) if state.get("completed", {}) is Dictionary else completed
34 for step in next_steps:
35 if not step is Dictionary:
36 continue
37 var entry = step.duplicate(true)
38 entry["id"] = str(entry.get("id", ""))
39 entry["title"] = str(entry.get("title", entry.get("id", "")))
40 entry["text"] = str(entry.get("text", ""))
41 entry["conditions"] = entry.get("conditions", {}) if entry.get("conditions", {}) is Dictionary else {}
42 if str(entry.get("id", "")) != "":
43 steps.append(entry)
44
45
46
47func set_complete(step_id:String, value:bool = true) -> void:
48 completed[step_id] = value
49
50
51
52func is_complete(step_id:String) -> bool:
53 return bool(completed.get(step_id, false))
54
55
56
57func update_from_context(context:Dictionary) -> void:
58 for step in steps:
59 var id = str(step.get("id", ""))
60 if id == "" or is_complete(id):
61 continue
62 if condition_evaluator.matches(step.get("conditions", {}), context):
63 completed[id] = true
64
65
66
67func get_next_step(context:Dictionary = {}) -> Dictionary:
68 if not context.is_empty():
69 update_from_context(context)
70 for step in steps:
71 var id = str(step.get("id", ""))
72 if id != "" and not is_complete(id):
73 return step.duplicate(true)
74 return {}
75
76
77
78func get_checklist(context:Dictionary = {}) -> Array:
79 if not context.is_empty():
80 update_from_context(context)
81 var rows := []
82 for step in steps:
83 var row = step.duplicate(true)
84 row["complete"] = is_complete(str(step.get("id", "")))
85 rows.append(row)
86 return rows
87
88
89
90func get_state() -> Dictionary:
91 return {"completed": completed.duplicate(true)}
92
93
94
95func apply_state(state:Dictionary) -> void:
96 completed = state.get("completed", {}).duplicate(true) if state.get("completed", {}) is Dictionary else {}
bool
Mark a tutorial step complete/incomplete.