difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict";
cc._RF.push(module, '1bb25BmGBJFCpbHBgOQTGGE', 'spine_loading_item');
// Scripts/common/spine_loading_item.js
 
"use strict";
 
var SpineItem = function SpineItem(anima_id, anima_name, callback) {
  this.anima_id = anima_id;
  this.anima_name = anima_name;
  this.finish_cb = [];
  this.finish_cb.push(callback);
  this.load_finish = false;
  this.startUpdate();
};
 
var proto = SpineItem.prototype;
proto.startUpdate = function () {
  if (H5_RES) {
    var root_url = this.root_url = H5_RES + "spine/" + this.anima_id + "/";
    var text_url = this.text_url = root_url + this.anima_name + ".text";
    var ske_url = this.ske_url = root_url + this.anima_name + ".json";
    var atlas_url = this.atlas_url = root_url + this.anima_name + ".atlas";
    cc.loader.load({
      url: text_url,
      type: 'txt'
    }, function (err, text_data) {
      if (!err) {
        var texture_names = this.texture_names = this.texture_names = JSON.parse(text_data).testures;
        var textures = [];
 
        for (var text_i in texture_names) {
          var finish_nb = 0;
          var texture_url = root_url + texture_names[text_i];
          cc.loader.load(texture_url, function (text_i, err, texture_data) {
            if (!err) {
              textures.splice(text_i, 0, texture_data);
 
              if (textures.length == texture_names.length) {
                cc.loader.load({
                  url: atlas_url,
                  type: 'txt'
                }, function (error, atlasJson) {
                  cc.loader.load({
                    url: ske_url,
                    type: 'txt'
                  }, function (error, spineJson) {
                    var asset = this.asset = new sp.SkeletonData();
                    asset.skeletonJson = spineJson;
                    asset.atlasText = atlasJson;
                    asset.textures = textures;
                    asset.textureNames = texture_names;
                    this.load_finish = true;
 
                    if (this.finish_cb) {
                      for (var cb_i in this.finish_cb) {
                        this.finish_cb[cb_i](asset);
                      }
                    }
                  }.bind(this));
                }.bind(this));
              }
            }
          }.bind(this, text_i));
        }
      }
    }.bind(this));
  }
}, proto.release = function () {
  for (var name_i in this.texture_names) {
    var texture_url = this.root_url + this.texture_names[name_i];
    cc.loader.release(texture_url);
  }
 
  cc.loader.release(this.text_url);
  cc.loader.release(this.ske_url);
  cc.loader.release(this.atlas_url);
  delete this.asset;
}, proto.addCallback = function (callback) {
  if (this.load_finish) {
    callback(this.asset);
    return;
  }
 
  this.finish_cb.push(callback);
}, module.exports = SpineItem;
 
cc._RF.pop();