diff --git a/scripts/game/game_state.gd b/scripts/game/game_state.gd index 38afaae..cc151f1 100644 --- a/scripts/game/game_state.gd +++ b/scripts/game/game_state.gd @@ -1,6 +1,7 @@ extends Node var selected_ship_path: String = "" +var restart_inventory: Dictionary = {} func _ready() -> void: var game_window := get_tree().root diff --git a/scripts/game/ship_controller.gd b/scripts/game/ship_controller.gd index abe1d3f..ec449ae 100644 --- a/scripts/game/ship_controller.gd +++ b/scripts/game/ship_controller.gd @@ -66,6 +66,10 @@ func _ready() -> void: _sprite.texture = ship_texture var largest_dimension := maxf(ship_texture.get_width(), ship_texture.get_height()) _sprite.scale = Vector2.ONE * (64.0 / largest_dimension) + # Inventory children have already applied the restored equipment bonuses. + hull = max_hull + shields = max_shields + energy = max_energy _update_shield_visual() func _ensure_input_action(action_name: StringName, physical_key: Key) -> void: @@ -125,6 +129,7 @@ func _destroy_ship() -> void: func _restart_level_after_destruction() -> void: await get_tree().create_timer(1.1).timeout if is_inside_tree(): + $ShipInventory.preserve_for_restart() get_tree().reload_current_scene() func _physics_process(delta: float) -> void: diff --git a/scripts/items/ship_inventory.gd b/scripts/items/ship_inventory.gd index 6c22110..4c652dd 100644 --- a/scripts/items/ship_inventory.gd +++ b/scripts/items/ship_inventory.gd @@ -18,7 +18,13 @@ func _ready() -> void: cargo.resize(CARGO_SIZE) weapon_slots.resize(WEAPON_SLOT_COUNT) module_slots.resize(MODULE_SLOT_COUNT) - _add_starter_items() + if GameState.restart_inventory.is_empty(): + _add_starter_items() + else: + cargo.assign(GameState.restart_inventory["cargo"]) + weapon_slots.assign(GameState.restart_inventory["weapon"]) + module_slots.assign(GameState.restart_inventory["module"]) + GameState.restart_inventory.clear() _recalculate_ship_stats() inventory_changed.emit() @@ -29,6 +35,14 @@ func get_cargo_used() -> int: used += 1 return used +func preserve_for_restart() -> void: + # Copy the slot arrays; resources retain levels and individual modifiers. + GameState.restart_inventory = { + "cargo": cargo.duplicate(), + "weapon": weapon_slots.duplicate(), + "module": module_slots.duplicate(), + } + func get_item(slot_kind: String, index: int) -> ItemInstance: var slots := _get_slots(slot_kind) if index < 0 or index >= slots.size():