Add README

This commit is contained in:
2026-03-21 09:14:38 +01:00
parent 64e9fbbe6f
commit c55b59fcad
3 changed files with 292 additions and 7 deletions

View File

@@ -1,15 +1,11 @@
class_name GeneratorUnlockGoalData
extends Resource
const GOAL_DATA_SCRIPT: Script = preload("res://core/goals/goal_data.gd")
@export var target_generator_id: StringName = &""
@export var goal: Resource
@export var goal: GoalData
func get_goal_data() -> Resource:
func get_goal_data() -> GoalData:
if goal == null:
return null
if goal.get_script() != GOAL_DATA_SCRIPT:
return null
return goal

View File

@@ -1,5 +1,7 @@
extends Node
signal goal_achieved(goal_id: StringName, target_generator_id: StringName)
class GeneratorUnlockGoal extends RefCounted:
var target_generator_id: StringName
var goal: Resource
@@ -16,6 +18,8 @@ const GENERATOR_UNLOCK_GOAL_DATA_SCRIPT: Script = preload("res://core/generator-
var _runtime_goals: Array[GeneratorUnlockGoal] = []
var _known_generator_ids: Dictionary = {}
var _warned_unknown_target_ids: Dictionary = {}
var _is_evaluating_goals: bool = false
var _pending_goal_evaluation: bool = false
func _ready() -> void:
_collect_known_generator_ids()
@@ -37,10 +41,20 @@ func _on_generator_state_changed(generator_id: StringName, _state: Dictionary) -
func _evaluate_all_goals() -> void:
if _runtime_goals.is_empty():
return
if _is_evaluating_goals:
_pending_goal_evaluation = true
return
_is_evaluating_goals = true
for runtime_goal in _runtime_goals:
_evaluate_goal(runtime_goal)
_is_evaluating_goals = false
if _pending_goal_evaluation:
_pending_goal_evaluation = false
_evaluate_all_goals.call_deferred()
func _evaluate_goal(runtime_goal: GeneratorUnlockGoal) -> bool:
if runtime_goal == null:
return false
@@ -55,11 +69,23 @@ func _evaluate_goal(runtime_goal: GeneratorUnlockGoal) -> bool:
if not bool(runtime_goal.goal.call("is_met")):
return false
var goal_id: StringName = _extract_goal_id(runtime_goal.goal)
GameState.set_generator_unlocked(runtime_goal.target_generator_id, true)
GameState.set_generator_available(runtime_goal.target_generator_id, true)
print("[UnlockSystem] Goal completed: %s -> %s" % [String(runtime_goal.goal.get("id")), String(runtime_goal.target_generator_id)])
goal_achieved.emit(goal_id, runtime_goal.target_generator_id)
print("[UnlockSystem] Goal completed: %s -> %s" % [String(goal_id), String(runtime_goal.target_generator_id)])
return true
func _extract_goal_id(goal: Resource) -> StringName:
if goal == null:
return &""
var goal_id_text: String = String(goal.get("id")).strip_edges()
if goal_id_text.is_empty():
return &""
return StringName(goal_id_text)
func _is_goal_completed(runtime_goal: GeneratorUnlockGoal) -> bool:
return (
GameState.is_generator_unlocked(runtime_goal.target_generator_id)