Initial Commit
This commit is contained in:
commit
48a5e71e00
1136 changed files with 64347 additions and 0 deletions
93
ChatAvatars/CatSlimes/chat_avatar.gd
Normal file
93
ChatAvatars/CatSlimes/chat_avatar.gd
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
@tool
|
||||
extends CharacterBody2D
|
||||
class_name CatSlimeAvatar
|
||||
|
||||
@export var skin: SpriteFrames:
|
||||
set(value):
|
||||
skin = value
|
||||
if visual:
|
||||
visual.sprite_frames = skin
|
||||
|
||||
@export var avatar_name: String = "Twitch User":
|
||||
set(value):
|
||||
avatar_name = value
|
||||
if display_name:
|
||||
display_name.text = value
|
||||
_resize_collision()
|
||||
|
||||
@onready var visual: AnimatedSprite2D = %Visual
|
||||
@onready var display_name: Label = %DisplayName
|
||||
@onready var state_machine: StateMachine = %StateMachine
|
||||
@onready var overlap: Area2D = %Overlap
|
||||
@onready var overlap_collision: CollisionShape2D = %OverlapCollision
|
||||
|
||||
var is_gravity_disabled: bool = false
|
||||
var _overlapping: Array[Node] = []
|
||||
var _hide_tween: Tween
|
||||
var _show_tween: Tween
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
visual.animation_changed.connect(_handle_animation_changed)
|
||||
overlap.area_entered.connect(_handle_overlap_entered)
|
||||
overlap.area_exited.connect(_handle_overlap_exited)
|
||||
|
||||
visual.sprite_frames = skin
|
||||
display_name.text = avatar_name
|
||||
_resize_collision()
|
||||
|
||||
func _handle_animation_changed() -> void:
|
||||
if visual.animation == &"sleep":
|
||||
visual.offset = Vector2(16,-16)
|
||||
else:
|
||||
visual.offset = Vector2.ZERO
|
||||
|
||||
func _handle_overlap_entered(node: Node) -> void:
|
||||
_overlapping.append(node)
|
||||
|
||||
func _handle_overlap_exited(node: Node) -> void:
|
||||
_overlapping.erase(node)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if _overlapping.size() > 0: # Overlapping
|
||||
if _hide_tween: return # Tween in progress
|
||||
if display_name.modulate.a == 0.0: return # Display name is already hidden.
|
||||
if _show_tween: # Show Tween is running, stop it, and clear it out.
|
||||
_show_tween.kill()
|
||||
_show_tween = null
|
||||
_hide_tween = create_tween()
|
||||
_hide_tween.tween_property(display_name, "modulate:a", 0.0, 0.5)
|
||||
_hide_tween.tween_callback(func(): _hide_tween = null)
|
||||
else: # Not Overlapping
|
||||
if _show_tween: return # Tween in progress
|
||||
if display_name.modulate.a == 1.0: return # Display name is shown.
|
||||
if _hide_tween: # Hide Tween is running, stop it, and clear it out.
|
||||
_hide_tween.kill()
|
||||
_hide_tween = null
|
||||
_show_tween = create_tween()
|
||||
_show_tween.tween_property(display_name, "modulate:a", 1.0, 0.5)
|
||||
_show_tween.tween_callback(func(): _show_tween = null)
|
||||
pass
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
if is_gravity_disabled:
|
||||
velocity.y = 0
|
||||
else:
|
||||
velocity.y += get_gravity().y * delta
|
||||
move_and_slide()
|
||||
|
||||
if state_machine.current_state.name.to_lower() != "born":
|
||||
if velocity.length() > 0 and visual.animation != &"walk":
|
||||
visual.play(&"walk")
|
||||
elif velocity.length() == 0 and visual.animation != &"idle":
|
||||
visual.play(&"idle")
|
||||
|
||||
visual.flip_h = velocity.x < 0
|
||||
|
||||
func _resize_collision() -> void:
|
||||
await get_tree().process_frame
|
||||
var lsize = display_name.size
|
||||
overlap_collision.shape.size.x = lsize.x
|
||||
Loading…
Add table
Add a link
Reference in a new issue