2024-10-06 09:38:15 +00:00
|
|
|
class_name RoomTemplate extends Node3D
|
|
|
|
|
|
2024-10-18 16:10:51 +00:00
|
|
|
var initialised: bool = false
|
2025-12-12 23:22:21 +00:00
|
|
|
var id: State.rooms = State.rooms.NULL
|
2024-10-18 16:10:51 +00:00
|
|
|
|
2026-01-15 20:40:00 +00:00
|
|
|
@onready var scene_player : AnimationPlayer = %ScenePlayer
|
2026-01-17 11:11:21 +00:00
|
|
|
@onready var card_board : CardBoard # Optional Board, if present - set by the board in its own _ready()
|
2026-01-15 20:40:00 +00:00
|
|
|
|
2025-12-13 10:06:15 +00:00
|
|
|
var save_game:SaveGame = null
|
2024-10-06 09:38:15 +00:00
|
|
|
|
2025-12-12 23:22:21 +00:00
|
|
|
signal proceed(next_scene_path: String)
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
State.room = self
|
|
|
|
|
State.current_room = id
|
|
|
|
|
|
2026-01-19 09:34:01 +00:00
|
|
|
if not State.save_game:
|
|
|
|
|
push_warning("Room initialised without a SaveGame. Creating proxy save.")
|
|
|
|
|
State.save_game = ResourceLoader.load("res://dev-util/debug_save.tres")
|
|
|
|
|
|
|
|
|
|
save_game = State.save_game
|
|
|
|
|
save_game.current_room = id
|
|
|
|
|
|
|
|
|
|
if not Main.normal_boot:
|
|
|
|
|
start_room.call_deferred()
|
|
|
|
|
|
|
|
|
|
|
2025-12-15 16:57:26 +00:00
|
|
|
func disable()-> void:
|
2026-01-19 09:34:01 +00:00
|
|
|
push_warning("Room disabling is deprecated / unter reconstruction")
|
2026-01-18 09:48:03 +00:00
|
|
|
|
2026-01-05 17:18:48 +00:00
|
|
|
func get_ready():
|
2026-01-19 09:34:01 +00:00
|
|
|
# Override this function to initialize more things. it's called by start_room
|
2025-12-12 23:22:21 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
func play() -> String:
|
2026-01-19 09:34:01 +00:00
|
|
|
start_room.call_deferred()
|
|
|
|
|
var next_room : StringName = await proceed
|
|
|
|
|
prints("----------", "PROCEEDING", next_room, "--------------")
|
|
|
|
|
return next_room
|
2025-12-12 23:22:21 +00:00
|
|
|
|
|
|
|
|
|
2024-10-18 16:10:51 +00:00
|
|
|
func start_room():
|
2026-01-19 09:34:01 +00:00
|
|
|
await get_ready()
|
|
|
|
|
prints("----------", "START_ROOM", self.name, "--------------")
|
|
|
|
|
|
2024-10-18 16:10:51 +00:00
|
|
|
|
2025-12-13 10:14:10 +00:00
|
|
|
func pull_save_state(_save: SaveGame) -> void:
|
2026-01-19 09:34:01 +00:00
|
|
|
# Override this function to load the state of the chapter from State.save_game
|
2026-01-16 12:03:39 +00:00
|
|
|
restore_player_from_save(_save)
|
|
|
|
|
|
|
|
|
|
## Attempts to find player controller and restore position/rotation from save
|
|
|
|
|
func restore_player_from_save(save: SaveGame) -> void:
|
|
|
|
|
var player: PlayerController = null
|
2026-01-18 09:48:03 +00:00
|
|
|
|
2026-01-16 12:03:39 +00:00
|
|
|
# Try to find player controller in common locations
|
|
|
|
|
if has_node("%PlayerController"):
|
|
|
|
|
player = get_node("%PlayerController")
|
|
|
|
|
elif has_node("logic/PlayerController"):
|
|
|
|
|
player = get_node("logic/PlayerController")
|
2026-01-18 09:48:03 +00:00
|
|
|
|
2026-01-16 12:03:39 +00:00
|
|
|
if player and player is PlayerController:
|
|
|
|
|
player.restore_from_save(save)
|
|
|
|
|
else:
|
|
|
|
|
print_debug("RoomTemplate: Could not find PlayerController to restore position")
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-10-06 09:38:15 +00:00
|
|
|
func save_room():
|
2025-03-25 21:34:13 +00:00
|
|
|
save_game.save_to_file(get_tree().root.get_texture())
|
2025-06-03 21:17:29 +00:00
|
|
|
|
|
|
|
|
func unload():
|
2026-01-19 09:34:01 +00:00
|
|
|
# Override this function to clean up things not owned by this room
|
2025-06-03 21:17:29 +00:00
|
|
|
pass
|
2026-01-16 20:13:27 +00:00
|
|
|
|
|
|
|
|
## Called before a scene starts to allow room-specific preparation (e.g., animations)
|
|
|
|
|
## Override in subclasses to add custom scene preparation logic
|
|
|
|
|
func prepare_scene_start(_scene_id: Scenes.id, _is_repeating: bool) -> void:
|
|
|
|
|
await get_tree().process_frame # Dummy wait for LSP warning otherwise
|