"use strict";
cc._RF.push(module, '91e03UgqK1DF6kUGFDm5kkm', 'data_mgr');
// Lwd/script/manager/data_mgr.js

"use strict";

/**
 * 数据管理器
 */
lwd_g.data_mgr = {
  nowNode: null,
  //当前点击节点
  playId: null,
  //播放id
  playType: null,
  //播放类型
  itemInfo: null,
  //已经答对的节点
  temPlayAudio: [],
  //临时的播放列表
  data: null,
  //表所有数据
  pageId: 0,
  //页id
  dragonName: null,
  //龙骨动画名字
  lineColor: ['#2AFF51', '#FF0000', '#FF51E0', '#E5FB31', '#43DFEF', '#FFC788', ' #FFFFFF', ' #FF7474'],
  //线的颜色
  _imageResList: [],
  //图片资源列表
  _audioResList: [],
  //音频资源列表
  _animaResList: [],
  //动画资源列表
  //获得默认数据
  getDefaultData: function getDefaultData() {
    var dataJson = {};
    var data = {
      "contentObj": {
        "pageArr": [{
          "pageInfo": [{
            "a_pic_url": "http://staging-teach.cdn.ireadabc.com/f6f4bbef497409fef3c8f1d375893829.png",
            "b_pic_url": "http://staging-teach.cdn.ireadabc.com/7b18a7931d64f7b9e8b7ecd25cb5e3d4.png",
            "a_audio_url": "http://staging-teach.cdn.ireadabc.com/5285e1e88a26a08783757e9c43a8653f.mp3",
            "b_audio_url": "http://staging-teach.cdn.ireadabc.com/440cf9d57752b30691d90ed565e8c924.mp3",
            "groupLabel": "111",
            "groupPic": "http://staging-teach.cdn.ireadabc.com/c8abf7383d65bcbdba8f390785cece60.png",
            "group_audio_url": "http://staging-teach.cdn.ireadabc.com/83513f8d6083ebe072e3f9e47a21558a.mp3",
            "type": "Image",
            "ske_json": "",
            "tex_json": "",
            "tex_png": ""
          }]
        }, {
          "pageInfo": [{
            "a_pic_url": "http://staging-teach.cdn.ireadabc.com/f6f4bbef497409fef3c8f1d375893829.png",
            "b_pic_url": "http://staging-teach.cdn.ireadabc.com/7b18a7931d64f7b9e8b7ecd25cb5e3d4.png",
            "a_audio_url": "http://staging-teach.cdn.ireadabc.com/5285e1e88a26a08783757e9c43a8653f.mp3",
            "b_audio_url": "http://staging-teach.cdn.ireadabc.com/440cf9d57752b30691d90ed565e8c924.mp3",
            "groupLabel": "111",
            "groupPic": "http://staging-teach.cdn.ireadabc.com/c8abf7383d65bcbdba8f390785cece60.png",
            "group_audio_url": "http://staging-teach.cdn.ireadabc.com/83513f8d6083ebe072e3f9e47a21558a.mp3",
            "type": "Image",
            "ske_json": "",
            "tex_json": "",
            "tex_png": ""
          }]
        }, {
          "pageInfo": [{
            "a_pic_url": "http://staging-teach.cdn.ireadabc.com/f6f4bbef497409fef3c8f1d375893829.png",
            "b_pic_url": "http://staging-teach.cdn.ireadabc.com/7b18a7931d64f7b9e8b7ecd25cb5e3d4.png",
            "a_audio_url": "http://staging-teach.cdn.ireadabc.com/5285e1e88a26a08783757e9c43a8653f.mp3",
            "b_audio_url": "http://staging-teach.cdn.ireadabc.com/440cf9d57752b30691d90ed565e8c924.mp3",
            "groupLabel": "111",
            "groupPic": "http://staging-teach.cdn.ireadabc.com/c8abf7383d65bcbdba8f390785cece60.png",
            "group_audio_url": "http://staging-teach.cdn.ireadabc.com/83513f8d6083ebe072e3f9e47a21558a.mp3",
            "type": "Image",
            "ske_json": "",
            "tex_json": "",
            "tex_png": ""
          }]
        }],
        "title": "adsadsa dsa dsa dsa",
        "audio_url": "http://staging-teach.cdn.ireadabc.com/f51e3fedc88aa69a99f6ef579f7de047.mp3"
      }
    };
    return data;
  },
  //{"contentObj":{"pageArr":[{"pageInfo":[{"a_pic_url":"http://staging-teach.cdn.ireadabc.com/4c987bc8980e235c6b6e2ae9a409cfc1.png","b_pic_url":"http://staging-teach.cdn.ireadabc.com/1ffb03273ae56047adab077dc8cc794c.png","a_audio_url":"","b_audio_url":"","groupLabel":"11111","groupPic":"http://staging-teach.cdn.ireadabc.com/2d349cf780b1fcec761a2350936183f0.png","type":"Image"},{"a_pic_url":"","b_pic_url":"","a_audio_url":"","b_audio_url":"","groupLabel":"a","groupPic":""	,"type":"Spine","ske_json":"http://staging-teach.cdn.ireadabc.com/e48564e39f64ef92dee4309b3493652a.json","ske_json_name":"mao_ske.json","tex_json":"http://staging-teach.cdn.ireadabc.com/233b2f102f321086b70c239a1bd4ba1a.json","tex_json_name":"mao_tex.json","tex_png":"http://staging-teach.cdn.ireadabc.com/d5c00d0cf339484801dc235ed33200d0.png","tex_png_name":"mao_tex.png"}]},{"pageInfo":[]},{"pageInfo":[{"a_pic_url":"","b_pic_url":"","a_audio_url":"","b_audio_url":"","groupLabel":"","groupPic":"","type":"Spine","uploadData":"","uploadUrl":"","ske_json":"http://staging-teach.cdn.ireadabc.com/e48564e39f64ef92dee4309b3493652a.json","ske_json_name":"mao_ske.json"}]}],"title":"16516510","audio_url":"http://staging-teach.cdn.ireadabc.com/bfcd329e246551615375ce0788fc397e.mp3"},"type":"Image"}
  //重置数据
  resGameData: function resGameData() {
    this._imageResList = [];
    this._audioResList = [];
    this._animaResList = [];
    this.temPlayAudio = [];
  },
  //获得播放路径
  getPlayUrl: function getPlayUrl() {
    for (var i in this._audioResList) {
      var audioInfo = this._audioResList[i];

      if (this.playId == audioInfo.typeId && this.playType == audioInfo.positionId) {
        return audioInfo.url;
      }
    }
  },
  //获得整条数据
  getResultInfo: function getResultInfo(id) {
    var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;
    return pageInfo[id];
  },
  //获得图片信息 type 1上面，type 2下面
  getImgInfo: function getImgInfo(type) {
    var list = [];

    for (var i in lwd_g.data_mgr._imageResList) {
      var imgList = lwd_g.data_mgr._imageResList[i];

      if (imgList.positionId == type) {
        list.push(imgList);
      }
    }

    return list;
  },
  //处理数据
  proGameData: function proGameData() {
    this.addPreloadImage();
    this.addPreloadAudio();
    this.addPreloadAnima();
    this.preload();
    console.log("数据处理完毕:");
  },
  //预加载图片
  addPreloadImage: function addPreloadImage() {
    //btnState 0正常显示，1显示成功，2显示灰色，3连线完成
    var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;

    for (var i in pageInfo) {
      this._imageResList.push({
        url: pageInfo[i].a_pic_url,
        typeId: i,
        positionId: 1,
        btnState: 0
      });

      this._imageResList.push({
        url: pageInfo[i].b_pic_url,
        typeId: i,
        positionId: 2,
        btnState: 0
      });

      this._imageResList.push({
        url: pageInfo[i].groupPic,
        typeId: i,
        positionId: 0
      });
    }
  },
  //预加载声音
  addPreloadAudio: function addPreloadAudio() {
    var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;

    for (var i in pageInfo) {
      this._audioResList.push({
        url: pageInfo[i].a_audio_url,
        typeId: i,
        positionId: 1,
        isPlay: false
      });

      this._audioResList.push({
        url: pageInfo[i].b_audio_url,
        typeId: i,
        positionId: 2,
        isPlay: false
      });

      this.temPlayAudio.push(i);
    }
  },
  addPreloadAnima: function addPreloadAnima() {},
  preload: function preload() {
    var _this = this;

    var preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);

    cc.assetManager.loadAny(preloadArr, null, null, function (err, data) {
      //结束回调
      _this.loadEnd();

      if (window && window["air"]) {
        window["air"].hideAirClassLoading();
      }

      cc.debug.setDisplayStats(false);
    });
  },
  loadEnd: function loadEnd() {
    //更新游戏界面信息
    lwd_g.game.inst.UpdataUi();
    lwd_g.game.inst.isLoadEnd = true; // g.speaker.inst.play_start(() => {
    // 	lwd_g.game.inst.playAudioTitle(() => {
    // 		lwd_g.game.inst.mask_node.active = false;
    // 		//游戏开始
    // 		lwd_g.game.inst.gameStart();
    // 	});
    // });
    // //播放游戏开始音效
    // g.speaker.inst.play_start();
    // setTimeout(() => {
    // 	lwd_g.game.inst.playAudioTitle();
    // }, 2000);
    //setTimeout(() => {
    // lwd_g.game.inst.mask_node.active = false;
    // //游戏开始
    // lwd_g.game.inst.gameStart();
    //}, 4000)
  }
};

cc._RF.pop();