Randoloot/tests/ships/artillery_orb_radar_test.gd
2026-10-25 22:38:13 +01:00

100 lines
4.4 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Node2D
const ORBS := preload("res://scripts/items/special_orbs.gd")
const PICKUP := preload("res://scripts/items/loot_pickup.gd")
const SLOT := preload("res://scenes/ui/inventory_slot_view.tscn")
func _ready() -> void:
GameState.start_new_run()
var game := preload("res://scenes/game/game.tscn").instantiate()
add_child(game)
game.set_physics_process(false)
var player: CharacterBody2D = game.player
player.set_physics_process(false)
player.get_node("WeaponController").set_physics_process(false)
for enemy in get_tree().get_nodes_in_group("enemies"): enemy.set_physics_process(false)
var inventory: ShipInventory = player.get_node("ShipInventory")
inventory.cargo.fill(null)
var pickup := Node2D.new()
pickup.set_script(PICKUP)
pickup.item = ORBS.create_item("piercing",2)
pickup.position = player.position
game.add_child(pickup)
pickup._physics_process(0)
assert(pickup.is_queued_for_deletion() and inventory.cargo[0].stack_count==2)
for i in range(1,inventory.get_cargo_capacity()):
var item := ItemInstance.new()
item.definition = preload("res://resources/items/hull_plating.tres")
inventory.cargo[i] = item
var same := Node2D.new()
same.set_script(PICKUP)
same.item = ORBS.create_item("piercing",3)
same.position = player.position
game.add_child(same)
same._physics_process(0)
assert(same.is_queued_for_deletion() and inventory.cargo[0].stack_count==5,"Stack pickup works even with full cargo")
var other := Node2D.new()
other.set_script(PICKUP)
other.item = ORBS.create_item("booster")
other.position = player.position
game.add_child(other)
other._physics_process(0)
assert(not other.is_queued_for_deletion(),"Different orb stays in space while cargo is full")
inventory.cargo[1] = null
other._physics_process(0)
assert(other.is_queued_for_deletion() and inventory.cargo[1].definition.orb_id=="booster")
var source := SLOT.instantiate()
source.slot_kind = "cargo"
source.slot_index = 0
add_child(source)
var target := SLOT.instantiate()
target.slot_kind = "weapon"
target.slot_index = 0
add_child(target)
var click := InputEventMouseButton.new()
click.button_index = MOUSE_BUTTON_LEFT
click.pressed = true
click.double_click = true
source._gui_input(click)
assert(inventory.selected_orb==inventory.cargo[0])
click.double_click = false
target._gui_input(click)
assert("piercing" in inventory.weapon_slots[0].special_orbs and inventory.cargo[0].stack_count==4 and inventory.selected_orb==null)
assert(source.get_node("StackOverlay/Count").text=="×4")
assert(inventory.select_orb(1))
assert(not inventory.use_selected_orb(inventory.weapon_slots[0]) and inventory.cargo[1].stack_count==1,"Invalid target never consumes an orb")
var escape := InputEventKey.new()
escape.keycode = KEY_ESCAPE
escape.pressed = true
inventory._input(escape)
assert(inventory.selected_orb==null)
var engine := ItemInstance.new()
engine.definition = preload("res://resources/items/engine_extension.tres")
inventory.module_slots[2] = engine
assert(inventory.select_orb(1) and inventory.use_selected_orb(engine))
assert(inventory.cargo[1]==null and "booster" in engine.special_orbs)
var radar := Control.new()
radar.set_script(preload("res://scripts/ui/scanner_overlay.gd"))
radar.player = player
add_child(radar)
var freighter: Node2D = game.get_node("Freighter")
freighter.position = player.position+Vector2(1000000,1000000)
assert(radar.is_target_in_range(freighter),"Freighter ignores distance")
radar._physics_process(0)
assert(radar.targets.has(freighter))
var cannon := ItemInstance.new()
cannon.definition = preload("res://resources/items/artillery_cannon.tres")
assert(cannon.get_stat_total("damage")==50 and cannon.definition.ammunition_cost==10)
cannon.damage_min = 74
cannon.damage_max = 74
assert(is_equal_approx(cannon.get_stat_total("damage"),50),"Already rolled artillery receives the balance correction")
var fx := preload("res://scripts/game/artillery_effect.gd")
fx.launch(player,player.position,Vector2.RIGHT)
assert(fx._sound.get_length()>0.1)
source.queue_free()
target.queue_free()
game.get_node("HUD")._toggle_inventory()
await get_tree().create_timer(0.4).timeout
await RenderingServer.frame_post_draw
get_viewport().get_texture().get_image().save_png("res://artifacts/orb_cargo_stacks.png")
print("ARTILLERY_ORB_RADAR_TEST: PASS (50 base damage, CC0 audio, cargo drops, full-cargo stacking, double-click target use, invalid target/cancel, stack counter, unlimited freighter radar)")