Store resources in generic inventories
This commit is contained in:
parent
02643c76c4
commit
1721edd123
24 changed files with 385 additions and 172 deletions
48
tests/test_generic_inventory.gd
Normal file
48
tests/test_generic_inventory.gd
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
extends SceneTree
|
||||
|
||||
const INVENTORY = preload("res://Inventory.gd")
|
||||
const TEST_RESOURCE: String = "crystal"
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
var game_state: Node = root.get_node("GameState")
|
||||
game_state.buildings.clear()
|
||||
game_state.bank_inventory.set_amount(TEST_RESOURCE, 40)
|
||||
game_state.fleet_inventory.set_amount(TEST_RESOURCE, 0)
|
||||
|
||||
var mothership_id: int = game_state.add_building(GameState.BUILDING_MOTHERSHIP, Vector2.ZERO)
|
||||
var crafter_id: int = game_state.add_building(GameState.BUILDING_SHIP_CRAFTER, Vector2(100, 0))
|
||||
if game_state.transfer_resource_to_fleet(mothership_id, TEST_RESOURCE, 15) != 15:
|
||||
return _fail("third resource could not move from bank to fleet")
|
||||
if game_state.transfer_resource_to_building(crafter_id, TEST_RESOURCE, 9) != 9:
|
||||
return _fail("third resource could not move from fleet to building")
|
||||
if game_state.transfer_resource_to_fleet(crafter_id, TEST_RESOURCE, 4) != 4:
|
||||
return _fail("third resource could not move back out of building")
|
||||
if game_state.banked_resource(TEST_RESOURCE) != 25 \
|
||||
or game_state.fleet_resource(TEST_RESOURCE) != 10 \
|
||||
or game_state.building_resource(crafter_id, TEST_RESOURCE) != 5:
|
||||
return _fail("third-resource amounts were not conserved")
|
||||
|
||||
var limited: RefCounted = INVENTORY.new({}, 10)
|
||||
limited.resource_capacities[TEST_RESOURCE] = 6
|
||||
if limited.deposit(TEST_RESOURCE, 99) != 6 or limited.deposit("water", 99) != 4:
|
||||
return _fail("total or per-resource capacity was not enforced")
|
||||
|
||||
var legacy_id: int = game_state.next_building_id
|
||||
game_state.next_building_id += 1
|
||||
game_state.buildings.append({"id": legacy_id, "type": GameState.BUILDING_SHIP_CRAFTER,
|
||||
"position": Vector2.ZERO, "stock": 7, "gas_stock": 3, "orders": []})
|
||||
if game_state.building_resource(legacy_id, GameState.RESOURCE_ORE) != 7 \
|
||||
or game_state.building_resource(legacy_id, GameState.RESOURCE_GAS) != 3:
|
||||
return _fail("legacy building stock was not migrated")
|
||||
var migrated: Dictionary = game_state.find_building(legacy_id)
|
||||
if migrated.has("stock") or migrated.has("gas_stock") or not migrated.has("inventory"):
|
||||
return _fail("legacy fields remained after migration")
|
||||
|
||||
print("TEST_GENERIC_INVENTORY: PASS")
|
||||
quit(0)
|
||||
|
||||
|
||||
func _fail(message: String) -> void:
|
||||
print("TEST_GENERIC_INVENTORY: FAIL (%s)" % message)
|
||||
quit(1)
|
||||
1
tests/test_generic_inventory.gd.uid
Normal file
1
tests/test_generic_inventory.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://53pexhmp3ns0
|
||||
|
|
@ -42,7 +42,8 @@ const CRAFTER_AT: Vector2 = Vector2(3000.0, 0.0)
|
|||
func _total() -> int:
|
||||
var sum: int = game_state.rocks + game_state.fleet_cargo
|
||||
for b in game_state.buildings:
|
||||
sum += int(b.get("stock", 0))
|
||||
if b.type != GameState.BUILDING_MOTHERSHIP:
|
||||
sum += game_state.building_resource(int(b.id), GameState.RESOURCE_ORE)
|
||||
return sum
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func _total() -> int:
|
|||
var sum: int = game_state.rocks + game_state.fleet_cargo
|
||||
for b in game_state.buildings:
|
||||
if b.type != GameState.BUILDING_MOTHERSHIP:
|
||||
sum += int(b.get("stock", 0))
|
||||
sum += game_state.building_resource(int(b.id), GameState.RESOURCE_ORE)
|
||||
return sum
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func _process(delta: float) -> bool:
|
|||
match stage:
|
||||
0:
|
||||
# --- gather a rock -------------------------------------------
|
||||
scene.get_node("RockField").set_process(false)
|
||||
scene.get_node("SurfaceFeatures/ResourceProvider").set_process(false)
|
||||
rock = load("res://Rock.tscn").instantiate()
|
||||
rock.build_shape(1)
|
||||
# Placed OUTSIDE the pickup shape but inside attract_radius, so
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ const CRAFTER_AT: Vector2 = Vector2(900.0, -300.0)
|
|||
func _total() -> int:
|
||||
var sum: int = game_state.rocks + game_state.fleet_cargo
|
||||
for b in game_state.buildings:
|
||||
sum += int(b.get("stock", 0))
|
||||
if b.type != GameState.BUILDING_MOTHERSHIP:
|
||||
sum += game_state.building_resource(int(b.id), GameState.RESOURCE_ORE)
|
||||
for t in game_state.transporters:
|
||||
sum += int(t.get("carrying", 0))
|
||||
# Ore inside a build that has STARTED but not finished (#23). It has left
|
||||
|
|
|
|||
Loading…
Reference in a new issue