Save and load game fixes (and some other small fixes) (#466)

This commit is contained in:
Julian Murgia
2021-11-29 14:21:29 +01:00
committed by GitHub
parent dcb9db488d
commit b031d69cd9
19 changed files with 177 additions and 79 deletions

View File

@@ -372,7 +372,7 @@ func _get_dir_deg(deg: int, animations: ESCAnimationResource) -> int:
# It's an error to have the animations misconfigured
if dir == -1:
escoria.logger.report_errors(
"escitem.gd:_get_dir_deg()",
"esc_movable.gd:_get_dir_deg()",
["No direction found for " + str(deg)]
)

View File

@@ -68,7 +68,8 @@ func run(command_params: Array) -> int:
and (
not escoria.globals_manager.get_global("ESC_LAST_SCENE").empty()
or (
escoria.event_manager.get_running_event("_front").name \
escoria.event_manager.get_running_event("_front") != null \
and escoria.event_manager.get_running_event("_front").name \
in ["newgame", "exit_scene", "room_selector"]
and escoria.globals_manager.get_global(
"ESC_LAST_SCENE"
@@ -129,6 +130,7 @@ func run(command_params: Array) -> int:
var room_scene = res_room.instance()
if room_scene:
if command_params[1] \
and escoria.event_manager.get_running_event("_front") != null \
and escoria.event_manager.get_running_event("_front").name \
== "room_selector":
room_scene.enabled_automatic_transitions = true

View File

@@ -219,7 +219,15 @@ func _compile(lines: Array) -> Array:
returned.append(dialog_option)
elif command_regex.search(line):
var command = ESCCommand.new(line)
returned.append(command)
if command.command_exists():
returned.append(command)
else:
escoria.logger.report_errors(
"Invalid command detected: %s" % command.name,
[
"Command implementation not found in any command directory"
]
)
else:
escoria.logger.report_errors(
"Invalid ESC line detected",

View File

@@ -177,10 +177,21 @@ func get_running_event(name: String) -> ESCEvent:
# The event finished running
#
# #### Parameters
# - finished_statement: statement object that finished
# - return_code: Return code of the finished event
# - channel_name: Name of the channel that the event came from
func _on_event_finished(return_code: int, channel_name: String) -> void:
func _on_event_finished(finished_statement: ESCStatement, return_code: int, channel_name: String) -> void:
var event = _running_events[channel_name]
if not event:
escoria.logger.report_warnings(
"esc_event_manager.gd:_on_event_finished()",
[
"Event %s finished without being in _running_events[%s]"
% [finished_statement.name, channel_name]
]
)
return
escoria.logger.debug(
"Event %s ended with return code %d" % [event.name, return_code]
)

View File

@@ -29,6 +29,19 @@ func _process(_delta):
# - object: Object to register
# - force: Register the object, even if it has already been registered
func register_object(object: ESCObject, force: bool = false) -> void:
if object.global_id.empty():
object.global_id = str(object.node.get_path()).split("/root/", false)[0]
object.node.global_id = object.global_id
escoria.logger.report_warnings(
"esc_object_manager.gd:register_object()",
[
"Registering object with empty global_id.",
"Using node's full path as global_id: %s"
% object.node.global_id
]
)
if objects.has(object.global_id) and not force:
escoria.logger.report_errors(
"ESCObjectManager.register_object: Object already registered",

View File

@@ -82,16 +82,7 @@ func _init(command_string):
# Check, if conditions match
func is_valid() -> bool:
var command_found = false
for base_path in ProjectSettings.get("escoria/main/command_directories"):
var command_path = "%s/%s.gd" % [
base_path.trim_suffix("/"),
self.name
]
if ResourceLoader.exists(command_path):
command_found = true
if not command_found:
if not command_exists():
escoria.logger.report_errors(
"Invalid command detected: %s" % self.name,
[
@@ -103,6 +94,21 @@ func is_valid() -> bool:
return .is_valid()
# Checks that the command exists
#
# *Returns* True if the command exists, else false.
func command_exists() -> bool:
var command_found = false
for base_path in ProjectSettings.get("escoria/main/command_directories"):
var command_path = "%s/%s.gd" % [
base_path.trim_suffix("/"),
self.name
]
if ResourceLoader.exists(command_path):
command_found = true
return command_found
# Run this command
func run() -> int:
var command_object = escoria.command_registry.get_command(self.name)

View File

@@ -4,7 +4,7 @@ class_name ESCStatement
# Emitted when the event did finish running
signal finished(return_code)
signal finished(event, return_code)
# Emitted when the event was interrupted
signal interrupted(return_code)
@@ -54,13 +54,18 @@ func run() -> int:
final_rc = rc
break
emit_signal("finished", final_rc)
emit_signal("finished", self, final_rc)
return final_rc
# Interrupt the statement in the middle of its execution.
func interrupt():
escoria.logger.info("Interrupting event %s" % str(self))
escoria.logger.info("Interrupting event %s (%s)" % \
[
self.name if "name" in self else "group",
str(self)
]
)
_is_interrupted = true
for statement in statements:
if statement.is_finished:

View File

@@ -110,13 +110,6 @@ func _ready():
player.update_idle()
escoria.object_manager.get_object("_camera").node.set_target(player)
for n in get_children():
if n is ESCLocation and n.is_start_location:
escoria.object_manager.register_object(
ESCObject.new(n.name, n),
true
)
if global_id.empty():
global_id = name

View File

@@ -166,12 +166,18 @@ func load_game(id: int):
var file: File = File.new()
if not file.file_exists(save_file_path):
escoria.logger.report_errors(
"esc_save_data_resources.gd",
"esc_save_manager.gd:load_game()",
["Save file %s doesn't exist" % save_file_path])
return
escoria.logger.info(
"esc_save_manager.gd:load_game()",
["Loading savegame %s" % str(id)])
var save_game: Resource = ResourceLoader.load(save_file_path)
escoria.event_manager.interrupt_running_event()
var load_event = ESCEvent.new(":load")
var load_statements = []
@@ -181,6 +187,12 @@ func load_game(id: int):
[ProjectSettings.get_setting("escoria/ui/default_transition")]
)
)
load_statements.append(
ESCCommand.new("hide_menu main")
)
load_statements.append(
ESCCommand.new("hide_menu pause")
)
## GLOBALS
for k in save_game.globals.keys():
@@ -192,7 +204,7 @@ func load_game(id: int):
## ROOM
load_statements.append(
ESCCommand.new("change_scene %s true" \
ESCCommand.new("change_scene %s false" \
% save_game.main["current_scene_filename"])
)
@@ -261,6 +273,9 @@ func load_game(id: int):
escoria.set_game_paused(false)
escoria.event_manager.queue_event(load_event)
escoria.logger.debug(
"esc_save_manager.gd:load_game()",
["Load event queued."])
# Save the game settings in the settings file.

View File

@@ -60,8 +60,7 @@ func add_new_item_by_id(item_id: String) -> void:
escoria.logger.report_errors(
"inventory_ui.gd:add_new_item_by_id()",
[
"Item global id '%s' does not exist." % item_id,
"Check item's id in ESCORIA_ALL_ITEMS scene."
"Item global id '%s' does not exist." % item_id
]
)

View File

@@ -12,6 +12,13 @@ __meta__ = {
}
slot_ui_scene = ExtResource( 2 )
[node name="Panel" type="Panel" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_editor_description_": ""
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_left = 0.3
anchor_top = 0.3

View File

@@ -14,6 +14,15 @@ __meta__ = {
}
slot_ui_scene = ExtResource( 1 )
[node name="Panel" type="Panel" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -1.0
margin_bottom = -1.0
__meta__ = {
"_editor_description_": ""
}
[node name="save_name_popup" parent="." instance=ExtResource( 4 )]
visible = false

View File

@@ -27,11 +27,16 @@ func _on_quit_pressed():
# Hide the options panel again
func _on_options_back_button_pressed():
$options.hide()
$main.show()
reset()
# Hide the load panel
func _on_load_game_back_button_pressed():
reset()
# Resets the UI to initial state
func reset():
$load_game.hide()
$options.hide()
$main.show()

View File

@@ -11,6 +11,13 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Panel" type="Panel" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_editor_description_": ""
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0

View File

@@ -31,21 +31,26 @@ func _on_quit_pressed():
escoria.quit()
# Hide the save slots again
# Hide the save slots after clicking back button
func _on_save_game_back_button_pressed():
$VBoxContainer.show()
$save_game.hide()
reset()
# Hide the load slots again
# Hide the load slots after clicking back button
func _on_load_game_back_button_pressed():
$VBoxContainer.show()
$load_game.hide()
reset()
# Set wether saving is enabled currently
# Set whether saving is enabled currently
#
# #### Parameters
# - p_enabled: Enable or disable saving
func set_save_enabled(p_enabled: bool):
$VBoxContainer/menuitems/save_game.disabled = !p_enabled
# Resets the UI to initial state
func reset():
$save_game.hide()
$load_game.hide()
$VBoxContainer.show()

View File

@@ -204,9 +204,12 @@ func _on_event_done(_event_name: String):
func hide_main_menu():
if get_node(main_menu).visible:
get_node(main_menu).hide()
show_ui()
func show_main_menu():
if not get_node(main_menu).visible:
hide_ui()
get_node(main_menu).reset()
get_node(main_menu).show()
func unpause_game():
@@ -219,6 +222,7 @@ func unpause_game():
func pause_game():
if not get_node(pause_menu).visible:
get_node(pause_menu).reset()
get_node(pause_menu).set_save_enabled(escoria.save_manager.save_enabled)
get_node(pause_menu).show()
escoria.object_manager.get_object("_camera").node.current = false

View File

@@ -185,11 +185,12 @@ func _on_event_done(event_name: String):
func hide_main_menu():
if get_node(main_menu).visible:
get_node(main_menu).hide()
get_node(main_menu).hide()
func show_main_menu():
if not get_node(main_menu).visible:
get_node(main_menu).show()
get_node(main_menu).reset()
get_node(main_menu).show()
func unpause_game():
if get_node(pause_menu).visible:
@@ -200,6 +201,7 @@ func unpause_game():
func pause_game():
if not get_node(pause_menu).visible:
get_node(main_menu).reset()
get_node(pause_menu).set_save_enabled(
escoria.save_manager.save_enabled
)

View File

@@ -6,13 +6,18 @@
script = ExtResource( 1 )
escoria_version = "0.1.0"
game_version = "0.1.0"
name = "testwalk"
date = "23/11/2021 19:51"
name = "test"
date = "28/11/2021 16:50"
main = {
"current_scene_filename": "res://game/rooms/room15/room15.tscn",
"current_scene_filename": "res://game/rooms/room01/room01.tscn",
"last_scene_global_id": ""
}
globals = {
"ESC_LAST_SCENE": "",
"FORCE_LAST_SCENE_NULL": false,
"dialog_advance": 0,
"dialog_popup_advance": 0,
"room1_visited": true
}
objects = {
"_camera": {
@@ -23,7 +28,7 @@ objects = {
"_music": {
"active": true,
"interactive": true,
"state": "default"
"state": "res://game/sfx/contemplation.ogg"
},
"_sound": {
"active": true,
@@ -37,43 +42,48 @@ objects = {
},
"player": {
"active": true,
"global_transform": Transform2D( 1, 0, 0, 1, 243.677, 455.569 ),
"global_transform": Transform2D( 1, 0, 0, 1, 870, 461 ),
"interactive": true,
"last_deg": 1,
"last_dir": 0,
"last_deg": 71,
"last_dir": 2,
"state": "default"
},
"r12_l_exit": {
"r1_destination_point": {
"active": true,
"interactive": true,
"state": "default"
},
"r15_l_exit": {
"r1_destination_point2": {
"active": true,
"interactive": true,
"state": "default"
},
"r15_r_exit": {
"r1_destination_point3": {
"active": true,
"interactive": true,
"state": "default"
},
"say_long": {
"r1_r_exit": {
"active": true,
"interactive": true,
"state": "default"
},
"say_long_left": {
"r1_start": {
"active": true,
"interactive": true,
"state": "default"
},
"start": {
"r1_wall_item1": {
"active": true,
"interactive": true,
"state": "default"
},
"switch_animation": {
"r1_wall_item2": {
"active": true,
"interactive": true,
"state": "default"
},
"trigger_talk": {
"active": true,
"interactive": true,
"state": "default"

View File

@@ -6,18 +6,15 @@
script = ExtResource( 1 )
escoria_version = "0.1.0"
game_version = "0.1.0"
name = "testwalk2"
date = "23/11/2021 20:19"
name = "test2"
date = "28/11/2021 16:50"
main = {
"current_scene_filename": "res://game/rooms/room15/room15.tscn",
"current_scene_filename": "res://game/rooms/room02/room02.tscn",
"last_scene_global_id": ""
}
globals = {
"ANIMATION_RESOURCES": {
"player": "res://game/characters/mark/mark_animations_weird.tres"
},
"BYPASS_LAST_SCENE": false,
"ESC_LAST_SCENE": "room1",
"FORCE_LAST_SCENE_NULL": false,
"dialog_advance": 0,
"dialog_popup_advance": 0,
"room1_visited": true
@@ -31,12 +28,12 @@ objects = {
"_music": {
"active": true,
"interactive": true,
"state": "off"
"state": "res://game/sfx/contemplation.ogg"
},
"_sound": {
"active": true,
"interactive": true,
"state": "off"
"state": "default"
},
"_speech": {
"active": true,
@@ -45,43 +42,43 @@ objects = {
},
"player": {
"active": true,
"global_transform": Transform2D( 1, 0, 0, 1, 606, 441 ),
"global_transform": Transform2D( 1, 0, 0, 1, 52.1462, 384.691 ),
"interactive": true,
"last_deg": 251,
"last_dir": 6,
"last_deg": 161,
"last_dir": 4,
"state": "default"
},
"r12_l_exit": {
"r2_bridge": {
"active": true,
"interactive": false,
"state": "default"
},
"r2_button": {
"active": true,
"interactive": true,
"state": "default"
},
"r15_l_exit": {
"r2_button_right": {
"active": true,
"interactive": true,
"state": "default"
},
"r15_r_exit": {
"r2_l_exit": {
"active": true,
"interactive": true,
"state": "default"
},
"say_long": {
"r2_player_start": {
"active": true,
"interactive": true,
"state": "default"
},
"say_long_left": {
"r2_r_exit": {
"active": true,
"interactive": true,
"state": "default"
},
"start": {
"active": true,
"interactive": true,
"state": "default"
},
"switch_animation": {
"r2_right_platform": {
"active": true,
"interactive": true,
"state": "default"