Added a new character and modified the way :setup and :ready events are run.
This commit is contained in:
@@ -42,7 +42,7 @@ var commands = {
|
||||
"cut_scene": { "min_args": 2, "types": [TYPE_STRING, TYPE_STRING, TYPE_BOOL, TYPE_BOOL, TYPE_BOOL] },
|
||||
"debug": { "min_args": 1 },
|
||||
"dec_global": { "min_args": 2, "types": [TYPE_STRING, TYPE_INT] },
|
||||
"dialog_config": { "min_args": 3, "types": [TYPE_STRING, TYPE_BOOL, TYPE_BOOL] },
|
||||
# "dialog_config": { "min_args": 3, "types": [TYPE_STRING, TYPE_BOOL, TYPE_BOOL] },
|
||||
"enable_terrain": { "min_args": 1, "types": [TYPE_STRING]},
|
||||
"game_over": { "min_args": 1, "types": [TYPE_BOOL] },
|
||||
"inc_global": { "min_args": 2, "types": [TYPE_STRING, TYPE_INT] },
|
||||
|
||||
@@ -272,6 +272,13 @@ func set_global(name, val, force_change_reserved : bool = false):
|
||||
# printt("global changed at global_vm, emitting for ", name, val)
|
||||
emit_signal("global_changed", name)
|
||||
|
||||
func set_globals(pattern : String, val):
|
||||
for key in globals:
|
||||
if key.match(pattern):
|
||||
set_global(key, val)
|
||||
# globals[key] = val
|
||||
# emit_signal("global_changed", key)
|
||||
|
||||
func dec_global(name, diff):
|
||||
var global = get_global(name)
|
||||
global = int(global) if global else 0
|
||||
@@ -282,12 +289,6 @@ func inc_global(name, diff):
|
||||
global = int(global) if global else 0
|
||||
set_global(name, str(global + diff))
|
||||
|
||||
func set_globals(pat, val):
|
||||
for key in globals:
|
||||
if key.match(pat):
|
||||
globals[key] = val
|
||||
emit_signal("global_changed", key)
|
||||
|
||||
func is_global_equal_to(name, val):
|
||||
var global = get_global(name)
|
||||
if global and val and global == val:
|
||||
@@ -353,14 +354,27 @@ func change_scene(params, context, run_events=true):
|
||||
if !game_scene:
|
||||
escoria.report_errors("esc_runner.gd:change_scene()",
|
||||
["Failed loading scene " + ProjectSettings.get_setting("escoria/ui/game_scene")])
|
||||
|
||||
|
||||
# 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)
|
||||
escoria.main.set_scene(room_scene, run_events)
|
||||
var events = escoria.main.set_scene(room_scene, run_events)
|
||||
|
||||
# If scene was never visited, add "ready" event to the events stack
|
||||
if !scenes_cache.has(room_scene.global_id) \
|
||||
and "ready" in events:
|
||||
run_event(events["ready"])
|
||||
|
||||
# :setup is pretty much required in the code, but fortunately
|
||||
# we can help out with cases where one isn't necessary otherwise
|
||||
if not "setup" in events:
|
||||
var fake_setup = escoria.esc_compiler.compile_str(":setup\n")
|
||||
events["setup"] = fake_setup["setup"]
|
||||
# Finally we add the setup on to of the events stack so that it is ran first
|
||||
run_event(events["setup"])
|
||||
|
||||
escoria.inputs_manager.is_hotspot_focused = false
|
||||
if !scenes_cache_list.has(params[0]):
|
||||
scenes_cache_list.push_back(params[0])
|
||||
@@ -628,3 +642,17 @@ func object_exit_scene(name : String):
|
||||
printt("Object " + name + " removed from scene.")
|
||||
objects.erase(name)
|
||||
|
||||
#func jump(p_label):
|
||||
# while stack.size() > 0:
|
||||
# var top = stack[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 || stack.size() == 1:
|
||||
# report_errors("", ["Label not found: "+p_label+", can't jump"])
|
||||
# stack.remove(stack.size()-1)
|
||||
# break
|
||||
# else:
|
||||
# stack.remove(stack.size()-1)
|
||||
|
||||
@@ -5,14 +5,19 @@ extends Node
|
||||
var current_context
|
||||
onready var esc_runner = get_parent()
|
||||
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
|
||||
func finished(context = null):
|
||||
if context != null:
|
||||
context.waiting = false
|
||||
else:
|
||||
current_context.waiting = false
|
||||
|
||||
if escoria.current_state == escoria.GAME_STATE.WAIT:
|
||||
escoria.current_state = escoria.GAME_STATE.DEFAULT
|
||||
|
||||
|
||||
func check_obj(name, cmd):
|
||||
@@ -22,6 +27,7 @@ func check_obj(name, cmd):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func resume(context):
|
||||
current_context = context
|
||||
if context.waiting:
|
||||
@@ -49,6 +55,7 @@ func resume(context):
|
||||
context.ip = 0
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
func run(context):
|
||||
var cmd = context.instructions[context.ip]
|
||||
if cmd.name == "label":
|
||||
@@ -70,25 +77,53 @@ func dialog_line_finished() -> void:
|
||||
escoria.dialog_player.is_speaking = false
|
||||
escoria.current_state = escoria.GAME_STATE.DEFAULT
|
||||
|
||||
|
||||
"""
|
||||
accept_input [ALL|NONE|SKIP]
|
||||
What type of input does the game accept. ALL is the default, SKIP allows skipping
|
||||
of dialog but nothing else, NONE denies all input. Including opening the menu etc.
|
||||
SKIP and NONE also disable autosaves. Note that SKIP gets reset to ALL when the
|
||||
event is done, but NONE persists. This allows you to create cut scenes with SKIP
|
||||
where the dialog can be skipped, but also initiate locked-down cutscenes with
|
||||
accept_input NONE in :setup and accept_input ALL later in :ready.
|
||||
"""
|
||||
func accept_input():
|
||||
func accept_input(command_params : Array):
|
||||
# var p_input = command_params[0]
|
||||
# var input = escoria.esc_runner.acceptable_inputs["INPUT_" + p_input]
|
||||
# escoria.esc_runner.set_accept_input(input)
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
func autosave():
|
||||
# escoria.request_autosave()
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
anim object name [reverse] [flip_x] [flip_y]
|
||||
Executes the animation specificed with the "name" parameter on the object,
|
||||
without blocking. The next command in the event will be executed immediately after.
|
||||
Optional parameters:
|
||||
reverse plays the animation in reverse when true
|
||||
flip_x flips the x axis of the object's sprites when true (object's root node needs to be Node2D)
|
||||
flip_y flips the y axis of the object's sprites when true (object's root node needs to be Node2D)
|
||||
"""
|
||||
func anim():
|
||||
pass
|
||||
func anim(command_params : Array):
|
||||
if !check_obj(command_params[0], "anim"):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
private_play_animation(command_params)
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
"""
|
||||
Groups Commands can be grouped using the character ">" to start a group, and
|
||||
incrementing the indentation of the commands that belong to the group. Example:
|
||||
>
|
||||
set_global door_open true
|
||||
animation player pick_up
|
||||
# end of group
|
||||
"""
|
||||
func branch(command_params : Array):
|
||||
var branch_ev = esctypes.ESCEvent.new("branch", command_params, [])
|
||||
@@ -96,65 +131,104 @@ func branch(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
camera_push target [time] [type]
|
||||
Push camera to target. Target must have camera_pos set.
|
||||
If it's of type Camera2D, its zoom will be used as well as position.
|
||||
- A time value of 0 will set the camera immediately.
|
||||
- type is any of the Tween.TransitionType values without the prefix, eg. LINEAR,
|
||||
QUART or CIRC; defaults to QUART.
|
||||
"""
|
||||
func camera_push():
|
||||
pass
|
||||
func camera_push(command_params : Array):
|
||||
var target = escoria.esc_runner.get_object(command_params[0])
|
||||
var time = command_params[1] if command_params.size() > 1 else 1
|
||||
var type = command_params[2] if command_params.size() > 2 else "QUAD"
|
||||
escoria.main.current_scene.game.get_node("camera").push(target, time, type)
|
||||
|
||||
|
||||
"""
|
||||
camera_set_drag_margin_enabled h v
|
||||
- "h" and "v" 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
|
||||
|
||||
|
||||
"""
|
||||
camera_set_pos speed x y
|
||||
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():
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
camera_set_target speed object [object2 object3 ...]
|
||||
Configures the camera to follow 1 or more objects, using "speed" as speed limit.
|
||||
This is the default behavior (default follow object is "player").
|
||||
If there's more than 1 object, the camera follows the average position of all
|
||||
the objects specified.
|
||||
"""
|
||||
func camera_set_target():
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
camera_set_zoom magnitude [time]
|
||||
Zooms the camera in/out to the desired magnitude. Values larger than 1 zooms
|
||||
the camera out, and smaller values zooms in, relative to the default value of 1.
|
||||
An optional time in seconds controls how long it takes for the camera to zoom
|
||||
into position.
|
||||
"""
|
||||
func camera_set_zoom():
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
camera_set_zoom_height pixels [time]
|
||||
Similar to the command abo/ve, but uses pixel height instead of magnitude to zoom.
|
||||
"""
|
||||
func camera_set_zoom_height():
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
camera_shift x y [time] [type]
|
||||
Shift camera by x and y pixels over time seconds.
|
||||
- type is any of the Tween.TransitionType values without the prefix, eg. LINEAR,
|
||||
QUART or CIRC; defaults to QUART.
|
||||
"""
|
||||
func camera_shift():
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
change_scene path [run_events]
|
||||
Loads a new scene, specified by "path".
|
||||
The run_events variable is a boolean (default true) which you never want to set
|
||||
manually! It's there only to benefit save games, so they don't conflict with the
|
||||
scene's events.
|
||||
"""
|
||||
func change_scene(params):
|
||||
func change_scene(command_params : Array):
|
||||
# Savegames must have events disabled, so saving the game adds a false to params
|
||||
var run_events = true
|
||||
if params.size() == 2:
|
||||
run_events = bool(params[1])
|
||||
if command_params.size() == 2:
|
||||
run_events = bool(command_params[1])
|
||||
|
||||
# looking for localized string format in scene. this should be somewhere else
|
||||
var sep = params[0].find(":\"")
|
||||
var sep = command_params[0].find(":\"")
|
||||
if sep >= 0:
|
||||
var path = params[0].substr(sep + 2, params[0].length() - (sep + 2))
|
||||
var path = command_params[0].substr(sep + 2, command_params[0].length() - (sep + 2))
|
||||
escoria.esc_runner.call_deferred("change_scene", [path], current_context, run_events)
|
||||
else:
|
||||
escoria.esc_runner.call_deferred("change_scene", params, current_context, run_events)
|
||||
escoria.esc_runner.call_deferred("change_scene", command_params, current_context, run_events)
|
||||
|
||||
current_context.waiting = true
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
func custom():
|
||||
@@ -162,30 +236,76 @@ func custom():
|
||||
|
||||
|
||||
"""
|
||||
cut_scene object name [reverse] [flip_x] [flip_y]
|
||||
Executes the animation specificed with the "name" parameter on the object, BLOCKING.
|
||||
The next command in the event will be executed when the animation is finished
|
||||
playing.
|
||||
Optional parameters:
|
||||
- reverse plays the animation in reverse when true
|
||||
- flip_x flips the x axis of the object's sprites when true
|
||||
(object's root node needs to be Node2D)
|
||||
- flip_y flips the y axis of the object's sprites when true
|
||||
(object's root node needs to be Node2D)
|
||||
"""
|
||||
func cut_scene():
|
||||
pass
|
||||
func cut_scene(command_params : Array):
|
||||
if !check_obj(command_params[0], "cut_scene"):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
private_play_animation(command_params)
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
|
||||
|
||||
"""
|
||||
PRIVATE
|
||||
Play animation using parameters.
|
||||
Used by commands anim() and cut_scene()
|
||||
"""
|
||||
func debug():
|
||||
pass
|
||||
func private_play_animation(command_params : Array):
|
||||
var obj = escoria.esc_runner.get_object(command_params[0])
|
||||
var anim_id = command_params[1]
|
||||
var reverse = false
|
||||
if command_params.size() > 2:
|
||||
reverse = command_params[2]
|
||||
var flip = Vector2(1, 1)
|
||||
if command_params.size() > 3 && command_params[3]:
|
||||
flip.x = -1
|
||||
if command_params.size() > 4 && command_params[4]:
|
||||
flip.y = -1
|
||||
current_context.waiting = true
|
||||
obj.play_anim(anim_id, current_context, reverse, flip)
|
||||
|
||||
|
||||
"""
|
||||
debug string [string2 ...]
|
||||
Takes 1 or more strings, prints them to the console.
|
||||
"""
|
||||
func dec_global():
|
||||
pass
|
||||
func debug(command_params : Array):
|
||||
for p in command_params:
|
||||
printt(p)
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
"""
|
||||
dec_global name value
|
||||
Subtracts the value from global with given "name".
|
||||
Value and global must both be integers.
|
||||
"""
|
||||
func inc_global():
|
||||
pass
|
||||
func dec_global(command_params : Array):
|
||||
escoria.esc_runner.dec_global(command_params[0], command_params[1])
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
"""
|
||||
inc_global name value
|
||||
Adds the value to global with given "name".
|
||||
Value and global must both be integers.
|
||||
"""
|
||||
func inc_global(command_params : Array):
|
||||
escoria.esc_runner.inc_global(command_params[0], command_params[1])
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
"""
|
||||
Start a dialog choice.
|
||||
"""
|
||||
func dialog(command_params : Array):
|
||||
current_context.waiting = true
|
||||
@@ -198,13 +318,14 @@ func dialog(command_params : Array):
|
||||
return esctypes.EVENT_LEVEL_STATE.YIELD
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
func dialog_config():
|
||||
pass
|
||||
#func dialog_config():
|
||||
## escoria.esc_runner.dialog_config(params)
|
||||
## return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
# pass
|
||||
|
||||
|
||||
"""
|
||||
enable_terrain node_name
|
||||
Enable the ESCTerrain's NavigationPolygonInstance defined by given node name.
|
||||
Disables previously activated NavigationPolygonInstance.
|
||||
"""
|
||||
@@ -223,18 +344,25 @@ func game_over(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
Adds element in inventory.
|
||||
Usage: inventory_add my_item
|
||||
equivalent to: set_global i/my_item true
|
||||
"""
|
||||
func inventory_add(command_params : Array):
|
||||
pass
|
||||
set_global(["i/"+command_params[0], "true"])
|
||||
|
||||
|
||||
"""
|
||||
Removes element from inventory.
|
||||
Usage: inventory_remove my_item
|
||||
equivalent to: set_global i/my_item false
|
||||
"""
|
||||
func inventory_remove(command_params : Array):
|
||||
pass
|
||||
set_global(["i/"+command_params[0], "false"])
|
||||
|
||||
|
||||
"""
|
||||
TODO: This is dependant to the user UI. It must remain flexible enough.
|
||||
"""
|
||||
func inventory_open(command_params : Array):
|
||||
pass
|
||||
@@ -243,9 +371,10 @@ func inventory_open(command_params : Array):
|
||||
"""
|
||||
"""
|
||||
func jump(command_params : Array):
|
||||
# escoria.esc_runner.jump(command_params[0])
|
||||
# return esctypes.EVENT_LEVEL_STATE.JUMP
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
func play_snd(command_params : Array):
|
||||
@@ -318,11 +447,11 @@ func set_active(command_params : Array):
|
||||
Set the angle of an object.
|
||||
Usage: set_angle object_id angle_degrees
|
||||
"""
|
||||
func set_angle(params : Array):
|
||||
if !check_obj(params[0], "set_angle"):
|
||||
func set_angle(command_params : Array):
|
||||
if !check_obj(command_params[0], "set_angle"):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
var obj = escoria.esc_runner.get_object(params[0])
|
||||
obj.set_angle(int(params[1]))
|
||||
var obj = escoria.esc_runner.get_object(command_params[0])
|
||||
obj.set_angle(int(command_params[1]))
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
@@ -355,9 +484,16 @@ func set_global(command_params : Array):
|
||||
|
||||
|
||||
"""
|
||||
set_globals pattern value
|
||||
Changes the value of multiple globals using a wildcard pattern.
|
||||
Example:
|
||||
# clears the inventory
|
||||
set_globals i/* false
|
||||
"""
|
||||
func set_globals(command_params : Array):
|
||||
pass
|
||||
var pattern : String = command_params[0]
|
||||
var val = command_params[1]
|
||||
escoria.esc_runner.set_globals(pattern, val)
|
||||
|
||||
|
||||
"""
|
||||
@@ -402,17 +538,18 @@ 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(params):
|
||||
if !check_obj(params[0], "teleport"):
|
||||
func teleport(command_params : Array):
|
||||
if !check_obj(command_params[0], "teleport"):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
if !check_obj(params[1], "teleport"):
|
||||
if !check_obj(command_params[1], "teleport"):
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
var angle
|
||||
if params.size() > 2:
|
||||
angle = int(params[2])
|
||||
if command_params.size() > 2:
|
||||
angle = int(command_params[2])
|
||||
|
||||
escoria.esc_runner.get_object(params[0]).teleport(escoria.esc_runner.get_object(params[1]), angle)
|
||||
escoria.esc_runner.get_object(command_params[0]) \
|
||||
.teleport(escoria.esc_runner.get_object(command_params[1]), angle)
|
||||
return esctypes.EVENT_LEVEL_STATE.RETURN
|
||||
|
||||
|
||||
|
||||
@@ -116,6 +116,8 @@ func update_terrain(on_event_finished_name = null):
|
||||
return
|
||||
if on_event_finished_name != null and on_event_finished_name != "setup":
|
||||
return
|
||||
if is_exit:
|
||||
return
|
||||
|
||||
var pos = position
|
||||
z_index = pos.y if pos.y <= VisualServer.CANVAS_ITEM_Z_MAX else VisualServer.CANVAS_ITEM_Z_MAX
|
||||
|
||||
@@ -126,10 +126,13 @@ func _ready():
|
||||
terrain = escoria.room_terrain
|
||||
|
||||
last_scale = scale
|
||||
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _process(time):
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
$debug.text = str(z_index)
|
||||
|
||||
if task == PLAYER_TASKS.WALK or task == PLAYER_TASKS.SLIDE:
|
||||
|
||||
@@ -65,7 +65,7 @@ func _on_mouse_right_click_inventory_item(inventory_item_global_id, event : Inpu
|
||||
|
||||
func _on_mouse_double_left_click_inventory_item(inventory_item_global_id, event : InputEvent) -> void:
|
||||
printt("Inventory item double left clicked ", inventory_item_global_id)
|
||||
escoria.main.current_scene.game.double_left_click_on_inventory_item(inventory_item_global_id, event)
|
||||
escoria.main.current_scene.game.left_double_click_on_inventory_item(inventory_item_global_id, event)
|
||||
|
||||
func _on_mouse_entered_inventory_item(inventory_item_global_id) -> void:
|
||||
printt("Inventory item focused ", inventory_item_global_id)
|
||||
|
||||
@@ -21,36 +21,43 @@ func set_scene(p_scene, run_events=true):
|
||||
"""
|
||||
if !p_scene:
|
||||
escoria.report_errors("main", ["Trying to set empty scene"])
|
||||
|
||||
if current_scene != null:
|
||||
clear_scene()
|
||||
|
||||
get_node("/root").add_child(p_scene)
|
||||
|
||||
# Ensure we don't have a regular event running when changing scenes
|
||||
if escoria.esc_runner.running_event:
|
||||
assert(escoria.esc_runner.running_event.ev_name == "load")
|
||||
|
||||
var events : Dictionary = {}
|
||||
if "esc_script" in p_scene and p_scene.esc_script and run_events:
|
||||
var events = escoria.esc_compiler.load_esc_file(p_scene.esc_script)
|
||||
events = escoria.esc_compiler.load_esc_file(p_scene.esc_script)
|
||||
|
||||
# :setup is pretty much required in the code, but fortunately
|
||||
# we can help out with cases where one isn't necessary otherwise
|
||||
if not "setup" in events:
|
||||
var fake_setup = escoria.esc_compiler.compile_str(":setup\n")
|
||||
events["setup"] = fake_setup["setup"]
|
||||
|
||||
escoria.esc_runner.run_event(events["setup"])
|
||||
# # :setup is pretty much required in the code, but fortunately
|
||||
# # we can help out with cases where one isn't necessary otherwise
|
||||
# if not "setup" in events:
|
||||
# var fake_setup = escoria.esc_compiler.compile_str(":setup\n")
|
||||
# events["setup"] = fake_setup["setup"]
|
||||
#
|
||||
# escoria.esc_runner.run_event(events["setup"])
|
||||
# # We need to ensure that :setup event is finished before adding the next event.
|
||||
# var setup_done = false
|
||||
# while !setup_done:
|
||||
# var event_name = yield(escoria.esc_runner, "event_done")
|
||||
# if event_name == "setup":
|
||||
# setup_done = true
|
||||
#
|
||||
# # If scene was never visited, run "ready" event
|
||||
# if !escoria.esc_runner.scenes_cache.has(p_scene.global_id) \
|
||||
# and "ready" in events:
|
||||
# escoria.esc_runner.run_event(events["ready"])
|
||||
#
|
||||
|
||||
# If scene was never visited, run "ready" event
|
||||
if !escoria.esc_runner.scenes_cache.has(p_scene.global_id) \
|
||||
and "ready" in events:
|
||||
escoria.esc_runner.run_event(events["ready"])
|
||||
|
||||
if current_scene != null:
|
||||
clear_scene()
|
||||
|
||||
# var game_scene =
|
||||
|
||||
get_node("/root").add_child(p_scene)
|
||||
set_current_scene(p_scene, run_events)
|
||||
set_camera_limits()
|
||||
|
||||
return events
|
||||
|
||||
func set_current_scene(p_scene, run_events=true):
|
||||
current_scene = p_scene
|
||||
@@ -83,6 +90,7 @@ func set_current_scene(p_scene, run_events=true):
|
||||
|
||||
escoria.esc_runner.register_object("_scene", p_scene, true) # Force overwrite of global
|
||||
|
||||
check_game_scene_methods()
|
||||
|
||||
func clear_scene():
|
||||
if current_scene == null:
|
||||
@@ -154,5 +162,36 @@ func set_camera_limits():
|
||||
}
|
||||
printt("setting camera limits from parameter ", scene_camera_limits)
|
||||
|
||||
escoria.esc_runner.get_object("camera").set_limits(limits)
|
||||
escoria.esc_runner.get_object("camera").set_offset(screen_ofs * 2)
|
||||
current_scene.game.get_node("camera").set_limits(limits)
|
||||
current_scene.game.get_node("camera").set_offset(screen_ofs * 2)
|
||||
|
||||
|
||||
"""
|
||||
The game.tscn scene's root node script MUST implement the following methods.
|
||||
If they do not exist, stop immediately. Implement them, even if empty
|
||||
"""
|
||||
func check_game_scene_methods():
|
||||
assert(current_scene.game.has_method("left_click_on_bg"))
|
||||
assert(current_scene.game.has_method("right_click_on_bg"))
|
||||
assert(current_scene.game.has_method("left_double_click_on_bg"))
|
||||
|
||||
assert(current_scene.game.has_method("element_focused"))
|
||||
assert(current_scene.game.has_method("element_unfocused"))
|
||||
|
||||
assert(current_scene.game.has_method("left_click_on_hotspot"))
|
||||
assert(current_scene.game.has_method("right_click_on_hotspot"))
|
||||
assert(current_scene.game.has_method("left_double_click_on_hotspot"))
|
||||
|
||||
assert(current_scene.game.has_method("left_click_on_item"))
|
||||
assert(current_scene.game.has_method("right_click_on_item"))
|
||||
assert(current_scene.game.has_method("left_double_click_on_item"))
|
||||
|
||||
assert(current_scene.game.has_method("open_inventory"))
|
||||
assert(current_scene.game.has_method("close_inventory"))
|
||||
|
||||
assert(current_scene.game.has_method("left_click_on_inventory_item"))
|
||||
assert(current_scene.game.has_method("right_click_on_inventory_item"))
|
||||
assert(current_scene.game.has_method("left_double_click_on_inventory_item"))
|
||||
|
||||
assert(current_scene.game.has_method("inventory_item_focused"))
|
||||
assert(current_scene.game.has_method("inventory_item_unfocused"))
|
||||
|
||||
@@ -68,16 +68,18 @@ func set_target(p_target, p_speed : float = 0.0):
|
||||
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera.gd:set_target()", ["Tween still active running camera_set_target: " + tweenstat])
|
||||
escoria.report_warnings("camera.gd:set_target()",
|
||||
["Tween still active running camera_set_target: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position, target_pos, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position,
|
||||
target_pos, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
tween.start()
|
||||
|
||||
func set_camera_zoom(p_zoom_level, p_time):
|
||||
if p_zoom_level <= 0.0:
|
||||
escoria.report_errors("camera.gd:set_camera_zoom()", ["Tried to set negative or zero zoom level"])
|
||||
escoria.report_errors("camera.gd:set_camera_zoom()",
|
||||
["Tried to set negative or zero zoom level"])
|
||||
|
||||
zoom_time = p_time
|
||||
zoom_target = Vector2(1, 1) * p_zoom_level
|
||||
@@ -87,13 +89,15 @@ func set_camera_zoom(p_zoom_level, p_time):
|
||||
else:
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera", ["Tween still active running camera_set_zoom: " + tweenstat])
|
||||
escoria.report_warnings("camera",
|
||||
["Tween still active running camera_set_zoom: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
tween.interpolate_property(self, "zoom", self.zoom, zoom_target, zoom_time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
|
||||
tween.interpolate_property(self, "zoom", self.zoom, zoom_target,
|
||||
zoom_time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
tween.start()
|
||||
|
||||
|
||||
func push(p_target, p_time, p_type):
|
||||
var time = float(p_time)
|
||||
var type = "TRANS_" + p_type
|
||||
@@ -116,16 +120,19 @@ func push(p_target, p_time, p_type):
|
||||
else:
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera", ["Tween still active running camera_push: " + tweenstat])
|
||||
escoria.report_warnings("camera",
|
||||
["Tween still active running camera_push: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
if camera_pos and camera_pos is Camera2D:
|
||||
tween.interpolate_property(self, "zoom", self.zoom, camera_pos.zoom, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position, camera_pos_coords, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
tween.interpolate_property(self, "zoom", self.zoom, camera_pos.zoom,
|
||||
time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position,
|
||||
camera_pos_coords, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
tween.start()
|
||||
|
||||
|
||||
func shift(p_x, p_y, p_time, p_type):
|
||||
var x = int(p_x)
|
||||
var y = int(p_y)
|
||||
@@ -133,21 +140,23 @@ func shift(p_x, p_y, p_time, p_type):
|
||||
var type = "TRANS_" + p_type
|
||||
|
||||
var new_pos = self.global_position + Vector2(x, y)
|
||||
|
||||
target = new_pos
|
||||
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera", ["Tween still active running camera_shift: " + tweenstat])
|
||||
escoria.report_warnings("camera",
|
||||
["Tween still active running camera_shift: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position, new_pos, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position,
|
||||
new_pos, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
tween.start()
|
||||
|
||||
|
||||
func target_reached(_obj=null, _key=null):
|
||||
tween.stop_all()
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
zoom_transform = self.get_canvas_transform()
|
||||
|
||||
|
||||
@@ -4,17 +4,19 @@ class_name ESCInventory
|
||||
func get_class():
|
||||
return "ESCInventory"
|
||||
|
||||
"""
|
||||
This script is set on the inventory UI scene's root node.
|
||||
The scene MUST contain the 2 following nodes:
|
||||
- one node named "ESCORIA_ALL_ITEMS" containing ALL ESCItems of the game. This is required
|
||||
to be able to get the ESCInventoryItem for a given ESCItem.
|
||||
- one Container node (under Control type) that will contain the inventory items.
|
||||
It must be set in the "items_container" export variable.
|
||||
"""
|
||||
|
||||
|
||||
# Define the actual container node to add items as children of. Should be a Container.
|
||||
export(NodePath) var items_container
|
||||
onready var all_items = $all_items
|
||||
|
||||
# Methods available for selecting an item
|
||||
enum ITEM_SELECTION_METHODS {
|
||||
VERB_ACTION, # Use a verb action, such as use or give, on inventory item
|
||||
ONE_CLICK, # One click on inventory item selects it (eventually put it on cursor)
|
||||
DRAG_N_DROP # (Useful for mobile) Drag n drop item on another or on background to use/give it
|
||||
}
|
||||
export(ITEM_SELECTION_METHODS) var selection_method
|
||||
onready var all_items = $ESCORIA_ALL_ITEMS
|
||||
|
||||
var items_ids_in_inventory : Dictionary = {} # { item_id : TextureButton}
|
||||
|
||||
@@ -52,7 +54,6 @@ func add_new_item_by_id(item_id : String) -> void:
|
||||
escoria.esc_runner.register_object(item_id, item_inventory_button)
|
||||
item_inventory_button.visible = true
|
||||
|
||||
# connect this new item TextureButton's signals to our inventory UI
|
||||
item_inventory_button.connect("mouse_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_left_click_inventory_item")
|
||||
item_inventory_button.connect("mouse_double_left_inventory_item",
|
||||
|
||||
Reference in New Issue
Block a user