summaryrefslogtreecommitdiff
path: root/addons/escoria-core/game/escoria.gd
diff options
context:
space:
mode:
Diffstat (limited to 'addons/escoria-core/game/escoria.gd')
-rw-r--r--addons/escoria-core/game/escoria.gd39
1 files changed, 30 insertions, 9 deletions
diff --git a/addons/escoria-core/game/escoria.gd b/addons/escoria-core/game/escoria.gd
index 9da2e9f..1fb5e91 100644
--- a/addons/escoria-core/game/escoria.gd
+++ b/addons/escoria-core/game/escoria.gd
@@ -1,6 +1,6 @@
@tool
-extends Node
class_name Escoria
+extends Node
## The main Escoria script.
@@ -173,7 +173,6 @@ func _input(event: InputEvent):
if event.is_action_pressed("ui_cancel"):
request_pause_menu.emit()
- pass
## Runs the event "event_name" from the "script" ESC script.[br]
@@ -188,19 +187,20 @@ func _input(event: InputEvent):
## [br]
## #### Returns[br]
## [br]
-## Returns Nothing. Waits for the event to finish before returning. (`Variant`)
-func run_event_from_script(script: ESCScript, event_name: String, from_statement_id: int = 0):
+## Returns ESCExecution. Waits for the event to finish before returning. (`Variant`)
+func run_event_from_script(script: ESCScript, event_name: String, _from_statement_id: int = 0):
if script == null:
escoria.logger.error(
self,
"Requested event %s on unloaded script %s." % [event_name, script] +
"Please load the ESC script using esc_compiler.load_esc_file()."
)
+ return ESCExecution.RC_WONT_QUEUE
if not _event_exists_in_script(script, event_name):
- return
+ return ESCExecution.RC_WONT_QUEUE
- escoria.event_manager.queue_event(script.events[event_name])
+ escoria.event_manager.queue_event(script.get_event_with_target(event_name))
var rc = await escoria.event_manager.event_finished
while rc[1] != event_name:
rc = await escoria.event_manager.event_finished
@@ -210,10 +210,12 @@ func run_event_from_script(script: ESCScript, event_name: String, from_statement
self,
"Start event of the start script returned unsuccessful: %d." % rc[0]
)
- return
+
+ return rc[0]
## Checks for the existence of both mandatory and optional events within a specified script.[br]
+## We ignore any target for the event, at least for now.[br]
## [br]
## #### Parameters[br]
## [br]
@@ -226,7 +228,7 @@ func run_event_from_script(script: ESCScript, event_name: String, from_statement
## [br]
## Returns True iff event_name exists within script. Method will terminate execution of the program if the specified event is required and doesn't exist. (`bool`)
func _event_exists_in_script(script: ESCScript, event_name: String) -> bool:
- if script.events.has(event_name):
+ if script.has_event_with_target(event_name):
return true
if event_name in escoria.event_manager.REQUIRED_EVENTS:
@@ -267,7 +269,9 @@ func _event_exists_in_script(script: ESCScript, event_name: String) -> bool:
func new_game():
escoria.event_manager.interrupt() # interrupt first because we're going to reset the interpreter
escoria.game_scene.escoria_show_ui()
+ _reset_new_game_runtime_state()
escoria.globals_manager.clear()
+ escoria.object_manager.reset_game_state()
escoria.interpreter_factory.reset_interpreter()
escoria.main.clear_previous_scene()
escoria.creating_new_game = true
@@ -276,7 +280,24 @@ func new_game():
true,
true
)
- run_event_from_script(escoria.start_script, escoria.event_manager.EVENT_NEW_GAME)
+
+ var rc = await run_event_from_script(escoria.start_script, escoria.event_manager.EVENT_NEW_GAME)
+ if rc == ESCExecution.RC_OK:
+ escoria.new_game_started.emit()
+
+
+func _reset_new_game_runtime_state() -> void:
+ escoria.action_manager.clear_current_action()
+ escoria.action_manager.clear_current_tool()
+ escoria.inputs_manager.hover_stack.clear()
+ escoria.inputs_manager.hotspot_focused = ""
+ escoria.inputs_manager.input_mode = escoria.inputs_manager.INPUT_ALL
+
+ if escoria.game_scene and escoria.game_scene.is_inside_tree():
+ escoria.game_scene.clear_tooltip()
+ escoria.game_scene.close_inventory()
+ escoria.game_scene.hide_main_menu()
+ escoria.game_scene.unpause_game()
## Function called to quit the game.[br]