@gongxh/bit-core 0.0.4 → 0.0.6
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/LICENSE +21 -0
- package/README.md +175 -56
- package/dist/bit-core.cjs +2190 -209
- package/dist/bit-core.d.ts +559 -20
- package/dist/bit-core.min.cjs +1 -1
- package/dist/bit-core.min.mjs +1 -1
- package/dist/bit-core.mjs +2179 -211
- package/package.json +33 -51
package/dist/bit-core.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Component } from 'cc';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 启用或禁用调试模式。
|
|
5
|
+
* @param enable - 如果为 true,则启用调试模式;如果为 false,则禁用调试模式。不设置默认不开启
|
|
6
|
+
*/
|
|
7
|
+
declare function enableDebugMode(enable: boolean): void;
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* @Author: Gongxh
|
|
5
11
|
* @Date: 2024-12-07
|
|
@@ -20,6 +26,46 @@ declare abstract class Adapter {
|
|
|
20
26
|
removeResizeListener(listener: (...args: any) => void): void;
|
|
21
27
|
}
|
|
22
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @Author: Gongxh
|
|
31
|
+
* @Date: 2024-12-07
|
|
32
|
+
* @Description:cocos游戏入口 定义了游戏启动时的基本配置和初始化流程。
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
declare abstract class CocosEntry extends Component {
|
|
36
|
+
fps: number;
|
|
37
|
+
enableDebug: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 虚函数,子类需要实现
|
|
40
|
+
* kunpo库初始化完成后调用
|
|
41
|
+
*/
|
|
42
|
+
abstract onInit(): void;
|
|
43
|
+
/**
|
|
44
|
+
* 时间相关
|
|
45
|
+
*/
|
|
46
|
+
private initTime;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @Author: Gongxh
|
|
51
|
+
* @Date: 2024-12-07
|
|
52
|
+
* @Description: cocos UI模块
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
declare abstract class Module extends Component {
|
|
56
|
+
/**
|
|
57
|
+
* 模块名称
|
|
58
|
+
* @type {string}
|
|
59
|
+
*/
|
|
60
|
+
readonly moduleName: string;
|
|
61
|
+
/**
|
|
62
|
+
* 虚函数,子类需要实现
|
|
63
|
+
* 模块初始化完成后调用的函数
|
|
64
|
+
* @abstract
|
|
65
|
+
*/
|
|
66
|
+
protected abstract onInit(): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
23
69
|
/**
|
|
24
70
|
* @Author: Gongxh
|
|
25
71
|
* @Date: 2024-12-07
|
|
@@ -131,10 +177,28 @@ declare class Screen {
|
|
|
131
177
|
}
|
|
132
178
|
|
|
133
179
|
/**
|
|
134
|
-
*
|
|
135
|
-
* @
|
|
180
|
+
* @Author: Gongxh
|
|
181
|
+
* @Date: 2025-03-04
|
|
182
|
+
* @Description: 二进制工具类 - 使用 JavaScript 标准库实现
|
|
136
183
|
*/
|
|
137
|
-
declare
|
|
184
|
+
declare class Binary {
|
|
185
|
+
/**
|
|
186
|
+
* 将对象转换为二进制数据
|
|
187
|
+
*/
|
|
188
|
+
static toBinary(obj: any): Uint8Array;
|
|
189
|
+
/**
|
|
190
|
+
* 将二进制数据转换JSON数据
|
|
191
|
+
* @param binary 二进制数据
|
|
192
|
+
* @returns
|
|
193
|
+
*/
|
|
194
|
+
static toJson(binary: any): any;
|
|
195
|
+
/**
|
|
196
|
+
* 检查数据是否为二进制格式
|
|
197
|
+
* @param data 要检查的数据
|
|
198
|
+
* @returns 是否为二进制格式
|
|
199
|
+
*/
|
|
200
|
+
static isBinaryFormat(data: Uint8Array): boolean;
|
|
201
|
+
}
|
|
138
202
|
|
|
139
203
|
/**
|
|
140
204
|
* @Author: Gongxh
|
|
@@ -163,40 +227,515 @@ declare function warn(...args: any[]): void;
|
|
|
163
227
|
*/
|
|
164
228
|
declare function error(...args: any[]): void;
|
|
165
229
|
|
|
230
|
+
/**
|
|
231
|
+
* 对字符串执行md5处理
|
|
232
|
+
*
|
|
233
|
+
* @export
|
|
234
|
+
* @param {string} message 要处理的字符串
|
|
235
|
+
* @returns {string} md5
|
|
236
|
+
*/
|
|
237
|
+
declare function md5(message: string): string;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @Author: Gongxh
|
|
241
|
+
* @Date: 2025-03-06
|
|
242
|
+
* @Description: 时间工具
|
|
243
|
+
*/
|
|
244
|
+
declare class Time {
|
|
245
|
+
/** 获取游戏系统启动时间戳 */
|
|
246
|
+
static get osBootTime(): number;
|
|
247
|
+
/** 获取主动设置的网络时间 单位ms */
|
|
248
|
+
static get netTime(): number;
|
|
249
|
+
/** 获取本地时间与网路时间的偏移量 单位ms */
|
|
250
|
+
static get netTimeDiff(): number;
|
|
251
|
+
/** 获取系统运行时间 */
|
|
252
|
+
static get runTime(): number;
|
|
253
|
+
/**
|
|
254
|
+
* 设置网络时间, 单位ms
|
|
255
|
+
* @param netTime 网络时间
|
|
256
|
+
*/
|
|
257
|
+
static setNetTime(netTime: number): void;
|
|
258
|
+
/**
|
|
259
|
+
* 获取当前时间 单位ms
|
|
260
|
+
*/
|
|
261
|
+
static now(): number;
|
|
262
|
+
/**
|
|
263
|
+
* 将毫秒转换为秒
|
|
264
|
+
* @param ms 毫秒
|
|
265
|
+
*/
|
|
266
|
+
static msTos(ms: number): number;
|
|
267
|
+
/**
|
|
268
|
+
* 将秒转换为毫秒
|
|
269
|
+
*/
|
|
270
|
+
static sToMs(s: number): number;
|
|
271
|
+
/**
|
|
272
|
+
* 获取年份
|
|
273
|
+
* @param timestamp 时间戳 (ms)
|
|
274
|
+
* @returns 年份
|
|
275
|
+
*/
|
|
276
|
+
static getYear(timestamp?: number): number;
|
|
277
|
+
/**
|
|
278
|
+
* 获取月份
|
|
279
|
+
* @param timestamp 时间戳 (ms)
|
|
280
|
+
* @returns 月份
|
|
281
|
+
*/
|
|
282
|
+
static getMonth(timestamp?: number): number;
|
|
283
|
+
/**
|
|
284
|
+
* 获取日期
|
|
285
|
+
* @param timestamp 时间戳 (ms)
|
|
286
|
+
* @returns 日期
|
|
287
|
+
*/
|
|
288
|
+
static getDay(timestamp?: number): number;
|
|
289
|
+
/**
|
|
290
|
+
* 获取小时
|
|
291
|
+
* @param timestamp 时间戳 (ms)
|
|
292
|
+
* @returns 小时
|
|
293
|
+
*/
|
|
294
|
+
static getHour(timestamp?: number): number;
|
|
295
|
+
/**
|
|
296
|
+
* 获取分钟
|
|
297
|
+
* @param timestamp 时间戳 (ms)
|
|
298
|
+
* @returns 分钟
|
|
299
|
+
*/
|
|
300
|
+
static getMinute(timestamp?: number): number;
|
|
301
|
+
/**
|
|
302
|
+
* 获取秒
|
|
303
|
+
* @param timestamp 时间戳 (ms)
|
|
304
|
+
* @returns 秒
|
|
305
|
+
*/
|
|
306
|
+
static getSecond(timestamp?: number): number;
|
|
307
|
+
/**
|
|
308
|
+
* 获取当天开始时间
|
|
309
|
+
* @param timestamp 时间戳 (ms)
|
|
310
|
+
* @returns 时间戳 (ms)
|
|
311
|
+
*/
|
|
312
|
+
static getDayStartTime(timestamp?: number): number;
|
|
313
|
+
/**
|
|
314
|
+
* 获取当天的结束时间
|
|
315
|
+
* @param timestamp 时间戳 (ms)
|
|
316
|
+
* @returns 时间戳 (ms)
|
|
317
|
+
*/
|
|
318
|
+
static getDayEndTime(timestamp?: number): number;
|
|
319
|
+
/**
|
|
320
|
+
* 获取传入时间是周几
|
|
321
|
+
* @param {number} [time] (ms)
|
|
322
|
+
* @returns {number}
|
|
323
|
+
*/
|
|
324
|
+
static getWeekDay(time?: number): number;
|
|
325
|
+
/**
|
|
326
|
+
* 获取当前周的开始时间
|
|
327
|
+
* @param timestamp 时间戳 (ms)
|
|
328
|
+
* @returns 时间戳 (ms)
|
|
329
|
+
*/
|
|
330
|
+
static getWeekStartTime(timestamp?: number): number;
|
|
331
|
+
static getWeekEndTime(timestamp?: number): number;
|
|
332
|
+
/**
|
|
333
|
+
* 获取当前月开始时间
|
|
334
|
+
* @param timestamp 时间戳 (ms)
|
|
335
|
+
* @returns 时间戳 (ms)
|
|
336
|
+
*/
|
|
337
|
+
static getMonthStartTime(timestamp?: number): number;
|
|
338
|
+
/**
|
|
339
|
+
* 获取当前月结束时间
|
|
340
|
+
* @param timestamp 时间戳 (ms)
|
|
341
|
+
* @returns 时间戳 (ms)
|
|
342
|
+
*/
|
|
343
|
+
static getMonthEndTime(timestamp?: number): number;
|
|
344
|
+
/**
|
|
345
|
+
* 获取当前年份开始时间
|
|
346
|
+
* @param timestamp 时间戳 (ms)
|
|
347
|
+
* @returns 时间戳 (ms)
|
|
348
|
+
*/
|
|
349
|
+
static getYearStartTime(timestamp?: number): number;
|
|
350
|
+
/**
|
|
351
|
+
* 获取当前年份结束时间
|
|
352
|
+
* @param timestamp 时间戳 (ms)
|
|
353
|
+
* @returns 时间戳 (ms)
|
|
354
|
+
*/
|
|
355
|
+
static getYearEndTime(timestamp?: number): number;
|
|
356
|
+
/**
|
|
357
|
+
* 获取当前月的天数
|
|
358
|
+
* @param timestamp 时间戳 (ms)
|
|
359
|
+
* @returns 天数
|
|
360
|
+
*/
|
|
361
|
+
static getMonthDays(timestamp?: number): number;
|
|
362
|
+
/**
|
|
363
|
+
* 是否是同一天
|
|
364
|
+
* @param timestamp1 时间戳1 (ms)
|
|
365
|
+
* @param now 时间戳2 (ms) 如果不传,则和当前时间比较
|
|
366
|
+
* @returns 是否是同一天
|
|
367
|
+
*/
|
|
368
|
+
static isSameDay(timestamp1: number, now?: number): boolean;
|
|
369
|
+
/**
|
|
370
|
+
* 是否是同一周
|
|
371
|
+
* @param timestamp1 时间戳1 (ms)
|
|
372
|
+
* @param now 时间戳2 (ms) 如果不传,则和当前时间比较
|
|
373
|
+
* @returns 是否是同一周
|
|
374
|
+
*/
|
|
375
|
+
static isSameWeek(timestamp1: number, now?: number): boolean;
|
|
376
|
+
/**
|
|
377
|
+
* 是否是同一月
|
|
378
|
+
* @param timestamp1 时间戳1 (ms)
|
|
379
|
+
* @param now 时间戳2 (ms) 如果不传,则和当前时间比较
|
|
380
|
+
* @returns 是否是同一月
|
|
381
|
+
*/
|
|
382
|
+
static isSameMonth(timestamp1: number, now?: number): boolean;
|
|
383
|
+
/**
|
|
384
|
+
* 是否是同一年
|
|
385
|
+
* @param timestamp1 时间戳1 (ms)
|
|
386
|
+
* @param now 时间戳2 (ms) 如果不传,则和当前时间比较
|
|
387
|
+
* @returns 是否是同一年
|
|
388
|
+
*/
|
|
389
|
+
static isSameYear(timestamp1: number, now?: number): boolean;
|
|
390
|
+
/**
|
|
391
|
+
* 通用时间格式化方法
|
|
392
|
+
* @param timestamp 时间戳 (ms)
|
|
393
|
+
* @param pattern 格式化模板
|
|
394
|
+
*
|
|
395
|
+
* 支持的占位符(大写补零,小写不补零):
|
|
396
|
+
* - YYYY: 四位年份 (2025) | YY: 两位年份 (25)
|
|
397
|
+
* - MM: 两位月份 (01-12) | M: 月份 (1-12)
|
|
398
|
+
* - DD: 两位日期 (01-31) | D: 日期 (1-31)
|
|
399
|
+
* - hh: 两位小时 (00-23) | h: 小时 (0-23)
|
|
400
|
+
* - mm: 两位分钟 (00-59) | m: 分钟 (0-59)
|
|
401
|
+
* - ss: 两位秒 (00-59) | s: 秒 (0-59)
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* Time.format(timestamp, 'YYYY-MM-DD hh:mm:ss') // "2025-01-05 14:30:45"
|
|
405
|
+
* Time.format(timestamp, 'YYYY年MM月DD日 hh:mm') // "2025年01月05日 14:30"
|
|
406
|
+
* Time.format(timestamp, 'M月D日 h时m分') // "1月5日 14时30分"
|
|
407
|
+
*/
|
|
408
|
+
static format(timestamp: number, pattern: string): string;
|
|
409
|
+
/**
|
|
410
|
+
* 格式化时间 格式: xxxx-xx-xx hh:mm:ss
|
|
411
|
+
* @param timestamp 时间戳 (ms)
|
|
412
|
+
*/
|
|
413
|
+
static formatTime(timestamp: number): string;
|
|
414
|
+
/**
|
|
415
|
+
* 格式化时间 格式: xxxx年xx月xx日 hh:mm:ss
|
|
416
|
+
* @param timestamp 时间戳 (ms)
|
|
417
|
+
*/
|
|
418
|
+
static formatTimeChinese(timestamp: number): string;
|
|
419
|
+
/**
|
|
420
|
+
* 通用时长格式化方法
|
|
421
|
+
* @param seconds 时长(秒)
|
|
422
|
+
* @param pattern 格式化模板
|
|
423
|
+
* @param options 格式化选项
|
|
424
|
+
*
|
|
425
|
+
* 支持的占位符(大写补零,小写不补零):
|
|
426
|
+
* - DD/D: 天数
|
|
427
|
+
* - HH/H: 总小时数(可超过24)
|
|
428
|
+
* - hh/h: 小时数(0-23范围)
|
|
429
|
+
* - MM/M: 总分钟数(可超过60)
|
|
430
|
+
* - mm/m: 分钟数(0-59范围)
|
|
431
|
+
* - ss/s: 秒数(0-59范围)
|
|
432
|
+
*
|
|
433
|
+
* options.autoHide: 自动隐藏为0的高位单位(默认false)
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* Time.formatDuration(3661, 'HH:mm:ss') // "01:01:01"
|
|
437
|
+
* Time.formatDuration(3661, 'MM:ss') // "61:01"
|
|
438
|
+
* Time.formatDuration(3661, 'H小时m分s秒') // "1小时1分1秒"
|
|
439
|
+
* Time.formatDuration(90061, 'DD天hh:mm:ss') // "1天01:01:01"
|
|
440
|
+
* Time.formatDuration(125, 'HH:mm:ss', { autoHide: true }) // "02:05"
|
|
441
|
+
* Time.formatDuration(3661, 'DD天HH时mm分ss秒', { autoHide: true }) // "1时1分1秒"
|
|
442
|
+
*/
|
|
443
|
+
static formatDuration(seconds: number, pattern: string, options?: {
|
|
444
|
+
autoHide?: boolean;
|
|
445
|
+
}): string;
|
|
446
|
+
/**
|
|
447
|
+
* 智能格式化时长 - 自动隐藏为0的高位单位
|
|
448
|
+
* @param time 时间 (s)
|
|
449
|
+
* @param pattern 格式化模板,默认 'D天h小时m分s秒'
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* Time.formatSmart(86461) // "1天1小时1分1秒"
|
|
453
|
+
* Time.formatSmart(3661) // "1小时1分1秒"
|
|
454
|
+
* Time.formatSmart(61) // "1分1秒"
|
|
455
|
+
* Time.formatSmart(1) // "1秒"
|
|
456
|
+
*/
|
|
457
|
+
static formatSmart(time: number, pattern?: string): string;
|
|
458
|
+
/**
|
|
459
|
+
* 智能格式化时长(简化版) - 只显示最大的两个单位,较小单位向上取整
|
|
460
|
+
* @param time 时间 (s)
|
|
461
|
+
* @param pattern 格式化模板,默认 'D天h小时|h小时m分|m分s秒',用 | 分隔不同级别
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* Time.formatSmartSimple(90061) // "1天2小时" (1.04小时向上取整为2)
|
|
465
|
+
* Time.formatSmartSimple(3661) // "1小时2分" (1.02分钟向上取整为2)
|
|
466
|
+
* Time.formatSmartSimple(61) // "1分2秒" (1.02秒向上取整为2)
|
|
467
|
+
* Time.formatSmartSimple(1) // "1秒"
|
|
468
|
+
* Time.formatSmartSimple(90061, 'D天h时|h时m分|m分s秒') // "1天2时"
|
|
469
|
+
*/
|
|
470
|
+
static formatSmartSimple(time: number, pattern?: string): string;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @Author: Gongxh
|
|
475
|
+
* @Date: 2025-04-11
|
|
476
|
+
* @Description:
|
|
477
|
+
*/
|
|
478
|
+
declare class Utils {
|
|
479
|
+
/**
|
|
480
|
+
* 版本号比较
|
|
481
|
+
* @param version1 本地版本号
|
|
482
|
+
* @param version2 远程版本号
|
|
483
|
+
* 如果返回值大于0,则version1大于version2
|
|
484
|
+
* 如果返回值等于0,则version1等于version2
|
|
485
|
+
* 如果返回值小于0,则version1小于version2
|
|
486
|
+
*/
|
|
487
|
+
static compareVersion(version1: string, version2: string): number;
|
|
488
|
+
/**
|
|
489
|
+
* 判断传入的字符串是否是json格式的字符串
|
|
490
|
+
*/
|
|
491
|
+
static isJsonString(str: string): boolean;
|
|
492
|
+
/**
|
|
493
|
+
* 获取url参数
|
|
494
|
+
* @param url
|
|
495
|
+
*/
|
|
496
|
+
static getUrlParam(url: string): {
|
|
497
|
+
url: string;
|
|
498
|
+
params: {
|
|
499
|
+
[key: string]: string;
|
|
500
|
+
};
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* 给url添加参数
|
|
504
|
+
* @param url
|
|
505
|
+
* @returns 新的url
|
|
506
|
+
*/
|
|
507
|
+
static addUrlParam(url: string, key: string, value: string): string;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @Author: Gongxh
|
|
512
|
+
* @Date: 2025-04-18
|
|
513
|
+
* @Description: 通用的 Promise 结果
|
|
514
|
+
*/
|
|
515
|
+
interface IPromiseResult {
|
|
516
|
+
/** 0:成功 其他:失败 */
|
|
517
|
+
code: number;
|
|
518
|
+
/** 失败信息 */
|
|
519
|
+
message: string;
|
|
520
|
+
}
|
|
521
|
+
interface ICheckUpdatePromiseResult extends IPromiseResult {
|
|
522
|
+
/** 需要更新的资源大小 (KB) */
|
|
523
|
+
size?: number;
|
|
524
|
+
}
|
|
525
|
+
|
|
166
526
|
/**
|
|
167
527
|
* @Author: Gongxh
|
|
168
528
|
* @Date: 2024-12-07
|
|
169
|
-
* @Description:
|
|
529
|
+
* @Description:
|
|
170
530
|
*/
|
|
531
|
+
declare class GlobalTimer {
|
|
532
|
+
/**
|
|
533
|
+
* 启动一个定时器,执行指定的回调函数。
|
|
534
|
+
* @param callback - 要定时执行的回调函数。
|
|
535
|
+
* @param interval - 定时器的时间间隔(秒)。
|
|
536
|
+
* @param loop - [loop=0] 重复次数:0:回调一次,1~n:回调n次,-1:无限重复
|
|
537
|
+
* @returns 返回定时器的ID。
|
|
538
|
+
*/
|
|
539
|
+
static startTimer(callback: () => void, interval: number, loop?: number): number;
|
|
540
|
+
/**
|
|
541
|
+
* 停止指定ID的计时器。
|
|
542
|
+
* @param timerId - 要停止的计时器的唯一标识符。
|
|
543
|
+
*/
|
|
544
|
+
static stopTimer(timerId: number): void;
|
|
545
|
+
/**
|
|
546
|
+
* 暂停指定ID的计时器。
|
|
547
|
+
* @param timerId - 要暂停的计时器的唯一标识符。
|
|
548
|
+
*/
|
|
549
|
+
static pauseTimer(timerId: number): void;
|
|
550
|
+
/**
|
|
551
|
+
* 恢复指定ID的计时器。
|
|
552
|
+
* @param timerId - 要恢复的计时器的唯一标识符。
|
|
553
|
+
*/
|
|
554
|
+
static resumeTimer(timerId: number): void;
|
|
555
|
+
/**
|
|
556
|
+
* 清除所有定时器。
|
|
557
|
+
*/
|
|
558
|
+
static clearAllTimer(): void;
|
|
559
|
+
}
|
|
171
560
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
561
|
+
/**
|
|
562
|
+
* @Author: Gongxh
|
|
563
|
+
* @Date: 2025-02-14
|
|
564
|
+
* @Description: 内部使用的全局定时器
|
|
565
|
+
*/
|
|
566
|
+
declare class InnerTimer {
|
|
567
|
+
private static _timer;
|
|
175
568
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
569
|
+
* 初始化全局定时器,设置定时器间隔为16毫秒。
|
|
570
|
+
* 此方法用于启动一个定时器实例,以便在整个应用程序中跟踪时间相关的操作。
|
|
178
571
|
*/
|
|
179
|
-
|
|
572
|
+
static initTimer(): void;
|
|
573
|
+
/**
|
|
574
|
+
* 启动一个定时器,执行指定的回调函数。
|
|
575
|
+
* @param callback - 要定时执行的回调函数。
|
|
576
|
+
* @param interval - 定时器的时间间隔(秒)。
|
|
577
|
+
* @param loop - [loop=0] 重复次数:0:回调一次,1~n:回调n次,-1:无限重复
|
|
578
|
+
* @returns 返回定时器的ID。
|
|
579
|
+
*/
|
|
580
|
+
static startTimer(callback: () => void, interval: number, loop?: number): number;
|
|
581
|
+
/**
|
|
582
|
+
* 停止指定ID的计时器。
|
|
583
|
+
* @param timerId - 要停止的计时器的唯一标识符。
|
|
584
|
+
*/
|
|
585
|
+
static stopTimer(timerId: number): void;
|
|
586
|
+
static update(dt: number): void;
|
|
180
587
|
}
|
|
181
588
|
|
|
182
589
|
/**
|
|
183
590
|
* @Author: Gongxh
|
|
184
591
|
* @Date: 2024-12-07
|
|
185
|
-
* @Description:
|
|
592
|
+
* @Description: 二叉堆(默认最小堆) 支持最大堆和最小堆
|
|
186
593
|
*/
|
|
594
|
+
declare abstract class HeapNode {
|
|
595
|
+
index: number;
|
|
596
|
+
abstract lessThan(other: HeapNode): boolean;
|
|
597
|
+
}
|
|
598
|
+
declare class BinaryHeap<T extends HeapNode> {
|
|
599
|
+
constructor(capacity: number);
|
|
600
|
+
/**
|
|
601
|
+
* 清空
|
|
602
|
+
*/
|
|
603
|
+
clear(): void;
|
|
604
|
+
/**
|
|
605
|
+
* 获取节点
|
|
606
|
+
* @param index 节点索引
|
|
607
|
+
*/
|
|
608
|
+
get(index: number): T;
|
|
609
|
+
/**
|
|
610
|
+
* 获取顶部节点
|
|
611
|
+
*/
|
|
612
|
+
top(): T;
|
|
613
|
+
/**
|
|
614
|
+
* 是否包含节点
|
|
615
|
+
* @param node 节点
|
|
616
|
+
*/
|
|
617
|
+
contains(node: T): boolean;
|
|
618
|
+
/**
|
|
619
|
+
* Push节点
|
|
620
|
+
* @param node 节点
|
|
621
|
+
*/
|
|
622
|
+
push(node: T): void;
|
|
623
|
+
/**
|
|
624
|
+
* Pop节点
|
|
625
|
+
* @returns
|
|
626
|
+
*/
|
|
627
|
+
pop(): T;
|
|
628
|
+
/**
|
|
629
|
+
* 移除节点
|
|
630
|
+
* @param node 要移除的节点
|
|
631
|
+
*/
|
|
632
|
+
remove(node: T): void;
|
|
633
|
+
/**
|
|
634
|
+
* 更新节点
|
|
635
|
+
* @param node 要更新的节点
|
|
636
|
+
*/
|
|
637
|
+
update(node: T): boolean;
|
|
638
|
+
get count(): number;
|
|
639
|
+
get empty(): boolean;
|
|
640
|
+
}
|
|
187
641
|
|
|
188
|
-
|
|
642
|
+
/** 单链表结结构节点 */
|
|
643
|
+
declare class LinkedNode<T> {
|
|
644
|
+
element: T;
|
|
645
|
+
next: LinkedNode<T>;
|
|
646
|
+
constructor(element: T);
|
|
647
|
+
}
|
|
648
|
+
/** 双向链表结结构节点 */
|
|
649
|
+
declare class DoublyNode<T> extends LinkedNode<T> {
|
|
650
|
+
prev: DoublyNode<T>;
|
|
651
|
+
next: DoublyNode<T>;
|
|
652
|
+
constructor(element: T);
|
|
653
|
+
}
|
|
654
|
+
/** 单向链表 */
|
|
655
|
+
declare class LinkedList<T> {
|
|
189
656
|
/**
|
|
190
|
-
*
|
|
191
|
-
* @
|
|
657
|
+
* create
|
|
658
|
+
* @param equalsFn 比较是否相等(支持自定义)
|
|
192
659
|
*/
|
|
193
|
-
|
|
660
|
+
constructor(equalsFn?: (a: T, b: T) => boolean);
|
|
661
|
+
/** 向链表尾部添加元素 */
|
|
662
|
+
push(element: T): void;
|
|
194
663
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @
|
|
664
|
+
* 在链表的指定位置插入一个元素。
|
|
665
|
+
* @param element 要插入的元素。
|
|
666
|
+
* @param index 插入位置的索引,从0开始计数。
|
|
667
|
+
* @returns 如果插入成功返回true,否则返回false。
|
|
198
668
|
*/
|
|
199
|
-
|
|
669
|
+
insert(element: T, index: number): boolean;
|
|
670
|
+
/**
|
|
671
|
+
* 获取链表中指定位置的元素,如果不存在返回 underfined
|
|
672
|
+
* @param index
|
|
673
|
+
*/
|
|
674
|
+
getElementAt(index: number): LinkedNode<T>;
|
|
675
|
+
/**
|
|
676
|
+
* 从链表中移除一个元素
|
|
677
|
+
* @param element
|
|
678
|
+
*/
|
|
679
|
+
remove(element: T): T;
|
|
680
|
+
/**
|
|
681
|
+
* 从链表的特定位置移除一个元素
|
|
682
|
+
* @param index
|
|
683
|
+
*/
|
|
684
|
+
removeAt(index: number): T;
|
|
685
|
+
/**
|
|
686
|
+
* 返回元素在链表中的索引,如果没有则返回-1
|
|
687
|
+
* @param element
|
|
688
|
+
*/
|
|
689
|
+
indexOf(element: T): number;
|
|
690
|
+
clear(): void;
|
|
691
|
+
getHead(): LinkedNode<T>;
|
|
692
|
+
isEmpty(): boolean;
|
|
693
|
+
size(): number;
|
|
694
|
+
toString(): string;
|
|
695
|
+
}
|
|
696
|
+
/** 双向链表 */
|
|
697
|
+
declare class DoublyLinkedList<T> extends LinkedList<T> {
|
|
698
|
+
/**
|
|
699
|
+
* create
|
|
700
|
+
* @param equalsFn 比较是否相等(支持自定义)
|
|
701
|
+
*/
|
|
702
|
+
constructor(equalsFn?: (a: T, b: T) => boolean);
|
|
703
|
+
/**
|
|
704
|
+
* 向链表尾部添加元素
|
|
705
|
+
* @param element
|
|
706
|
+
*/
|
|
707
|
+
push(element: T): void;
|
|
708
|
+
/**
|
|
709
|
+
* 向链表指定位置添加元素
|
|
710
|
+
* @param element
|
|
711
|
+
* @param index
|
|
712
|
+
*/
|
|
713
|
+
insert(element: T, index: number): boolean;
|
|
714
|
+
/**
|
|
715
|
+
* 从链表的特定位置移除一个元素
|
|
716
|
+
* @param index
|
|
717
|
+
*/
|
|
718
|
+
removeAt(index: number): T;
|
|
719
|
+
/**
|
|
720
|
+
* 获取链表中指定位置的元素,如果不存在返回 null
|
|
721
|
+
* @param index
|
|
722
|
+
*/
|
|
723
|
+
getElementAt(index: number): DoublyNode<T>;
|
|
724
|
+
getHead(): DoublyNode<T>;
|
|
725
|
+
getTail(): DoublyNode<T>;
|
|
726
|
+
clear(): void;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
declare class Stack<T> {
|
|
730
|
+
constructor(equalsFn?: (a: T, b: T) => boolean);
|
|
731
|
+
push(element: T): void;
|
|
732
|
+
pop(): T;
|
|
733
|
+
peek(): T;
|
|
734
|
+
size(): number;
|
|
735
|
+
isEmpty(): boolean;
|
|
736
|
+
clear(): void;
|
|
737
|
+
toString(): string;
|
|
200
738
|
}
|
|
201
739
|
|
|
202
|
-
export { Adapter, CocosEntry, Module, Platform, PlatformType, Screen, debug, enableDebugMode, error, info, log, warn };
|
|
740
|
+
export { Adapter, Binary, BinaryHeap, CocosEntry, DoublyLinkedList, DoublyNode, GlobalTimer, HeapNode, InnerTimer, LinkedList, LinkedNode, Module, Platform, PlatformType, Screen, Stack, Time, Utils, debug, enableDebugMode, error, info, log, md5, warn };
|
|
741
|
+
export type { ICheckUpdatePromiseResult, IPromiseResult };
|
package/dist/bit-core.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("cc");let t=!1;function i(e){1==e?(t=!0,console.warn("调试模式已开启")):t=!1}function s(...e){t&&console.log("bit-framework:",...e)}class r{}class o{constructor(){this.listeners=[]}addResizeListener(e){this.listeners.push(e)}removeResizeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}init(){o.instance=this,s("初始化适配器");let t=this.getDesignSize();r.DesignHeight=t.height,r.DesignWidth=t.width,e.view.setDesignResolutionSize(r.DesignWidth,r.DesignHeight,e.ResolutionPolicy.SHOW_ALL),this.resize(),this.registerListener((...e)=>{s("屏幕发生变化",...e),this.resize();for(const t of this.listeners)t(...e)})}resize(){r.SafeAreaHeight=60;const e=this.getScreenSize(),t=r.DesignWidth>r.DesignHeight;t==e.width>e.height?(r.ScreenWidth=e.width,r.ScreenHeight=e.height):(r.ScreenWidth=e.height,r.ScreenHeight=e.width),t?(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}`)}}var n;exports.PlatformType=void 0,(n=exports.PlatformType||(exports.PlatformType={}))[n.Android=1]="Android",n[n.IOS=2]="IOS",n[n.HarmonyOS=3]="HarmonyOS",n[n.WX=4]="WX",n[n.Alipay=5]="Alipay",n[n.Bytedance=6]="Bytedance",n[n.HuaweiQuick=7]="HuaweiQuick",n[n.Browser=1001]="Browser";class a{}a.isNative=!1,a.isMobile=!1,a.isNativeMobile=!1,a.isAndroid=!1,a.isIOS=!1,a.isHarmonyOS=!1,a.isWX=!1,a.isAlipay=!1,a.isBytedance=!1,a.isHuaweiQuick=!1,a.isBrowser=!1;class c{constructor(){this.initPlatform()}initPlatform(){switch(a.isNative=e.sys.isNative,a.isMobile=e.sys.isMobile,a.isNativeMobile=e.sys.isNative&&e.sys.isMobile,e.sys.os){case e.sys.OS.ANDROID:a.isAndroid=!0,s("系统类型 Android");break;case e.sys.OS.IOS:a.isIOS=!0,s("系统类型 IOS");break;case e.sys.OS.OPENHARMONY:a.isHarmonyOS=!0,s("系统类型 HarmonyOS")}switch(e.sys.platform){case e.sys.Platform.WECHAT_GAME:a.isWX=!0,a.platform=exports.PlatformType.WX;break;case e.sys.Platform.ALIPAY_MINI_GAME:a.isAlipay=!0,a.platform=exports.PlatformType.Alipay;break;case e.sys.Platform.BYTEDANCE_MINI_GAME:a.isBytedance=!0,a.platform=exports.PlatformType.Bytedance;break;case e.sys.Platform.HUAWEI_QUICK_GAME:a.isHuaweiQuick=!0,a.platform=exports.PlatformType.HuaweiQuick;break;default:a.isBrowser=!0,a.platform=exports.PlatformType.Browser}s(`platform: ${exports.PlatformType[a.platform]}`)}}function l(e,t,i,s){var r,o=arguments.length,n=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(o<3?r(n):o>3?r(t,i,n):r(t,i))||n);return o>3&&n&&Object.defineProperty(t,i,n),n}"function"==typeof SuppressedError&&SuppressedError;class h extends o{getScreenSize(){let t=e.screen.windowSize;return{width:Math.ceil(t.width/e.view.getScaleX()),height:Math.ceil(t.height/e.view.getScaleY())}}getDesignSize(){let t=e.view.getDesignResolutionSize();return{width:t.width,height:t.height}}registerListener(t){e.screen&&e.screen.on?(e.screen.on("window-resize",(...e)=>{s("window-resize"),t(...e)},this),e.screen.on("orientation-change",(...e)=>{s("orientation-change"),t(...e)},this),e.screen.on("fullscreen-change",(...e)=>{s("fullscreen-change"),t(...e)},this)):e.view.setResizeCallback(t)}}class f extends e.Component{init(){this.onInit()}}const{property:d}=e._decorator;class p extends e.Component{constructor(){super(...arguments),this.fps=60,this.enableDebug=!1}start(){this.enableDebug&&i(!0),s("开始初始化【bit-framework】"),e.game.frameRate=this.fps,e.director.addPersistRootNode(this.node),this.node.setSiblingIndex(this.node.children.length-1),new c,(new h).init(),this.initModule(),s("【bit-framework】初始化完成"),this.onInit()}initModule(){const e=this.getComponentsInChildren(f);for(const t of e)t.init()}}l([d({displayName:"游戏帧率"})],p.prototype,"fps",void 0),l([d({displayName:"开启调试输出"})],p.prototype,"enableDebug",void 0),exports.Adapter=o,exports.CocosEntry=p,exports.Module=f,exports.Platform=a,exports.Screen=r,exports.debug=s,exports.enableDebugMode=i,exports.error=function(...e){t&&console.error("bit-framework:",...e)},exports.info=function(...e){t&&console.info("bit-framework:",...e)},exports.log=function(...e){console.log("bit-framework:",...e)},exports.warn=function(...e){t&&console.warn("bit-framework:",...e)};
|
|
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)};
|