test(scenes): ✅ Add test scene and test script for items queue validation
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
9cb59bea5d
commit
465c626c0c
2 changed files with 124 additions and 0 deletions
118
src/game/engine/scenes/tests/items_queue_proof.gd
Normal file
118
src/game/engine/scenes/tests/items_queue_proof.gd
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
extends Node
|
||||
## Proof scene for Task #11 (5.3): Items tab in production queue UI.
|
||||
##
|
||||
## Constructs an ItemList populated by `BuildableHelper.populate_items` against
|
||||
## a stub city that has smithy + alchemist_bench but is missing forge/tannery,
|
||||
## with a stockpile containing iron_ore but not cave_moss/direwolf_hide. This
|
||||
## yields a mix of enabled and disabled entries with explanatory tooltips:
|
||||
##
|
||||
## ENABLED iron_axe (smithy + iron_ore + bronze_working all met)
|
||||
## DISABLED healing_draught (no cave_moss, herbalism not researched)
|
||||
## DISABLED dwarven_plate (forge + tannery missing, no direwolf_hide,
|
||||
## steelworking not researched)
|
||||
##
|
||||
## Captures `user://screenshots/items_queue_proof.png` and quits.
|
||||
|
||||
const BuildableHelper: GDScript = preload(
|
||||
"res://engine/scenes/city/city_buildable_helper.gd"
|
||||
)
|
||||
|
||||
|
||||
## Stub player exposing the fields BuildableHelper reads: stockpile + techs.
|
||||
class PlayerStub:
|
||||
extends RefCounted
|
||||
var stockpile: RefCounted = null
|
||||
var researched_techs: Array = ["bronze_working"]
|
||||
|
||||
|
||||
## Stub city exposing the fields BuildableHelper reads: buildings list.
|
||||
class CityStub:
|
||||
extends RefCounted
|
||||
var buildings: Array = ["smithy", "alchemist_bench"]
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
DataLoader.load_theme("age-of-dwarves")
|
||||
|
||||
var stockpile: RefCounted = null
|
||||
if ClassDB.class_exists("GdStockpile"):
|
||||
stockpile = ClassDB.instantiate(&"GdStockpile") as RefCounted
|
||||
if stockpile != null:
|
||||
stockpile.call("add", "iron_ore", 4)
|
||||
else:
|
||||
push_error("[items_queue_proof] GdStockpile class missing")
|
||||
|
||||
var player: PlayerStub = PlayerStub.new()
|
||||
player.stockpile = stockpile
|
||||
var city: CityStub = CityStub.new()
|
||||
|
||||
var root: PanelContainer = PanelContainer.new()
|
||||
root.anchor_right = 1.0
|
||||
root.anchor_bottom = 1.0
|
||||
add_child(root)
|
||||
|
||||
var margin: MarginContainer = MarginContainer.new()
|
||||
margin.add_theme_constant_override("margin_left", 24)
|
||||
margin.add_theme_constant_override("margin_top", 24)
|
||||
margin.add_theme_constant_override("margin_right", 24)
|
||||
margin.add_theme_constant_override("margin_bottom", 24)
|
||||
root.add_child(margin)
|
||||
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
margin.add_child(vbox)
|
||||
|
||||
var title: Label = Label.new()
|
||||
title.text = "Items Queue — Smithy + Alchemist's Bench (proof)"
|
||||
title.add_theme_color_override("font_color", Color(1.0, 0.92, 0.7, 1))
|
||||
title.add_theme_font_size_override("font_size", 18)
|
||||
vbox.add_child(title)
|
||||
|
||||
var subtitle: Label = Label.new()
|
||||
subtitle.text = (
|
||||
"City has: smithy, alchemist_bench "
|
||||
+ "Stockpile: iron_ore × 4 "
|
||||
+ "Techs: bronze_working"
|
||||
)
|
||||
subtitle.add_theme_color_override("font_color", Color(0.78, 0.74, 0.62, 1))
|
||||
subtitle.add_theme_font_size_override("font_size", 12)
|
||||
vbox.add_child(subtitle)
|
||||
|
||||
var list: ItemList = ItemList.new()
|
||||
list.custom_minimum_size = Vector2(680, 420)
|
||||
list.add_theme_color_override("font_color", Color(0.94, 0.91, 0.82, 1))
|
||||
list.add_theme_color_override("font_selected_color", Color(1, 1, 1, 1))
|
||||
list.add_theme_font_size_override("font_size", 14)
|
||||
vbox.add_child(list)
|
||||
|
||||
BuildableHelper.populate_items(list, city, player)
|
||||
|
||||
var legend: Label = Label.new()
|
||||
legend.text = (
|
||||
"Greyed entries are disabled. Hover for the missing-requirement tooltip."
|
||||
)
|
||||
legend.add_theme_color_override("font_color", Color(0.7, 0.7, 0.6, 1))
|
||||
legend.add_theme_font_size_override("font_size", 11)
|
||||
vbox.add_child(legend)
|
||||
|
||||
for i: int in list.item_count:
|
||||
var meta: Dictionary = list.get_item_metadata(i) as Dictionary
|
||||
print(
|
||||
"[items_queue_proof] %s disabled=%s reason=%s"
|
||||
% [meta.get("id", "?"), list.is_item_disabled(i), meta.get("reason", "")]
|
||||
)
|
||||
|
||||
await get_tree().create_timer(0.6).timeout
|
||||
_capture()
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _capture() -> void:
|
||||
var img: Image = get_viewport().get_texture().get_image()
|
||||
var dir: String = "user://screenshots"
|
||||
if not DirAccess.dir_exists_absolute(dir):
|
||||
DirAccess.make_dir_recursive_absolute(dir)
|
||||
var path: String = "%s/items_queue_proof.png" % dir
|
||||
img.save_png(path)
|
||||
print("[items_queue_proof] saved ", ProjectSettings.globalize_path(path))
|
||||
6
src/game/engine/scenes/tests/items_queue_proof.tscn
Normal file
6
src/game/engine/scenes/tests/items_queue_proof.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://engine/scenes/tests/items_queue_proof.gd" id="1"]
|
||||
|
||||
[node name="ItemsQueueProof" type="Node"]
|
||||
script = ExtResource("1")
|
||||
Loading…
Add table
Reference in a new issue