feat(character): add hand slot API (attach/detach/get_held_item/is_hand_free)
This commit is contained in:
@@ -87,6 +87,49 @@ func get_outfit(layer: int) -> String:
|
||||
return data.outfit[layer - 1]
|
||||
|
||||
|
||||
func attach_item(hand: String, item: Node2D) -> bool:
|
||||
if hand != "left" and hand != "right":
|
||||
return false
|
||||
var slot: Node2D = get_node_or_null("Hand" + hand.capitalize()) as Node2D
|
||||
if slot == null:
|
||||
return false
|
||||
if slot.get_child_count() > 0:
|
||||
return false
|
||||
var old_parent: Node = item.get_parent()
|
||||
if old_parent != null:
|
||||
old_parent.remove_child(item)
|
||||
slot.add_child(item)
|
||||
item.position = Vector2.ZERO
|
||||
return true
|
||||
|
||||
|
||||
func detach_item(hand: String) -> Node2D:
|
||||
if hand != "left" and hand != "right":
|
||||
return null
|
||||
var slot: Node2D = get_node_or_null("Hand" + hand.capitalize()) as Node2D
|
||||
if slot == null or slot.get_child_count() == 0:
|
||||
return null
|
||||
var item: Node2D = slot.get_child(0) as Node2D
|
||||
slot.remove_child(item)
|
||||
var scene_parent: Node = get_parent()
|
||||
if scene_parent != null:
|
||||
scene_parent.add_child(item)
|
||||
return item
|
||||
|
||||
|
||||
func get_held_item(hand: String) -> Node2D:
|
||||
if hand != "left" and hand != "right":
|
||||
return null
|
||||
var slot: Node2D = get_node_or_null("Hand" + hand.capitalize()) as Node2D
|
||||
if slot == null or slot.get_child_count() == 0:
|
||||
return null
|
||||
return slot.get_child(0) as Node2D
|
||||
|
||||
|
||||
func is_hand_free(hand: String) -> bool:
|
||||
return get_held_item(hand) == null
|
||||
|
||||
|
||||
func _update_visual_state() -> void:
|
||||
if data == null:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user