adding support and resolving crashes when running room scenes in debug mode

This commit is contained in:
betalars 2025-09-05 01:54:21 +02:00
parent 5a937a9f1b
commit e31047639c
5 changed files with 47 additions and 6 deletions

View File

@ -36,9 +36,6 @@ func get_ready():
func _ready():
Scenes.scene_finished.connect(_on_scene_finished)
if get_parent() == get_tree().root:
get_ready()
start_room()
card_picker.cards_picked.connect(card_board.populate_board)
func pull_save_state(save: SaveGame) -> void:

View File

@ -0,0 +1,24 @@
[gd_resource type="Resource" script_class="SaveGame" load_steps=3 format=3 uid="uid://bgplfqxa852wo"]
[ext_resource type="Script" uid="uid://d06gpwuxmkxkt" path="res://dev-util/savegame.gd" id="1_jr18u"]
[ext_resource type="Texture2D" uid="uid://bk5ja14r7r6i4" path="res://import/interface-elements/empty_save_slot.png" id="2_b2tdf"]
[resource]
script = ExtResource("1_jr18u")
filepath = "DEBUG"
unique_save_name = "DEBUG"
current_room = 0
mementos_complete = 1
board_state = {
"cards": {},
"randoms": [],
"stickies": {}
}
is_childhood_board_complete = false
thumbnail = ExtResource("2_b2tdf")
last_saved = 1756993270
is_valid = true
is_demo = false
is_empty = true
save_manually = false
metadata/_custom_type_script = "uid://d06gpwuxmkxkt"

View File

@ -57,6 +57,8 @@ func _validate_property(property: Dictionary):
func _init(initial_filepath = "") -> void:
if initial_filepath == "":
filepath = "%s/%s.json" % [State.user_saves_path, unique_save_name]
elif initial_filepath == "DEBUG":
filepath = initial_filepath
else:
filepath = initial_filepath
unique_save_name = initial_filepath.get_file()
@ -68,6 +70,14 @@ func _init(initial_filepath = "") -> void:
func read_save_file():
print("Opening Savegame: %s" % filepath)
if filepath == "DEBUG":
if OS.has_feature("debug") or OS.has_feature("demo"):
push_warning("Created DEBUG savegame. Progress will not be stored!")
else:
print(get_stack())
push_error("Created DEBUG savegame outside of demo or debug environment. This is unintentional and will lead to data loss. Please contact support and attatch the stack above.")
#TODO maybe cause a crash here?
return
if FileAccess.file_exists(filepath):
var file = FileAccess.open(filepath, FileAccess.READ)
@ -143,6 +153,10 @@ func _get_save_dict() -> Dictionary:
}
func save_to_file(current_screen: Texture):
if filepath == "DEBUG":
push_warning("Saving DEBUG save skipped. This is intentional.")
return
last_saved = Time.get_unix_time_from_system()
var thumbnail_image: Image = current_screen.get_image()
thumbnail_image.convert(Image.Format.FORMAT_RGB8)

View File

@ -6,7 +6,7 @@ var has_stage: bool = false:
if has_stage != on_stage:
if on_stage:
has_stage = true
if is_inside_tree():
if is_node_ready():
camera.make_current()
get_viewport().gui_release_focus()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
@ -14,10 +14,11 @@ var has_stage: bool = false:
jitter_tween.tween_property(self, "jitter_strength", 1, 1)
if has_entered: emit_signal("ui_exited")
elif has_stage:
camera.current = true
await ready
camera.make_current()
jitter_strength = 1
else:
if is_inside_tree() and has_stage:
if is_node_ready() and has_stage:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
var jitter_tween: Tween = create_tween()
jitter_tween.tween_property(self, "jitter_strength", 0, 0.5)

View File

@ -232,8 +232,13 @@ func _unhandled_input(event: InputEvent) -> void:
#endregion
func _ready():
await get_tree().process_frame
for child in get_tree().root.get_children():
if child is RoomTemplate and active_save_game == null:
push_warning("Room initialised without a SaveGame. Creating proxy save.")
#TODO: make this a bit more clean maybe?
active_save_game = ResourceLoader.load("res://dev-util/debug_save.tres")
if "has_stage" in child:
pass_stage_to(child)
break