fix: loading and starting new games

This commit is contained in:
tiger tiger tiger 2025-12-19 20:39:56 +01:00
parent d09a930faa
commit 0045ac17c7
4 changed files with 74 additions and 75 deletions

View File

@ -2203,6 +2203,17 @@ render_target_update_mode = 4
[node name="CollectableUi" parent="logic/CeilingMemento/UiWrapper/UiSprite/SubViewport" instance=ExtResource("25_ghmim")]
scene = 0
[node name="Frame" type="Sprite3D" parent="logic/CeilingMemento/UiWrapper"]
transform = Transform3D(0.70457107, 0, 0, 0, 0.7045709, 0, 0, 0, 0.70457107, 1.0969601, -0.6430273, -0.2718675)
visibility_range_end = 0.6
visibility_range_end_margin = 0.3
visibility_range_fade_mode = 1
modulate = Color(1.8247963, 1.8247963, 1.8247963, 1)
no_depth_test = true
texture = ExtResource("24_ghmim")
region_enabled = true
region_rect = Rect2(735.5, 0, 995.5, 1024)
[node name="HoverDetect" type="CollisionShape3D" parent="logic/CeilingMemento"]
transform = Transform3D(1, 0, -2.9802322e-08, 0, 1, 0, 2.9802322e-08, 0, 1, 0, 0.09362054, 0)
shape = SubResource("SphereShape3D_c7buh")
@ -2242,6 +2253,17 @@ render_target_update_mode = 4
[node name="CollectableUi" parent="logic/MindBoard/UiWrapper/UiSprite/SubViewport" instance=ExtResource("25_ghmim")]
is_board = true
[node name="Frame" type="Sprite3D" parent="logic/MindBoard/UiWrapper"]
transform = Transform3D(0.70457107, 0, 0, 0, 0.7045709, 0, 0, 0, 0.70457107, 1.0969601, -0.6430273, -0.2718675)
visibility_range_end = 0.6
visibility_range_end_margin = 0.3
visibility_range_fade_mode = 1
modulate = Color(1.8247963, 1.8247963, 1.8247963, 1)
no_depth_test = true
texture = ExtResource("24_ghmim")
region_enabled = true
region_rect = Rect2(735.5, 0, 995.5, 1024)
[node name="HoverDetect" type="CollisionShape3D" parent="logic/MindBoard"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0)
shape = SubResource("CapsuleShape3D_72g2i")
@ -2283,6 +2305,17 @@ render_target_update_mode = 4
scene = 4
is_exit = true
[node name="Frame" type="Sprite3D" parent="logic/Door/UiWrapper"]
transform = Transform3D(0.70457107, 0, 0, 0, 0.7045709, 0, 0, 0, 0.70457107, 1.0969601, -0.6430273, -0.2718675)
visibility_range_end = 0.6
visibility_range_end_margin = 0.3
visibility_range_fade_mode = 1
modulate = Color(1.8247963, 1.8247963, 1.8247963, 1)
no_depth_test = true
texture = ExtResource("24_ghmim")
region_enabled = true
region_rect = Rect2(735.5, 0, 995.5, 1024)
[node name="HoverDetect" type="CollisionShape3D" parent="logic/Door"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0)
shape = SubResource("CapsuleShape3D_72g2i")
@ -2497,6 +2530,7 @@ transform = Transform3D(-1, 0, -1.50996e-07, 0, 1, 0, 1.50996e-07, 0, -1, 0.9066
light_energy = 0.0
[node name="SceneUI" type="Control" parent="."]
visible = false
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0

View File

@ -34,7 +34,7 @@ var app_state: AppState = AppState.BOOT:
AppState.MENU:
credits_roll.hide()
pause_menu.hide()
main_menu.execute()
await main_menu.execute()
AppState.PLAY:
credits_roll.hide()
main_menu.hide()
@ -47,7 +47,7 @@ var app_state: AppState = AppState.BOOT:
AppState.CREDITS:
main_menu.hide()
pause_menu.hide()
await credits_roll.play()
credits_roll.play()
func _enter_tree() -> void:
print_debug("main.gd: _enter_tree()")
@ -69,17 +69,20 @@ func _ready() -> void:
app_state = AppState.PLAY
func load_game(save: SaveGame) -> void:
print_debug("main.gd: _load_game()")
func start_game(save: SaveGame) -> void:
print_debug("main.gd: play_game()")
var room_path := room_paths.get(save.current_room, youth_room_path) as String
await _load_room(room_path)
await State.room.play()
func _load_room(next_path: String) -> bool:
await curtain.show()
%Loading.play()
if State.room != null:
State.room.unload()
State.room = null
await curtain.show()
%Loading.play()
ResourceLoader.load_threaded_request(next_path, "PackedScene", true)
while true:
await get_tree().process_frame
@ -90,8 +93,8 @@ func _load_room(next_path: String) -> bool:
State.room = next_scene.instantiate() as RoomTemplate
get_tree().root.add_child(State.room)
await State.room.get_ready()
await curtain.hide()
%Loading.stop()
await curtain.hide()
return true
ResourceLoader.THREAD_LOAD_FAILED:
push_error("Failed to load room.")
@ -99,52 +102,6 @@ func _load_room(next_path: String) -> bool:
return false
#
#var in_game = false
#
#var current_room: RoomTemplate
#var currently_loading_room: String = "":
# set(path):
# if path != "":
# ResourceLoader.load_threaded_request(path, "PackedScene")
# menu_animation["parameters/conditions/loading_done"] = false
# menu_animation["parameters/conditions/load_save"] = true
# else:
# menu_animation["parameters/conditions/loading_done"] = true
# menu_animation["parameters/conditions/load_save"] = false
#
# currently_loading_room = path
#
## Called when the node enters the scene tree for the first time.
#func _ready():
# main_menu.start_game.connect(load_save)
# main_menu.roll_credits.connect(func(): state_machine.travel("credits_roll"))
# get_tree().tree_process_mode_changed.connect(pause_mode_changed)
# await get_tree().process_frame
# currently_loading_room = get_room_path_from_id(main_menu.save_game_handle.get_most_recent_save().current_room)
# State.pass_stage_to(main_menu)
#
# Scenes.scene_starting.connect(prepare_transition)
# Scenes.scene_finished.connect(transition)
#
#func _process(_delta: float) -> void:
# if currently_loading_room != "" and not await_swap:
# if ResourceLoader.load_threaded_get_status(currently_loading_room) == 3:
# if not current_room == null:
# current_room.queue_free()
# State.onready_room = get_room_id_from_path(currently_loading_room)
# current_room = ResourceLoader.load_threaded_get(currently_loading_room).instantiate()
# print_debug("add room")
# add_child(current_room)
# State.onready_room = State.rooms.NULL
# move_child(current_room, 0)
# currently_loading_room = ""
# room_loaded.emit()
#
# if Input.is_action_just_pressed("reset_demo") and (OS.has_feature("demo") or true):
# State.stage_list = [self]
# _return_to_menu()
#
func _unhandled_input(event: InputEvent) -> void:
if event is InputEvent:
match app_state:

View File

@ -9,12 +9,11 @@ class_name MainMenu extends Panel
@onready var quit_button: Button = $PanelContainer/QuitButton
@onready var save_game_list: SaveGameList = %SaveGameList
# Internal Signals
signal _next_room(result: String)
signal success
func execute() -> String:
func execute() -> void:
print_debug("main_menu.gd: execute()")
modulate.a = 0
assert(is_node_ready(), "MainMenu node not ready yet! (???)")
if State.save_game == null or State.save_game.current_room == 0:
@ -27,10 +26,9 @@ func execute() -> String:
new_game_button.theme_type_variation = ""
_activate()
var result = await _next_room
_deactivate()
return str(result)
await _appear()
await success
await _vanish()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@ -41,7 +39,7 @@ func _ready() -> void:
new_game_button.pressed.connect(_new_game)
load_game_button.pressed.connect(_load_save_game)
settings_button.pressed.connect(settings_popup.show_settings)
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)
func _new_game() -> void:
@ -52,24 +50,21 @@ func _new_game() -> void:
func _start_game() -> void:
print_debug("main_menu.gd: _start_game()")
hide()
State.room.start_room()
_deactivate()
success.emit()
await Main.start_game(State.save_game)
func _load_save_game() -> void:
print_debug("main_menu.gd: _load_save_game()")
_deactivate()
var save: SaveGame = await save_game_list.pick_save_slot()
if (save != null):
State.save_game = save
await Main.load_game(save)
_start_game()
#_activate()
func _choose(choice: String) -> void:
print_debug("main_menu.gd: _choose(", choice, ")")
_next_room.emit(choice)
_start_game()
_deactivate()
else:
_activate()
func _activate() -> void:
@ -94,3 +89,16 @@ func _deactivate() -> void:
child.focus_mode = FOCUS_NONE
child.modulate = Color.WEB_GRAY
child.mouse_filter = Control.MOUSE_FILTER_IGNORE
func _appear() -> void:
modulate.a = 0
show()
var tween := create_tween()
tween.tween_property(self, "modulate:a", 1.0, 0.5)
await tween.finished
func _vanish() -> void:
var tween := create_tween()
tween.tween_property(self, "modulate:a", 0.0, 0.5)
await tween.finished
hide()