import { RandomInt, asyncDelay } from "../script/JJ_Game_09_util";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

  @property
  type: string = "1"; // 1: 代表亮；2: 代表暗
  @property
  min: number = 3;
  @property
  max: number = 20;

  basePos: cc.Vec2;

  async start() {
  }
  async onEnable() {
    if (this.min == -1) {
      // 代表常亮, 按周期缩放就行
      this.scaleStar();
    } else {
      await this.float();
    }
  }

  scaleStar() {
    cc.tween(this.node)
    .by(.5, { scale: -0.07 }, { easing: 'sineInOut' })
    .to(.5, { scale: 1 }, { easing: 'sineInOut' })
    .union()
    .repeatForever()
    .start();
  }

  async float() {
    const delay = RandomInt(this.min, this.max);
    await asyncDelay(delay);
    cc.tween(this.node)
      .to(.5, { scale: this.type == "1" ? 0 : 1 }, { easing: 'sineInOut' })
      .to(.5, { scale: this.type == "1" ? 1 : 0 }, { easing: 'sineInOut' })
      .call(async () => {
        await this.float();
      })
      .start();
  }
}
