feat: room loading
This commit is contained in:
parent
b24d8ddb6c
commit
6eb9de2b7f
|
|
@ -9,6 +9,7 @@ signal ini_room
|
||||||
@onready var card_picker: CardPicker = %Picker
|
@onready var card_picker: CardPicker = %Picker
|
||||||
|
|
||||||
func start_room():
|
func start_room():
|
||||||
|
$UI.show()
|
||||||
save_game = State.save_game
|
save_game = State.save_game
|
||||||
save_game.current_room = State.rooms.YOUTH
|
save_game.current_room = State.rooms.YOUTH
|
||||||
Scenes.completed_sequences = save_game.mementos_complete
|
Scenes.completed_sequences = save_game.mementos_complete
|
||||||
|
|
@ -28,11 +29,11 @@ func start_room():
|
||||||
|
|
||||||
func get_ready():
|
func get_ready():
|
||||||
id = State.rooms.YOUTH
|
id = State.rooms.YOUTH
|
||||||
|
%UI.hide()
|
||||||
self.show()
|
self.show()
|
||||||
$sfx/distant_rain.play()
|
$sfx/distant_rain.play()
|
||||||
$"sfx/rain on window".play()
|
$"sfx/rain on window".play()
|
||||||
await get_tree().process_frame #TODO: this was 0.1s, not sure if needed at all
|
await get_tree().process_frame #TODO: this was 0.1s, not sure if needed at all
|
||||||
%Board.hide()
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
super._ready()
|
super._ready()
|
||||||
|
|
|
||||||
|
|
@ -1928,6 +1928,7 @@ transform = Transform3D(0.707304, 0, 0.706909, 0, 1, 0, -0.706909, 0, 0.707304,
|
||||||
shape = SubResource("BoxShape3D_bq15k")
|
shape = SubResource("BoxShape3D_bq15k")
|
||||||
|
|
||||||
[node name="UI" type="Control" parent="logic"]
|
[node name="UI" type="Control" parent="logic"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,16 @@ func _ready() -> void:
|
||||||
State.room = self
|
State.room = self
|
||||||
State.current_room = id
|
State.current_room = id
|
||||||
|
|
||||||
|
func disable()-> void:
|
||||||
|
has_stage = false
|
||||||
|
set_process_input(false)
|
||||||
|
set_process(false)
|
||||||
|
|
||||||
func load():
|
func load():
|
||||||
# Override this function to load the state of the chapter from State.save_game
|
# Override this function to load the state of the chapter from State.save_game
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func play() -> String:
|
func play() -> String:
|
||||||
get_ready()
|
|
||||||
start_room()
|
start_room()
|
||||||
return await proceed
|
return await proceed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,35 +20,62 @@ var normal_boot : bool = false
|
||||||
State.rooms.ENDING: ending_path
|
State.rooms.ENDING: ending_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum AppState {BOOT, MENU, PLAY, PAUSE, CREDITS}
|
||||||
|
|
||||||
|
var app_state: AppState = AppState.BOOT:
|
||||||
|
set(value):
|
||||||
|
app_state = value
|
||||||
|
print_debug("main.gd: app_state changing to: %s" % str(app_state))
|
||||||
|
match app_state:
|
||||||
|
AppState.BOOT:
|
||||||
|
credits_roll.hide()
|
||||||
|
main_menu.hide()
|
||||||
|
pause_menu.hide()
|
||||||
|
AppState.MENU:
|
||||||
|
credits_roll.hide()
|
||||||
|
pause_menu.hide()
|
||||||
|
main_menu.execute()
|
||||||
|
AppState.PLAY:
|
||||||
|
credits_roll.hide()
|
||||||
|
main_menu.hide()
|
||||||
|
pause_menu.hide()
|
||||||
|
curtain.hide()
|
||||||
|
AppState.PAUSE:
|
||||||
|
credits_roll.hide()
|
||||||
|
main_menu.hide()
|
||||||
|
pause_menu.show()
|
||||||
|
AppState.CREDITS:
|
||||||
|
main_menu.hide()
|
||||||
|
pause_menu.hide()
|
||||||
|
await credits_roll.play()
|
||||||
|
|
||||||
|
func _enter_tree() -> void:
|
||||||
|
print_debug("main.gd: _enter_tree()")
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
print_debug("main.gd: _ready()")
|
print_debug("main.gd: _ready()")
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
if normal_boot:
|
main_menu.continue_button.pressed.connect(func(): app_state = AppState.PLAY)
|
||||||
print_debug("main.gd: normal boot")
|
main_menu.credits_button.pressed.connect(func(): app_state = AppState.CREDITS)
|
||||||
var path := await main_menu.execute()
|
|
||||||
await _load_room(path)
|
|
||||||
else:
|
|
||||||
print_debug("main.gd: direct boot")
|
|
||||||
credits_roll.hide()
|
|
||||||
main_menu.hide()
|
|
||||||
pause_menu.hide()
|
|
||||||
|
|
||||||
await curtain.hide()
|
if normal_boot:
|
||||||
|
print_debug("main.gd: normal boot (loading last save and showing main menu)")
|
||||||
|
app_state = AppState.MENU
|
||||||
|
else:
|
||||||
|
print_debug("main.gd: direct boot (hiding menus and entering main loop)")
|
||||||
|
app_state = AppState.PLAY
|
||||||
#await _mainloop() # Debug functionality
|
#await _mainloop() # Debug functionality
|
||||||
|
|
||||||
|
func load_game(save: SaveGame) -> void:
|
||||||
|
print_debug("main.gd: _load_game()")
|
||||||
|
var room_path := room_paths.get(save.current_room, youth_room_path) as String
|
||||||
|
await _load_room(room_path)
|
||||||
|
|
||||||
func _mainloop() -> void:
|
func _load_room(next_path: String) -> bool:
|
||||||
while true:
|
|
||||||
var next_scene := await State.room.play()
|
|
||||||
if (next_scene == null):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
await _load_room(youth_room_path)
|
|
||||||
|
|
||||||
|
|
||||||
func _load_room(next_path: String) -> void:
|
|
||||||
if State.room != null:
|
if State.room != null:
|
||||||
State.room.unload()
|
State.room.unload()
|
||||||
|
State.room = null
|
||||||
|
await curtain.show()
|
||||||
ResourceLoader.load_threaded_request(next_path, "PackedScene", true)
|
ResourceLoader.load_threaded_request(next_path, "PackedScene", true)
|
||||||
while true:
|
while true:
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
|
|
@ -58,11 +85,13 @@ func _load_room(next_path: String) -> void:
|
||||||
var next_scene := ResourceLoader.load_threaded_get(youth_room_path) as PackedScene
|
var next_scene := ResourceLoader.load_threaded_get(youth_room_path) as PackedScene
|
||||||
State.room = next_scene.instantiate() as RoomTemplate
|
State.room = next_scene.instantiate() as RoomTemplate
|
||||||
get_tree().root.add_child(State.room)
|
get_tree().root.add_child(State.room)
|
||||||
hide()
|
await State.room.get_ready()
|
||||||
break
|
await curtain.hide()
|
||||||
|
return true
|
||||||
ResourceLoader.THREAD_LOAD_FAILED:
|
ResourceLoader.THREAD_LOAD_FAILED:
|
||||||
push_error("Failed to load youth room scene.")
|
push_error("Failed to load youth room scene.")
|
||||||
return
|
break
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -113,12 +142,17 @@ func _load_room(next_path: String) -> void:
|
||||||
#
|
#
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event is InputEvent:
|
if event is InputEvent:
|
||||||
if event.is_action_pressed("ui_menu"):
|
match app_state:
|
||||||
toggle_pause_menu()
|
AppState.BOOT:
|
||||||
|
pass
|
||||||
func toggle_pause_menu():
|
AppState.MENU:
|
||||||
print_debug("Toggling pause menu")
|
pass
|
||||||
pass
|
AppState.PLAY:
|
||||||
|
if event.is_action_pressed("ui_menu"):
|
||||||
|
app_state = AppState.PAUSE
|
||||||
|
AppState.PAUSE:
|
||||||
|
if event.is_action_pressed("ui_menu"):
|
||||||
|
app_state = AppState.PLAY
|
||||||
|
|
||||||
# if not get_tree().paused:
|
# if not get_tree().paused:
|
||||||
# get_tree().paused = true
|
# get_tree().paused = true
|
||||||
|
|
|
||||||
|
|
@ -201,14 +201,7 @@ text = "Skip this Story"
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
visible = false
|
visible = false
|
||||||
modulate = Color(1, 1, 1, 0)
|
modulate = Color(1, 1, 1, 0)
|
||||||
layout_mode = 0
|
layout_mode = 1
|
||||||
anchors_preset = 0
|
|
||||||
anchor_right = 0.0
|
|
||||||
anchor_bottom = 0.0
|
|
||||||
offset_top = 220.0
|
|
||||||
offset_bottom = 220.0
|
|
||||||
grow_horizontal = 1
|
|
||||||
grow_vertical = 1
|
|
||||||
|
|
||||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
||||||
bus = &"music"
|
bus = &"music"
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ var playing : bool
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
print_debug("credits_roll.gd: _ready()")
|
print_debug("credits_roll.gd: _ready()")
|
||||||
original = Handle.position
|
original = Handle.position
|
||||||
play()
|
set_process_input(false)
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
if playing:
|
if playing:
|
||||||
|
|
@ -23,6 +23,7 @@ func _input(event: InputEvent) -> void:
|
||||||
|
|
||||||
func play() -> void:
|
func play() -> void:
|
||||||
print_debug("credits_roll.gd: show()")
|
print_debug("credits_roll.gd: show()")
|
||||||
|
set_process_input(true)
|
||||||
offset = original
|
offset = original
|
||||||
Handle.position = original
|
Handle.position = original
|
||||||
playing = true
|
playing = true
|
||||||
|
|
@ -34,10 +35,10 @@ func play() -> void:
|
||||||
|
|
||||||
func stop() -> void:
|
func stop() -> void:
|
||||||
print_debug("credits_roll.gd: hide()")
|
print_debug("credits_roll.gd: hide()")
|
||||||
|
set_process_input(false)
|
||||||
var tween := create_tween()
|
var tween := create_tween()
|
||||||
tween.tween_property(self, "modulate:a", 0.0, 2.0)
|
tween.tween_property(self, "modulate:a", 0.0, 2.0)
|
||||||
await tween.finished
|
await tween.finished
|
||||||
playing = false
|
playing = false
|
||||||
visible = false
|
visible = false
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
extends Panel
|
extends Panel
|
||||||
class_name Curtain
|
class_name Curtain
|
||||||
|
|
||||||
|
var _tween : Tween = null
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
print_debug("curtain.gd: ready()")
|
print_debug("curtain.gd: ready()")
|
||||||
show()
|
show()
|
||||||
|
|
@ -8,13 +10,17 @@ func _ready() -> void:
|
||||||
func show() -> void:
|
func show() -> void:
|
||||||
visible = true
|
visible = true
|
||||||
print_debug("curtain.gd: show()")
|
print_debug("curtain.gd: show()")
|
||||||
var tween := create_tween()
|
if _tween != null:
|
||||||
tween.tween_property(self, "modulate:a", 1.0, 2.0)
|
_tween.kill()
|
||||||
await tween.finished
|
_tween = create_tween()
|
||||||
|
_tween.tween_property(self, "modulate:a", 1.0, 1.0)
|
||||||
|
await _tween.finished
|
||||||
|
|
||||||
func hide() -> void:
|
func hide() -> void:
|
||||||
print_debug("curtain.gd: hide()")
|
print_debug("curtain.gd: hide()")
|
||||||
var tween := create_tween()
|
if _tween != null:
|
||||||
tween.tween_property(self, "modulate:a", 0.0, 2.0)
|
_tween.kill()
|
||||||
await tween.finished
|
_tween = create_tween()
|
||||||
|
_tween.tween_property(self, "modulate:a", 0.0, 1.0)
|
||||||
|
await _tween.finished
|
||||||
visible = false
|
visible = false
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ class_name MainMenu extends Panel
|
||||||
@onready var settings_popup: SettingsPopup = %SettingsPopup
|
@onready var settings_popup: SettingsPopup = %SettingsPopup
|
||||||
@onready var credits_button: Button = $PanelContainer/CreditsButton
|
@onready var credits_button: Button = $PanelContainer/CreditsButton
|
||||||
@onready var quit_button: Button = $PanelContainer/QuitButton
|
@onready var quit_button: Button = $PanelContainer/QuitButton
|
||||||
@onready var save_game_handle: SaveGameList = %SaveGameList
|
@onready var save_game_list: SaveGameList = %SaveGameList
|
||||||
|
|
||||||
# Internal Signals
|
# Internal Signals
|
||||||
signal _next_room(result: String)
|
signal _next_room(result: String)
|
||||||
|
|
@ -26,8 +26,6 @@ func execute() -> String:
|
||||||
continue_button.disabled = false
|
continue_button.disabled = false
|
||||||
new_game_button.theme_type_variation = ""
|
new_game_button.theme_type_variation = ""
|
||||||
|
|
||||||
#save_game_handle.visible = save_game_handle.has_existing_saves()
|
|
||||||
|
|
||||||
_activate()
|
_activate()
|
||||||
var result = await _next_room
|
var result = await _next_room
|
||||||
_deactivate()
|
_deactivate()
|
||||||
|
|
@ -46,7 +44,6 @@ func _ready() -> void:
|
||||||
credits_button.pressed.connect(_choose.bind("credits")) #FIXME: Needs some other encoding, like path
|
credits_button.pressed.connect(_choose.bind("credits")) #FIXME: Needs some other encoding, like path
|
||||||
quit_button.pressed.connect(get_tree().quit)
|
quit_button.pressed.connect(get_tree().quit)
|
||||||
|
|
||||||
|
|
||||||
func _new_game() -> void:
|
func _new_game() -> void:
|
||||||
print_debug("main_menu.gd: start_new_game()")
|
print_debug("main_menu.gd: start_new_game()")
|
||||||
State.save_game = SaveGame.new()
|
State.save_game = SaveGame.new()
|
||||||
|
|
@ -60,8 +57,12 @@ func _start_game() -> void:
|
||||||
|
|
||||||
func _load_save_game() -> void:
|
func _load_save_game() -> void:
|
||||||
print_debug("main_menu.gd: _load_save_game()")
|
print_debug("main_menu.gd: _load_save_game()")
|
||||||
var save: SaveGame = await save_game_handle.pick_save_slot()
|
_deactivate()
|
||||||
_on_save_picked(save)
|
var save: SaveGame = await save_game_list.pick_save_slot()
|
||||||
|
if (save != null):
|
||||||
|
State.save_game = save
|
||||||
|
await Main.load_game(save)
|
||||||
|
_activate()
|
||||||
|
|
||||||
|
|
||||||
func _choose(choice: String) -> void:
|
func _choose(choice: String) -> void:
|
||||||
|
|
@ -70,7 +71,10 @@ func _choose(choice: String) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _activate() -> void:
|
func _activate() -> void:
|
||||||
load_game_button.disabled = not save_game_handle.has_existing_saves()
|
load_game_button.disabled = not save_game_list.has_more_saves()
|
||||||
|
continue_button.disabled = (State.save_game == null or State.save_game.is_empty)
|
||||||
|
|
||||||
|
load_game_button.disabled = not save_game_list.has_more_saves()
|
||||||
|
|
||||||
for child: Control in $PanelContainer.get_children():
|
for child: Control in $PanelContainer.get_children():
|
||||||
child.focus_mode = Control.FOCUS_ALL
|
child.focus_mode = Control.FOCUS_ALL
|
||||||
|
|
@ -88,10 +92,3 @@ func _deactivate() -> void:
|
||||||
child.focus_mode = FOCUS_NONE
|
child.focus_mode = FOCUS_NONE
|
||||||
child.modulate = Color.WEB_GRAY
|
child.modulate = Color.WEB_GRAY
|
||||||
child.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
child.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||||
|
|
||||||
|
|
||||||
func _on_save_picked(save: SaveGame):
|
|
||||||
print_debug("main_menu.gd: _on_save_picked(", save, ")")
|
|
||||||
if (save != null):
|
|
||||||
State.save_game = save
|
|
||||||
_next_room.emit("start_game")
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class_name PauseManu extends PanelContainer
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
resume_button.pressed.connect(owner.toggle_pause_menu)
|
resume_button.pressed.connect(func(): Main.app_state = Main.AppState.PLAY)
|
||||||
#to_menu_button.pressed.connect(_process)
|
#to_menu_button.pressed.connect(_process)
|
||||||
to_desktop_button.pressed.connect(func(): get_tree().quit())
|
to_desktop_button.pressed.connect(func(): get_tree().quit())
|
||||||
#to_settings_button.pressed.connect(_process)
|
#to_settings_button.pressed.connect(_process)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ func _validate_property(property: Dictionary) -> void:
|
||||||
if property.name == "saves":
|
if property.name == "saves":
|
||||||
property.usage = PROPERTY_USAGE_READ_ONLY + PROPERTY_USAGE_SCRIPT_VARIABLE + PROPERTY_USAGE_EDITOR
|
property.usage = PROPERTY_USAGE_READ_ONLY + PROPERTY_USAGE_SCRIPT_VARIABLE + PROPERTY_USAGE_EDITOR
|
||||||
|
|
||||||
|
var _tween: Tween = null
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_load_games()
|
_load_games()
|
||||||
|
|
@ -74,16 +75,18 @@ func _rebuild_buttons() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_game_picked(id: int) -> void:
|
func _on_game_picked(id: int) -> void:
|
||||||
hide()
|
_picked.emit(saves[id])
|
||||||
#_picked.emit(saves[id])
|
|
||||||
|
|
||||||
|
|
||||||
func get_most_recent_save() -> SaveGame:
|
func get_most_recent_save() -> SaveGame:
|
||||||
_sort_saves()
|
_sort_saves()
|
||||||
return saves[0] if saves.size() > 0 else SaveGame.new()
|
return saves[0] if saves.size() > 0 else SaveGame.new()
|
||||||
|
|
||||||
func has_existing_saves() -> bool:
|
func has_more_saves() -> bool:
|
||||||
return saves.size() > 1
|
for save in saves:
|
||||||
|
if save != State.save_game:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("ui_cancel"):
|
if event.is_action_pressed("ui_cancel"):
|
||||||
|
|
@ -102,16 +105,18 @@ func pick_save_slot() -> SaveGame:
|
||||||
# TODO: ugh, godot tweens are the wurst
|
# TODO: ugh, godot tweens are the wurst
|
||||||
func open() -> void:
|
func open() -> void:
|
||||||
show()
|
show()
|
||||||
set_process_input(true)
|
|
||||||
save_buttons[0].grab_focus()
|
save_buttons[0].grab_focus()
|
||||||
modulate = Color.TRANSPARENT
|
modulate = Color.TRANSPARENT
|
||||||
var tween := get_tree().create_tween()
|
if _tween != null:
|
||||||
tween.tween_property(self, "modulate", Color.WHITE, 0.5)
|
_tween.kill()
|
||||||
await tween.finished
|
_tween = create_tween()
|
||||||
|
_tween.tween_property(self, "modulate", Color.WHITE, 0.5)
|
||||||
|
await _tween.finished
|
||||||
|
|
||||||
func close() -> void:
|
func close() -> void:
|
||||||
set_process_input(false)
|
if _tween != null:
|
||||||
var tween := get_tree().create_tween()
|
_tween.kill()
|
||||||
tween.tween_property(self, "modulate", Color.TRANSPARENT, 0.5)
|
_tween = create_tween()
|
||||||
await tween.finished
|
_tween.tween_property(self, "modulate", Color.TRANSPARENT, 0.5)
|
||||||
|
await _tween.finished
|
||||||
hide()
|
hide()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue