123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, ch_sign, _crd;
- _export("default", void 0);
- return {
- setters: [function (_cc) {
- _cclegacy = _cc.cclegacy;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "6d031yryKRLYaiOHaXKh4Av", "sign", undefined);
- _export("default", ch_sign = class ch_sign {
- constructor() {
- this._sign_data = new Set();
- this._max = 7;
- this._creat_date = 0;
- this._sign_count = 0;
- this._mode = 1;
- }
- static getInstance() {
- if (!this._instance) this._instance = new ch_sign();
- return this._instance;
- }
- /**设定的签到天数*/
- get max_day() {
- return this._max;
- }
- getCreatDayCount() {
- if (this._creat_date == 0) {
- chsdk.log.warn("签到模块没有初始化");
- return 0;
- }
- return chsdk.date.getDiffDayNum(this._creat_date, chsdk.date.now()) + 1;
- }
- /**
- * 签到初始化
- * @param mode =1可以补签 =2不可补签
- * @param data 签到存档数据,可以为空为第一天
- * @param max_day 签到最大天数
- */
- init(mode, data, max_day) {
- if (max_day === void 0) {
- max_day = 7;
- }
- this._mode = mode;
- if (this._mode == 1) {
- if (data) {
- var _data$sign_list, _data$creat_date;
- data = data;
- var sign_list = (_data$sign_list = data.sign_list) != null ? _data$sign_list : [];
- var creat_date = (_data$creat_date = data.creat_date) != null ? _data$creat_date : chsdk.date.now();
- for (var i = 0; i < sign_list.length; i++) this._sign_data.add(sign_list[i]);
- this._sign_count = this._sign_data.size;
- this._creat_date = creat_date;
- } else {
- this._sign_count = 0;
- this._sign_data.clear();
- this._creat_date = chsdk.date.now();
- }
- } else {
- if (data) {
- var _data$sign_count, _data$last_date;
- data = data;
- this._sign_count = (_data$sign_count = data.sign_count) != null ? _data$sign_count : 0;
- this._creat_date = (_data$last_date = data.last_date) != null ? _data$last_date : 0;
- } else {
- this._sign_count = 0;
- this._creat_date = 0;
- }
- }
- this._max = max_day;
- }
- /**已签到的数据,用于存档*/
- getSignData() {
- if (this._mode == 1) {
- return {
- sign_list: Array.from(this._sign_data.keys()),
- creat_date: this._creat_date
- };
- } else if (this._mode == 2) {
- return {
- sign_count: this._sign_count,
- last_date: this._creat_date
- };
- }
- }
- /** 返回某一天的状态
- * 0 等待签到
- * 1 已经签到
- * 2 失效等待补签
- * */
- checkSigineState(day) {
- if (this._mode == 1) {
- if (day < 1 || day > this._max) return 0;
- if (this._sign_data.has(day)) return 1;
- var count = this.getCreatDayCount();
- if (count <= 0) return 0;
- if (day < count) return 2;
- } else if (this._mode == 2) {
- if (day <= this._sign_count) return 1;
- }
- return 0;
- }
- /**今天是否可以签到*/
- checkSigin() {
- if (this._mode == 1) {
- var count = this.getCreatDayCount();
- if (count <= 0 || count > this._max) return false;
- return !this._sign_data.has(count);
- } else if (this._mode == 2) {
- var _count = this._sign_count;
- if (_count >= this._max) return false;
- return !chsdk.date.isSameDate(this._creat_date, chsdk.date.now());
- }
- return false;
- }
- /**签到是否全部完成*/
- checkSiginComplete() {
- var count = this._sign_count;
- return count >= this._max;
- }
- /**
- * 是否能补签
- * 不能返回0,
- * 可以补签返回可以补签的那一天*/
- checkReSigin() {
- if (this._mode != 1) return 0;
- var count = this.getCreatDayCount() - 1;
- if (count <= 0) return 0;
- if (count > this._max) count = this._max;
- for (var i = 1; i <= count; i++) {
- if (!this._sign_data.has(i)) return i;
- }
- return 0;
- }
- /**签到
- * 失败返回 0
- * 成功返回签到当天
- */
- signIn() {
- if (!this.checkSigin()) {
- return 0;
- }
- if (this._mode == 1) {
- var day = this.getCreatDayCount();
- this._sign_data.add(day);
- this._sign_count = this._sign_data.size;
- return day;
- } else if (this._mode == 2) {
- this._sign_count++;
- this._creat_date = chsdk.date.now();
- return this._sign_count;
- }
- return 0;
- }
- /**补签
- * 失败返回 0
- * 成功返回补签那天
- */
- reSignIn() {
- if (this._mode != 1) return 0;
- var index = this.checkReSigin();
- if (index <= 0 || index > this._max) {
- return 0;
- }
- this._sign_data.add(index);
- this._sign_count = this._sign_data.size;
- return index;
- } //
- });
- ch_sign._instance = void 0;
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=a62597dd07a24c3714ad095eedbfc8f76f2d165c.js.map
|