refactor room and id handling
This commit is contained in:
parent
8c10640eb5
commit
8bdd48a365
|
|
@ -2,7 +2,7 @@ extends Room
|
||||||
class_name SubwaySequence
|
class_name SubwaySequence
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
id = State.rooms.TRANSITION
|
id = Room.ids.TRANSITION
|
||||||
super._ready()
|
super._ready()
|
||||||
|
|
||||||
func get_ready_async() -> void:
|
func get_ready_async() -> void:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,6 @@ extends Station
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
%PlayerDetect.body_entered.connect(func(body):
|
%PlayerDetect.body_entered.connect(func(body):
|
||||||
if visible and body is PlayerController:
|
if visible and body is PlayerController:
|
||||||
State.room.save_game.subway_burnout = true
|
State.active_room.save_game.subway_burnout = true
|
||||||
await Main.curtain.black()
|
await Main.curtain.black()
|
||||||
State.room.proceed.emit(Main.adulthood_room_path))
|
State.active_room.proceed.emit(Main.adulthood_room_path))
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,6 @@ extends Station
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
%PlayerDetect.body_entered.connect(func(body):
|
%PlayerDetect.body_entered.connect(func(body):
|
||||||
if visible and body is PlayerController:
|
if visible and body is PlayerController:
|
||||||
State.room.save_game.subway_burnout = false
|
State.active_room.save_game.subway_burnout = false
|
||||||
await Main.curtain.black()
|
await Main.curtain.black()
|
||||||
State.room.proceed.emit(Main.adulthood_room_path))
|
State.active_room.proceed.emit(Main.adulthood_room_path))
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,15 @@ class_name Room
|
||||||
## Tells the main loop to proceed to the next scene
|
## Tells the main loop to proceed to the next scene
|
||||||
signal proceed(next_scene_path: String)
|
signal proceed(next_scene_path: String)
|
||||||
|
|
||||||
@export var id: State.rooms = State.rooms.NULL
|
enum ids {
|
||||||
|
NULL,
|
||||||
|
YOUTH,
|
||||||
|
TRANSITION,
|
||||||
|
ADULTHOOD,
|
||||||
|
ENDING
|
||||||
|
}
|
||||||
|
|
||||||
|
@export var id: Room.ids = Room.ids.NULL
|
||||||
|
|
||||||
@onready var player: PlayerController = %PlayerController
|
@onready var player: PlayerController = %PlayerController
|
||||||
@onready var scene_player : AnimationPlayer = %SceneAnimationPlayer
|
@onready var scene_player : AnimationPlayer = %SceneAnimationPlayer
|
||||||
|
|
@ -19,10 +27,10 @@ var save_game : SaveGame:
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
assert(id != State.rooms.NULL, "Room " + str(self) + name + " has no proper ID set, it's still State.Rooms.NULL")
|
assert(id != Room.ids.NULL, "Room " + str(self) + name + " has no proper ID set, it's still Room.ids.NULL")
|
||||||
prints("room.gd", "_ready()", self)
|
prints("room.gd", "_ready()", self)
|
||||||
|
|
||||||
State.room = self
|
State.active_room = self
|
||||||
|
|
||||||
if not save_game:
|
if not save_game:
|
||||||
var debug_save_path := "res://dev-util/debug_save.tres"
|
var debug_save_path := "res://dev-util/debug_save.tres"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ class_name SaveGame extends Resource
|
||||||
# === Data Fields ===
|
# === Data Fields ===
|
||||||
|
|
||||||
@export var unique_save_name: String = ""
|
@export var unique_save_name: String = ""
|
||||||
@export var current_room: State.rooms = State.rooms.NULL
|
@export var current_room: Room.ids = Room.ids.NULL
|
||||||
@export_flags("Intro", "Childhood", "Voice Training", "Jui Jutsu") var mementos_complete: int = 0
|
@export_flags("Intro", "Childhood", "Voice Training", "Jui Jutsu") var mementos_complete: int = 0
|
||||||
@export_flags_2d_physics var sequences_enabled: int = 63
|
@export_flags_2d_physics var sequences_enabled: int = 63
|
||||||
|
|
||||||
|
|
@ -134,14 +134,14 @@ func save_to_file(screen_shot: Texture2D) -> void:
|
||||||
push_warning("SaveGame: DEBUG save skipped (intentional).")
|
push_warning("SaveGame: DEBUG save skipped (intentional).")
|
||||||
return
|
return
|
||||||
|
|
||||||
assert(State.room, "Trying to save while not in a room.")
|
assert(State.active_room, "Trying to save while not in a room.")
|
||||||
assert(State.room.id != State.rooms.NULL, "Trying to save in a room that's not correctly initialized.")
|
assert(State.active_room.id != Room.ids.NULL, "Trying to save in a room that's not correctly initialized.")
|
||||||
|
|
||||||
# Save game can track the room it is in by itself;
|
# Save game can track the room it is in by itself;
|
||||||
# and we should never save before having successfully entered a room.
|
# and we should never save before having successfully entered a room.
|
||||||
current_room = State.room.id
|
current_room = State.active_room.id
|
||||||
|
|
||||||
prints("-----------", "SAVE POINT", State.room, "-----------")
|
prints("-----------", "SAVE POINT", State.active_room, "-----------")
|
||||||
print("SaveGame: Saving to file: %s" % file_name)
|
print("SaveGame: Saving to file: %s" % file_name)
|
||||||
|
|
||||||
# Capture current state
|
# Capture current state
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ func _on_text_updated():
|
||||||
label.text = text
|
label.text = text
|
||||||
|
|
||||||
if from_youth:
|
if from_youth:
|
||||||
if State.current_room == State.rooms.YOUTH or State.onready_room == State.rooms.YOUTH:
|
if State.get_room_id() <= Room.ids.YOUTH:
|
||||||
background_sprite.animation = "youth"
|
background_sprite.animation = "youth"
|
||||||
else:
|
else:
|
||||||
background_sprite.animation = "aged"
|
background_sprite.animation = "aged"
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ func play_story() -> void:
|
||||||
Scenes.begin_sequence(playable.scene_id, repeat)
|
Scenes.begin_sequence(playable.scene_id, repeat)
|
||||||
|
|
||||||
# Allow room to prepare for scene (e.g., play animations)
|
# Allow room to prepare for scene (e.g., play animations)
|
||||||
await State.room.prepare_scene_start(playable.scene_id, repeat)
|
await State.active_room.prepare_scene_start(playable.scene_id, repeat)
|
||||||
|
|
||||||
canvas_layer.show()
|
canvas_layer.show()
|
||||||
await playable.appear()
|
await playable.appear()
|
||||||
|
|
@ -120,7 +120,7 @@ func play_story() -> void:
|
||||||
|
|
||||||
# Pick the cards if not already picked
|
# Pick the cards if not already picked
|
||||||
if not repeat:
|
if not repeat:
|
||||||
var picker := State.room.get_node("%Picker") as CardPicker
|
var picker := State.active_room.get_node("%Picker") as CardPicker
|
||||||
await picker.pick_cards(playable.scene_id)
|
await picker.pick_cards(playable.scene_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ signal intro
|
||||||
@export var scene_id : Scenes.id
|
@export var scene_id : Scenes.id
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
prints("story-playable.gd:", "_ready()", self, "room:", State.room)
|
prints("story-playable.gd:", "_ready()", self, "room:", State.active_room)
|
||||||
super._ready()
|
super._ready()
|
||||||
State.settings_changed.connect(func(): story_array = story_array)
|
State.settings_changed.connect(func(): story_array = story_array)
|
||||||
skip_control = %SkipControl
|
skip_control = %SkipControl
|
||||||
|
|
@ -231,4 +231,4 @@ func _on_text_finished():
|
||||||
|
|
||||||
|
|
||||||
func _emit_thunder() -> void:
|
func _emit_thunder() -> void:
|
||||||
if State.room is YouthRoom: (State.room as YouthRoom).play_thunder()
|
if State.active_room is YouthRoom: (State.active_room as YouthRoom).play_thunder()
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ class_name GlobalState
|
||||||
signal settings_changed
|
signal settings_changed
|
||||||
var _settings_initialized
|
var _settings_initialized
|
||||||
|
|
||||||
var room: Room
|
var active_room: Room
|
||||||
var save_game: SaveGame
|
|
||||||
signal environment_settings_changed
|
signal environment_settings_changed
|
||||||
|
|
||||||
# FIXME find a better way to switch fonts and maybe emit the theme_changed signal!
|
# FIXME find a better way to switch fonts and maybe emit the theme_changed signal!
|
||||||
|
|
@ -269,30 +268,18 @@ func queue_for_stage(target: Object, index: int = 1):
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region play state
|
#region utility functions
|
||||||
|
|
||||||
enum rooms {
|
func get_room_id(if_game_active = false) -> Room.ids:
|
||||||
NULL,
|
var id: Room.ids
|
||||||
YOUTH,
|
if active_room:
|
||||||
TRANSITION,
|
id = active_room.id
|
||||||
ADULTHOOD,
|
elif save_game:
|
||||||
ENDING
|
id = save_game.current_room
|
||||||
}
|
else:
|
||||||
|
id = Room.ids.NULL
|
||||||
|
|
||||||
enum sequences {
|
if if_game_active and not Main.is_game_active():
|
||||||
DRAVEN,
|
return Room.ids.NULL
|
||||||
CHILDHOOD,
|
|
||||||
VOICE,
|
|
||||||
JUI_JUTSU,
|
|
||||||
TRANS,
|
|
||||||
AUTISM,
|
|
||||||
UNI_START,
|
|
||||||
VOLUNTARY,
|
|
||||||
UNI_CONTINUE,
|
|
||||||
UNI_ALT,
|
|
||||||
THERAPY,
|
|
||||||
BURNOUT
|
|
||||||
}
|
|
||||||
|
|
||||||
var current_room: rooms = rooms.NULL
|
return id
|
||||||
var onready_room: rooms = rooms.NULL
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func rebuild():
|
||||||
"AM" if date_time["hour"] < 12 else "PM"]
|
"AM" if date_time["hour"] < 12 else "PM"]
|
||||||
|
|
||||||
var time_label := Label.new()
|
var time_label := Label.new()
|
||||||
time_label.text = localised_date_time if not save.current_room == State.rooms.NULL else "Start new game"
|
time_label.text = localised_date_time if not save.current_room == Room.ids.NULL else "Start new game"
|
||||||
|
|
||||||
var info:= VBoxContainer.new()
|
var info:= VBoxContainer.new()
|
||||||
info.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
info.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
|
|
@ -87,18 +87,18 @@ func rebuild():
|
||||||
var room:= Label.new()
|
var room:= Label.new()
|
||||||
room.theme_type_variation = "HeaderMedium"
|
room.theme_type_variation = "HeaderMedium"
|
||||||
match save.current_room:
|
match save.current_room:
|
||||||
State.rooms.NULL:
|
Room.ids.NULL:
|
||||||
room.text = "Empty Slot"
|
room.text = "Empty Slot"
|
||||||
State.rooms.YOUTH:
|
Room.ids.YOUTH:
|
||||||
if save.mementos_complete > 0:
|
if save.mementos_complete > 0:
|
||||||
room.text = "Youth Room"
|
room.text = "Youth Room"
|
||||||
else:
|
else:
|
||||||
room.text = "Intro Sequence"
|
room.text = "Intro Sequence"
|
||||||
State.rooms.TRANSITION:
|
Room.ids.TRANSITION:
|
||||||
room.text = "Transitioning to Adulthood"
|
room.text = "Transitioning to Adulthood"
|
||||||
State.rooms.ADULTHOOD:
|
Room.ids.ADULTHOOD:
|
||||||
room.text = "Exploring Adulthood"
|
room.text = "Exploring Adulthood"
|
||||||
State.rooms.ENDING:
|
Room.ids.ENDING:
|
||||||
room.text = "Ending"
|
room.text = "Ending"
|
||||||
|
|
||||||
var state: = Label.new()
|
var state: = Label.new()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue