systems rework: buffs, prestige graph, research, modular architecture
Decouples core systems from centralized globals in favor of catalogue-based architecture and data-driven content. Key changes: - Prestige: node-based buff tech tree, graph panel, progress bar - Research: multi-worker system, per-generator research, xp generation - Ascension: meta-currency layer via multi-currency prestige resets - Buffs: refactored as generator-independent via catalogues - UI: currency panel, edge-scrolling camera + zoom, current-goal panel - Alchemy Tower: crafting building with recipe/cost system - Testing: 7 test suites (ascension, prestige, research, goals) - Content: migrated from hardcoded idles/ to gym format (tiny_sword)
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
extends PanelContainer
|
||||
|
||||
class GoalDefinition extends RefCounted:
|
||||
var target_generator_id: StringName
|
||||
var goal: GoalData
|
||||
|
||||
func _init(target_id: StringName, goal_data: GoalData) -> void:
|
||||
target_generator_id = target_id
|
||||
func _init(goal_data: GoalData) -> void:
|
||||
goal = goal_data
|
||||
|
||||
const GOAL_DATA_SCRIPT: Script = preload("res://core/goals/goal_data.gd")
|
||||
@@ -23,69 +21,59 @@ class GoalRow extends RefCounted:
|
||||
requirements_label = requirements
|
||||
button = unlock_button
|
||||
|
||||
@onready var _summary_label: Label = $MarginContainer/VBoxContainer/SummaryLabel
|
||||
@onready var _goals_list: VBoxContainer = $MarginContainer/VBoxContainer/ScrollContainer/GoalsList
|
||||
@onready var _summary_label: Label = $MarginContainer/ScrollContainer/VBoxContainer/SummaryLabel
|
||||
@onready var _goals_list: VBoxContainer = $MarginContainer/ScrollContainer/VBoxContainer/ScrollContainer/GoalsList
|
||||
@onready var game_state: LevelGameState = find_parent("LevelGameState")
|
||||
|
||||
var _loaded_goals: Array[GoalDefinition] = []
|
||||
var _rows_by_goal_id: Dictionary = {}
|
||||
var _known_generator_ids: Dictionary = {}
|
||||
var _warned_unknown_target_ids: Dictionary = {}
|
||||
var _generators_by_id: Dictionary = {}
|
||||
|
||||
func _ready() -> void:
|
||||
_collect_known_generator_ids()
|
||||
_load_goals()
|
||||
_build_goal_rows()
|
||||
GameState.currency_changed.connect(_on_currency_changed)
|
||||
GameState.generator_state_changed.connect(_on_generator_state_changed)
|
||||
if game_state:
|
||||
game_state.currency_changed.connect(_on_currency_changed)
|
||||
game_state.generator_state_changed.connect(_on_generator_state_changed)
|
||||
game_state.goal_completed.connect(_on_goal_completed)
|
||||
|
||||
if not game_state.get_all_goals().is_empty():
|
||||
_load_goals()
|
||||
_build_goal_rows()
|
||||
else:
|
||||
game_state.ready.connect(_on_level_state_ready)
|
||||
|
||||
_refresh_ui()
|
||||
_refresh_ui.call_deferred()
|
||||
|
||||
func _on_currency_changed(_currency_id: StringName, _new_amount: BigNumber) -> void:
|
||||
_refresh_ui()
|
||||
|
||||
func _on_generator_state_changed(generator_id: StringName, _state: Dictionary) -> void:
|
||||
var generator_key: String = String(generator_id)
|
||||
if not generator_key.is_empty():
|
||||
_known_generator_ids[generator_key] = true
|
||||
_refresh_generator_lookup(generator_id)
|
||||
func _on_goal_completed(goal_id: StringName) -> void:
|
||||
_refresh_ui()
|
||||
|
||||
func _on_generator_state_changed(_generator_id: StringName, _state: Dictionary) -> void:
|
||||
_refresh_ui()
|
||||
|
||||
func _on_level_state_ready() -> void:
|
||||
_load_goals()
|
||||
_build_goal_rows()
|
||||
_refresh_ui()
|
||||
|
||||
func _load_goals() -> void:
|
||||
_loaded_goals.clear()
|
||||
_generators_by_id.clear()
|
||||
|
||||
var scene_root: Node = get_tree().current_scene
|
||||
var search_root: Node = scene_root if scene_root != null else self
|
||||
var generator_nodes: Array[Node] = search_root.find_children("*", "CurrencyGenerator", true, false)
|
||||
var all_goals_raw: Array = game_state.get_all_goals() if game_state else []
|
||||
var seen_goal_ids: Dictionary = {}
|
||||
for generator_node in generator_nodes:
|
||||
var generator: CurrencyGenerator = generator_node as CurrencyGenerator
|
||||
if generator == null:
|
||||
|
||||
for goal_raw in all_goals_raw:
|
||||
var goal: GoalData = goal_raw as GoalData
|
||||
if goal == null or not goal.has_id():
|
||||
continue
|
||||
|
||||
var generator_id: StringName = generator.get_generator_id()
|
||||
if generator_id == &"":
|
||||
continue
|
||||
_generators_by_id[String(generator_id)] = generator
|
||||
|
||||
if generator.data == null:
|
||||
continue
|
||||
if not generator.data.has_unlock_goal():
|
||||
continue
|
||||
|
||||
var resolved_goal: GoalData = generator.data.unlock_goal
|
||||
if resolved_goal == null:
|
||||
continue
|
||||
if not bool(resolved_goal.is_valid()):
|
||||
continue
|
||||
var goal_key: String = String(resolved_goal.get("id"))
|
||||
|
||||
var goal_key: String = String(goal.id)
|
||||
if seen_goal_ids.has(goal_key):
|
||||
push_warning("Goals debug UI: duplicate goal id '%s' skipped" % goal_key)
|
||||
continue
|
||||
|
||||
|
||||
seen_goal_ids[goal_key] = true
|
||||
_loaded_goals.append(GoalDefinition.new(generator_id, resolved_goal))
|
||||
_loaded_goals.append(GoalDefinition.new(goal))
|
||||
|
||||
func _build_goal_rows() -> void:
|
||||
_rows_by_goal_id.clear()
|
||||
@@ -102,7 +90,7 @@ func _build_goal_rows() -> void:
|
||||
|
||||
var title_label: Label = Label.new()
|
||||
title_label.custom_minimum_size = Vector2(220.0, 0.0)
|
||||
title_label.text = "%s -> %s" % [String(goal.goal.id), String(goal.target_generator_id)]
|
||||
title_label.text = String(goal.goal.id)
|
||||
|
||||
var status_label: Label = Label.new()
|
||||
status_label.custom_minimum_size = Vector2(95.0, 0.0)
|
||||
@@ -116,10 +104,10 @@ func _build_goal_rows() -> void:
|
||||
unlock_button.disabled = true
|
||||
unlock_button.pressed.connect(_on_unlock_pressed.bind(goal.goal.id))
|
||||
|
||||
row_container.add_child(unlock_button)
|
||||
row_container.add_child(title_label)
|
||||
row_container.add_child(status_label)
|
||||
row_container.add_child(requirements_label)
|
||||
row_container.add_child(unlock_button)
|
||||
_goals_list.add_child(row_container)
|
||||
|
||||
_rows_by_goal_id[String(goal.goal.id)] = GoalRow.new(goal, status_label, requirements_label, unlock_button)
|
||||
@@ -150,29 +138,20 @@ func _refresh_ui() -> void:
|
||||
func _refresh_goal_row(row: GoalRow) -> void:
|
||||
var goal: GoalDefinition = row.goal
|
||||
var already_unlocked: bool = _is_goal_completed(goal)
|
||||
var can_resolve_target: bool = _can_resolve_target(goal.target_generator_id)
|
||||
var met: bool = _is_goal_met(goal)
|
||||
var generator: CurrencyGenerator = _get_generator_for_goal(goal)
|
||||
var is_manual_goal: bool = _is_manual_goal_generator(generator)
|
||||
var can_unlock: bool = can_resolve_target and met and not already_unlocked and is_manual_goal
|
||||
var can_click: bool = met and not already_unlocked
|
||||
|
||||
row.requirements_label.text = _get_requirements_text(goal)
|
||||
row.button.disabled = not can_unlock
|
||||
row.button.disabled = not can_click
|
||||
if already_unlocked:
|
||||
row.button.text = "Done"
|
||||
elif is_manual_goal:
|
||||
row.button.text = "Unlock"
|
||||
else:
|
||||
row.button.text = "Auto"
|
||||
row.button.text = "Unlock"
|
||||
|
||||
if already_unlocked:
|
||||
row.status_label.text = "Unlocked"
|
||||
return
|
||||
|
||||
if not can_resolve_target:
|
||||
row.status_label.text = "Missing"
|
||||
return
|
||||
|
||||
if met:
|
||||
row.status_label.text = "Ready"
|
||||
return
|
||||
@@ -184,14 +163,17 @@ func _is_goal_met(goal: GoalDefinition) -> bool:
|
||||
return false
|
||||
if goal.goal == null:
|
||||
return false
|
||||
if game_state == null:
|
||||
return false
|
||||
|
||||
return bool(goal.goal.is_met())
|
||||
return bool(game_state.is_goal_met(goal.goal))
|
||||
|
||||
func _is_goal_completed(goal: GoalDefinition) -> bool:
|
||||
return (
|
||||
GameState.is_generator_unlocked(goal.target_generator_id)
|
||||
and GameState.is_generator_available(goal.target_generator_id)
|
||||
)
|
||||
if goal.goal == null or goal.goal.id.is_empty():
|
||||
return false
|
||||
if game_state == null:
|
||||
return false
|
||||
return game_state.is_goal_completed(goal.goal.id)
|
||||
|
||||
func _on_unlock_pressed(goal_id: StringName) -> void:
|
||||
var row: GoalRow = _rows_by_goal_id.get(String(goal_id))
|
||||
@@ -201,91 +183,18 @@ func _on_unlock_pressed(goal_id: StringName) -> void:
|
||||
var goal: GoalDefinition = row.goal
|
||||
if _is_goal_completed(goal):
|
||||
return
|
||||
if not _can_resolve_target(goal.target_generator_id):
|
||||
return
|
||||
if not _is_goal_met(goal):
|
||||
return
|
||||
|
||||
var generator: CurrencyGenerator = _get_generator_for_goal(goal)
|
||||
if generator == null:
|
||||
return
|
||||
|
||||
if not generator.try_unlock_from_goal():
|
||||
if game_state == null:
|
||||
return
|
||||
|
||||
print("[GoalsDebugUI] Unlocked goal '%s' -> %s" % [String(goal.goal.id), String(goal.target_generator_id)])
|
||||
if goal.goal.unlock_behavior == GoalData.UnlockBehavior.MANUAL:
|
||||
game_state._complete_goal_manually(goal.goal.id)
|
||||
|
||||
print("[GoalsDebugUI] Unlocked goal '%s'" % String(goal.goal.id))
|
||||
_refresh_ui()
|
||||
|
||||
func _can_resolve_target(target_generator_id: StringName) -> bool:
|
||||
var target_key: String = String(target_generator_id)
|
||||
if target_key.is_empty():
|
||||
return false
|
||||
|
||||
if _known_generator_ids.has(target_key) or GameState.generator_states.has(target_key):
|
||||
return true
|
||||
|
||||
if not _warned_unknown_target_ids.has(target_key):
|
||||
_warned_unknown_target_ids[target_key] = true
|
||||
push_warning("Goals debug UI target generator not found in scene/state: '%s'" % target_key)
|
||||
return false
|
||||
|
||||
func _collect_known_generator_ids() -> void:
|
||||
_known_generator_ids.clear()
|
||||
_generators_by_id.clear()
|
||||
|
||||
var scene_root: Node = get_tree().current_scene
|
||||
var search_root: Node = scene_root if scene_root != null else self
|
||||
var generator_nodes: Array[Node] = search_root.find_children("*", "CurrencyGenerator", true, false)
|
||||
for generator_node in generator_nodes:
|
||||
var generator: CurrencyGenerator = generator_node as CurrencyGenerator
|
||||
if generator == null:
|
||||
continue
|
||||
|
||||
var generator_key: String = String(generator.get_generator_id())
|
||||
if generator_key.is_empty():
|
||||
continue
|
||||
|
||||
_known_generator_ids[generator_key] = true
|
||||
_generators_by_id[generator_key] = generator
|
||||
|
||||
func _refresh_generator_lookup(generator_id: StringName) -> void:
|
||||
var generator_key: String = String(generator_id)
|
||||
if generator_key.is_empty():
|
||||
return
|
||||
|
||||
var scene_root: Node = get_tree().current_scene
|
||||
var search_root: Node = scene_root if scene_root != null else self
|
||||
var generator_nodes: Array[Node] = search_root.find_children("*", "CurrencyGenerator", true, false)
|
||||
for generator_node in generator_nodes:
|
||||
var generator: CurrencyGenerator = generator_node as CurrencyGenerator
|
||||
if generator == null:
|
||||
continue
|
||||
if generator.get_generator_id() != generator_id:
|
||||
continue
|
||||
|
||||
_generators_by_id[generator_key] = generator
|
||||
return
|
||||
|
||||
func _get_generator_for_goal(goal: GoalDefinition) -> CurrencyGenerator:
|
||||
if goal == null:
|
||||
return null
|
||||
|
||||
var key: String = String(goal.target_generator_id)
|
||||
if key.is_empty():
|
||||
return null
|
||||
|
||||
return _generators_by_id.get(key) as CurrencyGenerator
|
||||
|
||||
func _is_manual_goal_generator(generator: CurrencyGenerator) -> bool:
|
||||
if generator == null:
|
||||
return false
|
||||
if generator.data == null:
|
||||
return false
|
||||
if not generator.data.has_unlock_goal():
|
||||
return false
|
||||
|
||||
return not generator.data.unlocks_automatically_from_goal()
|
||||
|
||||
func _get_requirements_text(goal: GoalDefinition) -> String:
|
||||
if goal == null:
|
||||
return ""
|
||||
@@ -293,16 +202,22 @@ func _get_requirements_text(goal: GoalDefinition) -> String:
|
||||
return ""
|
||||
if goal.goal.get_script() != GOAL_DATA_SCRIPT:
|
||||
return ""
|
||||
if game_state == null:
|
||||
return ""
|
||||
|
||||
var parts: Array[String] = []
|
||||
for requirement_resource in goal.goal.get_valid_requirements():
|
||||
for requirement_resource in goal.goal.get_requirements():
|
||||
if requirement_resource == null:
|
||||
continue
|
||||
if requirement_resource.get_script() != GOAL_REQUIREMENT_SCRIPT:
|
||||
continue
|
||||
|
||||
var requirement_currency_id: StringName = requirement_resource.get_currency_id()
|
||||
var total_amount: BigNumber = GameState.get_total_currency_acquired_by_id(requirement_currency_id)
|
||||
var currency: Currency = requirement_resource.get_currency()
|
||||
if currency == null:
|
||||
continue
|
||||
|
||||
var requirement_currency_id: StringName = game_state.get_currency_id(currency)
|
||||
var total_amount: BigNumber = game_state.get_total_currency_acquired_by_id(requirement_currency_id)
|
||||
var required_amount: BigNumber = requirement_resource.get_amount()
|
||||
parts.append(
|
||||
"%s %s / %s" % [
|
||||
@@ -311,7 +226,19 @@ func _get_requirements_text(goal: GoalDefinition) -> String:
|
||||
required_amount.to_string_suffix(2)
|
||||
]
|
||||
)
|
||||
|
||||
if parts.is_empty():
|
||||
return "No requirements"
|
||||
return " | ".join(parts)
|
||||
|
||||
func _currency_label(currency_id: StringName) -> String:
|
||||
return GameState.get_currency_name(currency_id)
|
||||
if game_state == null:
|
||||
return "Unknown"
|
||||
return game_state.get_currency_name(currency_id)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if game_state:
|
||||
game_state.currency_changed.disconnect(_on_currency_changed)
|
||||
game_state.generator_state_changed.disconnect(_on_generator_state_changed)
|
||||
game_state.goal_completed.disconnect(_on_goal_completed)
|
||||
game_state.ready.disconnect(_on_level_state_ready)
|
||||
|
||||
Reference in New Issue
Block a user