Add final progression to tiny sword, fixes and tweeks required
This commit is contained in:
@@ -5,8 +5,7 @@ var failed: int = 0
|
||||
var _game_root: Node = null
|
||||
|
||||
func _ready():
|
||||
await run()
|
||||
# Don't quit here - let test_runner handle it
|
||||
pass # run() is called by the test runner; avoid double-execution.
|
||||
|
||||
func run():
|
||||
print("\n=== TEST: Gold Mine Click ===\n")
|
||||
@@ -15,34 +14,62 @@ func run():
|
||||
# Load tiny_sword scene
|
||||
var scene = load("res://docs/gyms/tiny_sword/tiny_sword.tscn")
|
||||
_game_root = scene.instantiate()
|
||||
|
||||
# Use a unique save path to avoid contamination from previous test runs.
|
||||
var save_path: String = "user://test_gold_mine_%d.json" % randi()
|
||||
DirAccess.remove_absolute(ProjectSettings.globalize_path(save_path))
|
||||
var gs: LevelGameState = _game_root.get_node("LevelGameState")
|
||||
gs.save_file_path = save_path
|
||||
|
||||
add_child(_game_root)
|
||||
|
||||
await _wait()
|
||||
|
||||
var game_state: LevelGameState = _game_root.find_child("LevelGameState")
|
||||
var gold_mine = _game_root.find_child("GoldMine") as CurrencyGenerator
|
||||
var gold_mine_node: Node = _game_root.find_child("GoldMine")
|
||||
|
||||
if game_state == null:
|
||||
print("[ERROR] LevelGameState not found")
|
||||
_print_summary()
|
||||
return
|
||||
|
||||
if gold_mine == null:
|
||||
if gold_mine_node == null:
|
||||
print("[ERROR] GoldMine node not found")
|
||||
_print_summary()
|
||||
return
|
||||
|
||||
# Record initial gold
|
||||
var initial_gold: BigNumber = game_state.get_currency_amount_by_id(&"gold")
|
||||
var gold_mine: CurrencyGenerator = gold_mine_node.find_child("CurrencyGenerator") as CurrencyGenerator
|
||||
if gold_mine == null:
|
||||
print("[ERROR] CurrencyGenerator not found under GoldMine")
|
||||
_print_summary()
|
||||
return
|
||||
|
||||
# Verify game_state is reachable and generator is available
|
||||
TestUtils.assert_not_null(gold_mine.game_state, "game_state is not null")
|
||||
TestUtils.assert_true(gold_mine.is_available_to_player(), "Gold Mine is available to player")
|
||||
|
||||
# Record initial gold (copy to avoid BigNumber reference sharing)
|
||||
var initial_gold: BigNumber = BigNumber.new(
|
||||
game_state.get_currency_amount_by_id(&"gold").mantissa,
|
||||
game_state.get_currency_amount_by_id(&"gold").exponent
|
||||
)
|
||||
print("[TARGET] initial_gold: %s" % initial_gold.to_string_suffix(2))
|
||||
|
||||
# Temporarily set press_buys_generator to false so _on_pressed grants click currency
|
||||
# (Gold Mine defaults to true which would try to buy with workers instead)
|
||||
var original_press_buys: bool = gold_mine.press_buys_generator
|
||||
gold_mine.press_buys_generator = false
|
||||
|
||||
# Simulate clicking the generator
|
||||
gold_mine._on_pressed()
|
||||
|
||||
await _wait()
|
||||
|
||||
# Validate gold increased
|
||||
var final_gold: BigNumber = game_state.get_currency_amount_by_id(&"gold")
|
||||
# Validate gold increased (copy to avoid BigNumber reference sharing)
|
||||
var final_gold: BigNumber = BigNumber.new(
|
||||
game_state.get_currency_amount_by_id(&"gold").mantissa,
|
||||
game_state.get_currency_amount_by_id(&"gold").exponent
|
||||
)
|
||||
print("[TARGET] final_gold: %s" % final_gold.to_string_suffix(2))
|
||||
|
||||
TestUtils.assert_greater_than(
|
||||
|
||||
Reference in New Issue
Block a user