Removed hardcoded access to node named "sprite" (#364)
This commit is contained in:
@@ -301,13 +301,15 @@ func update_terrain(on_event_finished_name = null) -> void:
|
||||
var color = parent.terrain.get_light(pos)
|
||||
parent.modulate = color
|
||||
|
||||
var sprite: Node = parent.get_sprite()
|
||||
|
||||
# Do not flip the entire character, because that would conflict
|
||||
# with shadows that expect to be siblings of $texture
|
||||
if pose_scale == -1 and parent.get_node("sprite").scale.x > 0:
|
||||
parent.get_node("sprite").scale.x *= pose_scale
|
||||
if pose_scale == -1 and sprite.scale.x > 0:
|
||||
sprite.scale.x *= pose_scale
|
||||
parent.collision.scale.x *= pose_scale
|
||||
elif pose_scale == 1 and parent.get_node("sprite").scale.x < 0:
|
||||
parent.get_node("sprite").scale.x *= -1
|
||||
elif pose_scale == 1 and sprite.scale.x < 0:
|
||||
sprite.scale.x *= -1
|
||||
parent.collision.scale.x *= -1
|
||||
|
||||
|
||||
|
||||
@@ -127,6 +127,12 @@ export(NodePath) var animation_player_node: NodePath = "" \
|
||||
# ESCAnimationsResource (for walking, idling...)
|
||||
var animations: ESCAnimationResource
|
||||
|
||||
# Reference to the animation node (null if none was found)
|
||||
var animation_sprite = null
|
||||
|
||||
# Reference to the sprite node
|
||||
var _sprite_node: Node = null
|
||||
|
||||
# Reference to the current terrain
|
||||
var terrain: ESCTerrain
|
||||
|
||||
@@ -331,6 +337,19 @@ func has_moved() -> bool:
|
||||
return _movable.moved if is_movable else false
|
||||
|
||||
|
||||
# Return the sprite node
|
||||
func get_sprite() -> Node:
|
||||
if _sprite_node == null:
|
||||
for child in self.get_children():
|
||||
if child is AnimatedSprite or child is Sprite:
|
||||
_sprite_node = child
|
||||
if _sprite_node == null:
|
||||
escoria.logger.error(
|
||||
"No sprite node found in the scene %s" % get_path()
|
||||
)
|
||||
return _sprite_node
|
||||
|
||||
|
||||
# Set the angle
|
||||
#
|
||||
# #### Parameters
|
||||
|
||||
@@ -87,9 +87,9 @@ func left_click_on_inventory_item(inventory_item_global_id: String, event: Input
|
||||
var item = escoria.object_manager.get_object(
|
||||
inventory_item_global_id
|
||||
).node
|
||||
if item.get_node("sprite").texture:
|
||||
if item.has_method("get_sprite") and item.get_sprite().texture:
|
||||
$ui/verbs_layer/verbs_menu.set_tool_texture(
|
||||
item.get_node("sprite").texture
|
||||
item.get_sprite().texture
|
||||
)
|
||||
elif item.inventory_item.texture_normal:
|
||||
$ui/verbs_layer/verbs_menu.set_tool_texture(
|
||||
|
||||
@@ -336,6 +336,14 @@ func has_moved() -> bool
|
||||
|
||||
Check wether this item moved
|
||||
|
||||
### get\_sprite
|
||||
|
||||
```gdscript
|
||||
func get_sprite() -> Node
|
||||
```
|
||||
|
||||
Return the sprite node
|
||||
|
||||
### set\_angle
|
||||
|
||||
```gdscript
|
||||
|
||||
Reference in New Issue
Block a user