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)
245 lines
6.9 KiB
GDScript
245 lines
6.9 KiB
GDScript
extends PanelContainer
|
|
|
|
class GoalDefinition extends RefCounted:
|
|
var goal: GoalData
|
|
|
|
func _init(goal_data: GoalData) -> void:
|
|
goal = goal_data
|
|
|
|
const GOAL_DATA_SCRIPT: Script = preload("res://core/goals/goal_data.gd")
|
|
const GOAL_REQUIREMENT_SCRIPT: Script = preload("res://core/goals/goal_requirement_data.gd")
|
|
|
|
class GoalRow extends RefCounted:
|
|
var goal: GoalDefinition
|
|
var status_label: Label
|
|
var requirements_label: Label
|
|
var button: Button
|
|
|
|
func _init(goal_definition: GoalDefinition, status: Label, requirements: Label, unlock_button: Button) -> void:
|
|
goal = goal_definition
|
|
status_label = status
|
|
requirements_label = requirements
|
|
button = unlock_button
|
|
|
|
@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 = {}
|
|
|
|
func _ready() -> void:
|
|
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_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()
|
|
|
|
var all_goals_raw: Array = game_state.get_all_goals() if game_state else []
|
|
var seen_goal_ids: Dictionary = {}
|
|
|
|
for goal_raw in all_goals_raw:
|
|
var goal: GoalData = goal_raw as GoalData
|
|
if goal == null or not goal.has_id():
|
|
continue
|
|
|
|
var goal_key: String = String(goal.id)
|
|
if seen_goal_ids.has(goal_key):
|
|
continue
|
|
|
|
seen_goal_ids[goal_key] = true
|
|
_loaded_goals.append(GoalDefinition.new(goal))
|
|
|
|
func _build_goal_rows() -> void:
|
|
_rows_by_goal_id.clear()
|
|
for child in _goals_list.get_children():
|
|
child.queue_free()
|
|
|
|
for goal in _loaded_goals:
|
|
if goal.goal == null:
|
|
continue
|
|
|
|
var row_container: HBoxContainer = HBoxContainer.new()
|
|
row_container.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
row_container.add_theme_constant_override("separation", 12)
|
|
|
|
var title_label: Label = Label.new()
|
|
title_label.custom_minimum_size = Vector2(220.0, 0.0)
|
|
title_label.text = String(goal.goal.id)
|
|
|
|
var status_label: Label = Label.new()
|
|
status_label.custom_minimum_size = Vector2(95.0, 0.0)
|
|
|
|
var requirements_label: Label = Label.new()
|
|
requirements_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
|
|
var unlock_button: Button = Button.new()
|
|
unlock_button.custom_minimum_size = Vector2(90.0, 0.0)
|
|
unlock_button.text = "Unlock"
|
|
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)
|
|
_goals_list.add_child(row_container)
|
|
|
|
_rows_by_goal_id[String(goal.goal.id)] = GoalRow.new(goal, status_label, requirements_label, unlock_button)
|
|
|
|
func _refresh_ui() -> void:
|
|
if _loaded_goals.is_empty():
|
|
_summary_label.text = "No valid goals loaded"
|
|
return
|
|
|
|
var ready_to_unlock: int = 0
|
|
var unlocked: int = 0
|
|
for goal in _loaded_goals:
|
|
if goal.goal == null:
|
|
continue
|
|
|
|
var row: GoalRow = _rows_by_goal_id.get(String(goal.goal.id))
|
|
if row == null:
|
|
continue
|
|
_refresh_goal_row(row)
|
|
|
|
if _is_goal_completed(goal):
|
|
unlocked += 1
|
|
elif _is_goal_met(goal):
|
|
ready_to_unlock += 1
|
|
|
|
_summary_label.text = "Goals: %d | Ready: %d | Unlocked: %d" % [_loaded_goals.size(), ready_to_unlock, unlocked]
|
|
|
|
func _refresh_goal_row(row: GoalRow) -> void:
|
|
var goal: GoalDefinition = row.goal
|
|
var already_unlocked: bool = _is_goal_completed(goal)
|
|
var met: bool = _is_goal_met(goal)
|
|
var can_click: bool = met and not already_unlocked
|
|
|
|
row.requirements_label.text = _get_requirements_text(goal)
|
|
row.button.disabled = not can_click
|
|
if already_unlocked:
|
|
row.button.text = "Done"
|
|
else:
|
|
row.button.text = "Unlock"
|
|
|
|
if already_unlocked:
|
|
row.status_label.text = "Unlocked"
|
|
return
|
|
|
|
if met:
|
|
row.status_label.text = "Ready"
|
|
return
|
|
|
|
row.status_label.text = "Locked"
|
|
|
|
func _is_goal_met(goal: GoalDefinition) -> bool:
|
|
if goal == null:
|
|
return false
|
|
if goal.goal == null:
|
|
return false
|
|
if game_state == null:
|
|
return false
|
|
|
|
return bool(game_state.is_goal_met(goal.goal))
|
|
|
|
func _is_goal_completed(goal: GoalDefinition) -> bool:
|
|
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))
|
|
if row == null:
|
|
return
|
|
|
|
var goal: GoalDefinition = row.goal
|
|
if _is_goal_completed(goal):
|
|
return
|
|
if not _is_goal_met(goal):
|
|
return
|
|
|
|
if game_state == null:
|
|
return
|
|
|
|
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 _get_requirements_text(goal: GoalDefinition) -> String:
|
|
if goal == null:
|
|
return ""
|
|
if goal.goal == null:
|
|
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_requirements():
|
|
if requirement_resource == null:
|
|
continue
|
|
if requirement_resource.get_script() != GOAL_REQUIREMENT_SCRIPT:
|
|
continue
|
|
|
|
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" % [
|
|
_currency_label(requirement_currency_id),
|
|
total_amount.to_string_suffix(2),
|
|
required_amount.to_string_suffix(2)
|
|
]
|
|
)
|
|
|
|
if parts.is_empty():
|
|
return "No requirements"
|
|
return " | ".join(parts)
|
|
|
|
func _currency_label(currency_id: StringName) -> String:
|
|
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)
|