import {
  Game,
  TouchSprite,
  RandomInt,
  Between,
  MyLabel,
  blinkItem,
  stopBlinkItem,
  asyncDelayTime,
  asyncTweenChange,
} from './Game';

import {
  Label,
  jelly,
  showPopParticle,
  tweenChange,
  rotateItem,
  scaleItem,
  delayCall,
  hideItem,
  showItem,
  moveItem,
  shake,
  ShapeRect,
} from './../Unit';

import TWEEN from '@tweenjs/tween.js';

import { defaultData } from './DefaultData';


export class MyGame extends Game {

  images = null;

  data = null;
  status = null;

  initData(data) {
    this.images = data.images;

    this.status = {};

    if (!data.data || Object.is(data.data, {}) || !data.data.tittle) {
      this.data = defaultData;
    } else {
      this.data = data.data;

      let imgUrlList = [];
      let audioUrlList = [];

      // imgUrlList.push(...this.data.bottomLineCards.map(card => card.img));
      // audioUrlList.push(this.data.tittle.audio);

      imgUrlList = imgUrlList.filter((data) => data != null && data != '');
      audioUrlList = audioUrlList.filter((data) => data != null && data != '');

      this.preLoadData(imgUrlList, audioUrlList);
    }
  }

  preLoadData(imgUrlList, audioUrlList) {
    imgUrlList.forEach((data) => {
      this._parent.addUrlToImages(data);
    });
    audioUrlList.forEach((data) => {
      this._parent.addUrlToAudioObj(data);
    });
  }

  initView() {
    // 初始化标题
    this.initTittle();

    // 初始化中间部分
    this.initMiddle();
  }

  initBg() {

  }

  initTittle() {
    console.log('汪汪汪 ')
    const titleBg = new TouchSprite();
    titleBg.init(this.images.get('img_title_bg'));
    this.addChild(titleBg);
    // titleBg.x = this.getFullScaleXY();
    // titleBg.y = titleBg.height / 2 * this.mapScale;
    // titleBg.setScaleXY(this.mapScale);
    // this.renderArr.push(titleBg);

    // const titleLetter = new Label(this.ctx);
    // titleLetter.x = titleBg.width * 1 / 8;
    // titleLetter.y = 0;
    // titleLetter.fontSize = 48;
    // titleLetter.fontColor = "#facf46";
    // titleLetter.fontName = 'BerlinSansFBDemi';
    // titleLetter.anchorX = 0;
    // titleLetter.anchorY = 0.5;
    // titleLetter.text = this.data.titleLetter;
    // titleBg.addChild(titleLetter);

    // const titleLabel = new Label(this.ctx);
    // titleLabel.x = titleBg.width * 5 / 8;
    // titleLabel.y = 0;
    // titleLabel.fontSize = 36;
    // titleLabel.fontColor = "#000000";
    // titleLabel.fontName = 'FuturaStd';
    // titleLabel.anchorX = 0;
    // titleLabel.anchorY = 0.5;
    // titleLabel.text = this.data.title;
    // titleBg.addChild(titleLabel);
  }

  initMiddle() {
    // const bg = new MySprite(this.ctx, this.images.get('img_grey_bg'));
    // bg.x = this.canvasWidth / 2;
    // bg.y = this.canvasHeight / 2;
    // bg.setScaleXY(this.mapScale);
    // bg.alpha = 0.5;
    // this.renderArr.push(bg);
    // this.bg = bg;
  }
}
