cc5f205a7e
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
976 B
GDScript
43 lines
976 B
GDScript
## SnapPoint — attachment position on furniture where a Character can snap into a pose.
|
|
## Add to any furniture node. The node auto-registers in the "snap_points" group on _ready.
|
|
class_name SnapPoint extends Node2D
|
|
|
|
signal character_snapped(character: Character)
|
|
signal character_unsnapped(character: Character)
|
|
|
|
@export var pose: String = "sitting"
|
|
@export var baby_only: bool = false
|
|
|
|
var occupant: Character = null
|
|
|
|
|
|
func _ready() -> void:
|
|
add_to_group("snap_points")
|
|
|
|
|
|
func is_free() -> bool:
|
|
return occupant == null
|
|
|
|
|
|
func accepts(character: Character) -> bool:
|
|
if not is_free():
|
|
return false
|
|
if not baby_only:
|
|
return true
|
|
if character.data == null:
|
|
return false
|
|
return character.data.state == CharacterData.State.BABY
|
|
|
|
|
|
func snap(character: Character) -> void:
|
|
occupant = character
|
|
character_snapped.emit(character)
|
|
|
|
|
|
func unsnap() -> void:
|
|
if occupant == null:
|
|
return
|
|
var prev: Character = occupant
|
|
occupant = null
|
|
character_unsnapped.emit(prev)
|