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
"use strict";
cc._RF.push(module, 'af379MpFlpO14jSJfyQDfdn', 'itemspool');
// Scripts/common/itemspool.js
 
"use strict";
 
window.ItemsPool = cc.Class({
  "extends": cc.Component,
  properties: {
    _hero_cache: [],
    _backpack_cache: []
  },
  getItem: function getItem(itemClass) {
    if (itemClass == "hero_exhibition_item") {
      if (this._hero_cache.length > 0) {
        return this._hero_cache.pop();
      } else {
        var HeroExhibitionItem = require("hero_exhibition_item");
 
        return new HeroExhibitionItem();
      }
    } else if (itemClass == "backpack_item") {
      if (this._backpack_cache.length > 0) {
        return this._backpack_cache.pop();
      } else {
        var BackpackItem = require("backpack_item");
 
        return new BackpackItem();
      }
    }
  },
  cacheItem: function cacheItem(item) {
    if (!item.root_wnd) {
      item = null;
      return;
    }
 
    var BackpackItem = require("backpack_item");
 
    var HeroExhibitionItem = require("hero_exhibition_item");
 
    item.setParent(ViewManager.getInstance().getSceneNode());
    item.init();
    item.hide();
 
    if (item instanceof BackpackItem) {
      this._backpack_cache.push(item);
    } else if (item instanceof HeroExhibitionItem) {
      this._hero_cache.push(item);
    }
  }
}); // // ItemsPool.getInstance().getItem("hero_exhibition_item");
 
ItemsPool.getInstance = function () {
  if (!ItemsPool.instance) {
    ItemsPool.instance = new ItemsPool();
  }
 
  return ItemsPool.instance;
}; // ItemsPool.getInstance().getItem("backpack_item");
 
 
module.exports = ItemsPool;
 
cc._RF.pop();