Finished ESC camera commands reimplementation.
Some cleaning done, and all logging commands put in escoria.logger script.
This commit is contained in:
@@ -88,7 +88,7 @@ func _process(time):
|
||||
else:
|
||||
bypass_missing_animation = true
|
||||
current_animation = animation_to_play
|
||||
escoria.report_warnings("movable.gd:_process()",
|
||||
escoria.logger.report_warnings("movable.gd:_process()",
|
||||
["Character " + parent.global_id + " has no animation " + animation_to_play,
|
||||
"Bypassing missing animation and proceed movement."], true)
|
||||
|
||||
@@ -106,16 +106,18 @@ func teleport(target, angle : Object = null) -> void:
|
||||
target can be Vector2 or Object
|
||||
"""
|
||||
if typeof(target) == TYPE_VECTOR2:
|
||||
printt("Item teleported at position", target, "with angle", angle)
|
||||
escoria.logger.info("Object " + target + " teleported at position" +
|
||||
str(target) + "with angle", [angle])
|
||||
parent.position = target
|
||||
elif typeof(target) == TYPE_OBJECT:
|
||||
if target.get("interact_positions") != null:
|
||||
parent.position = target.interact_positions.default #.global_position
|
||||
else:
|
||||
parent.position = target.position
|
||||
printt("Item teleported at", target.name, "position", parent.position, "with angle", angle)
|
||||
escoria.logger.info("Object " + target.name + " teleported at position "
|
||||
+ str(parent.position) + " with angle ", str(angle))
|
||||
else:
|
||||
escoria.report_errors("escitem.gd:teleport()", ["Target to teleport to is null or unusable (" + target + ")"])
|
||||
escoria.logger.report_errors("escitem.gd:teleport()", ["Target to teleport to is null or unusable (" + target + ")"])
|
||||
|
||||
# PUBLIC FUNCTION
|
||||
func walk_to(pos : Vector2, p_walk_context = null):
|
||||
@@ -208,7 +210,7 @@ func walk_stop(pos):
|
||||
# walk_context = null
|
||||
|
||||
yield(parent.animation_sprite, "animation_finished")
|
||||
printt(parent.global_id + " arrived at ", walk_context)
|
||||
escoria.logger.info(parent.global_id + " arrived at " + str(walk_context))
|
||||
parent.emit_signal("arrived", walk_context)
|
||||
|
||||
|
||||
@@ -271,7 +273,7 @@ func _get_dir_deg(deg : int, animations) -> int:
|
||||
|
||||
# It's an error to have the animations misconfigured
|
||||
if dir == -1:
|
||||
escoria.report_errors("escitem.gd:_get_dir_deg()", ["No direction found for " + str(deg)])
|
||||
escoria.logger.report_errors("escitem.gd:_get_dir_deg()", ["No direction found for " + str(deg)])
|
||||
|
||||
return dir
|
||||
|
||||
@@ -315,7 +317,7 @@ Whatever the implementation, this should be activated using "parameter "immediat
|
||||
"""
|
||||
func set_angle(deg : int, immediate = true):
|
||||
if deg < 0 or deg > 360:
|
||||
escoria.report_errors("movable.gd:set_angle()", ["Invalid degree to turn to " + str(deg)])
|
||||
escoria.logger.report_errors("movable.gd:set_angle()", ["Invalid degree to turn to " + str(deg)])
|
||||
moved = true
|
||||
last_deg = deg
|
||||
last_dir = _get_dir_deg(deg, parent.animations)
|
||||
|
||||
@@ -49,7 +49,7 @@ var commands = {
|
||||
"inc_global": { "min_args": 2, "types": [TYPE_STRING, TYPE_INT] },
|
||||
"inventory_add": { "min_args": 1 },
|
||||
"inventory_remove": { "min_args": 1 },
|
||||
"inventory_open": { "min_args": 1, "types": [TYPE_BOOL] },
|
||||
"inventory_display": { "min_args": 1, "types": [TYPE_BOOL] },
|
||||
"jump": { "min_args": 1 },
|
||||
"play_snd": { "min_args": 2, "types": [TYPE_STRING, TYPE_STRING, TYPE_BOOL] },
|
||||
"queue_animation": { "min_args": 2, "types": [TYPE_STRING, TYPE_STRING, TYPE_BOOL] },
|
||||
@@ -76,6 +76,7 @@ var commands = {
|
||||
"wait": true,
|
||||
"walk": { "min_args": 2 },
|
||||
"walk_to_pos": { "min_args": 3},
|
||||
"walk_to_pos_block": { "min_args": 3},
|
||||
"walk_block": { "min_args": 2 },
|
||||
|
||||
"%": { "alias": "label", "min_args": 1},
|
||||
@@ -96,7 +97,7 @@ var debug_commands = {
|
||||
func load_esc_file(esc_file_path : String) -> Dictionary:
|
||||
var f = File.new()
|
||||
if !f.file_exists(esc_file_path):
|
||||
escoria.report_errors("esc_compiler.gd:load_esc_file()", ["File " + esc_file_path + " not found."])
|
||||
escoria.logger.report_errors("esc_compiler.gd:load_esc_file()", ["File " + esc_file_path + " not found."])
|
||||
return {}
|
||||
return compile_script(esc_file_path)
|
||||
|
||||
@@ -114,7 +115,7 @@ func compile_script(p_path : String) -> Dictionary:
|
||||
var errors = []
|
||||
ev_table = compile(p_path, errors)
|
||||
if errors.size() > 0:
|
||||
escoria.call_deferred("report_errors", p_path, errors)
|
||||
escoria.logger.call_deferred("report_errors", p_path, errors)
|
||||
return ev_table
|
||||
|
||||
func check_command(commands_list : Dictionary, cmd : esctypes.ESCCommand, state : esctypes.ESCState, errors : Array):
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
extends Node
|
||||
|
||||
# This is the script that runs in background, checking for events in the events stack
|
||||
# and executing them.
|
||||
# Events are managed using 2 structures:
|
||||
# - event_queue: a queue for scheduled events. On each iteration, every event in the queue is updated
|
||||
# according time delta. If an event time occurs, it is run (see check_event_queue()).
|
||||
# - levels_stack: stack of events to be run immediately (from an event in ESC file usually)
|
||||
"""
|
||||
This is the script that runs in background, checking for events in the events
|
||||
stack and executing them.
|
||||
Events are managed using 2 structures:
|
||||
- event_queue: a queue for scheduled events. On each iteration, every event
|
||||
in the queue is updated according time delta. If an event time occurs, it is run
|
||||
(see check_event_queue()).
|
||||
- levels_stack: stack of events to be run immediately (from an event in ESC file
|
||||
usually)
|
||||
"""
|
||||
|
||||
signal global_changed(global_name)
|
||||
signal inventory_changed
|
||||
@@ -18,7 +22,6 @@ signal action_changed
|
||||
signal paused(p_paused)
|
||||
|
||||
onready var resource_cache = load("res://addons/escoria-core/game/core-scripts/resource_queue.gd").new()
|
||||
#save_data = load(ProjectSettings.get_setting("escoria/internals/save_data")).new()
|
||||
onready var save_data = load("res://addons/escoria-core/game/core-scripts/save_data/save_data.gd").new()
|
||||
|
||||
# Cached scenes
|
||||
@@ -80,14 +83,14 @@ func _ready():
|
||||
randomize()
|
||||
save_data.load_settings([self, "settings_loaded"])
|
||||
|
||||
printt("calling res cache start")
|
||||
printt("Calling resource cache start")
|
||||
resource_cache.start()
|
||||
|
||||
if !ProjectSettings.get_setting("escoria/platform/skip_cache"):
|
||||
scenes_cache_list.push_back(ProjectSettings.get_setting("escoria/main/curtain"))
|
||||
scenes_cache_list.push_back(ProjectSettings.get_setting("escoria/main/hud"))
|
||||
|
||||
printt("cache list ", scenes_cache_list)
|
||||
printt("Cache list ", [scenes_cache_list])
|
||||
for s in scenes_cache_list:
|
||||
if s != null:
|
||||
resource_cache.queue_resource(s, false, true)
|
||||
@@ -265,7 +268,7 @@ func get_global(name):
|
||||
#
|
||||
func set_global(name, val, force_change_reserved : bool = false):
|
||||
if name in reserved_globals and !force_change_reserved:
|
||||
escoria.report_warnings("esc_runner.gd:set_global()",
|
||||
escoria.logger.report_warnings("esc_runner.gd:set_global()",
|
||||
["Global " + name + " is reserved. Value not modified."])
|
||||
return
|
||||
globals[name] = val
|
||||
@@ -304,12 +307,28 @@ func is_global_less_than(name, val):
|
||||
if global and val and int(global) < int(val):
|
||||
return true
|
||||
|
||||
func jump(p_label):
|
||||
while levels_stack.size() > 0:
|
||||
var top = levels_stack[levels_stack.size()-1]
|
||||
printt("top labels: ", top.labels, p_label)
|
||||
if p_label in top.labels:
|
||||
top.ip = top.labels[p_label]
|
||||
return
|
||||
else:
|
||||
if top.break_stop || levels_stack.size() == 1:
|
||||
escoria.logger.report_errors("esc_runner.gd:jump()",
|
||||
["ESC: Jump to inexisting label: " + p_label])
|
||||
levels_stack.remove(levels_stack.size()-1)
|
||||
break
|
||||
else:
|
||||
levels_stack.remove(levels_stack.size()-1)
|
||||
|
||||
func check_autosave():
|
||||
pass
|
||||
|
||||
func set_current_action(action : String):
|
||||
if ! action is String:
|
||||
escoria.report_errors("esc_runner.gd",
|
||||
escoria.logger.report_errors("esc_runner.gd",
|
||||
["Trying to set_current_action: " + str(typeof(action))])
|
||||
|
||||
if action != current_action:
|
||||
@@ -325,7 +344,7 @@ func clear_current_tool():
|
||||
current_tool = null
|
||||
|
||||
func change_scene(params, context, run_events=true):
|
||||
printt("change scene to ", params[0], " with run_events ", run_events)
|
||||
escoria.logger.info("Change scene to " + params[0] + " with run_events " + str(run_events))
|
||||
# check_cache()
|
||||
# main.clear_scene()
|
||||
# camera = null
|
||||
@@ -341,10 +360,10 @@ func change_scene(params, context, run_events=true):
|
||||
var res_room = resource_cache.get_resource(params[0])
|
||||
var res_game = resource_cache.get_resource(ProjectSettings.get_setting("escoria/ui/game_scene"))
|
||||
if !res_room:
|
||||
escoria.report_errors("esc_runner.gd:change_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:change_scene()",
|
||||
["Resource not found: " + params[0]])
|
||||
if !res_game:
|
||||
escoria.report_errors("esc_runner.gd:change_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:change_scene()",
|
||||
["Resource not found: " + ProjectSettings.get_setting("escoria/ui/game_scene")])
|
||||
|
||||
resource_cache.clear()
|
||||
@@ -352,7 +371,7 @@ func change_scene(params, context, run_events=true):
|
||||
# Load game scene
|
||||
var game_scene = res_game.instance()
|
||||
if !game_scene:
|
||||
escoria.report_errors("esc_runner.gd:change_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:change_scene()",
|
||||
["Failed loading scene " + ProjectSettings.get_setting("escoria/ui/game_scene")])
|
||||
|
||||
# Load room scene
|
||||
@@ -380,7 +399,7 @@ func change_scene(params, context, run_events=true):
|
||||
scenes_cache_list.push_back(params[0])
|
||||
scenes_cache[room_scene.global_id] = params[0]
|
||||
else:
|
||||
escoria.report_errors("esc_runner.gd:change_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:change_scene()",
|
||||
["Failed loading scene " + params[0]])
|
||||
|
||||
if context != null:
|
||||
@@ -411,10 +430,10 @@ func superpose_scene(params, context, run_events=true):
|
||||
var res_room = resource_cache.get_resource(params[0])
|
||||
var res_game = resource_cache.get_resource(ProjectSettings.get_setting("escoria/ui/game_scene"))
|
||||
if !res_room:
|
||||
escoria.report_errors("esc_runner.gd:superpose_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:superpose_scene()",
|
||||
["Resource not found: " + params[0]])
|
||||
if !res_game:
|
||||
escoria.report_errors("esc_runner.gd:superpose_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:superpose_scene()",
|
||||
["Resource not found: " + ProjectSettings.get_setting("escoria/ui/game_scene")])
|
||||
|
||||
resource_cache.clear()
|
||||
@@ -422,14 +441,21 @@ func superpose_scene(params, context, run_events=true):
|
||||
# Load game scene
|
||||
var game_scene = res_game.instance()
|
||||
if !game_scene:
|
||||
escoria.report_errors("esc_runner.gd:superpose_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:superpose_scene()",
|
||||
["Failed loading scene " + ProjectSettings.get_setting("escoria/ui/game_scene")])
|
||||
|
||||
# Load room scene
|
||||
var room_scene = res_room.instance()
|
||||
if room_scene:
|
||||
get_node("/root").add_child(room_scene)
|
||||
|
||||
|
||||
var target = context.get("set_position")
|
||||
if target:
|
||||
if target is Vector2:
|
||||
room_scene.set_position(target)
|
||||
if target is String:
|
||||
var obj = get_object(target)
|
||||
room_scene.set_position(obj.get_global_position())
|
||||
|
||||
escoria.inputs_manager.hotspot_focused = false
|
||||
if !scenes_cache_list.has(params[0]):
|
||||
@@ -439,7 +465,7 @@ func superpose_scene(params, context, run_events=true):
|
||||
else:
|
||||
scenes_cache[room_scene.name] = params[0]
|
||||
else:
|
||||
escoria.report_errors("esc_runner.gd:superpose_scene()",
|
||||
escoria.logger.report_errors("esc_runner.gd:superpose_scene()",
|
||||
["Failed loading scene " + params[0]])
|
||||
|
||||
if context != null:
|
||||
@@ -448,13 +474,11 @@ func superpose_scene(params, context, run_events=true):
|
||||
# Re-apply actives
|
||||
for active in actives:
|
||||
set_active(active, actives[active])
|
||||
|
||||
|
||||
# cam_target = null
|
||||
# autosave_pending = true
|
||||
|
||||
|
||||
|
||||
|
||||
func run_game(actions : Dictionary):
|
||||
set_process(true)
|
||||
# `load` and `ready` are exclusive because you probably don't want to
|
||||
@@ -487,11 +511,11 @@ func clear():
|
||||
|
||||
func register_object(name : String, val : Object, force : bool = false):
|
||||
if !name:
|
||||
escoria.report_errors("esc_runner.gd:register_object()",
|
||||
escoria.logger.report_errors("esc_runner.gd:register_object()",
|
||||
["global_id not given for " + val.get_class() + " " + val.name])
|
||||
|
||||
if name in objects and not force:
|
||||
escoria.report_errors("esc_runner.gd:register_object()",
|
||||
escoria.logger.report_errors("esc_runner.gd:register_object()",
|
||||
["Trying to register already registered object " + name + ": " \
|
||||
+ val.get_class() + " (" + val.name + ")"])
|
||||
|
||||
@@ -528,7 +552,7 @@ func get_object(name):
|
||||
# p_params Array
|
||||
# - 0 Object Target object
|
||||
func activate(p_action : String, p_param : Array):
|
||||
printt("Action", p_action, "with params", p_param)
|
||||
escoria.logger.info("Action " + p_action + " with params ", [p_param])
|
||||
# if p_param[0].global_id:
|
||||
# printt("("+p_param[0].global_id+")")
|
||||
var what = p_param[0]
|
||||
@@ -539,8 +563,8 @@ func activate(p_action : String, p_param : Array):
|
||||
if what is ESCItem and what.use_from_inventory_only:
|
||||
if !inventory_has(what.global_id):
|
||||
# TODO Either use fallback here, or run pickup action before use
|
||||
escoria.report_warnings("esc_runner.gd:activate()", ["Trying to "
|
||||
+ p_action + " on object " + what.global_id
|
||||
escoria.logger.report_warnings("esc_runner.gd:activate()",
|
||||
["Trying to " + p_action + " on object " + what.global_id
|
||||
+ " but item must be in inventory."])
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
else:
|
||||
@@ -570,7 +594,7 @@ func activate(p_action : String, p_param : Array):
|
||||
if combine_with.get("combine_is_one_way") != null \
|
||||
and combine_with.combine_is_one_way:
|
||||
errors.append("Reason: " + combine_with.global_id + "'s item interaction is one-way.")
|
||||
escoria.report_warnings("esc_runner.gd:activate()", errors)
|
||||
escoria.logger.report_warnings("esc_runner.gd:activate()", errors)
|
||||
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
else:
|
||||
@@ -588,13 +612,13 @@ func activate(p_action : String, p_param : Array):
|
||||
if p_action in objects_events_table[what.global_id]:
|
||||
run_event(objects_events_table[what.global_id][p_action])
|
||||
else:
|
||||
escoria.report_warnings("esc_runner.gd:activate()",
|
||||
escoria.logger.report_warnings("esc_runner.gd:activate()",
|
||||
["Action '" + p_action + "' requested on object '" \
|
||||
+ what.global_id + "' but action doesn't exist in attached ESC file.",
|
||||
"TODO: manage fallbacks."])
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
else:
|
||||
escoria.report_warnings("esc_runner.gd:activate()",
|
||||
escoria.logger.report_warnings("esc_runner.gd:activate()",
|
||||
["Action '" + p_action + "' requested on object '" + what.global_id \
|
||||
+ "' but object does not exist in objects_events_table.", \
|
||||
"Does object " + what.global_id + " have an attached ESC file?"])
|
||||
@@ -662,7 +686,7 @@ func set_state(global_id : String, p_params : Array):
|
||||
var animation = actual_animator.get_animation(p_params[0])
|
||||
var animation_length = animation.length
|
||||
animation_node.seek(animation_length)
|
||||
print_debug("Item " + obj.global_id + " changed state to: " + p_params[0])
|
||||
escoria.logger.info("Item " + obj.global_id + " changed state to: " + p_params[0])
|
||||
|
||||
"""
|
||||
When object is active, it is VISIBLE.
|
||||
@@ -698,7 +722,7 @@ func object_exit_scene(name : String):
|
||||
if inventory_has(name):
|
||||
objects[name] = objects[name].duplicate()
|
||||
else:
|
||||
printt("Object " + name + " removed from scene.")
|
||||
escoria.logger.info("Object " + name + " removed from scene.")
|
||||
objects.erase(name)
|
||||
|
||||
#func jump(p_label):
|
||||
@@ -710,7 +734,7 @@ func object_exit_scene(name : String):
|
||||
# return
|
||||
# else:
|
||||
# if top.break_stop || stack.size() == 1:
|
||||
# report_errors("", ["Label not found: "+p_label+", can't jump"])
|
||||
# escoria.logger.report_errors("", ["Label not found: "+p_label+", can't jump"])
|
||||
# stack.remove(stack.size()-1)
|
||||
# break
|
||||
# else:
|
||||
@@ -720,6 +744,6 @@ func object_exit_scene(name : String):
|
||||
func check_obj(name, cmd):
|
||||
var obj = escoria.esc_runner.get_object(name)
|
||||
if obj == null:
|
||||
escoria.report_errors("", ["Global id "+name+" not found for " + cmd])
|
||||
escoria.logger.report_errors("", ["Global id "+name+" not found for " + cmd])
|
||||
return false
|
||||
return true
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
extends Node
|
||||
|
||||
# This script runs the ESCCommands contained in the ESCEvent.
|
||||
# This script implements the ESCCommands contained in the ESCEvent.
|
||||
# TODO : this script should use "Command" pattern.
|
||||
|
||||
var current_context
|
||||
onready var esc_runner = get_parent()
|
||||
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
|
||||
func finished(context = null):
|
||||
@@ -26,10 +22,10 @@ func resume(context):
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
var count = context.instructions.size()
|
||||
while context.ip < count:
|
||||
var top = esc_runner.levels_stack.size()
|
||||
var top = escoria.esc_runner.levels_stack.size()
|
||||
var ret = run(context)
|
||||
context.ip += 1
|
||||
if top < esc_runner.levels_stack.size():
|
||||
if top < escoria.esc_runner.levels_stack.size():
|
||||
return esctypes.EVENT_LEVEL_STATE.CALL
|
||||
if ret == esctypes.EVENT_LEVEL_STATE.YIELD:
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
@@ -52,11 +48,11 @@ func run(context):
|
||||
var cmd = context.instructions[context.ip]
|
||||
if cmd.name == "label":
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
if !esc_runner.test(cmd):
|
||||
if !escoria.esc_runner.test(cmd):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
#print("name is ", cmd.name)
|
||||
#if !(cmd.name in self):
|
||||
# esc_runner.report_errors("", ["Unexisting command "+cmd.name])
|
||||
# escoria.logger.report_errors("", ["Unexisting command "+cmd.name])
|
||||
return call(cmd.name, cmd.params)
|
||||
|
||||
|
||||
@@ -137,18 +133,28 @@ func camera_push(command_params : Array):
|
||||
escoria.esc_runner.get_object("camera").push(target, time, type)
|
||||
|
||||
|
||||
"""
|
||||
camera_set_limits camlimits_id
|
||||
Sets the camera limits to the one defined under "camlimits_id" in ESCRoom's
|
||||
camera_limits array.
|
||||
- camlimits_id : int : id of the camera limits to apply (defined in ESCRoom's
|
||||
camera_limits array)
|
||||
"""
|
||||
func camera_set_limits(command_params : Array):
|
||||
escoria.main.set_camera_limits(command_params[0])
|
||||
|
||||
|
||||
"""
|
||||
camera_set_drag_margin_enabled h v
|
||||
- "h" and "v" are booleans for whether or not horizontal and vertical drag
|
||||
camera_set_drag_margin_enabled horizontal_enabled vertical_enabled
|
||||
- horizontal_enabled : bool
|
||||
- vertical_enabled : bool are booleans for whether or not horizontal and vertical drag
|
||||
margins are enabled. You will likely want to set them false for advanced camera
|
||||
motions and true for regular gameplay and/or tracking NPCs.
|
||||
"""
|
||||
func camera_set_drag_margin_enabled():
|
||||
pass
|
||||
func camera_set_drag_margin_enabled(command_params : Array):
|
||||
var horizontal_enabled = command_params[0]
|
||||
var vertical_enabled = command_params[1]
|
||||
escoria.esc_runner.get_object("camera").set_drag_margin_enabled(horizontal_enabled, vertical_enabled)
|
||||
|
||||
|
||||
"""
|
||||
@@ -157,11 +163,10 @@ Moves the camera to a position defined by "x" and "y", at the speed defined by
|
||||
"speed" in pixels per second. If speed is 0, camera is teleported to the position.
|
||||
"""
|
||||
func camera_set_pos(command_params : Array):
|
||||
# var speed = command_params[0]
|
||||
# var x = command_params[1]
|
||||
# var y = command_params[2]
|
||||
# escoria.esc_runner.get_object("camera").set_pos(speed, x, y)
|
||||
pass
|
||||
var speed = command_params[0]
|
||||
var pos = Vector2(command_params[1], command_params[2])
|
||||
escoria.esc_runner.get_object("camera").set_target(pos, speed)
|
||||
|
||||
|
||||
"""
|
||||
camera_set_target speed object [object2 object3 ...]
|
||||
@@ -193,8 +198,10 @@ func camera_set_zoom(command_params : Array):
|
||||
camera_set_zoom_height pixels [time]
|
||||
Similar to the command above, but uses pixel height instead of magnitude to zoom.
|
||||
"""
|
||||
func camera_set_zoom_height():
|
||||
pass
|
||||
func camera_set_zoom_height(command_params : Array):
|
||||
var magnitude = command_params[0] / escoria.game_size.y
|
||||
var time = command_params[1] if command_params.size() > 1 else 0
|
||||
escoria.esc_runner.get_object("camera").set_camera_zoom(magnitude, float(time))
|
||||
|
||||
|
||||
"""
|
||||
@@ -369,18 +376,25 @@ func inventory_remove(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
TODO: This is dependant to the user UI. It must remain flexible enough.
|
||||
inventory_open true/false
|
||||
Shows or hides inventory. Uses code in game.tscn scene, thus developed outside of Escoria.
|
||||
"""
|
||||
func inventory_open(command_params : Array):
|
||||
pass
|
||||
func inventory_display(command_params : Array):
|
||||
var display : bool = bool(command_params[0])
|
||||
if display:
|
||||
escoria.main.current_scene.game.open_inventory()
|
||||
else:
|
||||
escoria.main.current_scene.game.close_inventory()
|
||||
|
||||
|
||||
"""
|
||||
jump label_name
|
||||
Jump to label_name block. Labels are blocks defined the same way as action_verbs:
|
||||
:label
|
||||
"""
|
||||
func jump(command_params : Array):
|
||||
# escoria.esc_runner.jump(command_params[0])
|
||||
# return esctypes.EVENT_LEVEL_STATE.JUMP
|
||||
pass
|
||||
escoria.esc_runner.jump(command_params[0])
|
||||
return esctypes.EVENT_LEVEL_STATE.JUMP
|
||||
|
||||
"""
|
||||
"""
|
||||
@@ -389,21 +403,34 @@ func play_snd(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
queue_animation object animation
|
||||
"""
|
||||
func queue_animation(command_params : Array):
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
queue_resource path [front_of_queue]
|
||||
Queues the load of a resource in a background thread. The path must be a full
|
||||
path inside your game, for example "res://scenes/next_scene.tscn".
|
||||
The "front_of_queue" parameter is optional (default value false), to put the
|
||||
resource in the front of the queue. Queued resources are cleared when a change
|
||||
scene happens (but after the scene is loaded, meaning you can queue resources
|
||||
that belong to the next scene).
|
||||
"""
|
||||
func queue_resource(command_params : Array):
|
||||
pass
|
||||
var path : String = command_params[0]
|
||||
var in_front : bool = command_params[1] if command_params.size() > 1 else false
|
||||
escoria.esc_runner.resource_cache.queue_resource(path, in_front)
|
||||
|
||||
|
||||
"""
|
||||
repeat
|
||||
Restarts the execution of the current scope at the start. A scope can be a group
|
||||
or an event.
|
||||
"""
|
||||
func repeat(command_params : Array):
|
||||
pass
|
||||
return esctypes.EVENT_LEVEL_STATE.REPEAT
|
||||
|
||||
|
||||
"""
|
||||
@@ -419,7 +446,9 @@ func say(command_params : Array) -> esctypes:
|
||||
var dialog_scene_name = ProjectSettings.get_setting("escoria/ui/default_dialog_scene")
|
||||
|
||||
if dialog_scene_name.empty():
|
||||
escoria.report_errors("level_esc_runners.gd:say()", ["Project setting 'escoria/ui/default_dialog_scene' is not set. Please set a default dialog scene."])
|
||||
escoria.logger.report_errors("level_esc_runners.gd:say()",
|
||||
["Project setting 'escoria/ui/default_dialog_scene' is not set.",
|
||||
"Please set a default dialog scene."])
|
||||
var file = dialog_scene_name.get_file()
|
||||
var extension = dialog_scene_name.get_extension()
|
||||
dialog_scene_name = file.rstrip("." + extension)
|
||||
@@ -442,8 +471,9 @@ func say(command_params : Array) -> esctypes:
|
||||
|
||||
|
||||
"""
|
||||
Sets object as active or inactive. Active objects are displayed in scene and respond
|
||||
to inputs. Inactives are hidden.
|
||||
set_active global_id true/false
|
||||
Sets object as active or inactive. Active objects are displayed in scene and
|
||||
respond to inputs. Inactives are hidden.
|
||||
"""
|
||||
func set_active(command_params : Array):
|
||||
if !escoria.esc_runner.check_obj(command_params[0], "set_active"):
|
||||
@@ -453,8 +483,8 @@ func set_active(command_params : Array):
|
||||
escoria.esc_runner.set_active(name, value)
|
||||
|
||||
"""
|
||||
set_angle object_id angle_degrees
|
||||
Set the angle of an object.
|
||||
Usage: set_angle object_id angle_degrees
|
||||
"""
|
||||
func set_angle(command_params : Array):
|
||||
if !escoria.esc_runner.check_obj(command_params[0], "set_angle"):
|
||||
@@ -468,6 +498,9 @@ func set_angle(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
set_state object_id state_name
|
||||
Set object state to state_name. States are recorded in escoria.states[].
|
||||
If the object has an animation named 'state_name', Escoria plays it.
|
||||
"""
|
||||
func set_state(command_params : Array):
|
||||
var global_id : String = command_params[0]
|
||||
@@ -476,9 +509,14 @@ func set_state(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
set_hud_visible true/false
|
||||
Hides the UI. Uses code in game.tscn scene, thus developed outside of Escoria.
|
||||
"""
|
||||
func set_hud_visible(command_params : Array):
|
||||
pass
|
||||
if command_params[0]:
|
||||
escoria.main.current_scene.game.show_ui()
|
||||
else:
|
||||
escoria.main.current_scene.game.hide_ui()
|
||||
|
||||
|
||||
"""
|
||||
@@ -488,6 +526,8 @@ func sched_event(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
set_global global_variable value
|
||||
Sets a global variable value. Value can be string, integer or boolean.
|
||||
"""
|
||||
func set_global(command_params : Array):
|
||||
var name : String = command_params[0]
|
||||
@@ -509,17 +549,27 @@ func set_globals(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
set_interactive global_id true/false
|
||||
Sets object as interactive or not. Interactive objects can be pointed and
|
||||
interacted with.
|
||||
"""
|
||||
func set_interactive(command_params : Array):
|
||||
var name : String = command_params[0]
|
||||
var global_id : String = command_params[0]
|
||||
var value = command_params[1]
|
||||
escoria.esc_runner.set_interactive(name, value)
|
||||
escoria.esc_runner.set_interactive(global_id, value)
|
||||
|
||||
|
||||
"""
|
||||
set_speed global_id speed_value
|
||||
Sets the speed of object defined by 'global_id' to 'speed_value'
|
||||
"""
|
||||
func set_speed(command_params : Array):
|
||||
pass
|
||||
if !escoria.esc_runner.check_obj(command_params[0], "set_speed"):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
var global_id : String = command_params[0]
|
||||
var speed_value = command_params[1]
|
||||
escoria.get_object(global_id).set_speed(speed_value)
|
||||
|
||||
|
||||
"""
|
||||
@@ -528,6 +578,12 @@ func slide(command_params : Array):
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
func slide_to_pos(command_params : Array):
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
func slide_block(command_params : Array):
|
||||
@@ -536,11 +592,22 @@ func slide_block(command_params : Array):
|
||||
|
||||
"""
|
||||
"""
|
||||
func spawn(command_params : Array):
|
||||
func slide_to_pos_block(command_params : Array):
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
spawn path [object2]
|
||||
Instances a scene determined by "path", and places in the position of object2
|
||||
(object2 is optional)
|
||||
"""
|
||||
func spawn(command_params : Array):
|
||||
superpose_scene(command_params)
|
||||
|
||||
"""
|
||||
stop
|
||||
Stops the execution of the current script when it reaches the 'stop' instruction.
|
||||
Usually used in the end of commands blocks.
|
||||
"""
|
||||
func stop(command_params : Array):
|
||||
return esctypes.EVENT_LEVEL_STATE.BREAK
|
||||
@@ -560,7 +627,10 @@ func superpose_scene(command_params : Array):
|
||||
# Savegames must have events disabled, so saving the game adds a false to params
|
||||
var run_events = true
|
||||
if command_params.size() == 2:
|
||||
run_events = bool(command_params[1])
|
||||
if command_params[1] in ["true", "false"]:
|
||||
run_events = true if command_params[1] == "true" else false
|
||||
else:
|
||||
current_context["set_position"] = command_params[1]
|
||||
|
||||
# looking for localized string format in scene. this should be somewhere else
|
||||
var sep = command_params[0].find(":\"")
|
||||
@@ -575,9 +645,9 @@ func superpose_scene(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
teleport obj1 obj2 [angle_degrees]
|
||||
Teleports obj1 at obj2's position. If angle_degrees is set (int), sets obj1's
|
||||
angle to angle_degrees.
|
||||
Usage: teleport obj1 obj2 [angle_degrees]
|
||||
"""
|
||||
func teleport(command_params : Array):
|
||||
if !escoria.esc_runner.check_obj(command_params[0], "teleport"):
|
||||
@@ -595,9 +665,22 @@ func teleport(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
teleport obj1 x y [angle_degrees]
|
||||
Teleports obj1 at (x,y). If angle_degrees is set (int), sets obj1's
|
||||
angle to angle_degrees.
|
||||
"""
|
||||
func teleport_pos(command_params : Array):
|
||||
pass
|
||||
if !escoria.esc_runner.check_obj(command_params[0], "teleport"):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
var x = command_params[1]
|
||||
var y = command_params[2]
|
||||
|
||||
var angle
|
||||
if command_params.size() > 2:
|
||||
angle = int(command_params[3])
|
||||
|
||||
escoria.esc_runner.get_object(command_params[0]).teleport(Vector2(x,y), angle)
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
"""
|
||||
@@ -622,29 +705,48 @@ func wait(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
walk object_id1 object_id2
|
||||
Make object1 walk towards object2. This command is not blocking (user input not disabled)
|
||||
Usage: walk object_id1 object_id2
|
||||
"""
|
||||
func walk(command_params : Array):
|
||||
current_context.waiting = false
|
||||
escoria.do("walk", command_params)
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
"""
|
||||
walk_block object_id1 object_id2
|
||||
Make object1 walk towards object2. This command is blocking (user input disabled)
|
||||
"""
|
||||
func walk_block(command_params : Array):
|
||||
current_context.waiting = true
|
||||
escoria.do("walk", command_params)
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
|
||||
|
||||
"""
|
||||
walk_to_pos object_id1 pos_x pos_y
|
||||
Make object1 walk towards object2. This command is not blocking (user input not disabled)
|
||||
Usage: walk_to_pos object_id1 pos_x pos_y
|
||||
"""
|
||||
func walk_to_pos(command_params : Array):
|
||||
current_context.waiting = false
|
||||
var destination_pos = Vector2(command_params[1], command_params[2])
|
||||
escoria.do("walk", [command_params[0], destination_pos])
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
"""
|
||||
walk_to_pos_block object_id1 pos_x pos_y
|
||||
Make object1 walk towards object2. This command is blocking (user input disabled)
|
||||
"""
|
||||
func walk_to_pos_block(command_params : Array):
|
||||
current_context.waiting = true
|
||||
var destination_pos = Vector2(command_params[1], command_params[2])
|
||||
escoria.do("walk", [command_params[0], destination_pos])
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
func walk_block(command_params : Array):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@ var last_dir : int
|
||||
|
||||
|
||||
func _ready():
|
||||
assert(!global_id.empty())
|
||||
|
||||
# Adds movable behavior
|
||||
Movable = Node.new()
|
||||
@@ -210,9 +209,12 @@ func element_exited(body):
|
||||
func teleport(target, angle : Object = null) -> void:
|
||||
Movable.teleport(target, angle)
|
||||
|
||||
func walk_to(pos : Vector2, p_walk_context = null):
|
||||
func walk_to(pos : Vector2, p_walk_context = null) -> void:
|
||||
Movable.walk_to(pos, p_walk_context)
|
||||
|
||||
func set_speed(speed_value : int) -> void:
|
||||
speed = speed_value
|
||||
|
||||
################################################################################
|
||||
|
||||
# TALKATIVE object functions
|
||||
|
||||
@@ -129,18 +129,20 @@ func _process(time):
|
||||
$debug.text = str(z_index)
|
||||
|
||||
|
||||
|
||||
func anim_finished():
|
||||
pass
|
||||
|
||||
|
||||
func get_camera_pos():
|
||||
if camera_position_node and get_node(camera_position_node):
|
||||
return get_node(camera_position_node).global_position
|
||||
return global_position
|
||||
|
||||
|
||||
func get_animations_list() -> PoolStringArray:
|
||||
return animation_sprite.get_sprite_frames().get_animation_names()
|
||||
|
||||
|
||||
func start_talking():
|
||||
if animation_sprite.is_playing():
|
||||
animation_sprite.stop()
|
||||
@@ -162,3 +164,8 @@ func walk_to(pos : Vector2, p_walk_context = null):
|
||||
|
||||
func set_angle(deg : int, immediate = true):
|
||||
Movable.set_angle(deg, immediate)
|
||||
|
||||
|
||||
func set_speed(speed_value : int) -> void:
|
||||
speed = speed_value
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ func _ready():
|
||||
if n is NavigationPolygonInstance:
|
||||
if n.enabled:
|
||||
if navigation_enabled_found:
|
||||
escoria.report_errors("escterrain.gd:_ready()", ["Multiple NavigationPolygonInstances enabled at the same time."])
|
||||
escoria.logger.report_errors("escterrain.gd:_ready()", ["Multiple NavigationPolygonInstances enabled at the same time."])
|
||||
navigation_enabled_found = true
|
||||
current_active_navigation_instance = n
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
tool
|
||||
extends Area2D
|
||||
class_name ESCTriggerZone
|
||||
|
||||
func get_class():
|
||||
return "ESCTriggerZone"
|
||||
|
||||
|
||||
export(String) var global_id
|
||||
export(String, FILE, "*.esc") var esc_script
|
||||
|
||||
func _ready():
|
||||
assert(!global_id.empty())
|
||||
escoria.register_object(self)
|
||||
connect("area_entered", self, "element_entered")
|
||||
connect("area_exited", self, "element_exited")
|
||||
connect("body_entered", self, "element_entered")
|
||||
connect("body_exited", self, "element_exited")
|
||||
|
||||
|
||||
func element_entered(body):
|
||||
if body is ESCBackground or body.get_parent() is ESCBackground:
|
||||
return
|
||||
escoria.do("trigger_in", [global_id, body.global_id])
|
||||
|
||||
|
||||
func element_exited(body):
|
||||
escoria.do("trigger_out", [global_id, body.global_id])
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,49 @@
|
||||
# Logging
|
||||
onready var warning_is_reported : bool = false
|
||||
var warning_path : String
|
||||
|
||||
func warning(string : String):
|
||||
printerr("(W)\t" + string)
|
||||
func warning(string : String, args = []):
|
||||
var argsstr = str(args) if !args.empty() else ""
|
||||
printerr("(W)\t" + string + " \t" + argsstr)
|
||||
|
||||
func info(string : String):
|
||||
print("(I)\t" + string)
|
||||
|
||||
func info(string : String, args = []):
|
||||
var argsstr = str(args) if !args.empty() else ""
|
||||
print("(I)\t" + string + " \t" + argsstr)
|
||||
|
||||
func error(string : String):
|
||||
printerr("(E)\t" + string)
|
||||
|
||||
func error(string : String, args = []):
|
||||
var argsstr = str(args) if !args.empty() else ""
|
||||
printerr("(E)\t" + string + " \t" + argsstr)
|
||||
|
||||
|
||||
func report_warnings(p_path : String, warnings : Array, report_once = false) -> void:
|
||||
if p_path != warning_path:
|
||||
warning_is_reported = false
|
||||
|
||||
if !warning_is_reported:
|
||||
var text = "Warnings in file "+p_path+"\n"
|
||||
for w in warnings:
|
||||
if w is Array:
|
||||
text += str(w)+"\n"
|
||||
else:
|
||||
text += w+"\n"
|
||||
warning(text)
|
||||
|
||||
if report_once:
|
||||
warning_is_reported = true
|
||||
|
||||
|
||||
func report_errors(p_path : String, errors : Array) -> void:
|
||||
var text = "Errors in file "+p_path+"\n"
|
||||
for e in errors:
|
||||
if e is Array:
|
||||
text += str(e)+"\n"
|
||||
else:
|
||||
text += e+"\n"
|
||||
error(text)
|
||||
if ProjectSettings.get_setting("escoria/debug/terminate_on_errors"):
|
||||
print_stack()
|
||||
assert(false)
|
||||
# If your game stopped here, you may want to look at the Output tab and
|
||||
# check for the error that caused the game to stop.
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
extends Sprite
|
||||
|
||||
signal left_click_on_bg
|
||||
signal right_click_on_bg # Connect this in your game/signal_script
|
||||
|
||||
export var action = "walk"
|
||||
var area
|
||||
|
||||
# Godot doesn't do doubleclicks so we must
|
||||
var last_lmb_dt = 0
|
||||
var waiting_dblclick = null # null or [pos, event]
|
||||
|
||||
func input(_viewport, event, _shape_idx):
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
# If we are hovering items, do not allow background to receive a click
|
||||
# and let the items sort out who's on top and gets to be `clicked`
|
||||
if vm.hover_stack:
|
||||
return
|
||||
|
||||
if event.is_action("game_general"):
|
||||
last_lmb_dt = 0
|
||||
waiting_dblclick = [get_global_mouse_position(), event]
|
||||
elif event.is_action("game_rmb"):
|
||||
emit_signal("right_click_on_bg", self, get_global_mouse_position(), event)
|
||||
|
||||
func get_action():
|
||||
return action
|
||||
|
||||
func _physics_process(dt):
|
||||
last_lmb_dt += dt
|
||||
|
||||
if waiting_dblclick and last_lmb_dt > vm.DOUBLECLICK_TIMEOUT:
|
||||
emit_signal("left_click_on_bg", self, waiting_dblclick[0], waiting_dblclick[1])
|
||||
last_lmb_dt = 0
|
||||
waiting_dblclick = null
|
||||
|
||||
func _enter_tree():
|
||||
# Use size of background texture to calculate collision shape
|
||||
var size = get_texture().get_size()
|
||||
|
||||
area = Area2D.new()
|
||||
var shape = RectangleShape2D.new()
|
||||
|
||||
var sid = area.create_shape_owner(area)
|
||||
|
||||
# Move origin of Area2D to center of Sprite
|
||||
var transform = area.shape_owner_get_transform(sid)
|
||||
transform.origin = size / 2
|
||||
area.shape_owner_set_transform(sid, transform)
|
||||
|
||||
# Set extents of RectangleShape2D to cover entire Sprite
|
||||
shape.set_extents(size / 2)
|
||||
area.shape_owner_add_shape(sid, shape)
|
||||
|
||||
add_child(area)
|
||||
|
||||
func _ready():
|
||||
var conn_err
|
||||
|
||||
conn_err = area.connect("input_event", self, "input")
|
||||
if conn_err:
|
||||
vm.report_errors("item", ["area.input_event -> input error: " + String(conn_err)])
|
||||
|
||||
conn_err = connect("left_click_on_bg", $"/root/scene/game", "ev_left_click_on_bg")
|
||||
if conn_err:
|
||||
vm.report_errors("item", ["left_click_on_bg -> ev_left_click_on_bg error: " + String(conn_err)])
|
||||
|
||||
add_to_group("background")
|
||||
|
||||
@@ -132,7 +132,6 @@ func load_autosave(p_callback):
|
||||
|
||||
|
||||
func _do_load(fname):
|
||||
|
||||
var f = File.new()
|
||||
if !f.file_exists(fname):
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user