75 lines
2.4 KiB
GDScript
75 lines
2.4 KiB
GDScript
class_name RoomTemplate extends Node3D
|
|
|
|
var initialised: bool = false
|
|
var id: State.rooms = State.rooms.NULL
|
|
|
|
@onready var scene_player : AnimationPlayer = %SceneAnimationPlayer
|
|
@onready var card_board : CardBoard # Optional Board, if present - set by the board in its own _ready()
|
|
|
|
var save_game : SaveGame:
|
|
get: return State.save_game
|
|
|
|
signal proceed(next_scene_path: String)
|
|
|
|
func _ready() -> void:
|
|
State.room = self
|
|
|
|
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")
|
|
|
|
|
|
if not Main.normal_boot:
|
|
push_warning("------- DEBUG MODE --------")
|
|
play.call_deferred()
|
|
|
|
|
|
func get_ready():
|
|
prints("----------", "GET_READY", self.name, "--------------")
|
|
for i in range(20): await get_tree().process_frame
|
|
|
|
func play() -> String:
|
|
await get_ready()
|
|
await start_room()
|
|
var next_room : StringName = await proceed
|
|
prints("----------", "PROCEEDING", next_room, "--------------")
|
|
return next_room
|
|
|
|
|
|
func start_room():
|
|
prints("----------", "START_ROOM", self.name, "--------------")
|
|
await get_tree().process_frame # so this registers as a coroutine in IDE
|
|
|
|
|
|
func pull_save_state(_save: SaveGame) -> void:
|
|
# Override this function to load the state of the chapter from State.save_game
|
|
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
|
|
|
|
# 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")
|
|
|
|
if player and player is PlayerController:
|
|
player.restore_from_save(save)
|
|
else:
|
|
print("RoomTemplate: Could not find PlayerController to restore position")
|
|
|
|
func save_room():
|
|
save_game.save_to_file(get_tree().root.get_texture())
|
|
|
|
func unload():
|
|
# Override this function to clean up things not owned by this room
|
|
pass
|
|
|
|
## 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:
|
|
prints("PREPARE SCENE", _scene_id, _is_repeating)
|
|
await get_tree().process_frame # Dummy wait for LSP warning otherwise
|