Skip to content

Commit

Permalink
feat: Keep current animations resource (#459)
Browse files Browse the repository at this point in the history
Co-authored-by: Dennis Ploeger <[email protected]>
  • Loading branch information
dploeger and dploeger authored Nov 23, 2021
1 parent 4f07278 commit 7963f03
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,22 @@ func validate(arguments: Array):
func run(command_params: Array) -> int:
(escoria.object_manager.get_object(command_params[0]).node as ESCPlayer)\
.animations = load(command_params[1])
if not escoria.globals_manager.has(
escoria.globals_manager.GLOBAL_ANIMATION_RESOURCES
):
escoria.globals_manager.set_global(
escoria.globals_manager.GLOBAL_ANIMATION_RESOURCES,
{},
true
)
var animations = escoria.globals_manager.get_global(
escoria.globals_manager.GLOBAL_ANIMATION_RESOURCES
)
animations[command_params[0]] = command_params[1]
escoria.globals_manager.set_global(
escoria.globals_manager.GLOBAL_ANIMATION_RESOURCES,
animations,
true
)
return ESCExecution.RC_OK

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func validate(arguments: Array):

# Run the command
func run(command_params: Array) -> int:
escoria.object_manager.get_object(command_params[1]).node.set_state(
escoria.object_manager.get_object(command_params[0]).node.set_state(
"off"
)
return ESCExecution.RC_OK
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ extends Resource
class_name ESCGlobalsManager


const GLOBAL_ANIMATION_RESOURCES = "ANIMATION_RESOURCES"


# Emitted when a global is changed
signal global_changed(global, old_value, new_value)


# A list of reserved globals which can not be overridden
const RESERVED_GLOBALS = [
"ESC_LAST_SCENE",
"BYPASS_LAST_SCENE"
"BYPASS_LAST_SCENE",
"ANIMATION_RESOURCES"
]


Expand Down Expand Up @@ -104,6 +108,4 @@ func set_global_wildcard(pattern: String, value) -> void:
func save_game(p_savegame: ESCSaveGame) -> void:
p_savegame.globals = {}
for g in _globals:
if g in RESERVED_GLOBALS:
continue
p_savegame.globals[g] = _globals[g]
1 change: 1 addition & 0 deletions addons/escoria-core/game/core-scripts/esc_exit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(String, FILE, "*.ogg,*.mp3,*.wav") var switch_sound = ""
func _enter_tree():
is_exit = true
player_orients_on_arrival = false
default_action = "walk"


func _ready():
Expand Down
12 changes: 12 additions & 0 deletions addons/escoria-core/game/core-scripts/esc_room.gd
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ func _ready():
),
true
)
if escoria.globals_manager.has(
escoria.globals_manager.GLOBAL_ANIMATION_RESOURCES
):
var animations = escoria.globals_manager.get_global(
escoria.globals_manager.GLOBAL_ANIMATION_RESOURCES
)

if player.global_id in animations and \
ResourceLoader.exists(animations[player.global_id]):
player.animations = ResourceLoader.load(
animations[player.global_id]
)
escoria.object_manager.get_object("_camera").node.set_target(player)

for n in get_children():
Expand Down
34 changes: 23 additions & 11 deletions addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ func load_game(id: int):

## GLOBALS
for k in save_game.globals.keys():
load_statements.append(
ESCCommand.new("set_global %s \"%s\"\n" \
% [k, save_game.globals[k]])
escoria.globals_manager.set_global(
k,
save_game.globals[k],
true
)

## ROOM
load_statements.append(
ESCCommand.new("change_scene %s true" \
Expand All @@ -197,7 +198,8 @@ func load_game(id: int):

## OBJECTS
for object_global_id in save_game.objects.keys():
if save_game.objects[object_global_id].has("active"):
if escoria.object_manager.has(object_global_id) and \
save_game.objects[object_global_id].has("active"):
load_statements.append(ESCCommand.new("set_active %s %s" \
% [object_global_id,
save_game.objects[object_global_id]["active"]])
Expand Down Expand Up @@ -230,12 +232,22 @@ func load_game(id: int):
)

if object_global_id in ["_music", "_sound", "_speech"]:
load_statements.append(
ESCCommand.new("play_snd %s %s" % [
save_game.objects[object_global_id]["state"],
object_global_id,
])
)
if save_game.objects[object_global_id]["state"] in [
"default",
"off"
]:
load_statements.append(
ESCCommand.new("stop_snd %s" % [
object_global_id,
])
)
else:
load_statements.append(
ESCCommand.new("play_snd %s %s" % [
save_game.objects[object_global_id]["state"],
object_global_id,
])
)

load_statements.append(
ESCCommand.new(
Expand Down
Loading

0 comments on commit 7963f03

Please sign in to comment.