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. # Changes the value of a global.
# #
@@ -7,6 +7,9 @@
# - *name*: Name of the global # - *name*: Name of the global
# - *value*: Value to set the global to (can be of type string, boolean, integer # - *value*: Value to set the global to (can be of type string, boolean, integer
# or float) # 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 # @ESC
extends ESCBaseCommand extends ESCBaseCommand
@@ -17,12 +20,16 @@ class_name SetGlobalCommand
func configure() -> ESCCommandArgumentDescriptor: func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new( return ESCCommandArgumentDescriptor.new(
2, 2,
[TYPE_STRING, [TYPE_INT, TYPE_BOOL, TYPE_STRING]], [TYPE_STRING, [TYPE_INT, TYPE_BOOL, TYPE_STRING], TYPE_BOOL],
[null, null] [null, null, false]
) )
# Run the command # Run the command
func run(command_params: Array) -> int: 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 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): if escoria.inventory_manager.inventory_has(object.global_id):
# Re-instance the node if it is an item present in inventory; that is, # Re-instance the node if it is an item present in inventory; that is,
# re-register it with the new current room. # re-register it with the new current room.
object.node = object.node.duplicate() if object.node != null:
register_object(object, null) object.node = object.node.duplicate()
register_object(object, null, true)
room_objects.erase(object.global_id) room_objects.erase(object.global_id)
@@ -389,6 +390,15 @@ func save_game(p_savegame: ESCSaveGame) -> void:
p_savegame.objects[obj_global_id] = \ p_savegame.objects[obj_global_id] = \
objects[obj_global_id].get_save_data() 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: func get_start_location() -> ESCLocation:
if _room_exists(current_room_key): 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 # 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. # exit_scene event. Also room selector actions require the transition.
if enable_automatic_transitions and ( if enable_automatic_transitions and (
not escoria.globals_manager.get_global( \ not escoria.globals_manager.get_global(GLOBAL_LAST_SCENE).empty()
GLOBAL_LAST_SCENE).empty()
or ( or (
escoria.event_manager.get_running_event(escoria.event_manager.CHANNEL_FRONT) != null \ 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 \ 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 ## GLOBALS
for k in save_game.globals.keys(): for k in save_game.globals.keys():
ESCCommand.new("%s %s %s" % var global_value = save_game.globals[k]
[
_set_global.get_command_name(), if global_value is String and global_value.empty():
k, global_value = "''"
save_game.globals[k]
] load_statements.append(
ESCCommand.new("%s %s %s true" %
[
_set_global.get_command_name(),
k,
global_value
]
)
) )
## OBJECTS ## OBJECTS

View File

@@ -226,7 +226,11 @@ func set_game_paused(p_paused: bool):
emit_signal("paused") emit_signal("paused")
else: else:
emit_signal("resumed") 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. # Runs the event "event_name" from the "script" ESC script.