7const ConditionEvaluator = preload(
"res://scripts/systems/conditionEvaluator/condition_evaluator.gd")
8const DataCacheManager = preload(
"res://scripts/systems/dataCacheManager/data_cache_manager.gd")
12var condition_evaluator = ConditionEvaluator.new()
13var data_cache_manager = DataCacheManager.new()
17func load_steps(file_path:String) -> void:
19 var data = data_cache_manager.load_json(file_path)
20 if not data
is Dictionary:
22 configure(data.get(
"steps", []))
26func get_cache_stats() -> Dictionary:
27 return data_cache_manager.get_cache_stats()
31func configure(next_steps:Array, state:Dictionary = {}) -> void:
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:
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",
"")) !=
"":
47func set_complete(step_id:String, value:bool = true) -> void:
48 completed[step_id] = value
52func is_complete(step_id:String) -> bool:
53 return bool(completed.get(step_id, false))
57func update_from_context(context:Dictionary) -> void:
59 var id = str(step.get(
"id",
""))
60 if id ==
"" or is_complete(id):
62 if condition_evaluator.matches(step.get(
"conditions", {}), context):
67func get_next_step(context:Dictionary = {}) -> Dictionary:
68 if not context.is_empty():
69 update_from_context(context)
71 var id = str(step.get(
"id",
""))
72 if id !=
"" and not is_complete(id):
73 return step.duplicate(true)
78func get_checklist(context:Dictionary = {}) -> Array:
79 if not context.is_empty():
80 update_from_context(context)
83 var row = step.duplicate(true)
84 row[
"complete"] = is_complete(str(step.get(
"id",
"")))
90func get_state() -> Dictionary:
91 return {
"completed": completed.duplicate(true)}
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.