import LocalStorage from "../Data/LocalStorage";
import Hive from "../Objects/Hive";

const { ccclass, property } = cc._decorator;

@ccclass
export default class StageController extends cc.Component {
  @property(Array(cc.Node)) dogList: Array<cc.Node> = new Array<cc.Node>();
  @property(Array(cc.Node)) hiveList: Array<cc.Node> = new Array<cc.Node>();
  @property(Array(cc.Node)) blockedObjects: Array<cc.Node> =
    new Array<cc.Node>();

  static instance: StageController;
  currentSkin: string;

  protected onLoad(): void {
    StageController.instance = this;
    this.currentSkin = LocalStorage.getCurrentSkinPlayer();
  }

  onHunting() {
    for (let i = 0; i < this.hiveList.length; i++) {
      let hive = this.hiveList[i];
      hive.getComponent(Hive).isSpawnable = true;
    }
    for (let i = 0; i < this.dogList.length; i++) {
      let dog = this.dogList[i];
      dog.getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
      if (this.currentSkin == "Dog")
        dog.getComponent(cc.Animation).play("DogScare");
    }
  }

  onCompleted() {
    for (let i = 0; i < this.dogList.length; i++) {
      let dog = this.dogList[i];
      dog.getComponent(cc.Animation).play(`${this.currentSkin}Idle`);
    }
  }
}
