Randoloot/tests/items/item_icons_test.gd
2026-10-12 23:35:17 +02:00

60 lines
3.2 KiB
GDScript

extends Node
const GAME := preload("res://scenes/game/game.tscn")
const GENERATOR := preload("res://scripts/items/item_generator.gd")
func _ready() -> void:
GameState.start_new_run()
var game := GAME.instantiate()
add_child(game)
game.set_physics_process(false)
var ship := game.get_node("PlayerShip")
ship.set_physics_process(false)
ship.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 = ship.get_node("ShipInventory")
var extension_index := 0
for definition in GENERATOR.DEFINITIONS:
assert(definition.icon != null)
assert(definition.icon.get_width() == definition.icon.get_height())
if definition.item_id in ["reinforced_shield", "hull_plating", "engine_extension", "compact_generator", "ship_computer", "beam_laser", "machine_gun", "plasma_cannon", "missile_launcher", "unguided_missile", "afterburner", "shield_charge", "repair_drones"]:
assert(inventory.add_item(GENERATOR.generate_for_definition(definition, 8)))
var category_index := ShipInventory.MODULE_CATEGORIES.find(definition.category)
if category_index >= 0 and inventory.module_slots[category_index] == null:
var item := GENERATOR.generate_for_definition(definition, 8)
assert(inventory.add_item(item))
assert(inventory.move_item("cargo", inventory.cargo.find(item), "module", category_index))
if definition.category == ItemDefinition.Category.ACTIVE_EXTENSION:
var extension := GENERATOR.generate_for_definition(definition, 8)
assert(inventory.add_item(extension))
assert(inventory.move_item("cargo", inventory.cargo.find(extension), "extension", extension_index))
extension_index += 1
GameState.captain.parts = 20
ship.set("hull", ship.get("max_hull") - 10)
ship.set("shields", ship.get("max_shields") - 20)
ship.set("energy", ship.get("max_energy"))
var hud := game.get_node("HUD")
hud._toggle_inventory()
await get_tree().create_timer(0.3).timeout
var slots: Array = hud.inventory_panel.get_node("Contents/CargoGrid").get_children()
for slot in slots:
assert(is_equal_approx(slot.size.x, slot.size.y))
var item := inventory.get_item("cargo", slot.slot_index)
if item != null:
assert(slot.get_node("ItemIcon").texture == item.definition.icon)
assert(not slot.get_node("SlotLabel").visible)
var style: StyleBoxFlat = slot.get_theme_stylebox("panel")
assert(style.bg_color == item.get_background_color())
assert(style.border_color == item.get_type_color())
var salvage: Button = slot.get_node("ActionOverlay/SalvageButton")
assert(salvage.icon != null and salvage.text.is_empty())
assert(slot.get_global_rect().encloses(salvage.get_global_rect()))
for index in extension_index:
var ability_button: Button = hud._ability_buttons[index]
assert(ability_button.icon == inventory.extension_slots[index].definition.icon)
assert(ability_button.text.is_empty())
assert(ability_button.size.x < 64 * 0.8)
assert(ability_button.size.y < 64 * 0.8)
assert(inventory.extension_slots[2].definition.icon != preload("res://resources/items/hull_plating.tres").icon)
print("ITEM_ICONS_TEST: PASS square textures and slots, icon assignment, rarity backgrounds and borders, inventory and equipment")