Make ESCLocation is_start_location work (#421)
Introducing BYPASS_LAST_ROOM global to allow changing scene without considering the previous room Fixes godot-escoria/escoria-issues#40
This commit is contained in:
@@ -53,7 +53,8 @@ func run(command_params: Array) -> int:
|
||||
command_params[2]
|
||||
])
|
||||
|
||||
if escoria.main.current_scene:
|
||||
if escoria.main.current_scene \
|
||||
and not escoria.globals_manager.get_global("BYPASS_LAST_SCENE"):
|
||||
escoria.globals_manager.set_global(
|
||||
"ESC_LAST_SCENE",
|
||||
escoria.main.current_scene.global_id,
|
||||
@@ -112,5 +113,13 @@ func run(command_params: Array) -> int:
|
||||
]
|
||||
)
|
||||
return ESCExecution.RC_ERROR
|
||||
|
||||
# If the ESC_LAST_SCENE global was bypassed, reset bypass variable to false
|
||||
if escoria.globals_manager.get_global("BYPASS_LAST_SCENE"):
|
||||
escoria.globals_manager.set_global(
|
||||
"BYPASS_LAST_SCENE",
|
||||
false,
|
||||
true
|
||||
)
|
||||
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
@@ -11,7 +11,8 @@ signal global_changed(global, old_value, new_value)
|
||||
|
||||
# A list of reserved globals which can not be overridden
|
||||
const RESERVED_GLOBALS = [
|
||||
"ESC_LAST_SCENE"
|
||||
"ESC_LAST_SCENE",
|
||||
"BYPASS_LAST_SCENE"
|
||||
]
|
||||
|
||||
|
||||
@@ -22,6 +23,7 @@ export(Dictionary) var _globals = {}
|
||||
|
||||
func _init():
|
||||
set_global("ESC_LAST_SCENE", "", true)
|
||||
set_global("BYPASS_LAST_SCENE", false, true)
|
||||
|
||||
|
||||
# Check if a global was registered
|
||||
|
||||
@@ -83,8 +83,9 @@ func get_object(global_id: String) -> ESCObject:
|
||||
return objects[global_id]
|
||||
else:
|
||||
escoria.logger.report_warnings(
|
||||
"Invalid object retrieved",
|
||||
"esc_object_manager.gd:get_object()",
|
||||
[
|
||||
"Invalid object retrieved",
|
||||
"Object with global id %s not found" % global_id
|
||||
]
|
||||
)
|
||||
@@ -119,3 +120,17 @@ func save_game(p_savegame: ESCSaveGame) -> void:
|
||||
continue
|
||||
p_savegame.objects[obj_global_id] = \
|
||||
objects[obj_global_id].get_save_data()
|
||||
|
||||
|
||||
func get_start_location() -> ESCLocation:
|
||||
for object in objects.values():
|
||||
if object.node is ESCLocation and object.node.is_start_location:
|
||||
return object
|
||||
escoria.logger.report_warnings(
|
||||
"esc_object_manager.gd:get_start_location()",
|
||||
[
|
||||
"Room has no ESCLocation node with 'is_start_location' enabled.",
|
||||
"Player will be set at position (0,0) by default."
|
||||
]
|
||||
)
|
||||
return null
|
||||
|
||||
@@ -98,6 +98,13 @@ func _ready():
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
if (escoria.globals_manager.get_global("ESC_LAST_SCENE") == null \
|
||||
or escoria.globals_manager.get_global("ESC_LAST_SCENE").empty()) \
|
||||
and player != null \
|
||||
and escoria.object_manager.get_start_location() != null:
|
||||
player.teleport(escoria.object_manager.get_start_location().node)
|
||||
|
||||
|
||||
escoria.main.scene_transition.transition()
|
||||
yield(escoria.main.scene_transition, "transition_done")
|
||||
|
||||
|
||||
@@ -48,12 +48,14 @@ func _ready():
|
||||
|
||||
# Switch to the selected room
|
||||
func _on_button_pressed():
|
||||
escoria.globals_manager.set_global("BYPASS_LAST_SCENE", true, true)
|
||||
var script = escoria.esc_compiler.compile([
|
||||
":debug",
|
||||
"change_scene %s" % _options_paths[_selected_id]
|
||||
])
|
||||
escoria.event_manager.interrupt_running_event()
|
||||
escoria.event_manager.queue_event(script.events['debug'])
|
||||
|
||||
|
||||
|
||||
# A room was selected, store the selection
|
||||
|
||||
Reference in New Issue
Block a user