123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- 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=3bdf94f80cc7c4e432a1b8a5268e57b2c305372c.js.map
|