import { AutoDestroy } from "./common/AutoDestroy"

const { regClass, property } = Laya

@regClass()
export class ScoreAdd extends Laya.Script {
  declare owner: Laya.Box

  @property(Laya.Label)
  public label: Laya.Label

  onAwake(): void {
    this.label.scaleX = 0
    this.label.scaleY = 0

    const d = this.owner.getComponent(AutoDestroy)
    d.lifeTime = 2
  }

  onStart(): void {
    Laya.Tween.to(this.label, { scaleX: 1, scaleY: 1 }, 300, Laya.Ease.bounceIn, null, 0)

    Laya.Tween.to(this.label, { y: -102 }, 300, Laya.Ease.linearOut, null, 500)

    Laya.Tween.to(this.label, { alpha: 0 }, 300, Laya.Ease.linearOut, null, 500)
  }

  public onSetText(text: string): void {
    this.label.text = text
  }
}
