@gongxh/bit-core 0.0.6 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bit-core.cjs +40 -15
- package/dist/bit-core.d.ts +5 -0
- package/dist/bit-core.min.cjs +1 -1
- package/dist/bit-core.min.mjs +1 -1
- package/dist/bit-core.mjs +40 -15
- package/package.json +35 -34
- package/LICENSE +0 -21
package/dist/bit-core.cjs
CHANGED
|
@@ -463,15 +463,15 @@ class TimerNodePool {
|
|
|
463
463
|
const index = timerId >>> TimerIdBit;
|
|
464
464
|
const version = timerId & TimerVersionMask;
|
|
465
465
|
if (index < 0 || index >= this._pool.length) {
|
|
466
|
-
return
|
|
466
|
+
return undefined;
|
|
467
467
|
}
|
|
468
468
|
const timerNode = this._pool[index];
|
|
469
469
|
if (timerNode.recycled) {
|
|
470
|
-
return
|
|
470
|
+
return undefined;
|
|
471
471
|
}
|
|
472
472
|
const timerNodeVersion = timerNode.id & TimerVersionMask;
|
|
473
473
|
if (timerNodeVersion != version) {
|
|
474
|
-
return
|
|
474
|
+
return undefined;
|
|
475
475
|
}
|
|
476
476
|
return timerNode;
|
|
477
477
|
}
|
|
@@ -592,24 +592,31 @@ class Timer {
|
|
|
592
592
|
this._recycle(timerNode);
|
|
593
593
|
}
|
|
594
594
|
else if (timerNode.loop > 0) {
|
|
595
|
-
|
|
596
|
-
|
|
595
|
+
const missedCount = Math.floor((elapsedTime - timerNode.expireTime) / timerNode.interval) + 1;
|
|
596
|
+
timerNode.loop -= missedCount;
|
|
597
|
+
if (timerNode.loop <= 0) {
|
|
597
598
|
heap.pop();
|
|
598
599
|
this._recycle(timerNode);
|
|
599
600
|
}
|
|
600
601
|
else {
|
|
601
|
-
|
|
602
|
-
timerNode.expireTime = timerNode.expireTime + timerNode.interval;
|
|
602
|
+
timerNode.expireTime += timerNode.interval * missedCount;
|
|
603
603
|
heap.update(timerNode);
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
else {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
timerNode.expireTime = timerNode.expireTime + timerNode.interval;
|
|
607
|
+
const missedCount = Math.floor((elapsedTime - timerNode.expireTime) / timerNode.interval) + 1;
|
|
608
|
+
timerNode.expireTime += timerNode.interval * missedCount;
|
|
610
609
|
heap.update(timerNode);
|
|
611
610
|
}
|
|
612
|
-
|
|
611
|
+
// 执行回调,捕获异常防止中断后续定时器
|
|
612
|
+
if (callback) {
|
|
613
|
+
try {
|
|
614
|
+
callback();
|
|
615
|
+
}
|
|
616
|
+
catch (error) {
|
|
617
|
+
console.error("Timer callback error:", error);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
613
620
|
timerNode = heap.top();
|
|
614
621
|
}
|
|
615
622
|
}
|
|
@@ -735,15 +742,22 @@ class InnerTimer {
|
|
|
735
742
|
* @param loop - [loop=0] 重复次数:0:回调一次,1~n:回调n次,-1:无限重复
|
|
736
743
|
* @returns 返回定时器的ID。
|
|
737
744
|
*/
|
|
745
|
+
static get Timer() {
|
|
746
|
+
if (this._timer) {
|
|
747
|
+
return this._timer;
|
|
748
|
+
}
|
|
749
|
+
this.initTimer();
|
|
750
|
+
return this._timer;
|
|
751
|
+
}
|
|
738
752
|
static startTimer(callback, interval, loop = 0) {
|
|
739
|
-
return this.
|
|
753
|
+
return this.Timer.start(callback, interval, loop);
|
|
740
754
|
}
|
|
741
755
|
/**
|
|
742
756
|
* 停止指定ID的计时器。
|
|
743
757
|
* @param timerId - 要停止的计时器的唯一标识符。
|
|
744
758
|
*/
|
|
745
759
|
static stopTimer(timerId) {
|
|
746
|
-
this.
|
|
760
|
+
this.Timer.stop(timerId);
|
|
747
761
|
}
|
|
748
762
|
static update(dt) {
|
|
749
763
|
var _a;
|
|
@@ -899,8 +913,14 @@ class Time {
|
|
|
899
913
|
* @returns 时间戳 (ms)
|
|
900
914
|
*/
|
|
901
915
|
static getWeekStartTime(timestamp) {
|
|
902
|
-
|
|
916
|
+
const ts = timestamp || this.now();
|
|
917
|
+
// getWeekDay 返回 1-7 (周一到周日),需要减去 (weekDay - 1) 天得到周一
|
|
918
|
+
return this.getDayStartTime(ts - (this.getWeekDay(ts) - 1) * 86400000);
|
|
903
919
|
}
|
|
920
|
+
/**
|
|
921
|
+
* @param timestamp 时间戳 (ms)
|
|
922
|
+
* @returns 时间戳 (ms)
|
|
923
|
+
*/
|
|
904
924
|
static getWeekEndTime(timestamp) {
|
|
905
925
|
return this.getWeekStartTime(timestamp) + 86400000 * 7;
|
|
906
926
|
}
|
|
@@ -1203,6 +1223,11 @@ Time._netTime = 0;
|
|
|
1203
1223
|
* @internal
|
|
1204
1224
|
*/
|
|
1205
1225
|
Time._netTimeDiff = 0;
|
|
1226
|
+
/**
|
|
1227
|
+
* 获取当前毫秒时间戳
|
|
1228
|
+
* @internal
|
|
1229
|
+
*/
|
|
1230
|
+
Time._nowTimestamp = () => Date.now();
|
|
1206
1231
|
|
|
1207
1232
|
/**
|
|
1208
1233
|
* @Author: Gongxh
|
|
@@ -2341,7 +2366,7 @@ class DoublyLinkedList extends LinkedList {
|
|
|
2341
2366
|
current.prev = undefined;
|
|
2342
2367
|
return current.element;
|
|
2343
2368
|
}
|
|
2344
|
-
return
|
|
2369
|
+
return undefined;
|
|
2345
2370
|
}
|
|
2346
2371
|
/**
|
|
2347
2372
|
* 获取链表中指定位置的元素,如果不存在返回 null
|
package/dist/bit-core.d.ts
CHANGED
|
@@ -328,6 +328,10 @@ declare class Time {
|
|
|
328
328
|
* @returns 时间戳 (ms)
|
|
329
329
|
*/
|
|
330
330
|
static getWeekStartTime(timestamp?: number): number;
|
|
331
|
+
/**
|
|
332
|
+
* @param timestamp 时间戳 (ms)
|
|
333
|
+
* @returns 时间戳 (ms)
|
|
334
|
+
*/
|
|
331
335
|
static getWeekEndTime(timestamp?: number): number;
|
|
332
336
|
/**
|
|
333
337
|
* 获取当前月开始时间
|
|
@@ -577,6 +581,7 @@ declare class InnerTimer {
|
|
|
577
581
|
* @param loop - [loop=0] 重复次数:0:回调一次,1~n:回调n次,-1:无限重复
|
|
578
582
|
* @returns 返回定时器的ID。
|
|
579
583
|
*/
|
|
584
|
+
private static get Timer();
|
|
580
585
|
static startTimer(callback: () => void, interval: number, loop?: number): number;
|
|
581
586
|
/**
|
|
582
587
|
* 停止指定ID的计时器。
|
package/dist/bit-core.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("cc");let e=!1;function i(t){1==t?(e=!0,console.warn("调试模式已开启")):e=!1}function s(...t){e&&console.log("bit-framework:",...t)}class r{}class n{constructor(){this.listeners=[]}addResizeListener(t){this.listeners.push(t)}removeResizeListener(t){this.listeners=this.listeners.filter(e=>e!==t)}init(){n.instance=this,s("初始化适配器");let e=this.getDesignSize();r.DesignHeight=e.height,r.DesignWidth=e.width,t.view.setDesignResolutionSize(r.DesignWidth,r.DesignHeight,t.ResolutionPolicy.SHOW_ALL),this.resize(),this.registerListener((...t)=>{s("屏幕发生变化",...t),this.resize();for(const e of this.listeners)e(...t)})}resize(){r.SafeAreaHeight=60;const t=this.getScreenSize(),e=r.DesignWidth>r.DesignHeight;e==t.width>t.height?(r.ScreenWidth=t.width,r.ScreenHeight=t.height):(r.ScreenWidth=t.height,r.ScreenHeight=t.width),e?(r.SafeWidth=r.ScreenWidth-2*r.SafeAreaHeight,r.SafeHeight=r.ScreenHeight):(r.SafeWidth=r.ScreenWidth,r.SafeHeight=r.ScreenHeight-2*r.SafeAreaHeight),this.printScreen()}printScreen(){s(`设计分辨率: ${r.DesignWidth}x${r.DesignHeight}`),s(`屏幕分辨率: ${r.ScreenWidth}x${r.ScreenHeight}`),s(`安全区域高度: ${r.SafeAreaHeight}`),s(`安全区宽高: ${r.SafeWidth}x${r.SafeHeight}`)}}function o(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o}"function"==typeof SuppressedError&&SuppressedError;class a{}class h{constructor(t){this._size=0,this._capacity=t<=0?4:t,this._nodes=new Array(this._capacity)}clear(){this._size=0}get(t){return this._nodes[t]}top(){return this._nodes[0]}contains(t){return t.index>=0&&t.index<this._size}push(t){const e=++this._size;e>this._capacity&&(this._capacity=this._nodes.length*=2),this._sortUp(t,e-1)}pop(){if(0==this._size)return null;const t=this._nodes,e=t[0];e.index=-1,t[0]=null;const i=--this._size;if(i>0){const e=t[i];t[i]=null,this._sortDown(e,0)}return e}remove(t){if(!this.contains(t))return;const e=--this._size,i=this._nodes;if(t.index<e){const s=i[t.index]=i[e];s.index=t.index,i[e]=null,this.update(s)}else i[e]=null;t.index=-1}update(t){if(!this.contains(t))return!1;const e=t.index,i=this._nodes;return e>0&&i[e].lessThan(i[this._parent(e)])?this._sortUp(i[e],e):this._sortDown(i[e],e),!0}_parent(t){return t-1>>1}get count(){return this._size}get empty(){return 0==this._size}_sortUp(t,e){let i=this._parent(e);const s=this._nodes;for(;e>0&&t.lessThan(s[i]);)s[i].index=e,s[e]=s[i],e=i,i=this._parent(i);t.index=e,s[e]=t}_sortDown(t,e){let i=1+(e<<1);const s=this._nodes,r=this._size;for(;i<r;){let n=t;if(s[i].lessThan(n)&&(n=s[i]),i+1<r&&s[i+1].lessThan(n)&&(++i,n=s[i]),t==n)break;n.index=e,s[e]=n,e=i,i=1+(i<<1)}t.index=e,s[e]=t}}class c extends a{constructor(t){super(),this.loop=0,this.id=t}lessThan(t){const e=t;return Math.abs(this.expireTime-e.expireTime)<=1e-5?this.orderIndex<e.orderIndex:this.expireTime<e.expireTime}}const l=19,u=524287,p=u;class m{constructor(t){this._pool=new Array,this._freeIndices=new Array;for(let e=0;e<t;++e){const t=new c(e<<l);t.recycled=!0,this._pool.push(t),this._freeIndices.push(e)}}allocate(){let t;const e=this._pool;if(0==this._freeIndices.length){if(8192==e.length)throw new Error("超出时钟个数: 8192");t=new c(e.length<<l),e.push(t)}else{if(t=e[this._freeIndices.pop()],t.recycled=!1,(t.id&u)==p)throw new Error("时钟版本号过高: "+p);++t.id}return t}recycle(t){const e=t>>>l;if(e<0||e>=this._pool.length)throw new Error("定时器不存在");const i=this._pool[e];if(i.recycled)throw new Error("定时器已经被回收");i.recycled=!0,i.callback=null,this._freeIndices.push(e)}get(t){const e=t>>>l,i=t&u;if(e<0||e>=this._pool.length)return null;const s=this._pool[e];if(s.recycled)return null;return(s.id&u)!=i?null:s}clear(){const t=this._pool,e=t.length,i=this._freeIndices;i.length=0;for(let s=0;s<e;++s)t[s].recycled=!0,t[s].callback=null,i.push(s)}}class f{get timerCount(){return this._heap.count}constructor(t){this._timerNodeOrder=0,this._elapsedTime=0,this._heap=new h(t),this._pool=new m(t),this._pausedTimers=new Map}start(t,e,i=0){const s=this._getTimerNode(t,e,i);return this._heap.push(s),s.id}stop(t){const e=this._pool.get(t);e&&(e.pause&&this._pausedTimers.delete(t),this._heap.remove(e),this._pool.recycle(t))}pause(t){const e=this._pool.get(t);e&&(e.pause=!0,e.pauseRemainTime=e.expireTime-this._elapsedTime,this._heap.remove(e),this._pausedTimers.set(t,e))}resume(t){const e=this._pausedTimers.get(t);e&&(e.pause=!1,e.expireTime=this._elapsedTime+e.pauseRemainTime,this._pausedTimers.delete(t),this._heap.push(e))}update(t){const e=this._elapsedTime+=t,i=this._heap;let s=i.top();for(;s&&s.expireTime<=e;){const t=s.callback;0==s.loop||s.loop>0&&0==--s.loop?(i.pop(),this._recycle(s)):(s.expireTime=s.expireTime+s.interval,i.update(s)),t(),s=i.top()}}clear(){this._heap.clear(),this._pool.clear(),this._pausedTimers.clear(),this._timerNodeOrder=0}_getTimerNode(t,e,i){const s=this._pool.allocate();return s.orderIndex=++this._timerNodeOrder,s.callback=t,s.interval=e,s.expireTime=this._elapsedTime+e,s.loop=i,s.pause=!1,s}_recycle(t){this._pool.recycle(t.id)}}class d{static initTimer(){this._timer=new f(16)}static get Timer(){return this._timer||this.initTimer(),this._timer}static startTimer(t,e,i=0){return this.Timer.start(t,e,i)}static stopTimer(t){this.Timer.stop(t)}static pauseTimer(t){this.Timer.pause(t)}static resumeTimer(t){this.Timer.resume(t)}static clearAllTimer(){this.Timer.clear()}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}d._timer=null;class g{static initTimer(){this._timer=new f(16)}static startTimer(t,e,i=0){return this._timer.start(t,e,i)}static stopTimer(t){this._timer.stop(t)}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}g._timer=null;let _=null;class T{static get osBootTime(){return this._osBootTime}static get netTime(){return this._netTime}static get netTimeDiff(){return this._netTimeDiff}static get runTime(){return Math.floor(t.game.totalTime)}static _configBoot(){this._osBootTime=Math.floor(Date.now()),_=new Date,this._nowTimestamp=()=>this._osBootTime+this.runTime,s("系统启动时间",this.formatTime(this._osBootTime))}static setNetTime(t){if(0==t)return;this._netTime=t;const e=this._nowTimestamp();this._netTimeDiff=Math.floor(this.netTime-e),s(`设置网络时间: net(${this.formatTime(this.netTime)}), boot(${this.formatTime(this.osBootTime)}), diff(${Math.abs(this.netTimeDiff/1e3)}秒)`)}static now(){return this._nowTimestamp()+this.netTimeDiff}static msTos(t){return Math.floor((t||0)/1e3)}static sToMs(t){return 1e3*(t||0)}static getYear(t){return _.setTime(t||this.now()),_.getFullYear()}static getMonth(t){return _.setTime(t||this.now()),_.getMonth()+1}static getDay(t){return _.setTime(t||this.now()),_.getDate()}static getHour(t){return _.setTime(t||this.now()),_.getHours()}static getMinute(t){return _.setTime(t||this.now()),_.getMinutes()}static getSecond(t){return _.setTime(t||this.now()),_.getSeconds()}static getDayStartTime(t){return _.setTime(t||this.now()),_.setHours(0,0,0,0),_.getTime()}static getDayEndTime(t){return this.getDayStartTime(t)+864e5}static getWeekDay(t){return _.setTime(t||T.now()),_.getDay()||7}static getWeekStartTime(t){return this.getDayStartTime(t-864e5*this.getWeekDay(t))}static getWeekEndTime(t){return this.getWeekStartTime(t)+6048e5}static getMonthStartTime(t){return _.setTime(t||this.now()),_.setDate(1),_.setHours(0,0,0,0),_.getTime()}static getMonthEndTime(t){return _.setTime(t||this.now()),_.setDate(1),_.setHours(0,0,0,0),_.setMonth(_.getMonth()+1),_.getTime()}static getYearStartTime(t){return _.setTime(t||this.now()),_.setMonth(0),_.setDate(1),_.setHours(0,0,0,0),_.getTime()}static getYearEndTime(t){return _.setTime(t||this.now()),_.setMonth(0),_.setDate(1),_.setHours(0,0,0,0),_.setFullYear(_.getFullYear()+1),_.getTime()}static getMonthDays(t){const e=this.getMonthEndTime(t),i=this.getMonthStartTime(t);return Math.round((e-i)/864e5)}static isSameDay(t,e){return!((e=e||this.now())-t>864e5)&&this.getDayStartTime(t)===this.getDayStartTime(e)}static isSameWeek(t,e){return!((e=e||this.now())-t>6048e5)&&this.getWeekStartTime(t)===this.getWeekStartTime(e)}static isSameMonth(t,e){e=e||this.now(),_.setTime(t);const i=_.getMonth(),s=_.getFullYear();_.setTime(e);const r=_.getMonth(),n=_.getFullYear();return i===r&&s===n}static isSameYear(t,e){e=e||this.now(),_.setTime(t);const i=_.getFullYear();_.setTime(e);return i===_.getFullYear()}static format(t,e){_.setTime(t);const i=_.getFullYear(),s=_.getMonth()+1,r=_.getDate(),n=_.getHours(),o=_.getMinutes(),a=_.getSeconds(),h=t=>t<10?`0${t}`:`${t}`;return e.replace(/YYYY/g,`${i}`).replace(/YY/g,h(i%100)).replace(/MM/g,h(s)).replace(/M/g,`${s}`).replace(/DD/g,h(r)).replace(/D/g,`${r}`).replace(/hh/g,h(n)).replace(/h/g,`${n}`).replace(/mm/g,h(o)).replace(/m/g,`${o}`).replace(/ss/g,h(a)).replace(/s/g,`${a}`)}static formatTime(t){return this.format(t,"YYYY-MM-DD hh:mm:ss")}static formatTimeChinese(t){return this.format(t,"YYYY年MM月DD日 hh:mm:ss")}static formatDuration(t,e,i){const s=Math.floor(t<0?0:t),r=Math.floor(s/86400),n=Math.floor(s/3600),o=Math.floor(s/60),a=Math.floor(s%86400/3600),h=Math.floor(s%3600/60),c=s%60,l=t=>t<10?`0${t}`:`${t}`;let u=e;return(null==i?void 0:i.autoHide)&&(0===r&&(u=u.replace(/DD天?|D天?/g,"")),0===r&&0===a&&0===n&&(u=u.replace(/HH[时:]?|H[时:]?|hh[时:]?|h[时:]?/g,"")),0===r&&0===a&&0===n&&0===h&&0===o&&(u=u.replace(/MM[分:]?|M[分:]?|mm[分:]?|m[分:]?/g,"")),u=u.replace(/^[:\s]+|[:\s]+$/g,"").replace(/\s{2,}/g," ")),u.replace(/DD/g,l(r)).replace(/D/g,`${r}`).replace(/HH/g,l(n)).replace(/H/g,`${n}`).replace(/hh/g,l(a)).replace(/h/g,`${a}`).replace(/MM/g,l(o)).replace(/M/g,`${o}`).replace(/mm/g,l(h)).replace(/m/g,`${h}`).replace(/ss/g,l(c)).replace(/s/g,`${c}`)}static formatSmart(t,e="D天h小时m分s秒"){return this.formatDuration(t,e,{autoHide:!0})}static formatSmartSimple(t,e="D天h小时|h小时m分|m分s秒"){const i=Math.floor(t<0?0:t),[s="D天h小时",r="h小时m分",n="m分s秒",o="s秒"]=e.split("|");if(i>=86400){const t=Math.floor(i/86400),e=Math.ceil(i%86400/3600);return this.formatDuration(86400*t+3600*e,s)}if(i>=3600){const t=Math.floor(i/3600),e=Math.ceil(i%3600/60);return this.formatDuration(3600*t+60*e,r)}if(i>=60){const t=Math.floor(i/60),e=Math.ceil(i%60);return this.formatDuration(60*t+e,n)}return this.formatDuration(i,o)}}T._osBootTime=0,T._netTime=0,T._netTimeDiff=0;class w extends n{getScreenSize(){let e=t.screen.windowSize;return{width:Math.ceil(e.width/t.view.getScaleX()),height:Math.ceil(e.height/t.view.getScaleY())}}getDesignSize(){let e=t.view.getDesignResolutionSize();return{width:e.width,height:e.height}}registerListener(e){t.screen&&t.screen.on?(t.screen.on("window-resize",(...t)=>{s("window-resize"),e(...t)},this),t.screen.on("orientation-change",(...t)=>{s("orientation-change"),e(...t)},this),t.screen.on("fullscreen-change",(...t)=>{s("fullscreen-change"),e(...t)},this)):t.view.setResizeCallback(e)}}class y extends t.Component{init(){this.onInit()}}var x;exports.PlatformType=void 0,(x=exports.PlatformType||(exports.PlatformType={}))[x.Android=1]="Android",x[x.IOS=2]="IOS",x[x.HarmonyOS=3]="HarmonyOS",x[x.WX=4]="WX",x[x.Alipay=5]="Alipay",x[x.Bytedance=6]="Bytedance",x[x.HuaweiQuick=7]="HuaweiQuick",x[x.Browser=1001]="Browser";class S{}S.isNative=!1,S.isMobile=!1,S.isNativeMobile=!1,S.isAndroid=!1,S.isIOS=!1,S.isHarmonyOS=!1,S.isWX=!1,S.isAlipay=!1,S.isBytedance=!1,S.isHuaweiQuick=!1,S.isBrowser=!1;class D{constructor(){this.initPlatform()}initPlatform(){switch(S.isNative=t.sys.isNative,S.isMobile=t.sys.isMobile,S.isNativeMobile=t.sys.isNative&&t.sys.isMobile,t.sys.os){case t.sys.OS.ANDROID:S.isAndroid=!0,s("系统类型 Android");break;case t.sys.OS.IOS:S.isIOS=!0,s("系统类型 IOS");break;case t.sys.OS.OPENHARMONY:S.isHarmonyOS=!0,s("系统类型 HarmonyOS")}switch(t.sys.platform){case t.sys.Platform.WECHAT_GAME:S.isWX=!0,S.platform=exports.PlatformType.WX;break;case t.sys.Platform.ALIPAY_MINI_GAME:S.isAlipay=!0,S.platform=exports.PlatformType.Alipay;break;case t.sys.Platform.BYTEDANCE_MINI_GAME:S.isBytedance=!0,S.platform=exports.PlatformType.Bytedance;break;case t.sys.Platform.HUAWEI_QUICK_GAME:S.isHuaweiQuick=!0,S.platform=exports.PlatformType.HuaweiQuick;break;default:S.isBrowser=!0,S.platform=exports.PlatformType.Browser}s(`platform: ${exports.PlatformType[S.platform]}`)}}const{property:M}=t._decorator;class b extends t.Component{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&i(!0),s("====================开始初始化====================="),t.game.frameRate=this.fps,t.director.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new D,(new w).init(),this.initTime(),this.initModule(),s("=====================初始化完成====================="),this.onInit()}initTime(){T._configBoot(),g.initTimer(),d.initTimer(),this.schedule(this.tick.bind(this),0,t.macro.REPEAT_FOREVER)}initModule(){const t=this.getComponentsInChildren(y);for(const e of t)e.init()}tick(t){g.update(t),d.update(t)}}o([M({displayName:"游戏帧率"})],b.prototype,"fps",void 0),o([M({displayName:"开启调试输出"})],b.prototype,"enableDebug",void 0);class v{static rotl(t,e){return t<<e|t>>>32-e}static rotr(t,e){return t<<32-e|t>>>e}static endianNumber(t){return 16711935&v.rotl(t,8)|4278255360&v.rotl(t,24)}static endianArray(t){for(let e=0,i=t.length;e<i;e++)t[e]=v.endianNumber(t[e]);return t}static randomBytes(t){const e=[];for(;t>0;t--)e.push(Math.floor(256*Math.random()));return e}static bytesToWords(t){const e=[];for(let i=0,s=0,r=t.length;i<r;i++,s+=8)e[s>>>5]|=t[i]<<24-s%32;return e}static wordsToBytes(t){const e=[];for(let i=0,s=32*t.length;i<s;i+=8)e.push(t[i>>>5]>>>24-i%32&255);return e}static bytesToHex(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return e.join("")}static hexToBytes(t){const e=[];for(let i=0,s=t.length;i<s;i+=2)e.push(parseInt(t.substr(i,2),16));return e}}const A=function(t){const e=function(t){const e=[];for(let i=0,s=(t=unescape(encodeURIComponent(t))).length;i<s;i++)e.push(255&t.charCodeAt(i));return e}(t),i=v.bytesToWords(e),s=8*e.length;let r=i.length,n=1732584193,o=-271733879,a=-1732584194,h=271733878;for(let t=0;t<r;t++)i[t]=16711935&(i[t]<<8|i[t]>>>24)|4278255360&(i[t]<<24|i[t]>>>8);i[s>>>5]|=128<<s%32,i[14+(s+64>>>9<<4)]=s;const c=A._ff,l=A._gg,u=A._hh,p=A._ii;r=i.length;for(let t=0;t<r;t+=16){const e=n,s=o,r=a,m=h;n=c(n,o,a,h,i[t+0],7,-680876936),h=c(h,n,o,a,i[t+1],12,-389564586),a=c(a,h,n,o,i[t+2],17,606105819),o=c(o,a,h,n,i[t+3],22,-1044525330),n=c(n,o,a,h,i[t+4],7,-176418897),h=c(h,n,o,a,i[t+5],12,1200080426),a=c(a,h,n,o,i[t+6],17,-1473231341),o=c(o,a,h,n,i[t+7],22,-45705983),n=c(n,o,a,h,i[t+8],7,1770035416),h=c(h,n,o,a,i[t+9],12,-1958414417),a=c(a,h,n,o,i[t+10],17,-42063),o=c(o,a,h,n,i[t+11],22,-1990404162),n=c(n,o,a,h,i[t+12],7,1804603682),h=c(h,n,o,a,i[t+13],12,-40341101),a=c(a,h,n,o,i[t+14],17,-1502002290),o=c(o,a,h,n,i[t+15],22,1236535329),n=l(n,o,a,h,i[t+1],5,-165796510),h=l(h,n,o,a,i[t+6],9,-1069501632),a=l(a,h,n,o,i[t+11],14,643717713),o=l(o,a,h,n,i[t+0],20,-373897302),n=l(n,o,a,h,i[t+5],5,-701558691),h=l(h,n,o,a,i[t+10],9,38016083),a=l(a,h,n,o,i[t+15],14,-660478335),o=l(o,a,h,n,i[t+4],20,-405537848),n=l(n,o,a,h,i[t+9],5,568446438),h=l(h,n,o,a,i[t+14],9,-1019803690),a=l(a,h,n,o,i[t+3],14,-187363961),o=l(o,a,h,n,i[t+8],20,1163531501),n=l(n,o,a,h,i[t+13],5,-1444681467),h=l(h,n,o,a,i[t+2],9,-51403784),a=l(a,h,n,o,i[t+7],14,1735328473),o=l(o,a,h,n,i[t+12],20,-1926607734),n=u(n,o,a,h,i[t+5],4,-378558),h=u(h,n,o,a,i[t+8],11,-2022574463),a=u(a,h,n,o,i[t+11],16,1839030562),o=u(o,a,h,n,i[t+14],23,-35309556),n=u(n,o,a,h,i[t+1],4,-1530992060),h=u(h,n,o,a,i[t+4],11,1272893353),a=u(a,h,n,o,i[t+7],16,-155497632),o=u(o,a,h,n,i[t+10],23,-1094730640),n=u(n,o,a,h,i[t+13],4,681279174),h=u(h,n,o,a,i[t+0],11,-358537222),a=u(a,h,n,o,i[t+3],16,-722521979),o=u(o,a,h,n,i[t+6],23,76029189),n=u(n,o,a,h,i[t+9],4,-640364487),h=u(h,n,o,a,i[t+12],11,-421815835),a=u(a,h,n,o,i[t+15],16,530742520),o=u(o,a,h,n,i[t+2],23,-995338651),n=p(n,o,a,h,i[t+0],6,-198630844),h=p(h,n,o,a,i[t+7],10,1126891415),a=p(a,h,n,o,i[t+14],15,-1416354905),o=p(o,a,h,n,i[t+5],21,-57434055),n=p(n,o,a,h,i[t+12],6,1700485571),h=p(h,n,o,a,i[t+3],10,-1894986606),a=p(a,h,n,o,i[t+10],15,-1051523),o=p(o,a,h,n,i[t+1],21,-2054922799),n=p(n,o,a,h,i[t+8],6,1873313359),h=p(h,n,o,a,i[t+15],10,-30611744),a=p(a,h,n,o,i[t+6],15,-1560198380),o=p(o,a,h,n,i[t+13],21,1309151649),n=p(n,o,a,h,i[t+4],6,-145523070),h=p(h,n,o,a,i[t+11],10,-1120210379),a=p(a,h,n,o,i[t+2],15,718787259),o=p(o,a,h,n,i[t+9],21,-343485551),n=n+e>>>0,o=o+s>>>0,a=a+r>>>0,h=h+m>>>0}return v.endianArray([n,o,a,h])};A._ff=function(t,e,i,s,r,n,o){const a=t+(e&i|~e&s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},A._gg=function(t,e,i,s,r,n,o){const a=t+(e&s|i&~s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},A._hh=function(t,e,i,s,r,n,o){const a=t+(e^i^s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},A._ii=function(t,e,i,s,r,n,o){const a=t+(i^(e|~s))+(r>>>0)+o;return(a<<n|a>>>32-n)+e};function H(t,e){return t===e}class U{constructor(t){this.element=t,this.next=void 0}}class k extends U{constructor(t){super(t),this.prev=void 0}}class E{constructor(t){this._equalsFn=t||H,this._count=0,this._head=void 0}push(t){const e=new U(t);let i;if(void 0===this._head)this._head=e;else{for(i=this._head;void 0!==i.next;)i=i.next;i.next=e}this._count++}insert(t,e){if(e>=0&&e<=this._count){const i=new U(t);if(0===e){const t=this._head;i.next=t,this._head=i}else{const t=this.getElementAt(e-1),s=t.next;i.next=s,t.next=i}return this._count++,!0}return!1}getElementAt(t){if(t>=0&&t<=this._count){let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}remove(t){return this.removeAt(this.indexOf(t))}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next;else{const i=this.getElementAt(t-1);e=i.next,i.next=e.next}return this._count--,e.next=void 0,e.element}}indexOf(t){let e=this._head;for(let i=0;i<this._count&&void 0!==e;i++){if(this._equalsFn(t,e.element))return i;e=e.next}return-1}clear(){this._head=void 0,this._count=0}getHead(){return this._head}isEmpty(){return 0===this.size()}size(){return this._count}toString(){if(void 0===this._head)return"";let t=`${this._head.element}`,e=this._head.next;for(let i=0;i<this.size()&&void 0!==e;i++)t=`${t},${e.element}`,e=e.next;return t}}class O extends E{constructor(t){super(t),this._tail=void 0}push(t){this.insert(t,this._count)}insert(t,e){if(e>=0&&e<=this._count){const i=new k(t);let s=this._head;if(0===e)void 0===this._head?(this._head=i,this._tail=i):(i.next=s,s.prev=i,this._head=i);else if(e===this._count)s=this._tail,s.next=i,i.prev=s,this._tail=i;else{const t=this.getElementAt(e-1);s=t.next,i.next=s,t.next=i,s.prev=i,i.prev=t}return this._count++,!0}return!1}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next,1===this._count?this._tail=void 0:this._head.prev=void 0;else if(t===this._count-1)e=this._tail,this._tail=e.prev,this._tail.next=void 0;else{e=this.getElementAt(t);const i=e.prev;i.next=e.next,e.next.prev=i}return this._count--,e.next=void 0,e.prev=void 0,e.element}return null}getElementAt(t){if(t>=0&&t<=this._count){if(t>.5*this._count){let e=this._tail;for(let i=this._count-1;i>t&&void 0!==e;i--)e=e.prev;return e}{let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}}getHead(){return this._head}getTail(){return this._tail}clear(){this._head=void 0,this._tail=void 0,this._count=0}}exports.Adapter=n,exports.Binary=class{static toBinary(t){const e=[];this.writeValue(t,e);const i=e.reduce((t,e)=>t+e.length,0),s=new Uint8Array(i);let r=0;for(const t of e)s.set(t,r),r+=t.length;return s}static toJson(t){const e=t instanceof ArrayBuffer?new Uint8Array(t):t;if(!this.isBinaryFormat(e))return t;const i=new DataView(e.buffer);return this.readValue(i,0)}static isBinaryFormat(t){if(!t||!t.length||t.length<1)return!1;const e=t[0];if(e<0||e>5)return!1;try{const e=new DataView(t.buffer);let i=0;return this.validateBinaryFormat(e,i),!0}catch(t){return!1}}static validateBinaryFormat(t,e){switch(t.getUint8(e)){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.validateBinaryFormat(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.validateBinaryFormat(t,e+s)}return s}default:throw new Error("无效的类型标记")}}static readValue(t,e){const i=t.getUint8(e++);switch(i){case 0:return null;case 1:return t.getFloat64(e,!0);case 2:{const i=t.getUint32(e,!0);e+=4;const s=new Uint8Array(t.buffer,e,i);return this.utf8ArrayToString(s)}case 3:return 1===t.getUint8(e);case 4:const s=t.getUint32(e,!0);e+=4;const r=[];for(let i=0;i<s;i++)r.push(this.readValue(t,e)),e+=this.getNextOffset(t,e);return r;case 5:{const i=t.getUint32(e,!0);e+=4;const s={};for(let r=0;r<i;r++){const i=t.getUint32(e,!0);e+=4;let r="";for(let s=0;s<i;s++)r+=String.fromCharCode(t.getUint8(e+s));e+=i,s[r]=this.readValue(t,e),e+=this.getNextOffset(t,e)}return s}default:throw new Error(`未知的类型: ${i}`)}}static writeValue(t,e){if(null!==t)switch(typeof t){case"number":{const i=new Uint8Array(9);i[0]=1;new DataView(i.buffer).setFloat64(1,t,!0),e.push(i);break}case"string":{const i=this.stringToUtf8Array(t),s=i.length,r=new Uint8Array(5+s);r[0]=2;new DataView(r.buffer).setUint32(1,s,!0),r.set(i,5),e.push(r);break}case"boolean":{const i=new Uint8Array(2);i[0]=3,i[1]=t?1:0,e.push(i);break}case"object":if(Array.isArray(t)){const i=new Uint8Array(5);i[0]=4;new DataView(i.buffer).setUint32(1,t.length,!0),e.push(i);for(const i of t)this.writeValue(i,e)}else{const i=Object.keys(t),s=new Uint8Array(5);s[0]=5;new DataView(s.buffer).setUint32(1,i.length,!0),e.push(s);for(const s of i){const i=s.length,r=new Uint8Array(4+i);new DataView(r.buffer).setUint32(0,i,!0);const n=(new TextEncoder).encode(s);r.set(n,4),e.push(r),this.writeValue(t[s],e)}}break;default:throw new Error("不支持的类型: "+typeof t)}else e.push(new Uint8Array([0]))}static getNextOffset(t,e){const i=t.getUint8(e);switch(i){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.getNextOffset(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.getNextOffset(t,e+s)}return s}default:throw new Error(`未知的类型: ${i}`)}}static utf8ArrayToString(t){if(!t||0===t.length)return"";let e="",i=0;try{for(;i<t.length;){let s=t[i++];if(s>127)if(s>191&&s<224){if(i>=t.length)break;s=(31&s)<<6|63&t[i++]}else if(s>223&&s<240){if(i+1>=t.length)break;s=(15&s)<<12|(63&t[i++])<<6|63&t[i++]}else{if(!(s>239&&s<248))continue;if(i+2>=t.length)break;s=(7&s)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++]}s<=65535?e+=String.fromCharCode(s):s<=1114111&&(s-=65536,e+=String.fromCharCode(s>>10|55296),e+=String.fromCharCode(1023&s|56320))}}catch(t){return console.error("UTF-8 解码错误:",t),""}return e}static stringToUtf8Array(t){if(!t||0===t.length)return new Uint8Array(0);const e=[];try{for(let i=0;i<t.length;i++){let s=t.charCodeAt(i);if(s<128)e.push(s);else if(s<2048)e.push(192|s>>6),e.push(128|63&s);else if(s<55296||s>=57344)e.push(224|s>>12),e.push(128|s>>6&63),e.push(128|63&s);else{if(i+1>=t.length)break;i++,s=(1023&s)<<10|1023&t.charCodeAt(i),s+=65536,e.push(240|s>>18),e.push(128|s>>12&63),e.push(128|s>>6&63),e.push(128|63&s)}}}catch(t){return console.error("UTF-8 编码错误:",t),new Uint8Array(0)}return new Uint8Array(e)}},exports.BinaryHeap=h,exports.CocosEntry=b,exports.DoublyLinkedList=O,exports.DoublyNode=k,exports.GlobalTimer=d,exports.HeapNode=a,exports.InnerTimer=g,exports.LinkedList=E,exports.LinkedNode=U,exports.Module=y,exports.Platform=S,exports.Screen=r,exports.Stack=class{constructor(t){this._items=new O(t)}push(t){this._items.push(t)}pop(){if(!this.isEmpty())return this._items.removeAt(this.size()-1)}peek(){if(!this.isEmpty())return this._items.getTail().element}size(){return this._items.size()}isEmpty(){return this._items.isEmpty()}clear(){this._items.clear()}toString(){return this._items.toString()}},exports.Time=T,exports.Utils=class{static compareVersion(t,e){let i=t.split("."),s=e.split(".");const r=Math.max(i.length,s.length);for(;i.length<r;)i.push("0");for(;s.length<r;)s.push("0");for(let t=0;t<r;++t){let e=parseInt(i[t]),r=parseInt(s[t]);if(e>r)return 1;if(e<r)return-1}return 0}static isJsonString(t){try{return JSON.parse(t),!0}catch(t){return!1}}static getUrlParam(t){let e={url:"",params:{}},i=t.split("?");if(e.url=i[0],i.length>1){let t=i[1].split("&");for(let i=0;i<t.length;i++){let s=t[i],[r,n]=s.split("=");e.params[r]=n}}return e}static addUrlParam(t,e,i){let s=this.getUrlParam(t);return s.params[e]=i,s.url+"?"+Object.entries(s.params).map(([t,e])=>`${t}=${e}`).join("&")}},exports.debug=s,exports.enableDebugMode=i,exports.error=function(...t){e&&console.error("bit-framework:",...t)},exports.info=function(...t){e&&console.info("bit-framework:",...t)},exports.log=function(...t){console.log("bit-framework:",...t)},exports.md5=function(t){if(null==t)throw new Error("Illegal argument "+t);return v.bytesToHex(v.wordsToBytes(A(t)))},exports.warn=function(...t){e&&console.warn("bit-framework:",...t)};
|
|
1
|
+
"use strict";var t=require("cc");let e=!1;function i(t){1==t?(e=!0,console.warn("调试模式已开启")):e=!1}function s(...t){e&&console.log("bit-framework:",...t)}class r{}class n{constructor(){this.listeners=[]}addResizeListener(t){this.listeners.push(t)}removeResizeListener(t){this.listeners=this.listeners.filter(e=>e!==t)}init(){n.instance=this,s("初始化适配器");let e=this.getDesignSize();r.DesignHeight=e.height,r.DesignWidth=e.width,t.view.setDesignResolutionSize(r.DesignWidth,r.DesignHeight,t.ResolutionPolicy.SHOW_ALL),this.resize(),this.registerListener((...t)=>{s("屏幕发生变化",...t),this.resize();for(const e of this.listeners)e(...t)})}resize(){r.SafeAreaHeight=60;const t=this.getScreenSize(),e=r.DesignWidth>r.DesignHeight;e==t.width>t.height?(r.ScreenWidth=t.width,r.ScreenHeight=t.height):(r.ScreenWidth=t.height,r.ScreenHeight=t.width),e?(r.SafeWidth=r.ScreenWidth-2*r.SafeAreaHeight,r.SafeHeight=r.ScreenHeight):(r.SafeWidth=r.ScreenWidth,r.SafeHeight=r.ScreenHeight-2*r.SafeAreaHeight),this.printScreen()}printScreen(){s(`设计分辨率: ${r.DesignWidth}x${r.DesignHeight}`),s(`屏幕分辨率: ${r.ScreenWidth}x${r.ScreenHeight}`),s(`安全区域高度: ${r.SafeAreaHeight}`),s(`安全区宽高: ${r.SafeWidth}x${r.SafeHeight}`)}}function o(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o}"function"==typeof SuppressedError&&SuppressedError;class a{}class h{constructor(t){this._size=0,this._capacity=t<=0?4:t,this._nodes=new Array(this._capacity)}clear(){this._size=0}get(t){return this._nodes[t]}top(){return this._nodes[0]}contains(t){return t.index>=0&&t.index<this._size}push(t){const e=++this._size;e>this._capacity&&(this._capacity=this._nodes.length*=2),this._sortUp(t,e-1)}pop(){if(0==this._size)return null;const t=this._nodes,e=t[0];e.index=-1,t[0]=null;const i=--this._size;if(i>0){const e=t[i];t[i]=null,this._sortDown(e,0)}return e}remove(t){if(!this.contains(t))return;const e=--this._size,i=this._nodes;if(t.index<e){const s=i[t.index]=i[e];s.index=t.index,i[e]=null,this.update(s)}else i[e]=null;t.index=-1}update(t){if(!this.contains(t))return!1;const e=t.index,i=this._nodes;return e>0&&i[e].lessThan(i[this._parent(e)])?this._sortUp(i[e],e):this._sortDown(i[e],e),!0}_parent(t){return t-1>>1}get count(){return this._size}get empty(){return 0==this._size}_sortUp(t,e){let i=this._parent(e);const s=this._nodes;for(;e>0&&t.lessThan(s[i]);)s[i].index=e,s[e]=s[i],e=i,i=this._parent(i);t.index=e,s[e]=t}_sortDown(t,e){let i=1+(e<<1);const s=this._nodes,r=this._size;for(;i<r;){let n=t;if(s[i].lessThan(n)&&(n=s[i]),i+1<r&&s[i+1].lessThan(n)&&(++i,n=s[i]),t==n)break;n.index=e,s[e]=n,e=i,i=1+(i<<1)}t.index=e,s[e]=t}}class c extends a{constructor(t){super(),this.loop=0,this.id=t}lessThan(t){const e=t;return Math.abs(this.expireTime-e.expireTime)<=1e-5?this.orderIndex<e.orderIndex:this.expireTime<e.expireTime}}const l=19,u=524287,p=u;class m{constructor(t){this._pool=new Array,this._freeIndices=new Array;for(let e=0;e<t;++e){const t=new c(e<<l);t.recycled=!0,this._pool.push(t),this._freeIndices.push(e)}}allocate(){let t;const e=this._pool;if(0==this._freeIndices.length){if(8192==e.length)throw new Error("超出时钟个数: 8192");t=new c(e.length<<l),e.push(t)}else{if(t=e[this._freeIndices.pop()],t.recycled=!1,(t.id&u)==p)throw new Error("时钟版本号过高: "+p);++t.id}return t}recycle(t){const e=t>>>l;if(e<0||e>=this._pool.length)throw new Error("定时器不存在");const i=this._pool[e];if(i.recycled)throw new Error("定时器已经被回收");i.recycled=!0,i.callback=null,this._freeIndices.push(e)}get(t){const e=t>>>l,i=t&u;if(e<0||e>=this._pool.length)return;const s=this._pool[e];if(s.recycled)return;return(s.id&u)==i?s:void 0}clear(){const t=this._pool,e=t.length,i=this._freeIndices;i.length=0;for(let s=0;s<e;++s)t[s].recycled=!0,t[s].callback=null,i.push(s)}}class f{get timerCount(){return this._heap.count}constructor(t){this._timerNodeOrder=0,this._elapsedTime=0,this._heap=new h(t),this._pool=new m(t),this._pausedTimers=new Map}start(t,e,i=0){const s=this._getTimerNode(t,e,i);return this._heap.push(s),s.id}stop(t){const e=this._pool.get(t);e&&(e.pause&&this._pausedTimers.delete(t),this._heap.remove(e),this._pool.recycle(t))}pause(t){const e=this._pool.get(t);e&&(e.pause=!0,e.pauseRemainTime=e.expireTime-this._elapsedTime,this._heap.remove(e),this._pausedTimers.set(t,e))}resume(t){const e=this._pausedTimers.get(t);e&&(e.pause=!1,e.expireTime=this._elapsedTime+e.pauseRemainTime,this._pausedTimers.delete(t),this._heap.push(e))}update(t){const e=this._elapsedTime+=t,i=this._heap;let s=i.top();for(;s&&s.expireTime<=e;){const t=s.callback;if(0==s.loop)i.pop(),this._recycle(s);else if(s.loop>0){const t=Math.floor((e-s.expireTime)/s.interval)+1;s.loop-=t,s.loop<=0?(i.pop(),this._recycle(s)):(s.expireTime+=s.interval*t,i.update(s))}else{const t=Math.floor((e-s.expireTime)/s.interval)+1;s.expireTime+=s.interval*t,i.update(s)}if(t)try{t()}catch(t){console.error("Timer callback error:",t)}s=i.top()}}clear(){this._heap.clear(),this._pool.clear(),this._pausedTimers.clear(),this._timerNodeOrder=0}_getTimerNode(t,e,i){const s=this._pool.allocate();return s.orderIndex=++this._timerNodeOrder,s.callback=t,s.interval=e,s.expireTime=this._elapsedTime+e,s.loop=i,s.pause=!1,s}_recycle(t){this._pool.recycle(t.id)}}class d{static initTimer(){this._timer=new f(16)}static get Timer(){return this._timer||this.initTimer(),this._timer}static startTimer(t,e,i=0){return this.Timer.start(t,e,i)}static stopTimer(t){this.Timer.stop(t)}static pauseTimer(t){this.Timer.pause(t)}static resumeTimer(t){this.Timer.resume(t)}static clearAllTimer(){this.Timer.clear()}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}d._timer=null;class g{static initTimer(){this._timer=new f(16)}static get Timer(){return this._timer||this.initTimer(),this._timer}static startTimer(t,e,i=0){return this.Timer.start(t,e,i)}static stopTimer(t){this.Timer.stop(t)}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}g._timer=null;let _=null;class T{static get osBootTime(){return this._osBootTime}static get netTime(){return this._netTime}static get netTimeDiff(){return this._netTimeDiff}static get runTime(){return Math.floor(t.game.totalTime)}static _configBoot(){this._osBootTime=Math.floor(Date.now()),_=new Date,this._nowTimestamp=()=>this._osBootTime+this.runTime,s("系统启动时间",this.formatTime(this._osBootTime))}static setNetTime(t){if(0==t)return;this._netTime=t;const e=this._nowTimestamp();this._netTimeDiff=Math.floor(this.netTime-e),s(`设置网络时间: net(${this.formatTime(this.netTime)}), boot(${this.formatTime(this.osBootTime)}), diff(${Math.abs(this.netTimeDiff/1e3)}秒)`)}static now(){return this._nowTimestamp()+this.netTimeDiff}static msTos(t){return Math.floor((t||0)/1e3)}static sToMs(t){return 1e3*(t||0)}static getYear(t){return _.setTime(t||this.now()),_.getFullYear()}static getMonth(t){return _.setTime(t||this.now()),_.getMonth()+1}static getDay(t){return _.setTime(t||this.now()),_.getDate()}static getHour(t){return _.setTime(t||this.now()),_.getHours()}static getMinute(t){return _.setTime(t||this.now()),_.getMinutes()}static getSecond(t){return _.setTime(t||this.now()),_.getSeconds()}static getDayStartTime(t){return _.setTime(t||this.now()),_.setHours(0,0,0,0),_.getTime()}static getDayEndTime(t){return this.getDayStartTime(t)+864e5}static getWeekDay(t){return _.setTime(t||T.now()),_.getDay()||7}static getWeekStartTime(t){const e=t||this.now();return this.getDayStartTime(e-864e5*(this.getWeekDay(e)-1))}static getWeekEndTime(t){return this.getWeekStartTime(t)+6048e5}static getMonthStartTime(t){return _.setTime(t||this.now()),_.setDate(1),_.setHours(0,0,0,0),_.getTime()}static getMonthEndTime(t){return _.setTime(t||this.now()),_.setDate(1),_.setHours(0,0,0,0),_.setMonth(_.getMonth()+1),_.getTime()}static getYearStartTime(t){return _.setTime(t||this.now()),_.setMonth(0),_.setDate(1),_.setHours(0,0,0,0),_.getTime()}static getYearEndTime(t){return _.setTime(t||this.now()),_.setMonth(0),_.setDate(1),_.setHours(0,0,0,0),_.setFullYear(_.getFullYear()+1),_.getTime()}static getMonthDays(t){const e=this.getMonthEndTime(t),i=this.getMonthStartTime(t);return Math.round((e-i)/864e5)}static isSameDay(t,e){return!((e=e||this.now())-t>864e5)&&this.getDayStartTime(t)===this.getDayStartTime(e)}static isSameWeek(t,e){return!((e=e||this.now())-t>6048e5)&&this.getWeekStartTime(t)===this.getWeekStartTime(e)}static isSameMonth(t,e){e=e||this.now(),_.setTime(t);const i=_.getMonth(),s=_.getFullYear();_.setTime(e);const r=_.getMonth(),n=_.getFullYear();return i===r&&s===n}static isSameYear(t,e){e=e||this.now(),_.setTime(t);const i=_.getFullYear();_.setTime(e);return i===_.getFullYear()}static format(t,e){_.setTime(t);const i=_.getFullYear(),s=_.getMonth()+1,r=_.getDate(),n=_.getHours(),o=_.getMinutes(),a=_.getSeconds(),h=t=>t<10?`0${t}`:`${t}`;return e.replace(/YYYY/g,`${i}`).replace(/YY/g,h(i%100)).replace(/MM/g,h(s)).replace(/M/g,`${s}`).replace(/DD/g,h(r)).replace(/D/g,`${r}`).replace(/hh/g,h(n)).replace(/h/g,`${n}`).replace(/mm/g,h(o)).replace(/m/g,`${o}`).replace(/ss/g,h(a)).replace(/s/g,`${a}`)}static formatTime(t){return this.format(t,"YYYY-MM-DD hh:mm:ss")}static formatTimeChinese(t){return this.format(t,"YYYY年MM月DD日 hh:mm:ss")}static formatDuration(t,e,i){const s=Math.floor(t<0?0:t),r=Math.floor(s/86400),n=Math.floor(s/3600),o=Math.floor(s/60),a=Math.floor(s%86400/3600),h=Math.floor(s%3600/60),c=s%60,l=t=>t<10?`0${t}`:`${t}`;let u=e;return(null==i?void 0:i.autoHide)&&(0===r&&(u=u.replace(/DD天?|D天?/g,"")),0===r&&0===a&&0===n&&(u=u.replace(/HH[时:]?|H[时:]?|hh[时:]?|h[时:]?/g,"")),0===r&&0===a&&0===n&&0===h&&0===o&&(u=u.replace(/MM[分:]?|M[分:]?|mm[分:]?|m[分:]?/g,"")),u=u.replace(/^[:\s]+|[:\s]+$/g,"").replace(/\s{2,}/g," ")),u.replace(/DD/g,l(r)).replace(/D/g,`${r}`).replace(/HH/g,l(n)).replace(/H/g,`${n}`).replace(/hh/g,l(a)).replace(/h/g,`${a}`).replace(/MM/g,l(o)).replace(/M/g,`${o}`).replace(/mm/g,l(h)).replace(/m/g,`${h}`).replace(/ss/g,l(c)).replace(/s/g,`${c}`)}static formatSmart(t,e="D天h小时m分s秒"){return this.formatDuration(t,e,{autoHide:!0})}static formatSmartSimple(t,e="D天h小时|h小时m分|m分s秒"){const i=Math.floor(t<0?0:t),[s="D天h小时",r="h小时m分",n="m分s秒",o="s秒"]=e.split("|");if(i>=86400){const t=Math.floor(i/86400),e=Math.ceil(i%86400/3600);return this.formatDuration(86400*t+3600*e,s)}if(i>=3600){const t=Math.floor(i/3600),e=Math.ceil(i%3600/60);return this.formatDuration(3600*t+60*e,r)}if(i>=60){const t=Math.floor(i/60),e=Math.ceil(i%60);return this.formatDuration(60*t+e,n)}return this.formatDuration(i,o)}}T._osBootTime=0,T._netTime=0,T._netTimeDiff=0,T._nowTimestamp=()=>Date.now();class w extends n{getScreenSize(){let e=t.screen.windowSize;return{width:Math.ceil(e.width/t.view.getScaleX()),height:Math.ceil(e.height/t.view.getScaleY())}}getDesignSize(){let e=t.view.getDesignResolutionSize();return{width:e.width,height:e.height}}registerListener(e){t.screen&&t.screen.on?(t.screen.on("window-resize",(...t)=>{s("window-resize"),e(...t)},this),t.screen.on("orientation-change",(...t)=>{s("orientation-change"),e(...t)},this),t.screen.on("fullscreen-change",(...t)=>{s("fullscreen-change"),e(...t)},this)):t.view.setResizeCallback(e)}}class y extends t.Component{init(){this.onInit()}}var x;exports.PlatformType=void 0,(x=exports.PlatformType||(exports.PlatformType={}))[x.Android=1]="Android",x[x.IOS=2]="IOS",x[x.HarmonyOS=3]="HarmonyOS",x[x.WX=4]="WX",x[x.Alipay=5]="Alipay",x[x.Bytedance=6]="Bytedance",x[x.HuaweiQuick=7]="HuaweiQuick",x[x.Browser=1001]="Browser";class S{}S.isNative=!1,S.isMobile=!1,S.isNativeMobile=!1,S.isAndroid=!1,S.isIOS=!1,S.isHarmonyOS=!1,S.isWX=!1,S.isAlipay=!1,S.isBytedance=!1,S.isHuaweiQuick=!1,S.isBrowser=!1;class D{constructor(){this.initPlatform()}initPlatform(){switch(S.isNative=t.sys.isNative,S.isMobile=t.sys.isMobile,S.isNativeMobile=t.sys.isNative&&t.sys.isMobile,t.sys.os){case t.sys.OS.ANDROID:S.isAndroid=!0,s("系统类型 Android");break;case t.sys.OS.IOS:S.isIOS=!0,s("系统类型 IOS");break;case t.sys.OS.OPENHARMONY:S.isHarmonyOS=!0,s("系统类型 HarmonyOS")}switch(t.sys.platform){case t.sys.Platform.WECHAT_GAME:S.isWX=!0,S.platform=exports.PlatformType.WX;break;case t.sys.Platform.ALIPAY_MINI_GAME:S.isAlipay=!0,S.platform=exports.PlatformType.Alipay;break;case t.sys.Platform.BYTEDANCE_MINI_GAME:S.isBytedance=!0,S.platform=exports.PlatformType.Bytedance;break;case t.sys.Platform.HUAWEI_QUICK_GAME:S.isHuaweiQuick=!0,S.platform=exports.PlatformType.HuaweiQuick;break;default:S.isBrowser=!0,S.platform=exports.PlatformType.Browser}s(`platform: ${exports.PlatformType[S.platform]}`)}}const{property:M}=t._decorator;class v extends t.Component{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&i(!0),s("====================开始初始化====================="),t.game.frameRate=this.fps,t.director.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new D,(new w).init(),this.initTime(),this.initModule(),s("=====================初始化完成====================="),this.onInit()}initTime(){T._configBoot(),g.initTimer(),d.initTimer(),this.schedule(this.tick.bind(this),0,t.macro.REPEAT_FOREVER)}initModule(){const t=this.getComponentsInChildren(y);for(const e of t)e.init()}tick(t){g.update(t),d.update(t)}}o([M({displayName:"游戏帧率"})],v.prototype,"fps",void 0),o([M({displayName:"开启调试输出"})],v.prototype,"enableDebug",void 0);class b{static rotl(t,e){return t<<e|t>>>32-e}static rotr(t,e){return t<<32-e|t>>>e}static endianNumber(t){return 16711935&b.rotl(t,8)|4278255360&b.rotl(t,24)}static endianArray(t){for(let e=0,i=t.length;e<i;e++)t[e]=b.endianNumber(t[e]);return t}static randomBytes(t){const e=[];for(;t>0;t--)e.push(Math.floor(256*Math.random()));return e}static bytesToWords(t){const e=[];for(let i=0,s=0,r=t.length;i<r;i++,s+=8)e[s>>>5]|=t[i]<<24-s%32;return e}static wordsToBytes(t){const e=[];for(let i=0,s=32*t.length;i<s;i+=8)e.push(t[i>>>5]>>>24-i%32&255);return e}static bytesToHex(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return e.join("")}static hexToBytes(t){const e=[];for(let i=0,s=t.length;i<s;i+=2)e.push(parseInt(t.substr(i,2),16));return e}}const A=function(t){const e=function(t){const e=[];for(let i=0,s=(t=unescape(encodeURIComponent(t))).length;i<s;i++)e.push(255&t.charCodeAt(i));return e}(t),i=b.bytesToWords(e),s=8*e.length;let r=i.length,n=1732584193,o=-271733879,a=-1732584194,h=271733878;for(let t=0;t<r;t++)i[t]=16711935&(i[t]<<8|i[t]>>>24)|4278255360&(i[t]<<24|i[t]>>>8);i[s>>>5]|=128<<s%32,i[14+(s+64>>>9<<4)]=s;const c=A._ff,l=A._gg,u=A._hh,p=A._ii;r=i.length;for(let t=0;t<r;t+=16){const e=n,s=o,r=a,m=h;n=c(n,o,a,h,i[t+0],7,-680876936),h=c(h,n,o,a,i[t+1],12,-389564586),a=c(a,h,n,o,i[t+2],17,606105819),o=c(o,a,h,n,i[t+3],22,-1044525330),n=c(n,o,a,h,i[t+4],7,-176418897),h=c(h,n,o,a,i[t+5],12,1200080426),a=c(a,h,n,o,i[t+6],17,-1473231341),o=c(o,a,h,n,i[t+7],22,-45705983),n=c(n,o,a,h,i[t+8],7,1770035416),h=c(h,n,o,a,i[t+9],12,-1958414417),a=c(a,h,n,o,i[t+10],17,-42063),o=c(o,a,h,n,i[t+11],22,-1990404162),n=c(n,o,a,h,i[t+12],7,1804603682),h=c(h,n,o,a,i[t+13],12,-40341101),a=c(a,h,n,o,i[t+14],17,-1502002290),o=c(o,a,h,n,i[t+15],22,1236535329),n=l(n,o,a,h,i[t+1],5,-165796510),h=l(h,n,o,a,i[t+6],9,-1069501632),a=l(a,h,n,o,i[t+11],14,643717713),o=l(o,a,h,n,i[t+0],20,-373897302),n=l(n,o,a,h,i[t+5],5,-701558691),h=l(h,n,o,a,i[t+10],9,38016083),a=l(a,h,n,o,i[t+15],14,-660478335),o=l(o,a,h,n,i[t+4],20,-405537848),n=l(n,o,a,h,i[t+9],5,568446438),h=l(h,n,o,a,i[t+14],9,-1019803690),a=l(a,h,n,o,i[t+3],14,-187363961),o=l(o,a,h,n,i[t+8],20,1163531501),n=l(n,o,a,h,i[t+13],5,-1444681467),h=l(h,n,o,a,i[t+2],9,-51403784),a=l(a,h,n,o,i[t+7],14,1735328473),o=l(o,a,h,n,i[t+12],20,-1926607734),n=u(n,o,a,h,i[t+5],4,-378558),h=u(h,n,o,a,i[t+8],11,-2022574463),a=u(a,h,n,o,i[t+11],16,1839030562),o=u(o,a,h,n,i[t+14],23,-35309556),n=u(n,o,a,h,i[t+1],4,-1530992060),h=u(h,n,o,a,i[t+4],11,1272893353),a=u(a,h,n,o,i[t+7],16,-155497632),o=u(o,a,h,n,i[t+10],23,-1094730640),n=u(n,o,a,h,i[t+13],4,681279174),h=u(h,n,o,a,i[t+0],11,-358537222),a=u(a,h,n,o,i[t+3],16,-722521979),o=u(o,a,h,n,i[t+6],23,76029189),n=u(n,o,a,h,i[t+9],4,-640364487),h=u(h,n,o,a,i[t+12],11,-421815835),a=u(a,h,n,o,i[t+15],16,530742520),o=u(o,a,h,n,i[t+2],23,-995338651),n=p(n,o,a,h,i[t+0],6,-198630844),h=p(h,n,o,a,i[t+7],10,1126891415),a=p(a,h,n,o,i[t+14],15,-1416354905),o=p(o,a,h,n,i[t+5],21,-57434055),n=p(n,o,a,h,i[t+12],6,1700485571),h=p(h,n,o,a,i[t+3],10,-1894986606),a=p(a,h,n,o,i[t+10],15,-1051523),o=p(o,a,h,n,i[t+1],21,-2054922799),n=p(n,o,a,h,i[t+8],6,1873313359),h=p(h,n,o,a,i[t+15],10,-30611744),a=p(a,h,n,o,i[t+6],15,-1560198380),o=p(o,a,h,n,i[t+13],21,1309151649),n=p(n,o,a,h,i[t+4],6,-145523070),h=p(h,n,o,a,i[t+11],10,-1120210379),a=p(a,h,n,o,i[t+2],15,718787259),o=p(o,a,h,n,i[t+9],21,-343485551),n=n+e>>>0,o=o+s>>>0,a=a+r>>>0,h=h+m>>>0}return b.endianArray([n,o,a,h])};A._ff=function(t,e,i,s,r,n,o){const a=t+(e&i|~e&s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},A._gg=function(t,e,i,s,r,n,o){const a=t+(e&s|i&~s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},A._hh=function(t,e,i,s,r,n,o){const a=t+(e^i^s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},A._ii=function(t,e,i,s,r,n,o){const a=t+(i^(e|~s))+(r>>>0)+o;return(a<<n|a>>>32-n)+e};function H(t,e){return t===e}class U{constructor(t){this.element=t,this.next=void 0}}class k extends U{constructor(t){super(t),this.prev=void 0}}class E{constructor(t){this._equalsFn=t||H,this._count=0,this._head=void 0}push(t){const e=new U(t);let i;if(void 0===this._head)this._head=e;else{for(i=this._head;void 0!==i.next;)i=i.next;i.next=e}this._count++}insert(t,e){if(e>=0&&e<=this._count){const i=new U(t);if(0===e){const t=this._head;i.next=t,this._head=i}else{const t=this.getElementAt(e-1),s=t.next;i.next=s,t.next=i}return this._count++,!0}return!1}getElementAt(t){if(t>=0&&t<=this._count){let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}remove(t){return this.removeAt(this.indexOf(t))}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next;else{const i=this.getElementAt(t-1);e=i.next,i.next=e.next}return this._count--,e.next=void 0,e.element}}indexOf(t){let e=this._head;for(let i=0;i<this._count&&void 0!==e;i++){if(this._equalsFn(t,e.element))return i;e=e.next}return-1}clear(){this._head=void 0,this._count=0}getHead(){return this._head}isEmpty(){return 0===this.size()}size(){return this._count}toString(){if(void 0===this._head)return"";let t=`${this._head.element}`,e=this._head.next;for(let i=0;i<this.size()&&void 0!==e;i++)t=`${t},${e.element}`,e=e.next;return t}}class O extends E{constructor(t){super(t),this._tail=void 0}push(t){this.insert(t,this._count)}insert(t,e){if(e>=0&&e<=this._count){const i=new k(t);let s=this._head;if(0===e)void 0===this._head?(this._head=i,this._tail=i):(i.next=s,s.prev=i,this._head=i);else if(e===this._count)s=this._tail,s.next=i,i.prev=s,this._tail=i;else{const t=this.getElementAt(e-1);s=t.next,i.next=s,t.next=i,s.prev=i,i.prev=t}return this._count++,!0}return!1}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next,1===this._count?this._tail=void 0:this._head.prev=void 0;else if(t===this._count-1)e=this._tail,this._tail=e.prev,this._tail.next=void 0;else{e=this.getElementAt(t);const i=e.prev;i.next=e.next,e.next.prev=i}return this._count--,e.next=void 0,e.prev=void 0,e.element}}getElementAt(t){if(t>=0&&t<=this._count){if(t>.5*this._count){let e=this._tail;for(let i=this._count-1;i>t&&void 0!==e;i--)e=e.prev;return e}{let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}}getHead(){return this._head}getTail(){return this._tail}clear(){this._head=void 0,this._tail=void 0,this._count=0}}exports.Adapter=n,exports.Binary=class{static toBinary(t){const e=[];this.writeValue(t,e);const i=e.reduce((t,e)=>t+e.length,0),s=new Uint8Array(i);let r=0;for(const t of e)s.set(t,r),r+=t.length;return s}static toJson(t){const e=t instanceof ArrayBuffer?new Uint8Array(t):t;if(!this.isBinaryFormat(e))return t;const i=new DataView(e.buffer);return this.readValue(i,0)}static isBinaryFormat(t){if(!t||!t.length||t.length<1)return!1;const e=t[0];if(e<0||e>5)return!1;try{const e=new DataView(t.buffer);let i=0;return this.validateBinaryFormat(e,i),!0}catch(t){return!1}}static validateBinaryFormat(t,e){switch(t.getUint8(e)){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.validateBinaryFormat(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.validateBinaryFormat(t,e+s)}return s}default:throw new Error("无效的类型标记")}}static readValue(t,e){const i=t.getUint8(e++);switch(i){case 0:return null;case 1:return t.getFloat64(e,!0);case 2:{const i=t.getUint32(e,!0);e+=4;const s=new Uint8Array(t.buffer,e,i);return this.utf8ArrayToString(s)}case 3:return 1===t.getUint8(e);case 4:const s=t.getUint32(e,!0);e+=4;const r=[];for(let i=0;i<s;i++)r.push(this.readValue(t,e)),e+=this.getNextOffset(t,e);return r;case 5:{const i=t.getUint32(e,!0);e+=4;const s={};for(let r=0;r<i;r++){const i=t.getUint32(e,!0);e+=4;let r="";for(let s=0;s<i;s++)r+=String.fromCharCode(t.getUint8(e+s));e+=i,s[r]=this.readValue(t,e),e+=this.getNextOffset(t,e)}return s}default:throw new Error(`未知的类型: ${i}`)}}static writeValue(t,e){if(null!==t)switch(typeof t){case"number":{const i=new Uint8Array(9);i[0]=1;new DataView(i.buffer).setFloat64(1,t,!0),e.push(i);break}case"string":{const i=this.stringToUtf8Array(t),s=i.length,r=new Uint8Array(5+s);r[0]=2;new DataView(r.buffer).setUint32(1,s,!0),r.set(i,5),e.push(r);break}case"boolean":{const i=new Uint8Array(2);i[0]=3,i[1]=t?1:0,e.push(i);break}case"object":if(Array.isArray(t)){const i=new Uint8Array(5);i[0]=4;new DataView(i.buffer).setUint32(1,t.length,!0),e.push(i);for(const i of t)this.writeValue(i,e)}else{const i=Object.keys(t),s=new Uint8Array(5);s[0]=5;new DataView(s.buffer).setUint32(1,i.length,!0),e.push(s);for(const s of i){const i=s.length,r=new Uint8Array(4+i);new DataView(r.buffer).setUint32(0,i,!0);const n=(new TextEncoder).encode(s);r.set(n,4),e.push(r),this.writeValue(t[s],e)}}break;default:throw new Error("不支持的类型: "+typeof t)}else e.push(new Uint8Array([0]))}static getNextOffset(t,e){const i=t.getUint8(e);switch(i){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.getNextOffset(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.getNextOffset(t,e+s)}return s}default:throw new Error(`未知的类型: ${i}`)}}static utf8ArrayToString(t){if(!t||0===t.length)return"";let e="",i=0;try{for(;i<t.length;){let s=t[i++];if(s>127)if(s>191&&s<224){if(i>=t.length)break;s=(31&s)<<6|63&t[i++]}else if(s>223&&s<240){if(i+1>=t.length)break;s=(15&s)<<12|(63&t[i++])<<6|63&t[i++]}else{if(!(s>239&&s<248))continue;if(i+2>=t.length)break;s=(7&s)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++]}s<=65535?e+=String.fromCharCode(s):s<=1114111&&(s-=65536,e+=String.fromCharCode(s>>10|55296),e+=String.fromCharCode(1023&s|56320))}}catch(t){return console.error("UTF-8 解码错误:",t),""}return e}static stringToUtf8Array(t){if(!t||0===t.length)return new Uint8Array(0);const e=[];try{for(let i=0;i<t.length;i++){let s=t.charCodeAt(i);if(s<128)e.push(s);else if(s<2048)e.push(192|s>>6),e.push(128|63&s);else if(s<55296||s>=57344)e.push(224|s>>12),e.push(128|s>>6&63),e.push(128|63&s);else{if(i+1>=t.length)break;i++,s=(1023&s)<<10|1023&t.charCodeAt(i),s+=65536,e.push(240|s>>18),e.push(128|s>>12&63),e.push(128|s>>6&63),e.push(128|63&s)}}}catch(t){return console.error("UTF-8 编码错误:",t),new Uint8Array(0)}return new Uint8Array(e)}},exports.BinaryHeap=h,exports.CocosEntry=v,exports.DoublyLinkedList=O,exports.DoublyNode=k,exports.GlobalTimer=d,exports.HeapNode=a,exports.InnerTimer=g,exports.LinkedList=E,exports.LinkedNode=U,exports.Module=y,exports.Platform=S,exports.Screen=r,exports.Stack=class{constructor(t){this._items=new O(t)}push(t){this._items.push(t)}pop(){if(!this.isEmpty())return this._items.removeAt(this.size()-1)}peek(){if(!this.isEmpty())return this._items.getTail().element}size(){return this._items.size()}isEmpty(){return this._items.isEmpty()}clear(){this._items.clear()}toString(){return this._items.toString()}},exports.Time=T,exports.Utils=class{static compareVersion(t,e){let i=t.split("."),s=e.split(".");const r=Math.max(i.length,s.length);for(;i.length<r;)i.push("0");for(;s.length<r;)s.push("0");for(let t=0;t<r;++t){let e=parseInt(i[t]),r=parseInt(s[t]);if(e>r)return 1;if(e<r)return-1}return 0}static isJsonString(t){try{return JSON.parse(t),!0}catch(t){return!1}}static getUrlParam(t){let e={url:"",params:{}},i=t.split("?");if(e.url=i[0],i.length>1){let t=i[1].split("&");for(let i=0;i<t.length;i++){let s=t[i],[r,n]=s.split("=");e.params[r]=n}}return e}static addUrlParam(t,e,i){let s=this.getUrlParam(t);return s.params[e]=i,s.url+"?"+Object.entries(s.params).map(([t,e])=>`${t}=${e}`).join("&")}},exports.debug=s,exports.enableDebugMode=i,exports.error=function(...t){e&&console.error("bit-framework:",...t)},exports.info=function(...t){e&&console.info("bit-framework:",...t)},exports.log=function(...t){console.log("bit-framework:",...t)},exports.md5=function(t){if(null==t)throw new Error("Illegal argument "+t);return b.bytesToHex(b.wordsToBytes(A(t)))},exports.warn=function(...t){e&&console.warn("bit-framework:",...t)};
|
package/dist/bit-core.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{view as t,ResolutionPolicy as e,game as i,screen as s,Component as r,sys as n,_decorator as o,director as a,macro as h}from"cc";let c=!1;function l(t){1==t?(c=!0,console.warn("调试模式已开启")):c=!1}function u(...t){console.log("bit-framework:",...t)}function m(...t){c&&console.log("bit-framework:",...t)}function f(...t){c&&console.info("bit-framework:",...t)}function g(...t){c&&console.warn("bit-framework:",...t)}function p(...t){c&&console.error("bit-framework:",...t)}class d{}class _{constructor(){this.listeners=[]}addResizeListener(t){this.listeners.push(t)}removeResizeListener(t){this.listeners=this.listeners.filter(e=>e!==t)}init(){_.instance=this,m("初始化适配器");let i=this.getDesignSize();d.DesignHeight=i.height,d.DesignWidth=i.width,t.setDesignResolutionSize(d.DesignWidth,d.DesignHeight,e.SHOW_ALL),this.resize(),this.registerListener((...t)=>{m("屏幕发生变化",...t),this.resize();for(const e of this.listeners)e(...t)})}resize(){d.SafeAreaHeight=60;const t=this.getScreenSize(),e=d.DesignWidth>d.DesignHeight;e==t.width>t.height?(d.ScreenWidth=t.width,d.ScreenHeight=t.height):(d.ScreenWidth=t.height,d.ScreenHeight=t.width),e?(d.SafeWidth=d.ScreenWidth-2*d.SafeAreaHeight,d.SafeHeight=d.ScreenHeight):(d.SafeWidth=d.ScreenWidth,d.SafeHeight=d.ScreenHeight-2*d.SafeAreaHeight),this.printScreen()}printScreen(){m(`设计分辨率: ${d.DesignWidth}x${d.DesignHeight}`),m(`屏幕分辨率: ${d.ScreenWidth}x${d.ScreenHeight}`),m(`安全区域高度: ${d.SafeAreaHeight}`),m(`安全区宽高: ${d.SafeWidth}x${d.SafeHeight}`)}}function T(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o}"function"==typeof SuppressedError&&SuppressedError;class w{}class y{constructor(t){this._size=0,this._capacity=t<=0?4:t,this._nodes=new Array(this._capacity)}clear(){this._size=0}get(t){return this._nodes[t]}top(){return this._nodes[0]}contains(t){return t.index>=0&&t.index<this._size}push(t){const e=++this._size;e>this._capacity&&(this._capacity=this._nodes.length*=2),this._sortUp(t,e-1)}pop(){if(0==this._size)return null;const t=this._nodes,e=t[0];e.index=-1,t[0]=null;const i=--this._size;if(i>0){const e=t[i];t[i]=null,this._sortDown(e,0)}return e}remove(t){if(!this.contains(t))return;const e=--this._size,i=this._nodes;if(t.index<e){const s=i[t.index]=i[e];s.index=t.index,i[e]=null,this.update(s)}else i[e]=null;t.index=-1}update(t){if(!this.contains(t))return!1;const e=t.index,i=this._nodes;return e>0&&i[e].lessThan(i[this._parent(e)])?this._sortUp(i[e],e):this._sortDown(i[e],e),!0}_parent(t){return t-1>>1}get count(){return this._size}get empty(){return 0==this._size}_sortUp(t,e){let i=this._parent(e);const s=this._nodes;for(;e>0&&t.lessThan(s[i]);)s[i].index=e,s[e]=s[i],e=i,i=this._parent(i);t.index=e,s[e]=t}_sortDown(t,e){let i=1+(e<<1);const s=this._nodes,r=this._size;for(;i<r;){let n=t;if(s[i].lessThan(n)&&(n=s[i]),i+1<r&&s[i+1].lessThan(n)&&(++i,n=s[i]),t==n)break;n.index=e,s[e]=n,e=i,i=1+(i<<1)}t.index=e,s[e]=t}}class S extends w{constructor(t){super(),this.loop=0,this.id=t}lessThan(t){const e=t;return Math.abs(this.expireTime-e.expireTime)<=1e-5?this.orderIndex<e.orderIndex:this.expireTime<e.expireTime}}const x=19,D=524287,M=D;class A{constructor(t){this._pool=new Array,this._freeIndices=new Array;for(let e=0;e<t;++e){const t=new S(e<<x);t.recycled=!0,this._pool.push(t),this._freeIndices.push(e)}}allocate(){let t;const e=this._pool;if(0==this._freeIndices.length){if(8192==e.length)throw new Error("超出时钟个数: 8192");t=new S(e.length<<x),e.push(t)}else{if(t=e[this._freeIndices.pop()],t.recycled=!1,(t.id&D)==M)throw new Error("时钟版本号过高: "+M);++t.id}return t}recycle(t){const e=t>>>x;if(e<0||e>=this._pool.length)throw new Error("定时器不存在");const i=this._pool[e];if(i.recycled)throw new Error("定时器已经被回收");i.recycled=!0,i.callback=null,this._freeIndices.push(e)}get(t){const e=t>>>x,i=t&D;if(e<0||e>=this._pool.length)return null;const s=this._pool[e];if(s.recycled)return null;return(s.id&D)!=i?null:s}clear(){const t=this._pool,e=t.length,i=this._freeIndices;i.length=0;for(let s=0;s<e;++s)t[s].recycled=!0,t[s].callback=null,i.push(s)}}class b{get timerCount(){return this._heap.count}constructor(t){this._timerNodeOrder=0,this._elapsedTime=0,this._heap=new y(t),this._pool=new A(t),this._pausedTimers=new Map}start(t,e,i=0){const s=this._getTimerNode(t,e,i);return this._heap.push(s),s.id}stop(t){const e=this._pool.get(t);e&&(e.pause&&this._pausedTimers.delete(t),this._heap.remove(e),this._pool.recycle(t))}pause(t){const e=this._pool.get(t);e&&(e.pause=!0,e.pauseRemainTime=e.expireTime-this._elapsedTime,this._heap.remove(e),this._pausedTimers.set(t,e))}resume(t){const e=this._pausedTimers.get(t);e&&(e.pause=!1,e.expireTime=this._elapsedTime+e.pauseRemainTime,this._pausedTimers.delete(t),this._heap.push(e))}update(t){const e=this._elapsedTime+=t,i=this._heap;let s=i.top();for(;s&&s.expireTime<=e;){const t=s.callback;0==s.loop||s.loop>0&&0==--s.loop?(i.pop(),this._recycle(s)):(s.expireTime=s.expireTime+s.interval,i.update(s)),t(),s=i.top()}}clear(){this._heap.clear(),this._pool.clear(),this._pausedTimers.clear(),this._timerNodeOrder=0}_getTimerNode(t,e,i){const s=this._pool.allocate();return s.orderIndex=++this._timerNodeOrder,s.callback=t,s.interval=e,s.expireTime=this._elapsedTime+e,s.loop=i,s.pause=!1,s}_recycle(t){this._pool.recycle(t.id)}}class v{static initTimer(){this._timer=new b(16)}static get Timer(){return this._timer||this.initTimer(),this._timer}static startTimer(t,e,i=0){return this.Timer.start(t,e,i)}static stopTimer(t){this.Timer.stop(t)}static pauseTimer(t){this.Timer.pause(t)}static resumeTimer(t){this.Timer.resume(t)}static clearAllTimer(){this.Timer.clear()}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}v._timer=null;class H{static initTimer(){this._timer=new b(16)}static startTimer(t,e,i=0){return this._timer.start(t,e,i)}static stopTimer(t){this._timer.stop(t)}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}H._timer=null;let U=null;class k{static get osBootTime(){return this._osBootTime}static get netTime(){return this._netTime}static get netTimeDiff(){return this._netTimeDiff}static get runTime(){return Math.floor(i.totalTime)}static _configBoot(){this._osBootTime=Math.floor(Date.now()),U=new Date,this._nowTimestamp=()=>this._osBootTime+this.runTime,m("系统启动时间",this.formatTime(this._osBootTime))}static setNetTime(t){if(0==t)return;this._netTime=t;const e=this._nowTimestamp();this._netTimeDiff=Math.floor(this.netTime-e),m(`设置网络时间: net(${this.formatTime(this.netTime)}), boot(${this.formatTime(this.osBootTime)}), diff(${Math.abs(this.netTimeDiff/1e3)}秒)`)}static now(){return this._nowTimestamp()+this.netTimeDiff}static msTos(t){return Math.floor((t||0)/1e3)}static sToMs(t){return 1e3*(t||0)}static getYear(t){return U.setTime(t||this.now()),U.getFullYear()}static getMonth(t){return U.setTime(t||this.now()),U.getMonth()+1}static getDay(t){return U.setTime(t||this.now()),U.getDate()}static getHour(t){return U.setTime(t||this.now()),U.getHours()}static getMinute(t){return U.setTime(t||this.now()),U.getMinutes()}static getSecond(t){return U.setTime(t||this.now()),U.getSeconds()}static getDayStartTime(t){return U.setTime(t||this.now()),U.setHours(0,0,0,0),U.getTime()}static getDayEndTime(t){return this.getDayStartTime(t)+864e5}static getWeekDay(t){return U.setTime(t||k.now()),U.getDay()||7}static getWeekStartTime(t){return this.getDayStartTime(t-864e5*this.getWeekDay(t))}static getWeekEndTime(t){return this.getWeekStartTime(t)+6048e5}static getMonthStartTime(t){return U.setTime(t||this.now()),U.setDate(1),U.setHours(0,0,0,0),U.getTime()}static getMonthEndTime(t){return U.setTime(t||this.now()),U.setDate(1),U.setHours(0,0,0,0),U.setMonth(U.getMonth()+1),U.getTime()}static getYearStartTime(t){return U.setTime(t||this.now()),U.setMonth(0),U.setDate(1),U.setHours(0,0,0,0),U.getTime()}static getYearEndTime(t){return U.setTime(t||this.now()),U.setMonth(0),U.setDate(1),U.setHours(0,0,0,0),U.setFullYear(U.getFullYear()+1),U.getTime()}static getMonthDays(t){const e=this.getMonthEndTime(t),i=this.getMonthStartTime(t);return Math.round((e-i)/864e5)}static isSameDay(t,e){return!((e=e||this.now())-t>864e5)&&this.getDayStartTime(t)===this.getDayStartTime(e)}static isSameWeek(t,e){return!((e=e||this.now())-t>6048e5)&&this.getWeekStartTime(t)===this.getWeekStartTime(e)}static isSameMonth(t,e){e=e||this.now(),U.setTime(t);const i=U.getMonth(),s=U.getFullYear();U.setTime(e);const r=U.getMonth(),n=U.getFullYear();return i===r&&s===n}static isSameYear(t,e){e=e||this.now(),U.setTime(t);const i=U.getFullYear();U.setTime(e);return i===U.getFullYear()}static format(t,e){U.setTime(t);const i=U.getFullYear(),s=U.getMonth()+1,r=U.getDate(),n=U.getHours(),o=U.getMinutes(),a=U.getSeconds(),h=t=>t<10?`0${t}`:`${t}`;return e.replace(/YYYY/g,`${i}`).replace(/YY/g,h(i%100)).replace(/MM/g,h(s)).replace(/M/g,`${s}`).replace(/DD/g,h(r)).replace(/D/g,`${r}`).replace(/hh/g,h(n)).replace(/h/g,`${n}`).replace(/mm/g,h(o)).replace(/m/g,`${o}`).replace(/ss/g,h(a)).replace(/s/g,`${a}`)}static formatTime(t){return this.format(t,"YYYY-MM-DD hh:mm:ss")}static formatTimeChinese(t){return this.format(t,"YYYY年MM月DD日 hh:mm:ss")}static formatDuration(t,e,i){const s=Math.floor(t<0?0:t),r=Math.floor(s/86400),n=Math.floor(s/3600),o=Math.floor(s/60),a=Math.floor(s%86400/3600),h=Math.floor(s%3600/60),c=s%60,l=t=>t<10?`0${t}`:`${t}`;let u=e;return(null==i?void 0:i.autoHide)&&(0===r&&(u=u.replace(/DD天?|D天?/g,"")),0===r&&0===a&&0===n&&(u=u.replace(/HH[时:]?|H[时:]?|hh[时:]?|h[时:]?/g,"")),0===r&&0===a&&0===n&&0===h&&0===o&&(u=u.replace(/MM[分:]?|M[分:]?|mm[分:]?|m[分:]?/g,"")),u=u.replace(/^[:\s]+|[:\s]+$/g,"").replace(/\s{2,}/g," ")),u.replace(/DD/g,l(r)).replace(/D/g,`${r}`).replace(/HH/g,l(n)).replace(/H/g,`${n}`).replace(/hh/g,l(a)).replace(/h/g,`${a}`).replace(/MM/g,l(o)).replace(/M/g,`${o}`).replace(/mm/g,l(h)).replace(/m/g,`${h}`).replace(/ss/g,l(c)).replace(/s/g,`${c}`)}static formatSmart(t,e="D天h小时m分s秒"){return this.formatDuration(t,e,{autoHide:!0})}static formatSmartSimple(t,e="D天h小时|h小时m分|m分s秒"){const i=Math.floor(t<0?0:t),[s="D天h小时",r="h小时m分",n="m分s秒",o="s秒"]=e.split("|");if(i>=86400){const t=Math.floor(i/86400),e=Math.ceil(i%86400/3600);return this.formatDuration(86400*t+3600*e,s)}if(i>=3600){const t=Math.floor(i/3600),e=Math.ceil(i%3600/60);return this.formatDuration(3600*t+60*e,r)}if(i>=60){const t=Math.floor(i/60),e=Math.ceil(i%60);return this.formatDuration(60*t+e,n)}return this.formatDuration(i,o)}}k._osBootTime=0,k._netTime=0,k._netTimeDiff=0;class E extends _{getScreenSize(){let e=s.windowSize;return{width:Math.ceil(e.width/t.getScaleX()),height:Math.ceil(e.height/t.getScaleY())}}getDesignSize(){let e=t.getDesignResolutionSize();return{width:e.width,height:e.height}}registerListener(e){s&&s.on?(s.on("window-resize",(...t)=>{m("window-resize"),e(...t)},this),s.on("orientation-change",(...t)=>{m("orientation-change"),e(...t)},this),s.on("fullscreen-change",(...t)=>{m("fullscreen-change"),e(...t)},this)):t.setResizeCallback(e)}}class O extends r{init(){this.onInit()}}var $;!function(t){t[t.Android=1]="Android",t[t.IOS=2]="IOS",t[t.HarmonyOS=3]="HarmonyOS",t[t.WX=4]="WX",t[t.Alipay=5]="Alipay",t[t.Bytedance=6]="Bytedance",t[t.HuaweiQuick=7]="HuaweiQuick",t[t.Browser=1001]="Browser"}($||($={}));class B{}B.isNative=!1,B.isMobile=!1,B.isNativeMobile=!1,B.isAndroid=!1,B.isIOS=!1,B.isHarmonyOS=!1,B.isWX=!1,B.isAlipay=!1,B.isBytedance=!1,B.isHuaweiQuick=!1,B.isBrowser=!1;class I{constructor(){this.initPlatform()}initPlatform(){switch(B.isNative=n.isNative,B.isMobile=n.isMobile,B.isNativeMobile=n.isNative&&n.isMobile,n.os){case n.OS.ANDROID:B.isAndroid=!0,m("系统类型 Android");break;case n.OS.IOS:B.isIOS=!0,m("系统类型 IOS");break;case n.OS.OPENHARMONY:B.isHarmonyOS=!0,m("系统类型 HarmonyOS")}switch(n.platform){case n.Platform.WECHAT_GAME:B.isWX=!0,B.platform=$.WX;break;case n.Platform.ALIPAY_MINI_GAME:B.isAlipay=!0,B.platform=$.Alipay;break;case n.Platform.BYTEDANCE_MINI_GAME:B.isBytedance=!0,B.platform=$.Bytedance;break;case n.Platform.HUAWEI_QUICK_GAME:B.isHuaweiQuick=!0,B.platform=$.HuaweiQuick;break;default:B.isBrowser=!0,B.platform=$.Browser}m(`platform: ${$[B.platform]}`)}}const{property:z}=o;class W extends r{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&l(!0),m("====================开始初始化====================="),i.frameRate=this.fps,a.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new I,(new E).init(),this.initTime(),this.initModule(),m("=====================初始化完成====================="),this.onInit()}initTime(){k._configBoot(),H.initTimer(),v.initTimer(),this.schedule(this.tick.bind(this),0,h.REPEAT_FOREVER)}initModule(){const t=this.getComponentsInChildren(O);for(const e of t)e.init()}tick(t){H.update(t),v.update(t)}}T([z({displayName:"游戏帧率"})],W.prototype,"fps",void 0),T([z({displayName:"开启调试输出"})],W.prototype,"enableDebug",void 0);class Y{static toBinary(t){const e=[];this.writeValue(t,e);const i=e.reduce((t,e)=>t+e.length,0),s=new Uint8Array(i);let r=0;for(const t of e)s.set(t,r),r+=t.length;return s}static toJson(t){const e=t instanceof ArrayBuffer?new Uint8Array(t):t;if(!this.isBinaryFormat(e))return t;const i=new DataView(e.buffer);return this.readValue(i,0)}static isBinaryFormat(t){if(!t||!t.length||t.length<1)return!1;const e=t[0];if(e<0||e>5)return!1;try{const e=new DataView(t.buffer);let i=0;return this.validateBinaryFormat(e,i),!0}catch(t){return!1}}static validateBinaryFormat(t,e){switch(t.getUint8(e)){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.validateBinaryFormat(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.validateBinaryFormat(t,e+s)}return s}default:throw new Error("无效的类型标记")}}static readValue(t,e){const i=t.getUint8(e++);switch(i){case 0:return null;case 1:return t.getFloat64(e,!0);case 2:{const i=t.getUint32(e,!0);e+=4;const s=new Uint8Array(t.buffer,e,i);return this.utf8ArrayToString(s)}case 3:return 1===t.getUint8(e);case 4:const s=t.getUint32(e,!0);e+=4;const r=[];for(let i=0;i<s;i++)r.push(this.readValue(t,e)),e+=this.getNextOffset(t,e);return r;case 5:{const i=t.getUint32(e,!0);e+=4;const s={};for(let r=0;r<i;r++){const i=t.getUint32(e,!0);e+=4;let r="";for(let s=0;s<i;s++)r+=String.fromCharCode(t.getUint8(e+s));e+=i,s[r]=this.readValue(t,e),e+=this.getNextOffset(t,e)}return s}default:throw new Error(`未知的类型: ${i}`)}}static writeValue(t,e){if(null!==t)switch(typeof t){case"number":{const i=new Uint8Array(9);i[0]=1;new DataView(i.buffer).setFloat64(1,t,!0),e.push(i);break}case"string":{const i=this.stringToUtf8Array(t),s=i.length,r=new Uint8Array(5+s);r[0]=2;new DataView(r.buffer).setUint32(1,s,!0),r.set(i,5),e.push(r);break}case"boolean":{const i=new Uint8Array(2);i[0]=3,i[1]=t?1:0,e.push(i);break}case"object":if(Array.isArray(t)){const i=new Uint8Array(5);i[0]=4;new DataView(i.buffer).setUint32(1,t.length,!0),e.push(i);for(const i of t)this.writeValue(i,e)}else{const i=Object.keys(t),s=new Uint8Array(5);s[0]=5;new DataView(s.buffer).setUint32(1,i.length,!0),e.push(s);for(const s of i){const i=s.length,r=new Uint8Array(4+i);new DataView(r.buffer).setUint32(0,i,!0);const n=(new TextEncoder).encode(s);r.set(n,4),e.push(r),this.writeValue(t[s],e)}}break;default:throw new Error("不支持的类型: "+typeof t)}else e.push(new Uint8Array([0]))}static getNextOffset(t,e){const i=t.getUint8(e);switch(i){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.getNextOffset(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.getNextOffset(t,e+s)}return s}default:throw new Error(`未知的类型: ${i}`)}}static utf8ArrayToString(t){if(!t||0===t.length)return"";let e="",i=0;try{for(;i<t.length;){let s=t[i++];if(s>127)if(s>191&&s<224){if(i>=t.length)break;s=(31&s)<<6|63&t[i++]}else if(s>223&&s<240){if(i+1>=t.length)break;s=(15&s)<<12|(63&t[i++])<<6|63&t[i++]}else{if(!(s>239&&s<248))continue;if(i+2>=t.length)break;s=(7&s)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++]}s<=65535?e+=String.fromCharCode(s):s<=1114111&&(s-=65536,e+=String.fromCharCode(s>>10|55296),e+=String.fromCharCode(1023&s|56320))}}catch(t){return console.error("UTF-8 解码错误:",t),""}return e}static stringToUtf8Array(t){if(!t||0===t.length)return new Uint8Array(0);const e=[];try{for(let i=0;i<t.length;i++){let s=t.charCodeAt(i);if(s<128)e.push(s);else if(s<2048)e.push(192|s>>6),e.push(128|63&s);else if(s<55296||s>=57344)e.push(224|s>>12),e.push(128|s>>6&63),e.push(128|63&s);else{if(i+1>=t.length)break;i++,s=(1023&s)<<10|1023&t.charCodeAt(i),s+=65536,e.push(240|s>>18),e.push(128|s>>12&63),e.push(128|s>>6&63),e.push(128|63&s)}}}catch(t){return console.error("UTF-8 编码错误:",t),new Uint8Array(0)}return new Uint8Array(e)}}class N{static rotl(t,e){return t<<e|t>>>32-e}static rotr(t,e){return t<<32-e|t>>>e}static endianNumber(t){return 16711935&N.rotl(t,8)|4278255360&N.rotl(t,24)}static endianArray(t){for(let e=0,i=t.length;e<i;e++)t[e]=N.endianNumber(t[e]);return t}static randomBytes(t){const e=[];for(;t>0;t--)e.push(Math.floor(256*Math.random()));return e}static bytesToWords(t){const e=[];for(let i=0,s=0,r=t.length;i<r;i++,s+=8)e[s>>>5]|=t[i]<<24-s%32;return e}static wordsToBytes(t){const e=[];for(let i=0,s=32*t.length;i<s;i+=8)e.push(t[i>>>5]>>>24-i%32&255);return e}static bytesToHex(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return e.join("")}static hexToBytes(t){const e=[];for(let i=0,s=t.length;i<s;i+=2)e.push(parseInt(t.substr(i,2),16));return e}}const F=function(t){const e=function(t){const e=[];for(let i=0,s=(t=unescape(encodeURIComponent(t))).length;i<s;i++)e.push(255&t.charCodeAt(i));return e}(t),i=N.bytesToWords(e),s=8*e.length;let r=i.length,n=1732584193,o=-271733879,a=-1732584194,h=271733878;for(let t=0;t<r;t++)i[t]=16711935&(i[t]<<8|i[t]>>>24)|4278255360&(i[t]<<24|i[t]>>>8);i[s>>>5]|=128<<s%32,i[14+(s+64>>>9<<4)]=s;const c=F._ff,l=F._gg,u=F._hh,m=F._ii;r=i.length;for(let t=0;t<r;t+=16){const e=n,s=o,r=a,f=h;n=c(n,o,a,h,i[t+0],7,-680876936),h=c(h,n,o,a,i[t+1],12,-389564586),a=c(a,h,n,o,i[t+2],17,606105819),o=c(o,a,h,n,i[t+3],22,-1044525330),n=c(n,o,a,h,i[t+4],7,-176418897),h=c(h,n,o,a,i[t+5],12,1200080426),a=c(a,h,n,o,i[t+6],17,-1473231341),o=c(o,a,h,n,i[t+7],22,-45705983),n=c(n,o,a,h,i[t+8],7,1770035416),h=c(h,n,o,a,i[t+9],12,-1958414417),a=c(a,h,n,o,i[t+10],17,-42063),o=c(o,a,h,n,i[t+11],22,-1990404162),n=c(n,o,a,h,i[t+12],7,1804603682),h=c(h,n,o,a,i[t+13],12,-40341101),a=c(a,h,n,o,i[t+14],17,-1502002290),o=c(o,a,h,n,i[t+15],22,1236535329),n=l(n,o,a,h,i[t+1],5,-165796510),h=l(h,n,o,a,i[t+6],9,-1069501632),a=l(a,h,n,o,i[t+11],14,643717713),o=l(o,a,h,n,i[t+0],20,-373897302),n=l(n,o,a,h,i[t+5],5,-701558691),h=l(h,n,o,a,i[t+10],9,38016083),a=l(a,h,n,o,i[t+15],14,-660478335),o=l(o,a,h,n,i[t+4],20,-405537848),n=l(n,o,a,h,i[t+9],5,568446438),h=l(h,n,o,a,i[t+14],9,-1019803690),a=l(a,h,n,o,i[t+3],14,-187363961),o=l(o,a,h,n,i[t+8],20,1163531501),n=l(n,o,a,h,i[t+13],5,-1444681467),h=l(h,n,o,a,i[t+2],9,-51403784),a=l(a,h,n,o,i[t+7],14,1735328473),o=l(o,a,h,n,i[t+12],20,-1926607734),n=u(n,o,a,h,i[t+5],4,-378558),h=u(h,n,o,a,i[t+8],11,-2022574463),a=u(a,h,n,o,i[t+11],16,1839030562),o=u(o,a,h,n,i[t+14],23,-35309556),n=u(n,o,a,h,i[t+1],4,-1530992060),h=u(h,n,o,a,i[t+4],11,1272893353),a=u(a,h,n,o,i[t+7],16,-155497632),o=u(o,a,h,n,i[t+10],23,-1094730640),n=u(n,o,a,h,i[t+13],4,681279174),h=u(h,n,o,a,i[t+0],11,-358537222),a=u(a,h,n,o,i[t+3],16,-722521979),o=u(o,a,h,n,i[t+6],23,76029189),n=u(n,o,a,h,i[t+9],4,-640364487),h=u(h,n,o,a,i[t+12],11,-421815835),a=u(a,h,n,o,i[t+15],16,530742520),o=u(o,a,h,n,i[t+2],23,-995338651),n=m(n,o,a,h,i[t+0],6,-198630844),h=m(h,n,o,a,i[t+7],10,1126891415),a=m(a,h,n,o,i[t+14],15,-1416354905),o=m(o,a,h,n,i[t+5],21,-57434055),n=m(n,o,a,h,i[t+12],6,1700485571),h=m(h,n,o,a,i[t+3],10,-1894986606),a=m(a,h,n,o,i[t+10],15,-1051523),o=m(o,a,h,n,i[t+1],21,-2054922799),n=m(n,o,a,h,i[t+8],6,1873313359),h=m(h,n,o,a,i[t+15],10,-30611744),a=m(a,h,n,o,i[t+6],15,-1560198380),o=m(o,a,h,n,i[t+13],21,1309151649),n=m(n,o,a,h,i[t+4],6,-145523070),h=m(h,n,o,a,i[t+11],10,-1120210379),a=m(a,h,n,o,i[t+2],15,718787259),o=m(o,a,h,n,i[t+9],21,-343485551),n=n+e>>>0,o=o+s>>>0,a=a+r>>>0,h=h+f>>>0}return N.endianArray([n,o,a,h])};function C(t){if(null==t)throw new Error("Illegal argument "+t);return N.bytesToHex(N.wordsToBytes(F(t)))}F._ff=function(t,e,i,s,r,n,o){const a=t+(e&i|~e&s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},F._gg=function(t,e,i,s,r,n,o){const a=t+(e&s|i&~s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},F._hh=function(t,e,i,s,r,n,o){const a=t+(e^i^s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},F._ii=function(t,e,i,s,r,n,o){const a=t+(i^(e|~s))+(r>>>0)+o;return(a<<n|a>>>32-n)+e};class R{static compareVersion(t,e){let i=t.split("."),s=e.split(".");const r=Math.max(i.length,s.length);for(;i.length<r;)i.push("0");for(;s.length<r;)s.push("0");for(let t=0;t<r;++t){let e=parseInt(i[t]),r=parseInt(s[t]);if(e>r)return 1;if(e<r)return-1}return 0}static isJsonString(t){try{return JSON.parse(t),!0}catch(t){return!1}}static getUrlParam(t){let e={url:"",params:{}},i=t.split("?");if(e.url=i[0],i.length>1){let t=i[1].split("&");for(let i=0;i<t.length;i++){let s=t[i],[r,n]=s.split("=");e.params[r]=n}}return e}static addUrlParam(t,e,i){let s=this.getUrlParam(t);return s.params[e]=i,s.url+"?"+Object.entries(s.params).map(([t,e])=>`${t}=${e}`).join("&")}}function V(t,e){return t===e}class P{constructor(t){this.element=t,this.next=void 0}}class j extends P{constructor(t){super(t),this.prev=void 0}}class L{constructor(t){this._equalsFn=t||V,this._count=0,this._head=void 0}push(t){const e=new P(t);let i;if(void 0===this._head)this._head=e;else{for(i=this._head;void 0!==i.next;)i=i.next;i.next=e}this._count++}insert(t,e){if(e>=0&&e<=this._count){const i=new P(t);if(0===e){const t=this._head;i.next=t,this._head=i}else{const t=this.getElementAt(e-1),s=t.next;i.next=s,t.next=i}return this._count++,!0}return!1}getElementAt(t){if(t>=0&&t<=this._count){let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}remove(t){return this.removeAt(this.indexOf(t))}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next;else{const i=this.getElementAt(t-1);e=i.next,i.next=e.next}return this._count--,e.next=void 0,e.element}}indexOf(t){let e=this._head;for(let i=0;i<this._count&&void 0!==e;i++){if(this._equalsFn(t,e.element))return i;e=e.next}return-1}clear(){this._head=void 0,this._count=0}getHead(){return this._head}isEmpty(){return 0===this.size()}size(){return this._count}toString(){if(void 0===this._head)return"";let t=`${this._head.element}`,e=this._head.next;for(let i=0;i<this.size()&&void 0!==e;i++)t=`${t},${e.element}`,e=e.next;return t}}class Q extends L{constructor(t){super(t),this._tail=void 0}push(t){this.insert(t,this._count)}insert(t,e){if(e>=0&&e<=this._count){const i=new j(t);let s=this._head;if(0===e)void 0===this._head?(this._head=i,this._tail=i):(i.next=s,s.prev=i,this._head=i);else if(e===this._count)s=this._tail,s.next=i,i.prev=s,this._tail=i;else{const t=this.getElementAt(e-1);s=t.next,i.next=s,t.next=i,s.prev=i,i.prev=t}return this._count++,!0}return!1}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next,1===this._count?this._tail=void 0:this._head.prev=void 0;else if(t===this._count-1)e=this._tail,this._tail=e.prev,this._tail.next=void 0;else{e=this.getElementAt(t);const i=e.prev;i.next=e.next,e.next.prev=i}return this._count--,e.next=void 0,e.prev=void 0,e.element}return null}getElementAt(t){if(t>=0&&t<=this._count){if(t>.5*this._count){let e=this._tail;for(let i=this._count-1;i>t&&void 0!==e;i--)e=e.prev;return e}{let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}}getHead(){return this._head}getTail(){return this._tail}clear(){this._head=void 0,this._tail=void 0,this._count=0}}class X{constructor(t){this._items=new Q(t)}push(t){this._items.push(t)}pop(){if(!this.isEmpty())return this._items.removeAt(this.size()-1)}peek(){if(!this.isEmpty())return this._items.getTail().element}size(){return this._items.size()}isEmpty(){return this._items.isEmpty()}clear(){this._items.clear()}toString(){return this._items.toString()}}export{_ as Adapter,Y as Binary,y as BinaryHeap,W as CocosEntry,Q as DoublyLinkedList,j as DoublyNode,v as GlobalTimer,w as HeapNode,H as InnerTimer,L as LinkedList,P as LinkedNode,O as Module,B as Platform,$ as PlatformType,d as Screen,X as Stack,k as Time,R as Utils,m as debug,l as enableDebugMode,p as error,f as info,u as log,C as md5,g as warn};
|
|
1
|
+
import{view as t,ResolutionPolicy as e,game as i,screen as s,Component as r,sys as n,_decorator as o,director as a,macro as h}from"cc";let c=!1;function l(t){1==t?(c=!0,console.warn("调试模式已开启")):c=!1}function u(...t){console.log("bit-framework:",...t)}function m(...t){c&&console.log("bit-framework:",...t)}function f(...t){c&&console.info("bit-framework:",...t)}function p(...t){c&&console.warn("bit-framework:",...t)}function g(...t){c&&console.error("bit-framework:",...t)}class d{}class _{constructor(){this.listeners=[]}addResizeListener(t){this.listeners.push(t)}removeResizeListener(t){this.listeners=this.listeners.filter(e=>e!==t)}init(){_.instance=this,m("初始化适配器");let i=this.getDesignSize();d.DesignHeight=i.height,d.DesignWidth=i.width,t.setDesignResolutionSize(d.DesignWidth,d.DesignHeight,e.SHOW_ALL),this.resize(),this.registerListener((...t)=>{m("屏幕发生变化",...t),this.resize();for(const e of this.listeners)e(...t)})}resize(){d.SafeAreaHeight=60;const t=this.getScreenSize(),e=d.DesignWidth>d.DesignHeight;e==t.width>t.height?(d.ScreenWidth=t.width,d.ScreenHeight=t.height):(d.ScreenWidth=t.height,d.ScreenHeight=t.width),e?(d.SafeWidth=d.ScreenWidth-2*d.SafeAreaHeight,d.SafeHeight=d.ScreenHeight):(d.SafeWidth=d.ScreenWidth,d.SafeHeight=d.ScreenHeight-2*d.SafeAreaHeight),this.printScreen()}printScreen(){m(`设计分辨率: ${d.DesignWidth}x${d.DesignHeight}`),m(`屏幕分辨率: ${d.ScreenWidth}x${d.ScreenHeight}`),m(`安全区域高度: ${d.SafeAreaHeight}`),m(`安全区宽高: ${d.SafeWidth}x${d.SafeHeight}`)}}function T(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o}"function"==typeof SuppressedError&&SuppressedError;class w{}class y{constructor(t){this._size=0,this._capacity=t<=0?4:t,this._nodes=new Array(this._capacity)}clear(){this._size=0}get(t){return this._nodes[t]}top(){return this._nodes[0]}contains(t){return t.index>=0&&t.index<this._size}push(t){const e=++this._size;e>this._capacity&&(this._capacity=this._nodes.length*=2),this._sortUp(t,e-1)}pop(){if(0==this._size)return null;const t=this._nodes,e=t[0];e.index=-1,t[0]=null;const i=--this._size;if(i>0){const e=t[i];t[i]=null,this._sortDown(e,0)}return e}remove(t){if(!this.contains(t))return;const e=--this._size,i=this._nodes;if(t.index<e){const s=i[t.index]=i[e];s.index=t.index,i[e]=null,this.update(s)}else i[e]=null;t.index=-1}update(t){if(!this.contains(t))return!1;const e=t.index,i=this._nodes;return e>0&&i[e].lessThan(i[this._parent(e)])?this._sortUp(i[e],e):this._sortDown(i[e],e),!0}_parent(t){return t-1>>1}get count(){return this._size}get empty(){return 0==this._size}_sortUp(t,e){let i=this._parent(e);const s=this._nodes;for(;e>0&&t.lessThan(s[i]);)s[i].index=e,s[e]=s[i],e=i,i=this._parent(i);t.index=e,s[e]=t}_sortDown(t,e){let i=1+(e<<1);const s=this._nodes,r=this._size;for(;i<r;){let n=t;if(s[i].lessThan(n)&&(n=s[i]),i+1<r&&s[i+1].lessThan(n)&&(++i,n=s[i]),t==n)break;n.index=e,s[e]=n,e=i,i=1+(i<<1)}t.index=e,s[e]=t}}class S extends w{constructor(t){super(),this.loop=0,this.id=t}lessThan(t){const e=t;return Math.abs(this.expireTime-e.expireTime)<=1e-5?this.orderIndex<e.orderIndex:this.expireTime<e.expireTime}}const x=19,D=524287,M=D;class v{constructor(t){this._pool=new Array,this._freeIndices=new Array;for(let e=0;e<t;++e){const t=new S(e<<x);t.recycled=!0,this._pool.push(t),this._freeIndices.push(e)}}allocate(){let t;const e=this._pool;if(0==this._freeIndices.length){if(8192==e.length)throw new Error("超出时钟个数: 8192");t=new S(e.length<<x),e.push(t)}else{if(t=e[this._freeIndices.pop()],t.recycled=!1,(t.id&D)==M)throw new Error("时钟版本号过高: "+M);++t.id}return t}recycle(t){const e=t>>>x;if(e<0||e>=this._pool.length)throw new Error("定时器不存在");const i=this._pool[e];if(i.recycled)throw new Error("定时器已经被回收");i.recycled=!0,i.callback=null,this._freeIndices.push(e)}get(t){const e=t>>>x,i=t&D;if(e<0||e>=this._pool.length)return;const s=this._pool[e];if(s.recycled)return;return(s.id&D)==i?s:void 0}clear(){const t=this._pool,e=t.length,i=this._freeIndices;i.length=0;for(let s=0;s<e;++s)t[s].recycled=!0,t[s].callback=null,i.push(s)}}class b{get timerCount(){return this._heap.count}constructor(t){this._timerNodeOrder=0,this._elapsedTime=0,this._heap=new y(t),this._pool=new v(t),this._pausedTimers=new Map}start(t,e,i=0){const s=this._getTimerNode(t,e,i);return this._heap.push(s),s.id}stop(t){const e=this._pool.get(t);e&&(e.pause&&this._pausedTimers.delete(t),this._heap.remove(e),this._pool.recycle(t))}pause(t){const e=this._pool.get(t);e&&(e.pause=!0,e.pauseRemainTime=e.expireTime-this._elapsedTime,this._heap.remove(e),this._pausedTimers.set(t,e))}resume(t){const e=this._pausedTimers.get(t);e&&(e.pause=!1,e.expireTime=this._elapsedTime+e.pauseRemainTime,this._pausedTimers.delete(t),this._heap.push(e))}update(t){const e=this._elapsedTime+=t,i=this._heap;let s=i.top();for(;s&&s.expireTime<=e;){const t=s.callback;if(0==s.loop)i.pop(),this._recycle(s);else if(s.loop>0){const t=Math.floor((e-s.expireTime)/s.interval)+1;s.loop-=t,s.loop<=0?(i.pop(),this._recycle(s)):(s.expireTime+=s.interval*t,i.update(s))}else{const t=Math.floor((e-s.expireTime)/s.interval)+1;s.expireTime+=s.interval*t,i.update(s)}if(t)try{t()}catch(t){console.error("Timer callback error:",t)}s=i.top()}}clear(){this._heap.clear(),this._pool.clear(),this._pausedTimers.clear(),this._timerNodeOrder=0}_getTimerNode(t,e,i){const s=this._pool.allocate();return s.orderIndex=++this._timerNodeOrder,s.callback=t,s.interval=e,s.expireTime=this._elapsedTime+e,s.loop=i,s.pause=!1,s}_recycle(t){this._pool.recycle(t.id)}}class A{static initTimer(){this._timer=new b(16)}static get Timer(){return this._timer||this.initTimer(),this._timer}static startTimer(t,e,i=0){return this.Timer.start(t,e,i)}static stopTimer(t){this.Timer.stop(t)}static pauseTimer(t){this.Timer.pause(t)}static resumeTimer(t){this.Timer.resume(t)}static clearAllTimer(){this.Timer.clear()}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}A._timer=null;class H{static initTimer(){this._timer=new b(16)}static get Timer(){return this._timer||this.initTimer(),this._timer}static startTimer(t,e,i=0){return this.Timer.start(t,e,i)}static stopTimer(t){this.Timer.stop(t)}static update(t){var e;null===(e=this._timer)||void 0===e||e.update(t)}}H._timer=null;let U=null;class k{static get osBootTime(){return this._osBootTime}static get netTime(){return this._netTime}static get netTimeDiff(){return this._netTimeDiff}static get runTime(){return Math.floor(i.totalTime)}static _configBoot(){this._osBootTime=Math.floor(Date.now()),U=new Date,this._nowTimestamp=()=>this._osBootTime+this.runTime,m("系统启动时间",this.formatTime(this._osBootTime))}static setNetTime(t){if(0==t)return;this._netTime=t;const e=this._nowTimestamp();this._netTimeDiff=Math.floor(this.netTime-e),m(`设置网络时间: net(${this.formatTime(this.netTime)}), boot(${this.formatTime(this.osBootTime)}), diff(${Math.abs(this.netTimeDiff/1e3)}秒)`)}static now(){return this._nowTimestamp()+this.netTimeDiff}static msTos(t){return Math.floor((t||0)/1e3)}static sToMs(t){return 1e3*(t||0)}static getYear(t){return U.setTime(t||this.now()),U.getFullYear()}static getMonth(t){return U.setTime(t||this.now()),U.getMonth()+1}static getDay(t){return U.setTime(t||this.now()),U.getDate()}static getHour(t){return U.setTime(t||this.now()),U.getHours()}static getMinute(t){return U.setTime(t||this.now()),U.getMinutes()}static getSecond(t){return U.setTime(t||this.now()),U.getSeconds()}static getDayStartTime(t){return U.setTime(t||this.now()),U.setHours(0,0,0,0),U.getTime()}static getDayEndTime(t){return this.getDayStartTime(t)+864e5}static getWeekDay(t){return U.setTime(t||k.now()),U.getDay()||7}static getWeekStartTime(t){const e=t||this.now();return this.getDayStartTime(e-864e5*(this.getWeekDay(e)-1))}static getWeekEndTime(t){return this.getWeekStartTime(t)+6048e5}static getMonthStartTime(t){return U.setTime(t||this.now()),U.setDate(1),U.setHours(0,0,0,0),U.getTime()}static getMonthEndTime(t){return U.setTime(t||this.now()),U.setDate(1),U.setHours(0,0,0,0),U.setMonth(U.getMonth()+1),U.getTime()}static getYearStartTime(t){return U.setTime(t||this.now()),U.setMonth(0),U.setDate(1),U.setHours(0,0,0,0),U.getTime()}static getYearEndTime(t){return U.setTime(t||this.now()),U.setMonth(0),U.setDate(1),U.setHours(0,0,0,0),U.setFullYear(U.getFullYear()+1),U.getTime()}static getMonthDays(t){const e=this.getMonthEndTime(t),i=this.getMonthStartTime(t);return Math.round((e-i)/864e5)}static isSameDay(t,e){return!((e=e||this.now())-t>864e5)&&this.getDayStartTime(t)===this.getDayStartTime(e)}static isSameWeek(t,e){return!((e=e||this.now())-t>6048e5)&&this.getWeekStartTime(t)===this.getWeekStartTime(e)}static isSameMonth(t,e){e=e||this.now(),U.setTime(t);const i=U.getMonth(),s=U.getFullYear();U.setTime(e);const r=U.getMonth(),n=U.getFullYear();return i===r&&s===n}static isSameYear(t,e){e=e||this.now(),U.setTime(t);const i=U.getFullYear();U.setTime(e);return i===U.getFullYear()}static format(t,e){U.setTime(t);const i=U.getFullYear(),s=U.getMonth()+1,r=U.getDate(),n=U.getHours(),o=U.getMinutes(),a=U.getSeconds(),h=t=>t<10?`0${t}`:`${t}`;return e.replace(/YYYY/g,`${i}`).replace(/YY/g,h(i%100)).replace(/MM/g,h(s)).replace(/M/g,`${s}`).replace(/DD/g,h(r)).replace(/D/g,`${r}`).replace(/hh/g,h(n)).replace(/h/g,`${n}`).replace(/mm/g,h(o)).replace(/m/g,`${o}`).replace(/ss/g,h(a)).replace(/s/g,`${a}`)}static formatTime(t){return this.format(t,"YYYY-MM-DD hh:mm:ss")}static formatTimeChinese(t){return this.format(t,"YYYY年MM月DD日 hh:mm:ss")}static formatDuration(t,e,i){const s=Math.floor(t<0?0:t),r=Math.floor(s/86400),n=Math.floor(s/3600),o=Math.floor(s/60),a=Math.floor(s%86400/3600),h=Math.floor(s%3600/60),c=s%60,l=t=>t<10?`0${t}`:`${t}`;let u=e;return(null==i?void 0:i.autoHide)&&(0===r&&(u=u.replace(/DD天?|D天?/g,"")),0===r&&0===a&&0===n&&(u=u.replace(/HH[时:]?|H[时:]?|hh[时:]?|h[时:]?/g,"")),0===r&&0===a&&0===n&&0===h&&0===o&&(u=u.replace(/MM[分:]?|M[分:]?|mm[分:]?|m[分:]?/g,"")),u=u.replace(/^[:\s]+|[:\s]+$/g,"").replace(/\s{2,}/g," ")),u.replace(/DD/g,l(r)).replace(/D/g,`${r}`).replace(/HH/g,l(n)).replace(/H/g,`${n}`).replace(/hh/g,l(a)).replace(/h/g,`${a}`).replace(/MM/g,l(o)).replace(/M/g,`${o}`).replace(/mm/g,l(h)).replace(/m/g,`${h}`).replace(/ss/g,l(c)).replace(/s/g,`${c}`)}static formatSmart(t,e="D天h小时m分s秒"){return this.formatDuration(t,e,{autoHide:!0})}static formatSmartSimple(t,e="D天h小时|h小时m分|m分s秒"){const i=Math.floor(t<0?0:t),[s="D天h小时",r="h小时m分",n="m分s秒",o="s秒"]=e.split("|");if(i>=86400){const t=Math.floor(i/86400),e=Math.ceil(i%86400/3600);return this.formatDuration(86400*t+3600*e,s)}if(i>=3600){const t=Math.floor(i/3600),e=Math.ceil(i%3600/60);return this.formatDuration(3600*t+60*e,r)}if(i>=60){const t=Math.floor(i/60),e=Math.ceil(i%60);return this.formatDuration(60*t+e,n)}return this.formatDuration(i,o)}}k._osBootTime=0,k._netTime=0,k._netTimeDiff=0,k._nowTimestamp=()=>Date.now();class E extends _{getScreenSize(){let e=s.windowSize;return{width:Math.ceil(e.width/t.getScaleX()),height:Math.ceil(e.height/t.getScaleY())}}getDesignSize(){let e=t.getDesignResolutionSize();return{width:e.width,height:e.height}}registerListener(e){s&&s.on?(s.on("window-resize",(...t)=>{m("window-resize"),e(...t)},this),s.on("orientation-change",(...t)=>{m("orientation-change"),e(...t)},this),s.on("fullscreen-change",(...t)=>{m("fullscreen-change"),e(...t)},this)):t.setResizeCallback(e)}}class O extends r{init(){this.onInit()}}var $;!function(t){t[t.Android=1]="Android",t[t.IOS=2]="IOS",t[t.HarmonyOS=3]="HarmonyOS",t[t.WX=4]="WX",t[t.Alipay=5]="Alipay",t[t.Bytedance=6]="Bytedance",t[t.HuaweiQuick=7]="HuaweiQuick",t[t.Browser=1001]="Browser"}($||($={}));class B{}B.isNative=!1,B.isMobile=!1,B.isNativeMobile=!1,B.isAndroid=!1,B.isIOS=!1,B.isHarmonyOS=!1,B.isWX=!1,B.isAlipay=!1,B.isBytedance=!1,B.isHuaweiQuick=!1,B.isBrowser=!1;class I{constructor(){this.initPlatform()}initPlatform(){switch(B.isNative=n.isNative,B.isMobile=n.isMobile,B.isNativeMobile=n.isNative&&n.isMobile,n.os){case n.OS.ANDROID:B.isAndroid=!0,m("系统类型 Android");break;case n.OS.IOS:B.isIOS=!0,m("系统类型 IOS");break;case n.OS.OPENHARMONY:B.isHarmonyOS=!0,m("系统类型 HarmonyOS")}switch(n.platform){case n.Platform.WECHAT_GAME:B.isWX=!0,B.platform=$.WX;break;case n.Platform.ALIPAY_MINI_GAME:B.isAlipay=!0,B.platform=$.Alipay;break;case n.Platform.BYTEDANCE_MINI_GAME:B.isBytedance=!0,B.platform=$.Bytedance;break;case n.Platform.HUAWEI_QUICK_GAME:B.isHuaweiQuick=!0,B.platform=$.HuaweiQuick;break;default:B.isBrowser=!0,B.platform=$.Browser}m(`platform: ${$[B.platform]}`)}}const{property:z}=o;class W extends r{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&l(!0),m("====================开始初始化====================="),i.frameRate=this.fps,a.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new I,(new E).init(),this.initTime(),this.initModule(),m("=====================初始化完成====================="),this.onInit()}initTime(){k._configBoot(),H.initTimer(),A.initTimer(),this.schedule(this.tick.bind(this),0,h.REPEAT_FOREVER)}initModule(){const t=this.getComponentsInChildren(O);for(const e of t)e.init()}tick(t){H.update(t),A.update(t)}}T([z({displayName:"游戏帧率"})],W.prototype,"fps",void 0),T([z({displayName:"开启调试输出"})],W.prototype,"enableDebug",void 0);class Y{static toBinary(t){const e=[];this.writeValue(t,e);const i=e.reduce((t,e)=>t+e.length,0),s=new Uint8Array(i);let r=0;for(const t of e)s.set(t,r),r+=t.length;return s}static toJson(t){const e=t instanceof ArrayBuffer?new Uint8Array(t):t;if(!this.isBinaryFormat(e))return t;const i=new DataView(e.buffer);return this.readValue(i,0)}static isBinaryFormat(t){if(!t||!t.length||t.length<1)return!1;const e=t[0];if(e<0||e>5)return!1;try{const e=new DataView(t.buffer);let i=0;return this.validateBinaryFormat(e,i),!0}catch(t){return!1}}static validateBinaryFormat(t,e){switch(t.getUint8(e)){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.validateBinaryFormat(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.validateBinaryFormat(t,e+s)}return s}default:throw new Error("无效的类型标记")}}static readValue(t,e){const i=t.getUint8(e++);switch(i){case 0:return null;case 1:return t.getFloat64(e,!0);case 2:{const i=t.getUint32(e,!0);e+=4;const s=new Uint8Array(t.buffer,e,i);return this.utf8ArrayToString(s)}case 3:return 1===t.getUint8(e);case 4:const s=t.getUint32(e,!0);e+=4;const r=[];for(let i=0;i<s;i++)r.push(this.readValue(t,e)),e+=this.getNextOffset(t,e);return r;case 5:{const i=t.getUint32(e,!0);e+=4;const s={};for(let r=0;r<i;r++){const i=t.getUint32(e,!0);e+=4;let r="";for(let s=0;s<i;s++)r+=String.fromCharCode(t.getUint8(e+s));e+=i,s[r]=this.readValue(t,e),e+=this.getNextOffset(t,e)}return s}default:throw new Error(`未知的类型: ${i}`)}}static writeValue(t,e){if(null!==t)switch(typeof t){case"number":{const i=new Uint8Array(9);i[0]=1;new DataView(i.buffer).setFloat64(1,t,!0),e.push(i);break}case"string":{const i=this.stringToUtf8Array(t),s=i.length,r=new Uint8Array(5+s);r[0]=2;new DataView(r.buffer).setUint32(1,s,!0),r.set(i,5),e.push(r);break}case"boolean":{const i=new Uint8Array(2);i[0]=3,i[1]=t?1:0,e.push(i);break}case"object":if(Array.isArray(t)){const i=new Uint8Array(5);i[0]=4;new DataView(i.buffer).setUint32(1,t.length,!0),e.push(i);for(const i of t)this.writeValue(i,e)}else{const i=Object.keys(t),s=new Uint8Array(5);s[0]=5;new DataView(s.buffer).setUint32(1,i.length,!0),e.push(s);for(const s of i){const i=s.length,r=new Uint8Array(4+i);new DataView(r.buffer).setUint32(0,i,!0);const n=(new TextEncoder).encode(s);r.set(n,4),e.push(r),this.writeValue(t[s],e)}}break;default:throw new Error("不支持的类型: "+typeof t)}else e.push(new Uint8Array([0]))}static getNextOffset(t,e){const i=t.getUint8(e);switch(i){case 0:return 1;case 1:return 9;case 2:return 5+t.getUint32(e+1,!0);case 3:return 2;case 4:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++)s+=this.getNextOffset(t,e+s);return s}case 5:{const i=t.getUint32(e+1,!0);let s=5;for(let r=0;r<i;r++){s+=4+t.getUint32(e+s,!0),s+=this.getNextOffset(t,e+s)}return s}default:throw new Error(`未知的类型: ${i}`)}}static utf8ArrayToString(t){if(!t||0===t.length)return"";let e="",i=0;try{for(;i<t.length;){let s=t[i++];if(s>127)if(s>191&&s<224){if(i>=t.length)break;s=(31&s)<<6|63&t[i++]}else if(s>223&&s<240){if(i+1>=t.length)break;s=(15&s)<<12|(63&t[i++])<<6|63&t[i++]}else{if(!(s>239&&s<248))continue;if(i+2>=t.length)break;s=(7&s)<<18|(63&t[i++])<<12|(63&t[i++])<<6|63&t[i++]}s<=65535?e+=String.fromCharCode(s):s<=1114111&&(s-=65536,e+=String.fromCharCode(s>>10|55296),e+=String.fromCharCode(1023&s|56320))}}catch(t){return console.error("UTF-8 解码错误:",t),""}return e}static stringToUtf8Array(t){if(!t||0===t.length)return new Uint8Array(0);const e=[];try{for(let i=0;i<t.length;i++){let s=t.charCodeAt(i);if(s<128)e.push(s);else if(s<2048)e.push(192|s>>6),e.push(128|63&s);else if(s<55296||s>=57344)e.push(224|s>>12),e.push(128|s>>6&63),e.push(128|63&s);else{if(i+1>=t.length)break;i++,s=(1023&s)<<10|1023&t.charCodeAt(i),s+=65536,e.push(240|s>>18),e.push(128|s>>12&63),e.push(128|s>>6&63),e.push(128|63&s)}}}catch(t){return console.error("UTF-8 编码错误:",t),new Uint8Array(0)}return new Uint8Array(e)}}class N{static rotl(t,e){return t<<e|t>>>32-e}static rotr(t,e){return t<<32-e|t>>>e}static endianNumber(t){return 16711935&N.rotl(t,8)|4278255360&N.rotl(t,24)}static endianArray(t){for(let e=0,i=t.length;e<i;e++)t[e]=N.endianNumber(t[e]);return t}static randomBytes(t){const e=[];for(;t>0;t--)e.push(Math.floor(256*Math.random()));return e}static bytesToWords(t){const e=[];for(let i=0,s=0,r=t.length;i<r;i++,s+=8)e[s>>>5]|=t[i]<<24-s%32;return e}static wordsToBytes(t){const e=[];for(let i=0,s=32*t.length;i<s;i+=8)e.push(t[i>>>5]>>>24-i%32&255);return e}static bytesToHex(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return e.join("")}static hexToBytes(t){const e=[];for(let i=0,s=t.length;i<s;i+=2)e.push(parseInt(t.substr(i,2),16));return e}}const F=function(t){const e=function(t){const e=[];for(let i=0,s=(t=unescape(encodeURIComponent(t))).length;i<s;i++)e.push(255&t.charCodeAt(i));return e}(t),i=N.bytesToWords(e),s=8*e.length;let r=i.length,n=1732584193,o=-271733879,a=-1732584194,h=271733878;for(let t=0;t<r;t++)i[t]=16711935&(i[t]<<8|i[t]>>>24)|4278255360&(i[t]<<24|i[t]>>>8);i[s>>>5]|=128<<s%32,i[14+(s+64>>>9<<4)]=s;const c=F._ff,l=F._gg,u=F._hh,m=F._ii;r=i.length;for(let t=0;t<r;t+=16){const e=n,s=o,r=a,f=h;n=c(n,o,a,h,i[t+0],7,-680876936),h=c(h,n,o,a,i[t+1],12,-389564586),a=c(a,h,n,o,i[t+2],17,606105819),o=c(o,a,h,n,i[t+3],22,-1044525330),n=c(n,o,a,h,i[t+4],7,-176418897),h=c(h,n,o,a,i[t+5],12,1200080426),a=c(a,h,n,o,i[t+6],17,-1473231341),o=c(o,a,h,n,i[t+7],22,-45705983),n=c(n,o,a,h,i[t+8],7,1770035416),h=c(h,n,o,a,i[t+9],12,-1958414417),a=c(a,h,n,o,i[t+10],17,-42063),o=c(o,a,h,n,i[t+11],22,-1990404162),n=c(n,o,a,h,i[t+12],7,1804603682),h=c(h,n,o,a,i[t+13],12,-40341101),a=c(a,h,n,o,i[t+14],17,-1502002290),o=c(o,a,h,n,i[t+15],22,1236535329),n=l(n,o,a,h,i[t+1],5,-165796510),h=l(h,n,o,a,i[t+6],9,-1069501632),a=l(a,h,n,o,i[t+11],14,643717713),o=l(o,a,h,n,i[t+0],20,-373897302),n=l(n,o,a,h,i[t+5],5,-701558691),h=l(h,n,o,a,i[t+10],9,38016083),a=l(a,h,n,o,i[t+15],14,-660478335),o=l(o,a,h,n,i[t+4],20,-405537848),n=l(n,o,a,h,i[t+9],5,568446438),h=l(h,n,o,a,i[t+14],9,-1019803690),a=l(a,h,n,o,i[t+3],14,-187363961),o=l(o,a,h,n,i[t+8],20,1163531501),n=l(n,o,a,h,i[t+13],5,-1444681467),h=l(h,n,o,a,i[t+2],9,-51403784),a=l(a,h,n,o,i[t+7],14,1735328473),o=l(o,a,h,n,i[t+12],20,-1926607734),n=u(n,o,a,h,i[t+5],4,-378558),h=u(h,n,o,a,i[t+8],11,-2022574463),a=u(a,h,n,o,i[t+11],16,1839030562),o=u(o,a,h,n,i[t+14],23,-35309556),n=u(n,o,a,h,i[t+1],4,-1530992060),h=u(h,n,o,a,i[t+4],11,1272893353),a=u(a,h,n,o,i[t+7],16,-155497632),o=u(o,a,h,n,i[t+10],23,-1094730640),n=u(n,o,a,h,i[t+13],4,681279174),h=u(h,n,o,a,i[t+0],11,-358537222),a=u(a,h,n,o,i[t+3],16,-722521979),o=u(o,a,h,n,i[t+6],23,76029189),n=u(n,o,a,h,i[t+9],4,-640364487),h=u(h,n,o,a,i[t+12],11,-421815835),a=u(a,h,n,o,i[t+15],16,530742520),o=u(o,a,h,n,i[t+2],23,-995338651),n=m(n,o,a,h,i[t+0],6,-198630844),h=m(h,n,o,a,i[t+7],10,1126891415),a=m(a,h,n,o,i[t+14],15,-1416354905),o=m(o,a,h,n,i[t+5],21,-57434055),n=m(n,o,a,h,i[t+12],6,1700485571),h=m(h,n,o,a,i[t+3],10,-1894986606),a=m(a,h,n,o,i[t+10],15,-1051523),o=m(o,a,h,n,i[t+1],21,-2054922799),n=m(n,o,a,h,i[t+8],6,1873313359),h=m(h,n,o,a,i[t+15],10,-30611744),a=m(a,h,n,o,i[t+6],15,-1560198380),o=m(o,a,h,n,i[t+13],21,1309151649),n=m(n,o,a,h,i[t+4],6,-145523070),h=m(h,n,o,a,i[t+11],10,-1120210379),a=m(a,h,n,o,i[t+2],15,718787259),o=m(o,a,h,n,i[t+9],21,-343485551),n=n+e>>>0,o=o+s>>>0,a=a+r>>>0,h=h+f>>>0}return N.endianArray([n,o,a,h])};function C(t){if(null==t)throw new Error("Illegal argument "+t);return N.bytesToHex(N.wordsToBytes(F(t)))}F._ff=function(t,e,i,s,r,n,o){const a=t+(e&i|~e&s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},F._gg=function(t,e,i,s,r,n,o){const a=t+(e&s|i&~s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},F._hh=function(t,e,i,s,r,n,o){const a=t+(e^i^s)+(r>>>0)+o;return(a<<n|a>>>32-n)+e},F._ii=function(t,e,i,s,r,n,o){const a=t+(i^(e|~s))+(r>>>0)+o;return(a<<n|a>>>32-n)+e};class R{static compareVersion(t,e){let i=t.split("."),s=e.split(".");const r=Math.max(i.length,s.length);for(;i.length<r;)i.push("0");for(;s.length<r;)s.push("0");for(let t=0;t<r;++t){let e=parseInt(i[t]),r=parseInt(s[t]);if(e>r)return 1;if(e<r)return-1}return 0}static isJsonString(t){try{return JSON.parse(t),!0}catch(t){return!1}}static getUrlParam(t){let e={url:"",params:{}},i=t.split("?");if(e.url=i[0],i.length>1){let t=i[1].split("&");for(let i=0;i<t.length;i++){let s=t[i],[r,n]=s.split("=");e.params[r]=n}}return e}static addUrlParam(t,e,i){let s=this.getUrlParam(t);return s.params[e]=i,s.url+"?"+Object.entries(s.params).map(([t,e])=>`${t}=${e}`).join("&")}}function V(t,e){return t===e}class P{constructor(t){this.element=t,this.next=void 0}}class j extends P{constructor(t){super(t),this.prev=void 0}}class L{constructor(t){this._equalsFn=t||V,this._count=0,this._head=void 0}push(t){const e=new P(t);let i;if(void 0===this._head)this._head=e;else{for(i=this._head;void 0!==i.next;)i=i.next;i.next=e}this._count++}insert(t,e){if(e>=0&&e<=this._count){const i=new P(t);if(0===e){const t=this._head;i.next=t,this._head=i}else{const t=this.getElementAt(e-1),s=t.next;i.next=s,t.next=i}return this._count++,!0}return!1}getElementAt(t){if(t>=0&&t<=this._count){let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}remove(t){return this.removeAt(this.indexOf(t))}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next;else{const i=this.getElementAt(t-1);e=i.next,i.next=e.next}return this._count--,e.next=void 0,e.element}}indexOf(t){let e=this._head;for(let i=0;i<this._count&&void 0!==e;i++){if(this._equalsFn(t,e.element))return i;e=e.next}return-1}clear(){this._head=void 0,this._count=0}getHead(){return this._head}isEmpty(){return 0===this.size()}size(){return this._count}toString(){if(void 0===this._head)return"";let t=`${this._head.element}`,e=this._head.next;for(let i=0;i<this.size()&&void 0!==e;i++)t=`${t},${e.element}`,e=e.next;return t}}class Q extends L{constructor(t){super(t),this._tail=void 0}push(t){this.insert(t,this._count)}insert(t,e){if(e>=0&&e<=this._count){const i=new j(t);let s=this._head;if(0===e)void 0===this._head?(this._head=i,this._tail=i):(i.next=s,s.prev=i,this._head=i);else if(e===this._count)s=this._tail,s.next=i,i.prev=s,this._tail=i;else{const t=this.getElementAt(e-1);s=t.next,i.next=s,t.next=i,s.prev=i,i.prev=t}return this._count++,!0}return!1}removeAt(t){if(t>=0&&t<this._count){let e=this._head;if(0===t)this._head=e.next,1===this._count?this._tail=void 0:this._head.prev=void 0;else if(t===this._count-1)e=this._tail,this._tail=e.prev,this._tail.next=void 0;else{e=this.getElementAt(t);const i=e.prev;i.next=e.next,e.next.prev=i}return this._count--,e.next=void 0,e.prev=void 0,e.element}}getElementAt(t){if(t>=0&&t<=this._count){if(t>.5*this._count){let e=this._tail;for(let i=this._count-1;i>t&&void 0!==e;i--)e=e.prev;return e}{let e=this._head;for(let i=0;i<t&&void 0!==e;i++)e=e.next;return e}}}getHead(){return this._head}getTail(){return this._tail}clear(){this._head=void 0,this._tail=void 0,this._count=0}}class X{constructor(t){this._items=new Q(t)}push(t){this._items.push(t)}pop(){if(!this.isEmpty())return this._items.removeAt(this.size()-1)}peek(){if(!this.isEmpty())return this._items.getTail().element}size(){return this._items.size()}isEmpty(){return this._items.isEmpty()}clear(){this._items.clear()}toString(){return this._items.toString()}}export{_ as Adapter,Y as Binary,y as BinaryHeap,W as CocosEntry,Q as DoublyLinkedList,j as DoublyNode,A as GlobalTimer,w as HeapNode,H as InnerTimer,L as LinkedList,P as LinkedNode,O as Module,B as Platform,$ as PlatformType,d as Screen,X as Stack,k as Time,R as Utils,m as debug,l as enableDebugMode,g as error,f as info,u as log,C as md5,p as warn};
|
package/dist/bit-core.mjs
CHANGED
|
@@ -461,15 +461,15 @@ class TimerNodePool {
|
|
|
461
461
|
const index = timerId >>> TimerIdBit;
|
|
462
462
|
const version = timerId & TimerVersionMask;
|
|
463
463
|
if (index < 0 || index >= this._pool.length) {
|
|
464
|
-
return
|
|
464
|
+
return undefined;
|
|
465
465
|
}
|
|
466
466
|
const timerNode = this._pool[index];
|
|
467
467
|
if (timerNode.recycled) {
|
|
468
|
-
return
|
|
468
|
+
return undefined;
|
|
469
469
|
}
|
|
470
470
|
const timerNodeVersion = timerNode.id & TimerVersionMask;
|
|
471
471
|
if (timerNodeVersion != version) {
|
|
472
|
-
return
|
|
472
|
+
return undefined;
|
|
473
473
|
}
|
|
474
474
|
return timerNode;
|
|
475
475
|
}
|
|
@@ -590,24 +590,31 @@ class Timer {
|
|
|
590
590
|
this._recycle(timerNode);
|
|
591
591
|
}
|
|
592
592
|
else if (timerNode.loop > 0) {
|
|
593
|
-
|
|
594
|
-
|
|
593
|
+
const missedCount = Math.floor((elapsedTime - timerNode.expireTime) / timerNode.interval) + 1;
|
|
594
|
+
timerNode.loop -= missedCount;
|
|
595
|
+
if (timerNode.loop <= 0) {
|
|
595
596
|
heap.pop();
|
|
596
597
|
this._recycle(timerNode);
|
|
597
598
|
}
|
|
598
599
|
else {
|
|
599
|
-
|
|
600
|
-
timerNode.expireTime = timerNode.expireTime + timerNode.interval;
|
|
600
|
+
timerNode.expireTime += timerNode.interval * missedCount;
|
|
601
601
|
heap.update(timerNode);
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
else {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
timerNode.expireTime = timerNode.expireTime + timerNode.interval;
|
|
605
|
+
const missedCount = Math.floor((elapsedTime - timerNode.expireTime) / timerNode.interval) + 1;
|
|
606
|
+
timerNode.expireTime += timerNode.interval * missedCount;
|
|
608
607
|
heap.update(timerNode);
|
|
609
608
|
}
|
|
610
|
-
|
|
609
|
+
// 执行回调,捕获异常防止中断后续定时器
|
|
610
|
+
if (callback) {
|
|
611
|
+
try {
|
|
612
|
+
callback();
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
console.error("Timer callback error:", error);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
611
618
|
timerNode = heap.top();
|
|
612
619
|
}
|
|
613
620
|
}
|
|
@@ -733,15 +740,22 @@ class InnerTimer {
|
|
|
733
740
|
* @param loop - [loop=0] 重复次数:0:回调一次,1~n:回调n次,-1:无限重复
|
|
734
741
|
* @returns 返回定时器的ID。
|
|
735
742
|
*/
|
|
743
|
+
static get Timer() {
|
|
744
|
+
if (this._timer) {
|
|
745
|
+
return this._timer;
|
|
746
|
+
}
|
|
747
|
+
this.initTimer();
|
|
748
|
+
return this._timer;
|
|
749
|
+
}
|
|
736
750
|
static startTimer(callback, interval, loop = 0) {
|
|
737
|
-
return this.
|
|
751
|
+
return this.Timer.start(callback, interval, loop);
|
|
738
752
|
}
|
|
739
753
|
/**
|
|
740
754
|
* 停止指定ID的计时器。
|
|
741
755
|
* @param timerId - 要停止的计时器的唯一标识符。
|
|
742
756
|
*/
|
|
743
757
|
static stopTimer(timerId) {
|
|
744
|
-
this.
|
|
758
|
+
this.Timer.stop(timerId);
|
|
745
759
|
}
|
|
746
760
|
static update(dt) {
|
|
747
761
|
var _a;
|
|
@@ -897,8 +911,14 @@ class Time {
|
|
|
897
911
|
* @returns 时间戳 (ms)
|
|
898
912
|
*/
|
|
899
913
|
static getWeekStartTime(timestamp) {
|
|
900
|
-
|
|
914
|
+
const ts = timestamp || this.now();
|
|
915
|
+
// getWeekDay 返回 1-7 (周一到周日),需要减去 (weekDay - 1) 天得到周一
|
|
916
|
+
return this.getDayStartTime(ts - (this.getWeekDay(ts) - 1) * 86400000);
|
|
901
917
|
}
|
|
918
|
+
/**
|
|
919
|
+
* @param timestamp 时间戳 (ms)
|
|
920
|
+
* @returns 时间戳 (ms)
|
|
921
|
+
*/
|
|
902
922
|
static getWeekEndTime(timestamp) {
|
|
903
923
|
return this.getWeekStartTime(timestamp) + 86400000 * 7;
|
|
904
924
|
}
|
|
@@ -1201,6 +1221,11 @@ Time._netTime = 0;
|
|
|
1201
1221
|
* @internal
|
|
1202
1222
|
*/
|
|
1203
1223
|
Time._netTimeDiff = 0;
|
|
1224
|
+
/**
|
|
1225
|
+
* 获取当前毫秒时间戳
|
|
1226
|
+
* @internal
|
|
1227
|
+
*/
|
|
1228
|
+
Time._nowTimestamp = () => Date.now();
|
|
1204
1229
|
|
|
1205
1230
|
/**
|
|
1206
1231
|
* @Author: Gongxh
|
|
@@ -2339,7 +2364,7 @@ class DoublyLinkedList extends LinkedList {
|
|
|
2339
2364
|
current.prev = undefined;
|
|
2340
2365
|
return current.element;
|
|
2341
2366
|
}
|
|
2342
|
-
return
|
|
2367
|
+
return undefined;
|
|
2343
2368
|
}
|
|
2344
2369
|
/**
|
|
2345
2370
|
* 获取链表中指定位置的元素,如果不存在返回 null
|
package/package.json
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
"name": "@gongxh/bit-core",
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "基于creator3.0+的bit-core库",
|
|
5
|
+
"main": "./dist/bit-core.cjs",
|
|
6
|
+
"module": "./dist/bit-core.mjs",
|
|
7
|
+
"types": "./dist/bit-core.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/bit-core.cjs",
|
|
11
|
+
"import": "./dist/bit-core.mjs",
|
|
12
|
+
"types": "./dist/bit-core.d.ts",
|
|
13
|
+
"default": "./dist/bit-core.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./min": {
|
|
16
|
+
"require": "./dist/bit-core.min.cjs",
|
|
17
|
+
"import": "./dist/bit-core.min.mjs"
|
|
18
|
+
}
|
|
14
19
|
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"build": "pnpm clean && rollup -c rollup.config.mjs"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"author": "bit老宫",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/gongxh0901/bit-framework.git",
|
|
32
|
+
"directory": "bit-core"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
|
36
|
+
"access": "public"
|
|
18
37
|
}
|
|
19
|
-
|
|
20
|
-
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
],
|
|
23
|
-
"author": "bit老宫",
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"repository": {
|
|
26
|
-
"type": "git",
|
|
27
|
-
"url": "https://github.com/gongxh0901/bit-framework.git",
|
|
28
|
-
"directory": "bit-core"
|
|
29
|
-
},
|
|
30
|
-
"publishConfig": {
|
|
31
|
-
"registry": "https://registry.npmjs.org/"
|
|
32
|
-
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"clean": "rm -rf dist",
|
|
35
|
-
"build": "pnpm clean && rollup -c rollup.config.mjs"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 bit老宫
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|