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)
|
var color = parent.terrain.get_light(pos)
|
||||||
parent.modulate = color
|
parent.modulate = color
|
||||||
|
|
||||||
|
var sprite: Node = parent.get_sprite()
|
||||||
|
|
||||||
# Do not flip the entire character, because that would conflict
|
# Do not flip the entire character, because that would conflict
|
||||||
# with shadows that expect to be siblings of $texture
|
# with shadows that expect to be siblings of $texture
|
||||||
if pose_scale == -1 and parent.get_node("sprite").scale.x > 0:
|
if pose_scale == -1 and sprite.scale.x > 0:
|
||||||
parent.get_node("sprite").scale.x *= pose_scale
|
sprite.scale.x *= pose_scale
|
||||||
parent.collision.scale.x *= pose_scale
|
parent.collision.scale.x *= pose_scale
|
||||||
elif pose_scale == 1 and parent.get_node("sprite").scale.x < 0:
|
elif pose_scale == 1 and sprite.scale.x < 0:
|
||||||
parent.get_node("sprite").scale.x *= -1
|
sprite.scale.x *= -1
|
||||||
parent.collision.scale.x *= -1
|
parent.collision.scale.x *= -1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,12 @@ export(NodePath) var animation_player_node: NodePath = "" \
|
|||||||
# ESCAnimationsResource (for walking, idling...)
|
# ESCAnimationsResource (for walking, idling...)
|
||||||
var animations: ESCAnimationResource
|
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
|
# Reference to the current terrain
|
||||||
var terrain: ESCTerrain
|
var terrain: ESCTerrain
|
||||||
|
|
||||||
@@ -331,6 +337,19 @@ func has_moved() -> bool:
|
|||||||
return _movable.moved if is_movable else false
|
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
|
# Set the angle
|
||||||
#
|
#
|
||||||
# #### Parameters
|
# #### 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(
|
var item = escoria.object_manager.get_object(
|
||||||
inventory_item_global_id
|
inventory_item_global_id
|
||||||
).node
|
).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(
|
$ui/verbs_layer/verbs_menu.set_tool_texture(
|
||||||
item.get_node("sprite").texture
|
item.get_sprite().texture
|
||||||
)
|
)
|
||||||
elif item.inventory_item.texture_normal:
|
elif item.inventory_item.texture_normal:
|
||||||
$ui/verbs_layer/verbs_menu.set_tool_texture(
|
$ui/verbs_layer/verbs_menu.set_tool_texture(
|
||||||
|
|||||||
@@ -336,6 +336,14 @@ func has_moved() -> bool
|
|||||||
|
|
||||||
Check wether this item moved
|
Check wether this item moved
|
||||||
|
|
||||||
|
### get\_sprite
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func get_sprite() -> Node
|
||||||
|
```
|
||||||
|
|
||||||
|
Return the sprite node
|
||||||
|
|
||||||
### set\_angle
|
### set\_angle
|
||||||
|
|
||||||
```gdscript
|
```gdscript
|
||||||
|
|||||||
Reference in New Issue
Block a user