fix: allows for proper reloading of all globals (reserved or otherwise); also now properly saves reserved objects; plus a couple small guards to correct issues while quitting after loading games in certain conditions

This commit is contained in:
Duncan Brown
2022-03-23 18:10:09 -04:00
committed by Julian Murgia
parent 84c84d3a0f
commit 7ff0176d62
5 changed files with 42 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
# `set_global name value`
# `set_global name value [ignore_reserved=false]`
#
# Changes the value of a global.
#
@@ -7,6 +7,9 @@
# - *name*: Name of the global
# - *value*: Value to set the global to (can be of type string, boolean, integer
# or float)
# - *force*: if false, setting a global whose name is reserved will
# trigger an error. Defaults to false. Reserved globals are: ESC_LAST_SCENE,
# FORCE_LAST_SCENE_NULL, ANIMATION_RESOURCES, ESC_CURRENT_SCENE
#
# @ESC
extends ESCBaseCommand
@@ -17,12 +20,16 @@ class_name SetGlobalCommand
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
2,
[TYPE_STRING, [TYPE_INT, TYPE_BOOL, TYPE_STRING]],
[null, null]
[TYPE_STRING, [TYPE_INT, TYPE_BOOL, TYPE_STRING], TYPE_BOOL],
[null, null, false]
)
# Run the command
func run(command_params: Array) -> int:
escoria.globals_manager.set_global(command_params[0], command_params[1])
escoria.globals_manager.set_global(
command_params[0],
command_params[1],
command_params[2]
)
return ESCExecution.RC_OK

View File

@@ -344,8 +344,9 @@ func unregister_object(object: ESCObject, room_key: ESCRoomObjectsKey) -> void:
if escoria.inventory_manager.inventory_has(object.global_id):
# Re-instance the node if it is an item present in inventory; that is,
# re-register it with the new current room.
object.node = object.node.duplicate()
register_object(object, null)
if object.node != null:
object.node = object.node.duplicate()
register_object(object, null, true)
room_objects.erase(object.global_id)
@@ -389,6 +390,15 @@ func save_game(p_savegame: ESCSaveGame) -> void:
p_savegame.objects[obj_global_id] = \
objects[obj_global_id].get_save_data()
# Add in reserved objects, too.
objects = reserved_objects_container.objects
for obj_global_id in objects:
if not objects[obj_global_id] is ESCObject:
continue
p_savegame.objects[obj_global_id] = \
objects[obj_global_id].get_save_data()
func get_start_location() -> ESCLocation:
if _room_exists(current_room_key):

View File

@@ -62,8 +62,7 @@ func change_scene(room_path: String, enable_automatic_transitions: bool) -> void
# This must happen if ESC_LAST_SCENE is set, or if we're running an
# exit_scene event. Also room selector actions require the transition.
if enable_automatic_transitions and (
not escoria.globals_manager.get_global( \
GLOBAL_LAST_SCENE).empty()
not escoria.globals_manager.get_global(GLOBAL_LAST_SCENE).empty()
or (
escoria.event_manager.get_running_event(escoria.event_manager.CHANNEL_FRONT) != null \
and escoria.event_manager.get_running_event(escoria.event_manager.CHANNEL_FRONT).name \

View File

@@ -293,12 +293,19 @@ func load_game(id: int):
## GLOBALS
for k in save_game.globals.keys():
ESCCommand.new("%s %s %s" %
[
_set_global.get_command_name(),
k,
save_game.globals[k]
]
var global_value = save_game.globals[k]
if global_value is String and global_value.empty():
global_value = "''"
load_statements.append(
ESCCommand.new("%s %s %s true" %
[
_set_global.get_command_name(),
k,
global_value
]
)
)
## OBJECTS

View File

@@ -226,7 +226,11 @@ func set_game_paused(p_paused: bool):
emit_signal("paused")
else:
emit_signal("resumed")
get_tree().paused = p_paused
var scene_tree = get_tree()
if is_instance_valid(scene_tree):
scene_tree.paused = p_paused
# Runs the event "event_name" from the "script" ESC script.