System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) { "use strict"; var _reporterNs, _cclegacy, ch, PeriodData, PeriodDataUpdate, GameData, _crd; function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _reportPossibleCrUseOfch(extras) { _reporterNs.report("ch", "../../ch/ch", _context.meta, extras); } function _reportPossibleCrUseOfPeriodData(extras) { _reporterNs.report("PeriodData", "./PeriodData", _context.meta, extras); } function _reportPossibleCrUseOfPeriodDataUpdate(extras) { _reporterNs.report("PeriodDataUpdate", "./PeriodData", _context.meta, extras); } _export("default", void 0); return { setters: [function (_unresolved_) { _reporterNs = _unresolved_; }, function (_cc) { _cclegacy = _cc.cclegacy; }, function (_unresolved_2) { ch = _unresolved_2.ch; }, function (_unresolved_3) { PeriodData = _unresolved_3.default; PeriodDataUpdate = _unresolved_3.PeriodDataUpdate; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "c88bd5RDxxIJ7YUSwv6V1cm", "GameData", undefined); /**游戏数据 * 有额外自定义数据可以继承此类 */ _export("default", GameData = class GameData { constructor(gid, uid, name, limt, day_limt, week_limt, month_limt) { this._key = void 0; this._uid = void 0; this._gid = void 0; this._save_time = void 0; this._ver = void 0; this._data = void 0; this._day_data = void 0; this._week_data = void 0; this._month_data = void 0; // this._dirty = false; this._key = name; this._gid = gid; this._uid = uid; this._data = new (_crd && PeriodData === void 0 ? (_reportPossibleCrUseOfPeriodData({ error: Error() }), PeriodData) : PeriodData)((_crd && PeriodDataUpdate === void 0 ? (_reportPossibleCrUseOfPeriodDataUpdate({ error: Error() }), PeriodDataUpdate) : PeriodDataUpdate).none, limt); this._day_data = new (_crd && PeriodData === void 0 ? (_reportPossibleCrUseOfPeriodData({ error: Error() }), PeriodData) : PeriodData)((_crd && PeriodDataUpdate === void 0 ? (_reportPossibleCrUseOfPeriodDataUpdate({ error: Error() }), PeriodDataUpdate) : PeriodDataUpdate).day, day_limt); this._week_data = new (_crd && PeriodData === void 0 ? (_reportPossibleCrUseOfPeriodData({ error: Error() }), PeriodData) : PeriodData)((_crd && PeriodDataUpdate === void 0 ? (_reportPossibleCrUseOfPeriodDataUpdate({ error: Error() }), PeriodDataUpdate) : PeriodDataUpdate).week, week_limt); this._month_data = new (_crd && PeriodData === void 0 ? (_reportPossibleCrUseOfPeriodData({ error: Error() }), PeriodData) : PeriodData)((_crd && PeriodDataUpdate === void 0 ? (_reportPossibleCrUseOfPeriodDataUpdate({ error: Error() }), PeriodDataUpdate) : PeriodDataUpdate).month, month_limt); } // get data() { return this._data; } get day_data() { return this._day_data; } get week_data() { return this._week_data; } get month_data() { return this._month_data; } get uid() { return this._uid; } checkNewDay() { var _this$_day_data, _this$_week_data, _this$_month_data; var now = (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).date.now(); (_this$_day_data = this._day_data) == null || _this$_day_data.check(now); (_this$_week_data = this._week_data) == null || _this$_week_data.check(now); (_this$_month_data = this._month_data) == null || _this$_month_data.check(now); } // compareVersion(version1, version2) { // 移除前面的 'v' 字符 var v1 = version1.replace(/^V/, ''); var v2 = version2.replace(/^V/, ''); // 分割版本号 var parts1 = v1.split('.').map(Number); // 将版本号分割并转为数字 var parts2 = v2.split('.').map(Number); // 比较每一部分 for (var i = 0; i < Math.max(parts1.length, parts2.length); i++) { var num1 = parts1[i] || 0; // 如果没有该部分,默认为 0 var num2 = parts2[i] || 0; if (num1 < num2) { return -1; // version1 < version2 } if (num1 > num2) { return 1; // version1 > version2 } } return 0; // 两个版本号相等 } // loadGameDataWithRetry(maxRetries, delayMs) { var _this = this; return _asyncToGenerator(function* () { if (maxRetries === void 0) { maxRetries = 3; } if (delayMs === void 0) { delayMs = 1000; } var attempt = 0; while (attempt < maxRetries) { var _data = yield _this.load_data(); if (_data != null) { return _data != null ? _data : null; } else { attempt++; yield new Promise(resolve => setTimeout(resolve, delayMs)); } } return null; })(); } // saveGameDataWithRetry(save_data, maxRetries, delayMs) { var _this2 = this; return _asyncToGenerator(function* () { if (maxRetries === void 0) { maxRetries = 3; } if (delayMs === void 0) { delayMs = 1000; } var attempt = 0; while (attempt < maxRetries) { var ret = yield _this2.save_data(save_data); if (ret) { return true; } else { attempt++; yield new Promise(resolve => setTimeout(resolve, delayMs)); } } return false; })(); } /**加载数据*/ load(ver) { var _this3 = this; return _asyncToGenerator(function* () { _this3.on_load(0); var load_data = (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).storage.getObject(_this3._key, _this3._gid); if (load_data) { if ((_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).sdk.get_inited() && load_data.uid != _this3._uid) load_data = null; } // if (!load_data) { var remote_data = yield _this3.loadGameDataWithRetry(); load_data = remote_data; } // } else if (remote_data && this.on_check(load_data, remote_data)) { // load_data = remote_data; // } // if (!load_data) { _this3.on_init(); console.log("无数据所以初始化"); } else { _this3.unserialize(load_data); console.log("有数据初始化"); } _this3.checkVer(ver); _this3.checkNewDay(); _this3.on_load(1); })(); } /**远程调用保存,如果不是强制远程保存,必并先设置脏数据*/ save(force) { var _this4 = this; return _asyncToGenerator(function* () { if (force === void 0) { force = false; } _this4.on_save(0); if (force) { _this4.setDirty(); } else if (!_this4._dirty) { _this4.on_save(1); return false; } var ret = yield _this4.saveGameDataWithRetry(_this4.serialize()); _this4.on_save(1); if (ret) _this4._dirty = false; return ret; })(); } /**设置脏数据后保存到本地*/ setDirty() { this._dirty = true; (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).storage.set(this._key, this.serialize(), this._gid); } checkVer(new_v) { if (!new_v) return; if (!this._ver) { this.on_ver(true, this._ver, new_v); } var k = this.compareVersion(this._ver, new_v); this.on_ver(k < 0, this._ver, new_v); this._ver = new_v; } /** * 序列化(数据库存储) */ serialize() { var save_data = {}; if (this._data) save_data.data = this._data.serialize(); if (this._day_data) save_data.day_data = this._day_data.serialize(); if (this._week_data) save_data.week_data = this._week_data.serialize(); if (this._month_data) save_data.month_data = this._month_data.serialize(); save_data.uid = this._uid; save_data.gid = this._gid; this._save_time = (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).date.now(); save_data.save_time = this._save_time; if (this._ver) save_data.ver = this._ver; this.on_serialize(save_data); return save_data; } /** * 反序列化 */ unserialize(load_data) { var _this$_data, _this$_day_data2, _this$_week_data2, _this$_month_data2, _load_data$uid, _load_data$gid, _ref; if (!load_data) return; (_this$_data = this._data) == null || _this$_data.unserialize(load_data.data); (_this$_day_data2 = this._day_data) == null || _this$_day_data2.unserialize(load_data.day_data); (_this$_week_data2 = this._week_data) == null || _this$_week_data2.unserialize(load_data.week_data); (_this$_month_data2 = this._month_data) == null || _this$_month_data2.unserialize(load_data.month_data); this._uid = (_load_data$uid = load_data.uid) != null ? _load_data$uid : this._uid; this._gid = (_load_data$gid = load_data.gid) != null ? _load_data$gid : this._gid; this._save_time = (_ref = load_data.save_time) != null ? _ref : (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).date.now(); if (load_data.ver) this._ver = load_data.ver; this.on_unserialize(load_data); } /**重写此方法初始自定义数据*/ on_init() {} /**重写此方法检测是否使用远程数据*/ on_check(local, remote) { return true; } /**重写 版本检测数据处理*/ on_ver(is_new, old_v, new_v) {} /**重写序列化加入自定义的数据*/ on_serialize(data) {} /**重写反序列化*/ on_unserialize(data) {} /**保存数据(0开始 1结束)*/ on_save(step) {} /**加载数据(0开始 1结束)*/ on_load(step) { if (step == 0) { console.log("开始加载数据"); } else if (step == 1) { console.log("加载数据结束"); } } /**重写成其它加载方式*/ load_data() { var _this5 = this; return _asyncToGenerator(function* () { var ret = yield (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).sdk.loadGameData(_this5._key); if (ret.code === 0) { return ret.data; } else { (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).log.warn("\u5C1D\u8BD5\u52A0\u8F7D\u6570\u636E\u5931\u8D25\uFF0C\u9519\u8BEF\u4EE3\u7801: " + ret.code + " " + ret.err); } return null; })(); } /**重写成其它保存方式*/ save_data(save_data) { var _this6 = this; return _asyncToGenerator(function* () { var ret = yield (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).sdk.saveGameData(_this6._key, save_data); if (ret.code == 0) { return true; } else { (_crd && ch === void 0 ? (_reportPossibleCrUseOfch({ error: Error() }), ch) : ch).log.warn("\u5C1D\u8BD5\u4FDD\u5B58\u6570\u636E\u5931\u8D25\uFF0C\u9519\u8BEF\u4EE3\u7801: " + ret.code + " " + ret.err); return false; } })(); } }); _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=69708f163aeb7f1d3d93c5d9454dca6576ef2581.js.map