feat(sprint-14): add GiftBox RESETTING auto-reset state
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
## GiftBox — tap while closed to open: lid rises and fades out, gift inside fades in.
|
||||
## Auto-resets after RESET_DELAY seconds.
|
||||
class_name GiftBox extends Node2D
|
||||
|
||||
enum State { CLOSED, OPENING, OPEN }
|
||||
enum State { CLOSED, OPENING, RESETTING }
|
||||
|
||||
const LID_OPEN_Y: float = -120.0
|
||||
const CLOSED_LID_Y: float = -60.0
|
||||
const OPEN_DURATION: float = 0.5
|
||||
const GIFT_FADE_DURATION: float = 0.4
|
||||
const RESET_DELAY: float = 3.0
|
||||
const BUTTON_HALF_WIDTH: float = 40.0
|
||||
const BUTTON_HALF_HEIGHT: float = 50.0
|
||||
|
||||
@@ -37,7 +40,7 @@ func _start_opening() -> void:
|
||||
_state = State.OPENING
|
||||
var lid: Node2D = get_node_or_null("Lid") as Node2D
|
||||
if lid == null:
|
||||
_state = State.OPEN
|
||||
_on_lid_opened()
|
||||
return
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
@@ -48,9 +51,26 @@ func _start_opening() -> void:
|
||||
|
||||
|
||||
func _on_lid_opened() -> void:
|
||||
_state = State.OPEN
|
||||
_state = State.RESETTING
|
||||
var gift: Node2D = get_node_or_null("Gift") as Node2D
|
||||
if gift == null:
|
||||
return
|
||||
var tween: Tween = create_tween()
|
||||
tween.tween_property(gift, "modulate:a", 1.0, GIFT_FADE_DURATION)
|
||||
if gift != null:
|
||||
tween.tween_property(gift, "modulate:a", 1.0, GIFT_FADE_DURATION)
|
||||
tween.tween_interval(RESET_DELAY)
|
||||
tween.tween_callback(_start_close_lid)
|
||||
|
||||
|
||||
func _start_close_lid() -> void:
|
||||
var lid: Node2D = get_node_or_null("Lid") as Node2D
|
||||
var gift: Node2D = get_node_or_null("Gift") as Node2D
|
||||
var tween: Tween = create_tween().set_parallel(true)
|
||||
if lid != null:
|
||||
tween.tween_property(lid, "position:y", CLOSED_LID_Y, OPEN_DURATION)
|
||||
tween.tween_property(lid, "modulate:a", 1.0, OPEN_DURATION)
|
||||
if gift != null:
|
||||
tween.tween_property(gift, "modulate:a", 0.0, OPEN_DURATION)
|
||||
tween.finished.connect(_on_reset_complete)
|
||||
|
||||
|
||||
func _on_reset_complete() -> void:
|
||||
_state = State.CLOSED
|
||||
|
||||
Reference in New Issue
Block a user