Randoloot/tests/ships/ship_statistics_test.gd
2026-10-19 22:33:24 +02:00

79 lines
3.7 KiB
GDScript

extends Node
const GENERATOR := preload("res://scripts/items/item_generator.gd")
func settle() -> void:
for frame in 8: await get_tree().process_frame
func shot(path: String) -> void:
await settle()
await RenderingServer.frame_post_draw
get_viewport().get_texture().get_image().save_png(path)
func _ready() -> void:
GameState.start_new_run()
GameState.system_level = 7
GameState.selected_ship_path = "res://assets/Ships/player/bastion.png"
var game := preload("res://scenes/game/game.tscn").instantiate()
add_child(game)
game.set_physics_process(false)
game.player.set_physics_process(false)
game.player.get_node("WeaponController").set_physics_process(false)
for enemy in get_tree().get_nodes_in_group("enemies"): enemy.set_physics_process(false)
var hud := game.get_node("HUD")
var ship: CharacterBody2D = game.player
var inv: ShipInventory = ship.get_node("ShipInventory")
inv.unlocked_weapon_slots = 3
inv.unlocked_extension_slots = 2
for i in range(3):
inv.weapon_slots[i] = GENERATOR.generate_for_definition(load("res://resources/items/" + ["plasma_cannon", "gamma_cannon", "missile_launcher"][i] + ".tres"), 7)
inv.extension_slots[0] = GENERATOR.generate_for_definition(preload("res://resources/items/teleport.tres"),7)
inv.extension_slots[1] = GENERATOR.generate_for_definition(preload("res://resources/items/recycler.tres"),7)
for definition in GENERATOR.DEFINITIONS:
var module_index := inv.MODULE_CATEGORIES.find(definition.category)
if module_index >= 0 and inv.module_slots[module_index] == null:
inv.module_slots[module_index] = GENERATOR.generate_for_definition(definition,7)
inv._recalculate_ship_stats()
inv.inventory_changed.emit()
await settle()
assert(hud._system_title.text == "System 7")
assert(is_equal_approx(hud._sidebar_toggle.size.x, 221) and is_equal_approx(hud._sidebar_toggle.size.y, 71.5))
assert(hud._system_badge.position.x > hud._captain_panel.get_global_rect().end.x)
hud._sidebar_toggle.pressed.emit()
var button := hud._sidebar.find_child("StatisticsButton",true,false) as Button
assert(button != null and button.is_visible_in_tree())
await shot("res://artifacts/ship_hud.png")
button.pressed.emit()
await settle()
var stats: PanelContainer = hud._ship_statistics
assert(stats.visible and stats.size.x == 690)
assert(stats._bindings.has("hull") and stats._bindings.has("critical") and stats._bindings.has("cargo"))
ship.absorption = Vector3(7,11,13)
ship.hull = 25
stats._refresh_values()
assert(stats._bindings.hull.label.text.begins_with("25 /"))
assert(stats._bindings.kinetic_absorption.label.text == "7.0%")
assert(stats._bindings.radiation_absorption.label.text == "13.0%")
assert(stats._bindings.dps.label.text == "%.1f" % inv.get_total_dps())
assert(stats.size.y == 490 and stats.position.y >= 0)
ship.hull = ship.max_hull * 0.75
await shot("res://artifacts/ship_statistics_parameters.png")
stats._select_tab("weapons")
for i in range(3):
assert(stats._bindings["weapon_dps_%d" % i].label.text == "%.1f" % inv.get_weapon_dps(i))
assert(is_equal_approx(inv.get_total_dps(),inv.get_weapon_dps(0)+inv.get_weapon_dps(1)+inv.get_weapon_dps(2)))
await shot("res://artifacts/ship_statistics_weapons.png")
stats._select_tab("equipment")
assert(stats._bindings.has("extension_0"))
await shot("res://artifacts/ship_statistics_systems.png")
GameState.system_level = 61
await settle()
assert(hud._system_title.text == "System 61" and hud._system_mode.text == "HARD")
var event := InputEventKey.new()
event.pressed = true
event.keycode = KEY_ESCAPE
stats._unhandled_key_input(event)
assert(not stats.visible)
game.free()
await get_tree().process_frame
print("SHIP_STATISTICS_TEST_OK: HUD badge, statistics button, live values, absorption, per-weapon DPS, tabs, cooldowns and close")
get_tree().quit()