Enhancement: load game scene once to allow run scene directly (#406)
Co-authored-by: StraToN <StraToN@users.noreply.github.com>
This commit is contained in:
@@ -74,13 +74,9 @@ func run(command_params: Array) -> int:
|
||||
escoria.main_menu_instance.hide()
|
||||
|
||||
var res_room = escoria.resource_cache.get_resource(command_params[0])
|
||||
var res_game = escoria.resource_cache.get_resource(
|
||||
ProjectSettings.get_setting("escoria/ui/game_scene")
|
||||
)
|
||||
|
||||
# Load game scene
|
||||
var game_scene = res_game.instance()
|
||||
if not game_scene:
|
||||
if not escoria.game_scene:
|
||||
escoria.logger.report_errors(
|
||||
"ChangeSceneCommand.run: Failed loading game scene",
|
||||
[
|
||||
@@ -92,39 +88,13 @@ func run(command_params: Array) -> int:
|
||||
# Load room scene
|
||||
var room_scene = res_room.instance()
|
||||
if room_scene:
|
||||
room_scene.add_child(game_scene)
|
||||
room_scene.move_child(game_scene, 0)
|
||||
room_scene.add_child(escoria.game_scene)
|
||||
room_scene.move_child(escoria.game_scene, 0)
|
||||
room_scene.game = escoria.game_scene
|
||||
escoria.main.set_scene(room_scene)
|
||||
|
||||
if "esc_script" in room_scene and room_scene.esc_script \
|
||||
and command_params[2]:
|
||||
|
||||
var script = escoria.esc_compiler.load_esc_file(
|
||||
room_scene.esc_script
|
||||
)
|
||||
|
||||
if script.events.has("setup"):
|
||||
escoria.event_manager.queue_event(script.events["setup"])
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != "setup":
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
if !command_params[1]:
|
||||
escoria.main.scene_transition.transition()
|
||||
yield(escoria.main.scene_transition, "transition_done")
|
||||
|
||||
if script.events.has("ready"):
|
||||
escoria.event_manager.queue_event(script.events["ready"])
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != "ready":
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
else:
|
||||
if !command_params[1]:
|
||||
if not "esc_script" in room_scene or not room_scene.esc_script \
|
||||
or not command_params[2] and !command_params[1]:
|
||||
escoria.main.scene_transition.transition()
|
||||
yield(escoria.main.scene_transition, "transition_done")
|
||||
|
||||
|
||||
@@ -99,6 +99,11 @@ func unregister_object(object: ESCObject) -> void:
|
||||
if not escoria.inventory_manager.inventory_has(object.global_id) \
|
||||
and not object.global_id in RESERVED_OBJECTS:
|
||||
objects.erase(object.global_id)
|
||||
else:
|
||||
if not object.global_id in RESERVED_OBJECTS:
|
||||
# Re-instance the node if it is an item present in inventory.
|
||||
objects[object.global_id].node = objects[object.global_id].node \
|
||||
.duplicate()
|
||||
|
||||
|
||||
# Insert data to save into savegame.
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
# This script contains functions called by gamedev's game.gd.
|
||||
# These functions convert input actions into game actions. For example:
|
||||
# "click on background" -> player walks to position
|
||||
# "click on item" -> player walks to item then performs the action defined
|
||||
# by current verb
|
||||
# This class performs certain tasks as a reaction to certain inputs, such as
|
||||
# player walking, player walking towards an object, etc.
|
||||
class_name ESCController
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@ var player
|
||||
var game
|
||||
|
||||
|
||||
# Compiled ESCScript
|
||||
var compiled_script: ESCScript
|
||||
|
||||
|
||||
# Start the random number generator when the camera limits should be displayed
|
||||
func _enter_tree():
|
||||
if editor_debug_mode == EditorRoomDebugDisplay.CAMERA_LIMITS:
|
||||
@@ -56,6 +60,13 @@ func _ready():
|
||||
return
|
||||
|
||||
game = $game
|
||||
if game == null:
|
||||
game = escoria.game_scene
|
||||
add_child(game)
|
||||
move_child(game, 0)
|
||||
|
||||
if escoria.main.current_scene == null:
|
||||
escoria.main.set_scene(self)
|
||||
|
||||
if player_scene:
|
||||
player = player_scene.instance()
|
||||
@@ -78,7 +89,24 @@ func _ready():
|
||||
|
||||
if global_id.empty():
|
||||
global_id = name
|
||||
|
||||
|
||||
if esc_script:
|
||||
run_script_event("setup")
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != "setup":
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
escoria.main.scene_transition.transition()
|
||||
yield(escoria.main.scene_transition, "transition_done")
|
||||
|
||||
run_script_event("ready")
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != "ready":
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
# Draw the camera limits visualization if enabled
|
||||
func _draw():
|
||||
@@ -123,3 +151,18 @@ func set_camera_limits(p_camera_limits: Array) -> void:
|
||||
func set_editor_debug_mode(p_editor_debug_mode: int) -> void:
|
||||
editor_debug_mode = p_editor_debug_mode
|
||||
update()
|
||||
|
||||
|
||||
# Runs the script event from the script attached, if any
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - event_name: the name of the event to run
|
||||
func run_script_event(event_name: String):
|
||||
if !esc_script:
|
||||
return
|
||||
if compiled_script == null:
|
||||
compiled_script = escoria.esc_compiler.load_esc_file(esc_script)
|
||||
|
||||
if compiled_script.events.has(event_name):
|
||||
escoria.event_manager.queue_event(compiled_script.events[event_name])
|
||||
|
||||
@@ -84,6 +84,9 @@ var save_manager: ESCSaveManager
|
||||
# into an actual action
|
||||
var controller: ESCController
|
||||
|
||||
# The game scene loaded
|
||||
var game_scene: ESCGame
|
||||
|
||||
|
||||
# Initialize various objects
|
||||
func _init():
|
||||
@@ -102,6 +105,10 @@ func _init():
|
||||
self.save_manager = ESCSaveManager.new()
|
||||
self.inputs_manager = ESCInputsManager.new()
|
||||
self.controller = ESCController.new()
|
||||
self.game_scene = resource_cache.get_resource(
|
||||
ProjectSettings.get_setting("escoria/ui/game_scene")
|
||||
).instance()
|
||||
|
||||
|
||||
|
||||
# Load settings
|
||||
@@ -110,7 +117,9 @@ func _ready():
|
||||
settings = ESCSaveSettings.new()
|
||||
settings = save_manager.load_settings()
|
||||
escoria._on_settings_loaded(escoria.settings)
|
||||
|
||||
self.main_menu_instance = resource_cache.get_resource(
|
||||
ProjectSettings.get_setting("escoria/ui/main_menu_scene")
|
||||
).instance()
|
||||
|
||||
# Called by Main menu "start new game"
|
||||
func new_game():
|
||||
|
||||
@@ -58,6 +58,8 @@ func clear_scene() -> void:
|
||||
|
||||
escoria.action_manager.clear_current_action()
|
||||
escoria.action_manager.clear_current_tool()
|
||||
|
||||
current_scene.remove_child(escoria.game_scene)
|
||||
|
||||
remove_child(current_scene)
|
||||
current_scene.free()
|
||||
|
||||
@@ -5,10 +5,10 @@ extends Node
|
||||
|
||||
# Start the main menu
|
||||
func _ready():
|
||||
var main_menu_path = ProjectSettings.get_setting(
|
||||
"escoria/ui/main_menu_scene"
|
||||
)
|
||||
var main_menu_scene = load(main_menu_path).instance()
|
||||
escoria.call_deferred("add_child", main_menu_scene)
|
||||
escoria.main_menu_instance = main_menu_scene
|
||||
if escoria.main_menu_instance == null:
|
||||
escoria.main_menu_instance = escoria.resource_cache.get_resource(
|
||||
ProjectSettings.get_setting("escoria/ui/main_menu_scene")
|
||||
).instance()
|
||||
escoria.call_deferred("add_child", escoria.main_menu_instance)
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Implement methods to react to inputs.
|
||||
- _on_event_done(event_name: String)
|
||||
"""
|
||||
|
||||
func _ready():
|
||||
func _enter_tree():
|
||||
ProjectSettings.set_setting("escoria/ui/tooltip_follows_mouse", true)
|
||||
escoria.action_manager.connect(
|
||||
"action_finished",
|
||||
|
||||
@@ -82,6 +82,14 @@ var game
|
||||
|
||||
The game scene instance
|
||||
|
||||
### compiled\_script
|
||||
|
||||
```gdscript
|
||||
var compiled_script: ESCScript
|
||||
```
|
||||
|
||||
Compiled ESCScript
|
||||
|
||||
## Method Descriptions
|
||||
|
||||
### set\_camera\_limits
|
||||
@@ -106,4 +114,16 @@ Set the editor debug mode
|
||||
|
||||
#### Parameters
|
||||
|
||||
- p_editor_debug_mode: The debug mode to set for the room
|
||||
- p_editor_debug_mode: The debug mode to set for the room
|
||||
|
||||
### run\_script\_event
|
||||
|
||||
```gdscript
|
||||
func run_script_event(event_name: String)
|
||||
```
|
||||
|
||||
Runs the script event from the script attached, if any
|
||||
|
||||
#### Parameters
|
||||
|
||||
- event_name: the name of the event to run
|
||||
@@ -202,6 +202,14 @@ var controller: ESCController
|
||||
The controller in charge of converting an action verb on a game object
|
||||
into an actual action
|
||||
|
||||
### game\_scene
|
||||
|
||||
```gdscript
|
||||
var game_scene: ESCGame
|
||||
```
|
||||
|
||||
The game scene loaded
|
||||
|
||||
## Method Descriptions
|
||||
|
||||
### new\_game
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
[ext_resource path="res://game/characters/mark/mark.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=5]
|
||||
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=6]
|
||||
[ext_resource path="res://game/rooms/room04/assets/background.png" type="Texture" id=7]
|
||||
[ext_resource path="res://game/rooms/room04/assets/depth_reduced.png" type="Texture" id=8]
|
||||
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=9]
|
||||
[ext_resource path="res://game/rooms/room04/assets/background_reduced.png" type="Texture" id=10]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=1]
|
||||
vertices = PoolVector2Array( 371.757, 688.152, 542.371, 788.052, 2.46706, 794.786, 11.4468, 698.255, 189.918, 682.54, 1564.36, 574.459, 1578.66, 529.011, 1635.23, 551.638, 1624.42, 800.399, 1536.87, 579.274, 1012.68, 786.929, 1197.79, 675.666, 908.294, 488.354, 996.968, 451.313, 600.739, 456.925, 673.699, 490.599, 127.06, 573.661, 23.7938, 614.07, 42.8757, 527.64, 125.717, 528.797 )
|
||||
@@ -27,16 +27,12 @@ editor_debug_mode = 1
|
||||
margin_right = 1666.0
|
||||
margin_bottom = 574.0
|
||||
mouse_filter = 2
|
||||
texture = ExtResource( 10 )
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="background"]
|
||||
scale = Vector2( 0.692794, 0.692794 )
|
||||
texture = ExtResource( 7 )
|
||||
centered = false
|
||||
|
||||
[node name="room_label" type="Label" parent="background"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 14.0
|
||||
|
||||
@@ -647,11 +647,9 @@ debug/terminate_on_warnings=false
|
||||
debug/terminate_on_errors=true
|
||||
debug/development_lang="en"
|
||||
ui/tooltip_follows_mouse=true
|
||||
ui/dialogs_folder="res://game/ui/commons/dialogs"
|
||||
ui/default_dialog_scene="res://game/ui/commons/dialogs/dialog_label.tscn"
|
||||
ui/main_menu_scene="res://game/ui/commons/main_menu/main_menu.tscn"
|
||||
ui/pause_menu_scene="res://game/ui/commons/pause_menu/pause_menu.tscn"
|
||||
internals/save_data=""
|
||||
main/text_lang="fr_FR"
|
||||
main/voice_lang="fr_FR"
|
||||
sound/music_volume=1
|
||||
@@ -672,8 +670,9 @@ ui/game_scene="res://addons/escoria-ui-simplemouse/game.tscn"
|
||||
ui/dialogs_chooser="res://game/ui/commons/dialogs/text_dialog_choice.tscn"
|
||||
sound/speech_folder="res://game/speech"
|
||||
sound/speech_extension="ogg"
|
||||
ui/transition_paths=[ "res://addons/escoria-core/game/scenes/transitions/shaders/" ]
|
||||
ui/default_transition="curtain"
|
||||
ui/transition_paths=[ "res://addons/escoria-core/game/scenes/transitions/shaders/" ]
|
||||
internals/save_data=""
|
||||
|
||||
[input]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user