Skip to content

Commit

Permalink
fix: allows for proper reloading of all globals (reserved or otherwis…
Browse files Browse the repository at this point in the history
…e); also now properly saves reserved objects; plus a couple small guards to correct issues while quitting after loading games in certain conditions
  • Loading branch information
BHSDuncan authored and StraToN committed Apr 8, 2022
1 parent 84c84d3 commit 7ff0176
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
15 changes: 11 additions & 4 deletions addons/escoria-core/game/core-scripts/esc/commands/set_global.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `set_global name value`
# `set_global name value [ignore_reserved=false]`
#
# Changes the value of a global.
#
Expand All @@ -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
Expand All @@ -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
14 changes: 12 additions & 2 deletions addons/escoria-core/game/core-scripts/esc/esc_object_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion addons/escoria-core/game/escoria.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7ff0176

Please sign in to comment.