"use strict";
cc._RF.push(module, '7121dH9/vVG+a4W/8mqf14W', 'res_mgr');
// Lwd/script/manager/res_mgr.js

"use strict";

/**
 * 资源管理器
 */
lwd_g.res_mgr = {
  //获得表数据数据
  getFormData: function getFormData() {
    console.log('初始化数据');

    try {
      window.courseware.getData(function (res) {
        //存入数据管理器
        lwd_g.data_mgr.data = res; //数据处理

        lwd_g.data_mgr.proGameData();
        console.log("获得表单数据:" + res);
      });
    } catch (error) {
      //console.error('没有查找到courseware.getData方法', error);
      //获得默认数据
      lwd_g.data_mgr.data = lwd_g.data_mgr.getDefaultData(); //数据处理

      lwd_g.data_mgr.proGameData();
    }
  },
  //
  getSprNode: function getSprNode(resName) {
    var sf = cc.find('Canvas/res/img/' + resName).getComponent(cc.Sprite).spriteFrame;
    var node = new cc.Node();
    node.addComponent(cc.Sprite).spriteFrame = sf;
    return node;
  },
  //得到图片资源
  getSpriteFrimeByUrl: function getSpriteFrimeByUrl(url, cb) {
    cc.assetManager.loadRemote(url, cc.SpriteFrame, function (e, sp) {
      var spriteFrame = new cc.SpriteFrame(sp);
      cb && cb(spriteFrame);
    });
  },
  getSprNodeByUrl: function getSprNodeByUrl(url, cb) {
    var node = new cc.Node();
    var spr = node.addComponent(cc.Sprite);
    this.getSpriteFrimeByUrl(url, function (sf) {
      spr.spriteFrame = sf;

      if (cb) {
        cb(node);
      }
    });
  },
  playAudioByUrl: function playAudioByUrl(audio_url, cb) {
    if (audio_url) {
      cc.assetManager.loadRemote(audio_url, function (err, audioClip) {
        cb && cb(audioClip);
      });
    }
  },
  //加载龙骨
  loadSpine: function loadSpine(animationDisplay, Info) {
    if (Info.type == 'Image') {
      return;
    }

    cc.assetManager.loadAny([{
      url: Info.tex_json,
      ext: '.txt'
    }, {
      url: Info.ske_json,
      ext: '.txt'
    }], function (error, assets) {
      if (error) {
        console.log(error);
      } else {
        cc.assetManager.loadRemote(Info.tex_png, function (error, texture) {
          if (error) {
            console.log(error);
          } else {
            var atlas = new dragonBones.DragonBonesAtlasAsset();
            atlas._uuid = Info.tex_json;
            atlas.atlasJson = assets[0];
            atlas.texture = texture;
            var asset = new dragonBones.DragonBonesAsset();
            asset._uuid = Info.ske_json;
            asset.dragonBonesJson = assets[1];
            animationDisplay.dragonAtlasAsset = atlas;
            animationDisplay.dragonAsset = asset;
            var data = asset._dragonBonesJsonData.armature[0];

            if (!data) {
              return;
            }

            animationDisplay.armatureName = data.name;
            lwd_g.data_mgr.dragonName = data.animation[0].name;
            animationDisplay.node.active = true;
          }
        });
      }
    });
  }
};

cc._RF.pop();