Offer only orderable vessels, and read out crew condition
A ship crafter shows what can actually be ordered there: a hull whose research is done, and - for the support craft - one with somewhere to be assigned. A transporter with no hub and a drone with no workshop have nowhere to go and would sit in the hangar as spent resources, so the structure that uses one is part of its availability. Hidden rather than greyed, as the build menu already treats an unresearched structure, and gated in queue_order() too so the model refuses what the menu declines to show. The craft buttons bound their handlers to a definition captured at startup. With a list that changes length that is a live bug - a slot would order whatever hull was there when the menu was built - so they bind to the slot and resolve through the current offer. The hub and workshop crew menus now NAME what is left in each vessel: "TRANSPORTER 2 9 / 20 RUNS", worst first, with one wide bar for the vessel closest to spent. The per-vessel bars they replaced drew about seven pixels tall on a phone and carried no figure, so the number the player is deciding on could not be read. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
This commit is contained in:
parent
fe3ae97f94
commit
296b49c8b8
10 changed files with 359 additions and 41 deletions
29
tests/_station_menu_preview.gd
Normal file
29
tests/_station_menu_preview.gd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
extends Node2D
|
||||
|
||||
# Preview, not a test - #216's crew menu on a transport hub: how many are
|
||||
# assigned, how many stand there, and what each of them has left.
|
||||
#
|
||||
# bash tests/screenshot.sh res://tests/_station_menu_preview.tscn shots/station_menu.png 3 720x1280
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
GameState.buildings.clear()
|
||||
GameState.extractors.clear()
|
||||
GameState.transporters.clear()
|
||||
GameState.reset_progression()
|
||||
GameState.intro_active = false
|
||||
GameState.unlocked = ["shipyards", "logistics", "freight", "freight_yards"]
|
||||
GameState.add_building(GameState.BUILDING_MOTHERSHIP, Vector2.ZERO)
|
||||
var hub_id: int = GameState.add_building(GameState.BUILDING_TRANSPORT_HUB,
|
||||
Vector2(700.0, 0.0))
|
||||
load("res://tests/_staff.gd").staff(GameState, hub_id, GameState.hub_capacity())
|
||||
# Worn to different degrees, so the bars have something to say.
|
||||
var wear: Array = [GameState.TRANSPORTER_TRIPS, 9, 2]
|
||||
for i in range(GameState.transporters.size()):
|
||||
GameState.transporters[i].trips_left = int(wear[i % wear.size()])
|
||||
|
||||
var main: Node = load("res://world/Main.tscn").instantiate()
|
||||
add_child(main)
|
||||
main.get_node("AsteroidField").set_process(false)
|
||||
main.get_node("EnemySpawner").set_process(false)
|
||||
main.get_node("UI/StationMenu").open_for(hub_id)
|
||||
6
tests/_station_menu_preview.tscn
Normal file
6
tests/_station_menu_preview.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://tests/_station_menu_preview.gd" id="1"]
|
||||
|
||||
[node name="StationMenuPreview" type="Node2D"]
|
||||
script = ExtResource("1")
|
||||
|
|
@ -107,10 +107,13 @@ func _process(delta: float) -> bool:
|
|||
print("unresearched carrier is unbuildable, as expected")
|
||||
|
||||
# --- D. locked state in the crafter UI -------------------------
|
||||
# An unresearched hull is now ABSENT from the crafter rather than
|
||||
# drawn greyed: a row nobody can press says nothing its absence
|
||||
# does not. What must hold is that it cannot be ordered from here.
|
||||
controller.craft_building_id = crafter_id
|
||||
controller._refresh_craft_status()
|
||||
if controller.craft_menu.vessel_buttons[FLEET_UI_INDEX].enabled:
|
||||
return _fail("a locked carrier shows enabled in the crafter menu")
|
||||
if controller.craft_menu.shown_types.has(GameState.VESSEL_CARRIER):
|
||||
return _fail("an unresearched carrier is still offered in the crafter menu")
|
||||
|
||||
stage = 1
|
||||
elapsed = 0.0
|
||||
|
|
|
|||
92
tests/test_crafter_availability.gd
Normal file
92
tests/test_crafter_availability.gd
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
extends SceneTree
|
||||
|
||||
# A ship crafter offers what can actually be ordered there, and nothing else.
|
||||
#
|
||||
# Two rules:
|
||||
# - a hull whose research is not done is not on offer (it never was
|
||||
# orderable; it was drawn greyed, which is a row that says nothing the
|
||||
# absence does not)
|
||||
# - a support vessel needs the structure that USES it. #216 made
|
||||
# transporters and repair drones ordinary craft, and one with no hub or
|
||||
# no workshop has nowhere to be assigned - it would sit in the hangar as
|
||||
# spent resources.
|
||||
#
|
||||
# Covers:
|
||||
# A. with no hub and no workshop, neither support craft can be ordered
|
||||
# B. building a hub offers the transporter, and only the transporter
|
||||
# C. building a workshop offers the drone
|
||||
# D. the model refuses the order too, not just the menu
|
||||
# E. an unresearched fleet hull is not on offer either
|
||||
|
||||
var state: Node
|
||||
var crafter_id: int
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
state = root.get_node("GameState")
|
||||
state.buildings.clear()
|
||||
state.extractors.clear()
|
||||
state.transporters.clear()
|
||||
state.repair_drones.clear()
|
||||
state.reset_progression()
|
||||
state.rocks = 900
|
||||
state.unlocked = ["shipyards", "logistics", "freight"]
|
||||
crafter_id = state.add_building(state.BUILDING_SHIP_CRAFTER, Vector2(400.0, 0.0))
|
||||
|
||||
|
||||
func _process(_delta: float) -> bool:
|
||||
# --- A. nothing to assign them to, so nothing on offer ------------
|
||||
if state.vessel_can_be_crafted(GameState.VESSEL_TRANSPORTER):
|
||||
return _fail("a transporter is orderable with no hub to put it in")
|
||||
if state.vessel_can_be_crafted(GameState.REPAIR_DRONE):
|
||||
return _fail("a repair drone is orderable with no workshop to put it in")
|
||||
# --- D. and the model refuses, not merely the menu ----------------
|
||||
if state.queue_order(crafter_id, GameState.VESSEL_TRANSPORTER):
|
||||
return _fail("the crafter queued a transporter with nowhere to send it")
|
||||
print("no hub, no workshop: neither support craft is on offer")
|
||||
|
||||
# --- B. a hub offers the transporter ------------------------------
|
||||
var hub_id: int = state.add_building(state.BUILDING_TRANSPORT_HUB, Vector2(900.0, 0.0))
|
||||
if not state.vessel_can_be_crafted(GameState.VESSEL_TRANSPORTER):
|
||||
return _fail("a hub is standing and the transporter is still not orderable")
|
||||
if state.vessel_can_be_crafted(GameState.REPAIR_DRONE):
|
||||
return _fail("a transport hub made the repair drone orderable")
|
||||
if not state.queue_order(crafter_id, GameState.VESSEL_TRANSPORTER):
|
||||
return _fail("the crafter refused a transporter with a hub standing")
|
||||
state.find_building(crafter_id).orders.clear()
|
||||
print("a hub offers the transporter, and only that")
|
||||
|
||||
# --- C. and a workshop the drone ----------------------------------
|
||||
state.add_building(GameState.BUILDING_WORKSHOP, Vector2(-900.0, 0.0))
|
||||
if not state.vessel_can_be_crafted(GameState.REPAIR_DRONE):
|
||||
return _fail("a workshop is standing and the drone is still not orderable")
|
||||
print("a workshop offers the repair drone")
|
||||
|
||||
# Taking the hub away takes the offer with it - there is nowhere to
|
||||
# assign one again.
|
||||
state.remove_buildings_of_type(state.BUILDING_TRANSPORT_HUB)
|
||||
if state.vessel_can_be_crafted(GameState.VESSEL_TRANSPORTER):
|
||||
return _fail("the last hub came down and the transporter is still on offer")
|
||||
print("the last hub down: the transporter is off the menu again")
|
||||
|
||||
# --- E. an unresearched hull is not on offer ----------------------
|
||||
var locked: String = ""
|
||||
for definition in load("res://vessels/VesselDefinitions.gd").fleet():
|
||||
if not state.vessel_is_unlocked(String(definition.definition_id)):
|
||||
locked = String(definition.definition_id)
|
||||
break
|
||||
if locked == "":
|
||||
return _fail("every fleet hull is already unlocked, so this proves nothing")
|
||||
if state.vessel_can_be_crafted(locked):
|
||||
return _fail("'%s' is unresearched and still on offer" % locked)
|
||||
print("an unresearched hull ('%s') is not on offer" % locked)
|
||||
|
||||
print("TEST_CRAFTER_AVAILABILITY: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
|
||||
|
||||
func _fail(message: String) -> bool:
|
||||
print("TEST_CRAFTER_AVAILABILITY: FAIL (%s)" % message)
|
||||
quit(1)
|
||||
return true
|
||||
|
|
@ -44,6 +44,17 @@ func _initialize() -> void:
|
|||
# Office. This test flies more than one vessel, so it needs the offices
|
||||
# standing before the fleet spawns into them.
|
||||
load("res://tests/_berths.gd").grant(root.get_node("GameState"), 6)
|
||||
# The crafter shows only what can be ordered there, so the vessels this
|
||||
# test inspects have to be orderable: every hull researched, and a hub and
|
||||
# a workshop standing for the two support craft. Section E in particular
|
||||
# needs a TWO-resource price on offer - it is about a price that used to
|
||||
# run off the end of its strip - and every ore-only hull would prove
|
||||
# nothing.
|
||||
for definition in load("res://vessels/VesselDefinitions.gd").craftable():
|
||||
if String(definition.unlock_id) != "":
|
||||
game_state.vessel_levels[String(definition.unlock_id)] = 1
|
||||
game_state.add_building(GameState.BUILDING_TRANSPORT_HUB, Vector2(4000.0, 4000.0))
|
||||
game_state.add_building(GameState.BUILDING_WORKSHOP, Vector2(4600.0, 4000.0))
|
||||
scene = load("res://world/Main.tscn").instantiate()
|
||||
root.add_child(scene)
|
||||
current_scene = scene
|
||||
|
|
@ -72,10 +83,18 @@ func _process(delta: float) -> bool:
|
|||
# exact match rather than by hunting for resource words in it: a
|
||||
# Gas Bomber is named after a resource and always will be, and
|
||||
# what #111 removed was the PRICE spelled out underneath.
|
||||
var fleet_defs: Array = VesselDefinitions.craftable()
|
||||
for i in range(mini(controller.craft_menu.vessel_labels.size(), fleet_defs.size())):
|
||||
# Read against what is ON OFFER, not the whole catalogue: a hull
|
||||
# that is unresearched, or a support craft with nowhere to be
|
||||
# assigned, is hidden rather than greyed, so slot i holds the ith
|
||||
# OFFERED vessel and the hidden slots keep whatever text the
|
||||
# scene was authored with.
|
||||
var offered: PackedStringArray = controller.craft_menu.shown_types
|
||||
if offered.is_empty():
|
||||
return _fail("the crafter offers nothing at all, so this proves nothing")
|
||||
for i in range(offered.size()):
|
||||
var caption: String = String(controller.craft_menu.vessel_labels[i].text)
|
||||
var expected: String = String(fleet_defs[i].display_name)
|
||||
var expected: String = String(VesselDefinitions.get_definition(
|
||||
String(offered[i])).display_name)
|
||||
if caption != expected:
|
||||
return _fail("a craft caption reads \"%s\", expected just \"%s\"" \
|
||||
% [caption, expected])
|
||||
|
|
@ -97,10 +116,10 @@ func _process(delta: float) -> bool:
|
|||
controller.craft_menu.vessel_buttons.size()])
|
||||
var priced: int = 0
|
||||
var stacked: int = 0
|
||||
for i in range(controller.craft_menu.price_tags.size()):
|
||||
# #216 added the two support craft to the crafter, so the rows
|
||||
# are craftable() now - fleet hulls first, then those.
|
||||
var definition: Resource = VesselDefinitions.craftable()[i]
|
||||
# Over the OFFERED vessels, for the same reason as the captions
|
||||
# above: a hidden strip belongs to no vessel.
|
||||
for i in range(mini(offered.size(), controller.craft_menu.price_tags.size())):
|
||||
var definition: Resource = VesselDefinitions.get_definition(String(offered[i]))
|
||||
var costs: Dictionary = game_state.product_costs(definition.definition_id)
|
||||
var strip: Control = controller.craft_menu.price_tags[i]
|
||||
if costs.is_empty():
|
||||
|
|
|
|||
95
tests/test_station_condition_readout.gd
Normal file
95
tests/test_station_condition_readout.gd
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
extends SceneTree
|
||||
|
||||
# The hub and workshop menus name what is left in each vessel they hold.
|
||||
#
|
||||
# #216 gave them crews that wear out, and the whole point of that is a
|
||||
# decision - "build another before this one is spent" - which the player can
|
||||
# only make if they can read the figure. A bar alone said "getting low"; the
|
||||
# number says how low.
|
||||
#
|
||||
# Covers:
|
||||
# A. a hub lists every transporter it holds, worst first, with runs left
|
||||
# B. a workshop says REPAIRS rather than RUNS, in its own capacity
|
||||
# C. an empty structure says nothing rather than "0 / 0"
|
||||
|
||||
var state: Node
|
||||
var scene: Node
|
||||
var menu: Control
|
||||
var hub_id: int
|
||||
var workshop_id: int
|
||||
var stage: int = 0
|
||||
var elapsed: float = 0.0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
state = root.get_node("GameState")
|
||||
state.buildings.clear()
|
||||
state.extractors.clear()
|
||||
state.transporters.clear()
|
||||
state.repair_drones.clear()
|
||||
state.reset_progression()
|
||||
state.reset_new_game()
|
||||
state.intro_active = false
|
||||
state.reset_quests()
|
||||
state.unlocked = ["shipyards", "logistics", "freight"]
|
||||
hub_id = state.add_building(state.BUILDING_TRANSPORT_HUB, Vector2(900.0, 0.0))
|
||||
workshop_id = state.add_building(GameState.BUILDING_WORKSHOP, Vector2(-900.0, 0.0))
|
||||
scene = load("res://world/Main.tscn").instantiate()
|
||||
root.add_child(scene)
|
||||
current_scene = scene
|
||||
menu = scene.get_node("UI/StationMenu")
|
||||
|
||||
|
||||
func _process(delta: float) -> bool:
|
||||
elapsed += delta
|
||||
if elapsed < 0.3:
|
||||
return false
|
||||
match stage:
|
||||
0:
|
||||
# --- C. nothing held, nothing claimed --------------------
|
||||
menu.open_for(hub_id)
|
||||
if menu.condition_list.text.strip_edges() != "":
|
||||
return _fail("an empty hub lists a crew: '%s'" % menu.condition_list.text)
|
||||
print("an empty hub lists nothing")
|
||||
|
||||
# --- A. worst first, with the figure ---------------------
|
||||
var staff: Script = load("res://tests/_staff.gd")
|
||||
staff.staff(state, hub_id, 2)
|
||||
state.transporters[0].trips_left = 4
|
||||
state.transporters[1].trips_left = GameState.TRANSPORTER_TRIPS
|
||||
menu.refresh()
|
||||
var listed: String = menu.condition_list.text
|
||||
if not listed.contains("4 / %d RUNS" % GameState.TRANSPORTER_TRIPS):
|
||||
return _fail("a hub holding a worn transporter does not say so: '%s'" % listed)
|
||||
if not listed.contains("%d / %d RUNS" % [GameState.TRANSPORTER_TRIPS,
|
||||
GameState.TRANSPORTER_TRIPS]):
|
||||
return _fail("the fresh transporter is missing from '%s'" % listed)
|
||||
# Worst first: the nearly-spent one is the decision.
|
||||
if listed.find("4 / ") > listed.find("%d / " % GameState.TRANSPORTER_TRIPS):
|
||||
return _fail("the worn transporter is listed after the fresh one")
|
||||
print("hub lists: %s" % listed.replace("\n", " | "))
|
||||
elapsed = 0.0
|
||||
stage = 1
|
||||
return false
|
||||
1:
|
||||
# --- B. a workshop counts repairs, in its own capacity ----
|
||||
load("res://tests/_staff.gd").staff(state, workshop_id, 1)
|
||||
state.repair_drones[0].repairs_left = 3
|
||||
menu.open_for(workshop_id)
|
||||
var drone_text: String = menu.condition_list.text
|
||||
if not drone_text.contains("3 / %d REPAIRS" % GameState.DRONE_REPAIRS):
|
||||
return _fail("a workshop does not report repairs left: '%s'" % drone_text)
|
||||
if drone_text.contains("RUNS"):
|
||||
return _fail("a workshop reports its drones in RUNS: '%s'" % drone_text)
|
||||
print("workshop lists: %s" % drone_text.replace("\n", " | "))
|
||||
|
||||
print("TEST_STATION_CONDITION_READOUT: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _fail(message: String) -> bool:
|
||||
print("TEST_STATION_CONDITION_READOUT: FAIL (%s)" % message)
|
||||
quit(1)
|
||||
return true
|
||||
Loading…
Reference in a new issue