Add ESCAnimationResource to hold characters animations. (#342)
Co-authored-by: StraToN <StraToN@users.noreply.github.com> Co-authored-by: Dennis Ploeger <develop@dieploegers.de> Co-authored-by: dploeger <dploeger@users.noreply.github.com>
This commit is contained in:
@@ -113,7 +113,7 @@ func _process(delta: float) -> void:
|
||||
current_animation = parent.animation_sprite.animation
|
||||
|
||||
var animation_to_play = \
|
||||
parent.animations.directions[last_dir][0]
|
||||
parent.animations.directions[last_dir].animation
|
||||
if current_animation != animation_to_play:
|
||||
if parent.animation_sprite.frames.has_animation(
|
||||
animation_to_play
|
||||
@@ -132,7 +132,8 @@ func _process(delta: float) -> void:
|
||||
true
|
||||
)
|
||||
|
||||
pose_scale = parent.animations.directions[last_dir][1]
|
||||
pose_scale = -1 if parent.animations.directions[last_dir].mirrored \
|
||||
else 1
|
||||
|
||||
update_terrain()
|
||||
else:
|
||||
@@ -242,12 +243,12 @@ func walk_stop(pos: Vector2) -> void:
|
||||
var orientation = walk_context.target_object.node.interaction_direction
|
||||
last_dir = orientation
|
||||
parent.animation_sprite.play(
|
||||
parent.animations.idles[orientation][0]
|
||||
parent.animations.idles[orientation].animation
|
||||
)
|
||||
pose_scale = parent.animations.idles[orientation][1]
|
||||
pose_scale = -1 if parent.animations.idles[orientation].mirrored else 1
|
||||
else:
|
||||
parent.animation_sprite.play(parent.animations.idles[last_dir][0])
|
||||
pose_scale = parent.animations.idles[last_dir][1]
|
||||
parent.animation_sprite.play(parent.animations.idles[last_dir].animation)
|
||||
pose_scale = -1 if parent.animations.idles[last_dir].mirrored else 1
|
||||
|
||||
update_terrain()
|
||||
|
||||
@@ -316,15 +317,15 @@ func update_terrain(on_event_finished_name = null) -> void:
|
||||
#
|
||||
# - deg: Degrees
|
||||
# - animations: Player animations script
|
||||
func _get_dir_deg(deg: int, animations: Script) -> int:
|
||||
func _get_dir_deg(deg: int, animations: ESCAnimationResource) -> int:
|
||||
# We turn the angle by -90° because angle_to_point gives the angle
|
||||
# against X axis, not Y
|
||||
deg = wrapi(deg - 90, 0, 360)
|
||||
var dir = -1
|
||||
var i = 0
|
||||
|
||||
for arr_angle_zone in animations.dir_angles:
|
||||
if is_angle_in_interval(deg, arr_angle_zone):
|
||||
for direction_angle in animations.dir_angles:
|
||||
if is_angle_in_interval(deg, direction_angle):
|
||||
dir = i
|
||||
break
|
||||
else:
|
||||
@@ -347,22 +348,23 @@ func _get_dir_deg(deg: int, animations: Script) -> int:
|
||||
# #### Parameters
|
||||
#
|
||||
# - angle: Angle to test
|
||||
# - interval: Array of size 2, containing the starting angle, and the size of
|
||||
# interval
|
||||
# eg: [90, 40] corresponds to angle between 90° and 130°
|
||||
func is_angle_in_interval(angle: float, interval: Array) -> bool:
|
||||
# - direction_angle: ESCDirectionAngle resource, containing the starting angle,
|
||||
# and the size of interval
|
||||
# eg: angle_start=90, angle_size=40 corresponds to angle between 90° and 130°
|
||||
func is_angle_in_interval(angle: float, direction_angle: ESCDirectionAngle) -> bool:
|
||||
angle = wrapi(angle, 0, 360)
|
||||
if angle == 0:
|
||||
angle = 360
|
||||
var start_angle = wrapi(interval[0], 0, 360)
|
||||
var angle_area = interval[1]
|
||||
var end_angle = wrapi(interval[0] + angle_area, 0, 360)
|
||||
var start_angle = wrapi(direction_angle.angle_start, 0, 360)
|
||||
var angle_area = direction_angle.angle_size
|
||||
var end_angle = wrapi(direction_angle.angle_start + angle_area, 0, 360)
|
||||
|
||||
if ((angle >= 270 and angle <= 360) \
|
||||
or (angle >= 0 and angle <= 90)) \
|
||||
and wrapi(angle + 180, 0, 360) > wrapi(interval[0] + 180, 0, 360) \
|
||||
and wrapi(angle + 180, 0, 360) > wrapi(direction_angle.angle_start
|
||||
+ 180, 0, 360) \
|
||||
and wrapi(angle + 180, 0, 360) <= wrapi(
|
||||
interval[0] + angle_area + 180, 0, 360
|
||||
direction_angle.angle_start + angle_area + 180, 0, 360
|
||||
):
|
||||
return true
|
||||
elif wrapi(angle, 0, 360) > start_angle \
|
||||
@@ -392,12 +394,12 @@ func set_angle(deg: int, immediate = true) -> void:
|
||||
# The character may have a state animation from before, which would be
|
||||
# resumed, so we immediately force the correct idle animation
|
||||
if parent.animation_sprite.animation != \
|
||||
parent.animations.idles[last_dir][0]:
|
||||
parent.animation_sprite.play(parent.animations.idles[last_dir][0])
|
||||
pose_scale = parent.animations.idles[last_dir][1]
|
||||
parent.animations.idles[last_dir].animation:
|
||||
parent.animation_sprite.play(parent.animations.idles[last_dir].animation)
|
||||
pose_scale = -1 if parent.animations.idles[last_dir].mirrored else 1
|
||||
update_terrain()
|
||||
|
||||
# Returns the angle that corresponds to the current direction of the object.
|
||||
func _get_angle() -> int:
|
||||
return parent.animations.dir_angles[last_dir][0]
|
||||
return parent.animations.dir_angles[last_dir].animation
|
||||
|
||||
|
||||
@@ -120,8 +120,8 @@ export(int) var speed: int = 300
|
||||
# Speed damp of this item if movable
|
||||
export(float) var v_speed_damp: float = 1.0
|
||||
|
||||
# Animations script (for walking, idling...)
|
||||
export(Script) var animations
|
||||
# ESCAnimationsResource (for walking, idling...)
|
||||
var animations: ESCAnimationResource
|
||||
|
||||
# The movable subnode
|
||||
var _movable: ESCMovable = null
|
||||
@@ -369,5 +369,14 @@ func _get_inventory_item() -> ESCInventoryItem:
|
||||
inventory_item = inventory_item_scene_file.instance()
|
||||
inventory_item.global_id = self.global_id
|
||||
return inventory_item
|
||||
|
||||
|
||||
|
||||
func _get_property_list():
|
||||
var properties = []
|
||||
properties.append({
|
||||
"name": "animations",
|
||||
"type": TYPE_OBJECT,
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "ESCAnimationResource"
|
||||
})
|
||||
return properties
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Class defining an animation to use for an angle.
|
||||
tool
|
||||
extends Resource
|
||||
class_name ESCAnimationName
|
||||
|
||||
# Name of the animation
|
||||
export(String) var animation: String
|
||||
|
||||
# Animation mirror (false is no mirror, true is mirrored)
|
||||
export(bool) var mirrored: bool
|
||||
@@ -0,0 +1,58 @@
|
||||
# Resource containing all defined animations and angles for
|
||||
# characters movement.
|
||||
tool
|
||||
extends Resource
|
||||
class_name ESCAnimationResource
|
||||
|
||||
|
||||
# Array containing the different angles available for animations.
|
||||
# Each angle is defined by an array [start_angle, angle_size].
|
||||
# start_angle must be between 0 and 360.
|
||||
# Angle 0 and 360 are the same and correspond to UP/NORTH
|
||||
# 90 is RIGHT/EAST, 180 is DOWN/SOUTH, etc
|
||||
var dir_angles: Array = []
|
||||
|
||||
# Array of animations for each direction, from UP to RIGHT_UP clockwise
|
||||
# [animation_name, scale]: scale parameter can be set to -1 to mirror
|
||||
# the animation
|
||||
var directions: Array = []
|
||||
|
||||
|
||||
# Array containing the idle animations for each direction (in the
|
||||
# order defined by dir_angles): scale parameter can be set to -1 to mirror
|
||||
# the animation
|
||||
var idles: Array = []
|
||||
|
||||
# Array containing the speak animations for each direction (in the
|
||||
# order defined by dir_angles): scale parameter can be set to -1 to mirror
|
||||
# the animation
|
||||
var speaks: Array = []
|
||||
|
||||
|
||||
func _get_property_list():
|
||||
var properties = []
|
||||
properties.append({
|
||||
"name": "dir_angles",
|
||||
"type": TYPE_ARRAY,
|
||||
"hint": 19,
|
||||
"hint_string": "17/17:ESCDirectionAngle"
|
||||
})
|
||||
properties.append({
|
||||
"name": "directions",
|
||||
"type": TYPE_ARRAY,
|
||||
"hint": 19,
|
||||
"hint_string": "17/17:ESCAnimationName"
|
||||
})
|
||||
properties.append({
|
||||
"name": "idles",
|
||||
"type": TYPE_ARRAY,
|
||||
"hint": 19,
|
||||
"hint_string": "17/17:ESCAnimationName"
|
||||
})
|
||||
properties.append({
|
||||
"name": "speaks",
|
||||
"type": TYPE_ARRAY,
|
||||
"hint": 19,
|
||||
"hint_string": "17/17:ESCAnimationName"
|
||||
})
|
||||
return properties
|
||||
@@ -0,0 +1,11 @@
|
||||
# Class defining an angle, with a start angle (between 0 and 360) and a size.
|
||||
tool
|
||||
extends Resource
|
||||
class_name ESCDirectionAngle
|
||||
|
||||
|
||||
# Start angle of the directional angle.
|
||||
export(int) var angle_start: int
|
||||
|
||||
# Size of the angle
|
||||
export(int) var angle_size: int
|
||||
Reference in New Issue
Block a user