Fix research xp generation

This commit is contained in:
2026-04-18 00:56:44 +02:00
parent 2bc81a73fd
commit dfb1161854
29 changed files with 485 additions and 47 deletions

View File

@@ -6,10 +6,7 @@ var _game_root: Node = null
func _ready():
await run()
if failed == 0:
get_tree().quit(0)
else:
get_tree().quit(1)
# Don't quit here - let test_runner handle it
func run():
print("\n=== TEST: Gold Mine Click ===\n")

View File

@@ -7,9 +7,9 @@ var _game_root: Node = null
func _ready():
await run()
if failed == 0:
get_tree().quit(0)
# get_tree().quit(0) // Let test_runner handle it
else:
get_tree().quit(1)
# get_tree().quit(1) // Let test_runner handle it
func run():
print("\n=== TEST: Prestige Mechanics ===\n")

View File

@@ -0,0 +1,159 @@
extends SceneTree
var passed: int = 0
var failed: int = 0
var _game_root: Node = null
var _local_passed: int = 0
var _local_failed: int = 0
func _init():
await run()
func run():
print("\n=== TEST: Research Activation ===\n")
TestUtils.set_test_name("research_activation")
var scene = load("res://docs/gyms/tiny_sword/tiny_sword.tscn")
_game_root = scene.instantiate()
root.add_child(_game_root)
await _wait()
var game_state: LevelGameState = _game_root.find_child("LevelGameState")
var research_panel: ResearchPanel = _game_root.find_child("ResearchPanel") as ResearchPanel
if game_state == null or research_panel == null:
print("[ERROR] Missing LevelGameState or ResearchPanel node")
_print_summary()
quit(1)
return
var gold_mine_node = game_state.find_child("GoldMine")
var gold_mine: CurrencyGenerator = gold_mine_node.find_child("CurrencyGenerator") as CurrencyGenerator if gold_mine_node else null
if gold_mine == null:
print("[ERROR] GoldMine node not found")
_print_summary()
quit(1)
return
# Test 1: Verify initial state - no research should be active
print("[TARGET] initial_active_research_id: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"",
"No research active initially"
)
# Test 2: Verify gold mine research exists and is linked to goldmine generator
var gold_research = game_state.research_catalogue.get_research_by_id(&"gold_research")
TestUtils.assert_not_null(
gold_research,
"Gold research exists in catalogue"
)
if gold_research != null:
TestUtils.assert_true(
gold_research.generator_id == &"goldmine",
"Gold research is linked to goldmine generator"
)
# Test 3: Activate gold research
research_panel.activate_research(&"gold_research")
await _wait()
print("[TARGET] active_after_gold_activation: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"gold_research",
"Gold research is active after activation"
)
TestUtils.assert_true(
research_panel.is_research_active(&"gold_research"),
"is_research_active returns true for gold_research"
)
# Test 4: Verify research XP is granted when research is active
var initial_gold_research_xp = game_state.get_research_xp(&"gold_research")
print("[TARGET] initial_gold_research_xp: %s" % initial_gold_research_xp.to_string_suffix(2))
# Simulate gold mine production (gold mine grants XP to gold_research)
gold_mine._on_pressed()
await _wait()
var final_gold_research_xp_active = game_state.get_research_xp(&"gold_research")
print("[TARGET] final_gold_research_xp_active: %s" % final_gold_research_xp_active.to_string_suffix(2))
TestUtils.assert_true(
final_gold_research_xp_active.mantissa > initial_gold_research_xp.mantissa,
"Gold research XP increases when active (gold mine produces)"
)
# Test 5: Deactivate gold research by activating another research
var farm_research = game_state.research_catalogue.get_research_by_id(&"farm_research")
TestUtils.assert_not_null(
farm_research,
"Farm research exists in catalogue"
)
if farm_research != null:
# Activate farm research (should deactivate gold research)
research_panel.activate_research(&"farm_research")
await _wait()
print("[TARGET] active_after_farm_activation: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"farm_research",
"Farm research is active after activation"
)
TestUtils.assert_false(
research_panel.is_research_active(&"gold_research"),
"Gold research is deactivated when farm is activated"
)
# Test 6: Verify research XP is NOT granted when research is inactive
var initial_gold_research_xp_inactive = game_state.get_research_xp(&"gold_research")
print("[TARGET] initial_gold_research_xp_inactive: %s" % initial_gold_research_xp_inactive.to_string_suffix(2))
# Simulate gold mine production (gold mine should NOT grant XP to inactive gold_research)
gold_mine._on_pressed()
await _wait()
var final_gold_research_xp_inactive = game_state.get_research_xp(&"gold_research")
print("[TARGET] final_gold_research_xp_inactive: %s" % final_gold_research_xp_inactive.to_string_suffix(2))
TestUtils.assert_equals(
final_gold_research_xp_inactive.mantissa,
initial_gold_research_xp_inactive.mantissa,
"Gold research XP does not increase when inactive (gold mine produces)"
)
# Test 7: Test mutual exclusivity with multiple activations
research_panel.activate_research(&"gold_research")
await _wait()
research_panel.activate_research(&"farm_research")
await _wait()
research_panel.activate_research(&"gold_research")
await _wait()
print("[TARGET] final_active_research_id: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"gold_research",
"Only one research can be active at a time"
)
_print_summary()
if failed == 0:
quit(0)
else:
quit(1)
func _wait() -> void:
await create_timer(0.5).timeout
func _print_summary():
TestUtils.print_result()
_local_passed = TestUtils.get_passed()
_local_failed = TestUtils.get_failed()
passed = _local_passed
failed = _local_failed

View File

@@ -0,0 +1 @@
uid://cf23bjqannrog

View File

@@ -1,18 +1,18 @@
extends Node
extends SceneTree
var test_scripts: Array[String] = []
var test_index: int = 0
var total_passed: int = 0
var total_failed: int = 0
func _ready():
func _init():
print("\n=== GODOT TEST RUNNER ===\n")
_discover_tests()
if test_scripts.is_empty():
print("[ERROR] No test scripts found in res://tests/")
print("[RESULT] FAIL")
get_tree().quit(1)
quit(1)
return
print("Found %d test(s): %s\n" % [test_scripts.size(), str(test_scripts)])
@@ -25,10 +25,10 @@ func _ready():
if total_failed == 0:
print("[OVERALL_RESULT] PASS")
get_tree().quit(0)
quit(0)
else:
print("[OVERALL_RESULT] FAIL")
get_tree().quit(1)
quit(1)
func _discover_tests() -> void:
var dir = DirAccess.open("res://tests")
@@ -53,11 +53,26 @@ func _run_next_test() -> void:
# Load and run test
var test_instance = load(test_script).new()
add_child(test_instance)
await test_instance.run()
get_root().add_child(test_instance)
total_passed += test_instance.get_passed()
total_failed += test_instance.get_failed()
# Check if test has run() method (new pattern) or uses _ready() (old pattern)
if test_instance.has_method("run"):
await test_instance.run()
# Clean up test instance
test_instance.queue_free()
else:
# For old pattern, wait a bit for _ready() to complete
await create_timer(0.2).timeout
# Clean up test instance
test_instance.queue_free()
# Get results if available
if test_instance.has_method("get_passed"):
total_passed += test_instance.get_passed()
total_failed += test_instance.get_failed()
# Wait for cleanup
await create_timer(0.1).timeout
print("")
test_index += 1