Save and load game fixes (and some other small fixes) (#466)
This commit is contained in:
@@ -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)]
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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]
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
[
|
||||
@@ -101,7 +92,22 @@ func is_valid() -> bool:
|
||||
return false
|
||||
|
||||
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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -166,11 +166,17 @@ 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.
|
||||
|
||||
Reference in New Issue
Block a user