System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, Container, _crd; _export("Container", void 0); return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "7b367Ns5DhICaZLmc2yobWd", "Container", undefined); _export("Container", Container = class Container { constructor() { this._itemList = null; this._itemList = new Array(); } addCount(type, count) { return this.addItem({ type: type, count: count }); } useCount(type, count) { for (var i = 0; i < this._itemList.length; i++) { if (this._itemList[i].type == type) { if (this._itemList[i].count >= count) { this._itemList[i].count -= count; return this._itemList[i]; } } } return null; } /** * 添加物品 * @param item * @returns */ addItem(item) { for (var i = 0; i < this._itemList.length; i++) { if (this._itemList[i].type == item.type) { this._itemList[i].count += item.count; return this._itemList[i]; } } this._itemList.push(item); return item; } getCount(type) { for (var i = 0; i < this._itemList.length; i++) { if (this._itemList[i].type == type) { return this._itemList[i].count; } } return 0; } get itemList() { return this._itemList; } set itemList(arr) { this._itemList = arr; } /** * 序列化(数据库存储) */ serialize() { var list = []; for (var i = 0; i < this._itemList.length; i++) { var item = this._itemList[i]; list.push({ type: item.type, count: item.count }); } var data = { "list": list }; return data; } /** * 反序列化(数据库读取) * @param data */ unserialize(data) { if (!data) return; var list = data.list; this._itemList = []; for (var i = 0; i < list.length; i++) { this._itemList.push({ type: list[i].type, count: list[i].count }); } } }); _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=1787d8e2147a43214097b7b6fea81022fa7297b5.js.map