8const ConditionEvaluator = preload(
"res://scripts/systems/conditionEvaluator/condition_evaluator.gd")
9const DataCacheManager = preload(
"res://scripts/systems/dataCacheManager/data_cache_manager.gd")
13var condition_evaluator = ConditionEvaluator.new()
14var data_cache_manager = DataCacheManager.new()
18func load_rules(file_path:String) -> void:
20 var data = data_cache_manager.load_json(file_path)
21 if data
is Dictionary:
22 configure(data.get(
"unlocks", []))
26func get_cache_stats() -> Dictionary:
27 return data_cache_manager.get_cache_stats()
31func configure(next_rules:Array, state:Dictionary = {}) -> void:
33 unlocked = state.get(
"unlocked", {}).duplicate(true)
if state.get(
"unlocked", {})
is Dictionary
else unlocked
34 for rule
in next_rules:
35 if not rule
is Dictionary:
37 var entry = rule.duplicate(true)
38 entry[
"id"] = str(entry.get(
"id",
""))
39 entry[
"target"] = str(entry.get(
"target", entry.get(
"id",
"")))
40 entry[
"category"] = str(entry.get(
"category",
"general"))
41 entry[
"conditions"] = entry.get(
"conditions", {})
if entry.get(
"conditions", {})
is Dictionary
else {}
42 if str(entry.get(
"id",
"")) !=
"" and str(entry.get(
"target",
"")) !=
"":
47func evaluate(context:Dictionary = {}) -> Array:
48 var newly_unlocked := []
50 var target = str(rule.get(
"target",
""))
51 if target ==
"" or is_unlocked(target):
53 if condition_evaluator.matches(rule.get(
"conditions", {}), context):
54 unlocked[target] = true
55 newly_unlocked.append(rule.duplicate(true))
60func is_unlocked(target_id:String) -> bool:
61 return bool(unlocked.get(target_id, false))
65func set_unlocked(target_id:String, value:bool = true) -> void:
66 unlocked[target_id] = value
70func get_unlocks(filters:Dictionary = {}) -> Array:
73 var row = rule.duplicate(true)
74 var target = str(row.get(
"target",
""))
75 row[
"unlocked"] = is_unlocked(target)
76 if filters.has(
"category")
and str(filters.get(
"category",
"")) != str(row.get(
"category",
"")):
78 if filters.has(
"unlocked")
and bool(filters.get(
"unlocked", false)) !=
bool(row.get(
"unlocked", false)):
85func get_state() -> Dictionary:
86 return {
"unlocked": unlocked.duplicate(true)}
90func apply_state(state:Dictionary) -> void:
91 unlocked = state.get(
"unlocked", {}).duplicate(true)
if state.get(
"unlocked", {})
is Dictionary
else {}
bool
Return whether a target is unlocked.