@shimotsuki/core 3.0.0 → 3.0.2

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/index.d.ts CHANGED
@@ -1,1113 +1,1114 @@
1
- import { Component, Node, Prefab, Vec3, Quat, math, Layers, AudioClip, AudioSource, Label, Button, Scene, SceneAsset, AsyncDelegate, Asset, Constructor, AssetManager, SpriteFrame, Sprite } from 'cc';
2
- import EventEmitter from 'eventemitter3';
3
- import { IReactionPublic, IReactionOptions } from '@shimotsuki/mobx';
4
- import { SocialGameClient, SocialGameClientOption, AllEventResponsePairs, ClientOption, MessageFns, AudienceOptions } from 'sgc';
5
- import { BinaryWriter } from '@bufbuild/protobuf/wire';
6
- import * as crypto_es_lib_cipher_core from 'crypto-es/lib/cipher-core';
7
-
8
- /**
9
- * @describe 基础管理类
10
- * @author 游金宇(KM)
11
- * @date 2024-09-12 11:49:30
12
- */
13
-
14
- declare class BaseManager {
15
- protected cat: Manager;
16
- constructor(manager: Manager);
17
- }
18
-
19
- /**
20
- * 音频管理
21
- */
22
- declare class AudioManager extends BaseManager {
23
- local_data: any;
24
- private music;
25
- private effect;
26
- private _volume_music;
27
- private _volume_effect;
28
- private _switch_music;
29
- private _switch_effect;
30
- private local_store_key;
31
- extra: {
32
- [key: string]: any;
33
- };
34
- constructor(cat: Manager);
35
- /**
36
- * 设置背景音乐播放完成回调
37
- * @param callback 背景音乐播放完成回调
38
- */
39
- setMusicComplete(callback?: Function | null): void;
40
- /**
41
- * 播放背景音乐
42
- * @param url 资源地址
43
- * @param callback 音乐播放完成事件
44
- */
45
- playMusic(url: string): Promise<void>;
46
- playMusic(bundleName: string, url: string): Promise<void>;
47
- /**
48
- * 停止音乐
49
- */
50
- stopMusic(): void;
51
- /**暂停音乐 */
52
- pauseMusic(): void;
53
- /**恢复音乐 */
54
- resumeMusic(): void;
55
- /**
56
- * 获取背景音乐播放进度
57
- */
58
- get progressMusic(): number;
59
- /**
60
- * 设置背景乐播放进度
61
- * @param value 播放进度值
62
- */
63
- set progressMusic(value: number);
64
- /**
65
- * 获取背景音乐音量
66
- */
67
- get volumeMusic(): number;
68
- /**
69
- * 设置背景音乐音量
70
- * @param value 音乐音量值
71
- */
72
- set volumeMusic(value: number);
73
- /**
74
- * 获取背景音乐开关值
75
- */
76
- get switchMusic(): boolean;
77
- /**
78
- * 设置背景音乐开关值
79
- * @param value 开关值
80
- */
81
- set switchMusic(value: boolean);
82
- /**
83
- * 播放音效
84
- * @param url 资源地址
85
- */
86
- playEffect(url: string): Promise<void>;
87
- playEffect(bundleName: string, url: string): Promise<void>;
88
- /**
89
- * 停止音效
90
- */
91
- stopEffect(): void;
92
- /**
93
- * 获取音效音量
94
- */
95
- get volumeEffect(): number;
96
- /**
97
- * 设置获取音效音量
98
- * @param value 音效音量值
99
- */
100
- set volumeEffect(value: number);
101
- /**
102
- * 获取音效开关值
103
- */
104
- get switchEffect(): boolean;
105
- /**
106
- * 设置音效开关值
107
- * @param value 音效开关值
108
- */
109
- set switchEffect(value: boolean);
110
- /** 恢复当前暂停的音乐与音效播放 */
111
- resumeAll(): void;
112
- /** 暂停当前音乐与音效的播放 */
113
- pauseAll(): void;
114
- /** 停止当前音乐与音效的播放 */
115
- stopAll(): void;
116
- /** 保存音乐音效的音量、开关配置数据到本地 */
117
- save(): this;
118
- /** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */
119
- load(): void;
120
- }
121
-
122
- /**
123
- * @describe 组件基类
124
- * @author 游金宇(KM)
125
- * @date 2023-09-19 12:32:22
126
- */
127
-
128
- type HOOK_NAME = 'destroyed' | 'started';
129
- type HOOK = {
130
- [key in HOOK_NAME]?: () => void;
131
- };
132
- interface IUIOption<T extends object = {}, U extends object = {}> {
133
- /**组件传值间属性值 */
134
- props?: T;
135
- /**组件数据 */
136
- data?: U;
137
- /**钩子 */
138
- hook?: HOOK;
139
- }
140
- /**参数 */
141
- /**initUI->onAutoObserver->onLoad->start */
142
- declare class BaseComponent<T extends object = {}, K extends object = {}> extends Component {
143
- /**组件(传值)属性 */
144
- props: T;
145
- /**自由属性 */
146
- data: K;
147
- cat: typeof globalThis._cat;
148
- /**autorun销毁 */
149
- private autorunDisposers;
150
- /**reaction销毁 */
151
- private reactionDisposers;
152
- private eventEmitter;
153
- hook: HOOK;
154
- /**初始化UI(可在本函数中进行节点赋值或注册节点事件等...) */
155
- protected initUI(): void;
156
- protected __preload(): void;
157
- constructor();
158
- /**依赖收集生命周期(可以在该生命周期中注册依赖收集回调) */
159
- protected onAutoObserver(): void;
160
- /**添加自动收集 */
161
- protected addAutorun(cb: (() => void) | (() => void)[]): this;
162
- /**添加自动收集 */
163
- protected addReaction<T, FireImmediately extends boolean = false>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: FireImmediately extends true ? T | undefined : T, r: IReactionPublic) => void, opts?: IReactionOptions<T, FireImmediately>): this;
164
- protected addAudoListener<E extends EventEmitter<any>>(eventEmitter: E): E;
165
- _onPreDestroy(): void;
166
- protected onDisable(): void;
167
- private deleteAllEventByEmitter;
168
- protected onEnable(): void;
169
- /**子类继承该方法(全局事件(this.cat.event)注册在components上的事件可以不添加取消监听(自动取消监听了)) */
170
- protected onEventListener(): void;
171
- /**子类继承该方法 */
172
- protected addListener(): void;
173
- /**子类继承该方法 */
174
- protected removeListener(): void;
175
- /**
176
- * 添加到父节点指定层级
177
- * @param parent 父节点
178
- * @param index 插入的层级索引
179
- * @param options 参数
180
- * @returns 自身组件
181
- */
182
- addToParent(parent: Node | Prefab | Component, index: number, options?: IUIOption<T, K>): this;
183
- addToParent(parent: Node | Prefab | Component, options?: IUIOption<T, K>): this;
184
- /**设置属性(覆盖原有属性) */
185
- setOptions(options?: IUIOption<T, K>): void;
186
- /**设置data属性(更新) */
187
- setUpdateData(data: Partial<K>): this | undefined;
188
- /**设置props属性(更新)*/
189
- setUpdateProps(props: Partial<T>): this | undefined;
190
- /**从父节点移除并销毁 */
191
- removeAndDestroy(): void;
192
- /**设置坐标 */
193
- setPosition(positin: Vec3): this;
194
- setScale(scale: Vec3): this;
195
- setAngle(angle: number): this;
196
- setRotation(rotation: Quat): this;
197
- setRotationFromEuler(rotation: math.Vec3): this;
198
- /**显示(同onEnable) */
199
- protected onShow(): void;
200
- /**隐藏(同onDisable) */
201
- protected onHide(): void;
202
- /**设置节点和子节点的层级 */
203
- setNodeAndChildrenLayer(layer: string | Layers.Enum): this;
204
- }
205
-
206
- /**
207
- * @describe UI层 所有的UI层需继承自该自组件
208
- * @author 游金宇(KM)
209
- * @date 2023-08-04 10:42:26
210
- */
211
-
212
- /**
213
- * left 从左往右
214
- * right 从右往左
215
- * top 从上往下
216
- * bot 从下往上
217
- * center 中间
218
- */
219
- type IDirection = 'left' | 'right' | 'top' | 'bot' | 'center';
220
- /**开启动画参数选项 */
221
- interface IOpenOptions<T extends object, U extends object> extends IUIOption<T, U> {
222
- /**动画 */
223
- isMotion?: boolean;
224
- /**动画时间 */
225
- duration?: number;
226
- /**方向 */
227
- direction?: IDirection;
228
- /**是否回弹 */
229
- isBounce?: boolean;
230
- /**回弹时间 */
231
- bounceDuration?: number;
232
- }
233
- /**关闭动画参数选项 */
234
- interface ICloseOptions<T extends object, U extends object> extends IUIOption<T, U> {
235
- /**动画 */
236
- isMotion?: boolean;
237
- /**动画时间 */
238
- duration?: number;
239
- /**方向 */
240
- direction?: IDirection;
241
- }
242
- declare class UILayer<T extends object = {}, U extends object = {}> extends BaseComponent<T, U> {
243
- /**上次进入的方向 */
244
- lastEnterDirection: IDirection;
245
- /**屏幕尺寸 */
246
- screen: math.Size;
247
- /**是否正在关闭 */
248
- isClosing: boolean;
249
- /**组件所在的UI最顶层(不包含UI) */
250
- root: Node;
251
- constructor();
252
- private _init;
253
- /**显示动画 */
254
- showTween<T extends object, U extends object = {}>({ isMotion, direction, duration, isBounce, bounceDuration }: IOpenOptions<T, U>): Promise<void>;
255
- /**隐藏动画 */
256
- hideTween<T extends object, U extends object>({ isMotion, direction, duration }: ICloseOptions<T, U>): Promise<void>;
257
- private handle;
258
- private deftween;
259
- }
260
-
261
- /**
262
- * @describe 音频组件基类
263
- * @author 游金宇(KM)
264
- * @date 2023-12-22 16:20:20
265
- */
266
-
267
- /**
268
- * EFFECT 音效
269
- * BGM 音乐
270
- */
271
- declare enum AudioTypeEnum {
272
- EFFECT = 0,
273
- BGM = 1
274
- }
275
- declare class AudioSourceBaseComponent<T extends object = {}, K extends object = {}> extends BaseComponent<T, K> {
276
- type: AudioTypeEnum;
277
- clip: AudioClip;
278
- loop: boolean;
279
- volume: number;
280
- playOnAwake: boolean;
281
- audioSource: AudioSource;
282
- onEnable(): void;
283
- __preload(): void;
284
- protected start(): void;
285
- protected stopAudio(): void;
286
- protected playAudio(): void;
287
- protected onPlayEffectHandler(): void;
288
- protected onStopEffectHandler(): void;
289
- protected onPlayMusicHandler(): void;
290
- protected onStopMusicHandler(): void;
291
- _onPreDestroy(): void;
292
- }
293
-
294
- /**带有音频通道的UIlayer组件 */
295
- declare class AudioSourceUILayer<T extends object, U extends object = {}> extends UILayer<T, U> {
296
- type: AudioTypeEnum;
297
- clip: AudioClip;
298
- loop: boolean;
299
- volume: number;
300
- playOnAwake: boolean;
301
- audioSource: AudioSource;
302
- onEnable(): void;
303
- __preload(): void;
304
- protected stopAudio(): void;
305
- protected playAudio(): void;
306
- protected onPlayEffectHandler(): void;
307
- protected onStopEffectHandler(): void;
308
- protected onPlayMusicHandler(): void;
309
- protected onStopMusicHandler(): void;
310
- _onPreDestroy(): void;
311
- }
312
-
313
- /**
314
- * @describe TOAST弹窗组件
315
- * @author 游金宇(KM)
316
- * @date 2024-09-12 11:42:29
317
- */
318
-
319
- declare enum ToastType {
320
- FIXED = 0,
321
- SLIDE = 1
322
- }
323
- type ToastProps = {
324
- title: string;
325
- type?: ToastType;
326
- fixed_time?: number;
327
- };
328
- declare class CoreToast extends BaseComponent<ToastProps> {
329
- fixed_node: Node;
330
- slide_node: Node;
331
- fixed_label: Label;
332
- slide_label: Label;
333
- onLoad(): void;
334
- protected start(): void;
335
- show(): Promise<void>;
336
- private playAnim;
337
- onDestroy(): void;
338
- }
339
-
340
- /**
341
- * @describe 根级别的UI层 所有的ROOT UI层需继承自该自组件
342
- * @author 游金宇(KM)
343
- * @date 2023-08-04 10:42:26
344
- */
345
-
346
- declare class RootUILayer<T extends object> extends UILayer<T> {
347
- protected onEnable(): void;
348
- protected onDisable(): void;
349
- private updateMask;
350
- }
351
-
352
- type CoreShowLoadingProps = {
353
- /**标题 */
354
- title?: string;
355
- /**阻挡 */
356
- mask?: boolean;
357
- /**显示黑色(弹窗存在公共的遮罩,这里不需要重复设置) */
358
- black?: boolean;
359
- };
360
- /**
361
- * @describe 加载框
362
- * @author 游金宇(KM)
363
- * @date 2024-09-12 11:49:51
364
- */
365
- declare class CoreShowLoading extends RootUILayer<CoreShowLoadingProps> {
366
- title: Label;
367
- loadingTween: Node;
368
- private loading_rotate;
369
- protected onAutoObserver(): void;
370
- update(deltaTime: number): void;
371
- }
372
-
373
- type CoreNoticeProps = {
374
- text: string;
375
- confrim?: () => void;
376
- };
377
- /**
378
- * @describe 通知框
379
- * @author 游金宇(KM)
380
- * @date 2024-09-12 11:49:51
381
- */
382
- declare class CoreNotice<T extends CoreNoticeProps = CoreNoticeProps> extends RootUILayer<T> {
383
- text: Label;
384
- btn_confirm: Button;
385
- btn_close: Button;
386
- protected onLoad(): void;
387
- start(): void;
388
- protected onConfrimHandler(): void;
389
- updateProps(props: CoreNoticeProps): void;
390
- }
391
-
392
- /**
393
- * @describe Scene层 所有的UI层需继承自该自组件
394
- * @author 游金宇(KM)
395
- * @date 2023-08-04 10:42:26
396
- */
397
-
398
- type SceneType<T> = T extends SceneLayer<infer U, infer K> ? {
399
- props: U;
400
- data: K;
401
- } : {
402
- props: object;
403
- data: object;
404
- };
405
- type ScenePropsType<T> = SceneType<T> extends {
406
- props: infer U extends object;
407
- data: infer K extends object;
408
- } ? U : never;
409
- type SceneDataType<T> = SceneType<T> extends {
410
- props: infer U extends object;
411
- data: infer K extends object;
412
- } ? K : never;
413
- declare class SceneLayer<T extends object = Object, K extends object = {}> extends BaseComponent<T, K> {
414
- /**是否为重新加载场景 */
415
- isReload: boolean;
416
- }
417
-
418
- declare enum ReconnectPrompt {
419
- RECONNECTED = "\u91CD\u8FDE\u6210\u529F",
420
- RECONNECTING = "\u6B63\u5728\u91CD\u8FDE",
421
- MAX_RECONNECT = "\u91CD\u8FDE\u6B21\u6570\u8D85\u51FA\u9650\u5236,\u8BF7\u68C0\u67E5\u7F51\u7EDC",
422
- RECONNECTED_ERROR = "\u91CD\u8FDE\u5931\u8D25,\u8BF7\u68C0\u67E5\u7F51\u7EDC",
423
- CONNECT_PARAM_ERROR = "\u6E38\u620F\u53C2\u6570\u9519\u8BEF,\u8BF7\u91CD\u65B0\u52A0\u8F7D",
424
- KICK = "\u8D26\u53F7\u5DF2\u4E0B\u7EBF",
425
- OFFLINE = "\u7F51\u7EDC\u5DF2\u65AD\u5F00",
426
- ONLINE = "\u7F51\u7EDC\u5DF2\u8FDE\u63A5",
427
- GAME_ERROR = "\u8FDE\u63A5\u6E38\u620F\u670D\u9519\u8BEF"
428
- }
429
-
430
- /**
431
- * @describe GUI组件类
432
- * @author 游金宇(KM)
433
- * @date 2024-09-12 11:46:22
434
- */
435
-
436
- type UIComponentType$1<T> = T extends UILayer<infer U, infer K> ? {
437
- props: U;
438
- data: K;
439
- } : {
440
- props: object;
441
- data: object;
442
- };
443
- type PropsType<T> = UIComponentType$1<T> extends {
444
- props: infer U extends object;
445
- data: infer K extends object;
446
- } ? U : never;
447
- type DataType<T> = UIComponentType$1<T> extends {
448
- props: infer U extends object;
449
- data: infer K extends object;
450
- } ? K : never;
451
- declare enum LayerType {
452
- UI = 0,
453
- /**加载 */
454
- LOADING = 1,
455
- /**提示 */
456
- TOAST = 2,
457
- /**断线重连 */
458
- RECONNECTTION = 3,
459
- /**系统服务通知(停机维护) */
460
- NOTICE = 4
461
- }
462
- /**Gui层 */
463
- declare class Gui extends BaseComponent {
464
- reconnection_ui_prefab: Prefab;
465
- toast_ui_prefab: Prefab;
466
- loading_ui_prefab: Prefab;
467
- notice_ui_prefab: Prefab;
468
- ui_prefab: Prefab;
469
- root_ui: Node;
470
- root_toast: Node;
471
- root_mask: Node;
472
- /**场景中的UI层 */
473
- private ui_container_component;
474
- /**断线重连UI弹窗 */
475
- private reconnection_ui_component;
476
- /**公告UI弹窗组件 */
477
- private notice_ui_component;
478
- /**加载UI弹窗 */
479
- private loading_ui_component;
480
- /**提示UI弹窗 */
481
- private toast_ui_component;
482
- /**当前场景对象名 */
483
- currentScene: string;
484
- protected onEventListener(): void;
485
- init(cat: Manager): this;
486
- protected start(): void;
487
- private toastQueue;
488
- private isScheduling;
489
- private minInterval;
490
- showToast(props: ToastProps): void;
491
- private processQueueWithInterval;
492
- /** 隐藏并清除所有提示 */
493
- hideToast(): this;
494
- /**显示Loading */
495
- showLoading({ title, mask, black }?: CoreShowLoadingProps): this;
496
- /**隐藏Loading */
497
- hideLoading(): this;
498
- /**
499
- * 显示断线重连
500
- * @param option 状态提示文案
501
- */
502
- showReconnect(option: ReconnectPrompt): this;
503
- /**隐藏断线重连 */
504
- hideReconnect(): this;
505
- /**
506
- * 显示公告
507
- * @param option 参数
508
- */
509
- showNotice(option: CoreNoticeProps): this;
510
- /**隐藏公告 */
511
- hideNotice(): this;
512
- /**
513
- * 加载并切换游戏场景
514
- * @param sceneName 场景名称、场景实例或场景资源,用于指定要加载的场景
515
- * @param options 可选参数,可以是场景加载的配置选项,或者是一个表示是否重新加载的布尔值
516
- * @param isReload 可选参数,明确指示是否重新加载场景(当options为布尔值时,此参数被忽略)
517
- * @returns 返回当前实例,支持链式调用
518
- */
519
- loadScene<T>(sceneName: string): this;
520
- loadScene<T>(sceneName: string, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>): this;
521
- loadScene<T>(sceneName: string, isReload: boolean): this;
522
- loadScene<T>(sceneName: string, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>, isReload: boolean): this;
523
- loadScene<T>(scene: Scene | SceneAsset): this;
524
- loadScene<T>(scene: Scene | SceneAsset, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>): this;
525
- loadScene<T>(scene: Scene | SceneAsset, isReload: boolean): this;
526
- loadScene<T>(scene: Scene | SceneAsset, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>, isReload: boolean): this;
527
- /**重置场景(清除当前默认当前场景) */
528
- resetScene(sceneName?: string): this;
529
- /**清除场景 */
530
- cleanScene(): void;
531
- /**
532
- * 场景变化
533
- * @param scene 场景
534
- * @param options 选项
535
- * @param isReload 是否重新加载
536
- */
537
- changeScene<T>(scene: Scene, options?: IUIOption<ScenePropsType<T>, SceneDataType<T>>, isReload?: boolean): void;
538
- private createUILayer;
539
- /**重新加载当前场景 */
540
- reloadScene(): void;
541
- /**关闭UI */
542
- closeUI<T extends UILayer<object>, U extends object>(ui: Node | T, options?: ICloseOptions<T, U>): Promise<void>;
543
- /**
544
- * 打开ui层
545
- * @param ui 界面的节点或组件
546
- * @param options 动画参数选项
547
- */
548
- openUI<T extends UILayer>(ui: Node, options?: IOpenOptions<PropsType<T>, DataType<T>>): Promise<void>;
549
- /**根据节点或组件 查询根UI层(继承自UILayer的)节点或组件 */
550
- private findUIBaseLayer;
551
- /**根层的变化 */
552
- private onRootUpdate;
553
- }
554
-
555
- declare class CoreBlackMask extends BaseComponent {
556
- tween: Node;
557
- }
558
-
559
- /**
560
- * @describe UI容器管理 在场景节点下 会随着场景销毁(非常驻节点)
561
- * @author 游金宇(KM)
562
- * @date 2024-09-12 11:45:31
563
- */
564
-
565
- declare class CoreUIContainer extends UILayer {
566
- scene_mask_node: Node;
567
- ui_container: Node;
568
- gui: Gui;
569
- protected onLoad(): void;
570
- get scene_mask(): CoreBlackMask;
571
- get brother(): Node[];
572
- get tweenChildren(): Node[];
573
- protected onEventListener(): void;
574
- /**增加层级 */
575
- addMask(): void;
576
- /**减少层级 */
577
- subMask(): void;
578
- blockMaskSiblingIndexChanged(): void;
579
- /**
580
- * 将UI节点挂载在tween上执行动画
581
- * @param node 节点
582
- */
583
- addNodeToTween(node: Node): this;
584
- show(): void;
585
- hide(): void;
586
- setGui(gui: Gui): this;
587
- /**根层的变化 */
588
- uiMaskChanged(): void;
589
- setSceneMaskActive(active: boolean): void;
590
- }
591
-
592
- /**
593
- * @describe 层级界面管理
594
- * @author 游金宇(KM)
595
- * @date 2023-08-03 20:02:45
596
- */
597
-
598
- type UIComponentType<T> = T extends UILayer<infer U> ? U : void;
599
- type SceneComponentType<T> = T extends SceneLayer<infer U> ? U : void;
600
- /**预制体路径 */
601
- declare enum BasePrefab {
602
- Root = "prefabs/root",
603
- Toast = "prefabs/toast",
604
- BlackMask = "prefabs/black-mask",
605
- Loading = "prefabs/loading",
606
- Notice = "prefabs/notice",
607
- Reconnection = "prefabs/reconnection"
608
- }
609
- declare class GuiManager extends BaseManager {
610
- #private;
611
- /**常驻顶层UI节点层级 */
612
- gui: Gui;
613
- /**
614
- * 获取预制体
615
- * @param type 类型
616
- * @returns
617
- */
618
- private getGuiPrefabByType;
619
- /**初始化 */
620
- init(): Promise<this>;
621
- }
622
-
623
- /**
624
- * @describe 基于社交游戏封装的游戏基础ws类
625
- * @author 游金宇(KM)
626
- * @date 2024-09-12 11:47:51
627
- */
628
-
629
- type ExtendedClientOption = ClientOption & {
630
- /** 是否弹出请求错误信息 */
631
- showRequestErrInfo?: boolean;
632
- };
633
- declare class WrapperSocialGameClient extends SocialGameClient {
634
- /**是否弹出请求错误信息 */
635
- protected showRequestErrInfo: boolean;
636
- /**日志黑名单 */
637
- protected logBlackList: string[];
638
- ignore: (route: string) => boolean;
639
- constructor(name: string, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>, clientOption?: ExtendedClientOption);
640
- destroy(): void;
641
- GameRequest<U>(route: string, req: BinaryWriter, res: MessageFns<U>, { forwardReq, forwardResp }?: AudienceOptions): Promise<U>;
642
- subscribe<T>(route: string, respType: MessageFns<T>, fn?: (data: T) => void): this;
643
- }
644
-
645
- declare class SocialGameClientManager extends BaseManager {
646
- private managedClients;
647
- /**在线 */
648
- private isGlobalOnline;
649
- /**在后台 */
650
- private isInBackground;
651
- /**正在重连 */
652
- private reconnecting;
653
- /**后台委托 */
654
- readonly onEventHideDelegate: AsyncDelegate<() => (Promise<void> | void)>;
655
- /**前台委托 */
656
- readonly onEventShowDelegate: AsyncDelegate<() => (Promise<void> | void)>;
657
- /**重载场景委托 */
658
- readonly onEventReloadSceneDelegate: AsyncDelegate<() => (Promise<void> | void)>;
659
- /**重连定时器 */
660
- private reconnectTimer;
661
- private scheduleReconnect;
662
- get activeClients(): WrapperSocialGameClient[];
663
- constructor(cat: Manager);
664
- /**
665
- * 创建并注册WebSocket客户端
666
- * @param name 客户端唯一标识(如"game", "room")
667
- * @param clientOption 客户端配置选项
668
- * @param opts 社交游戏选项
669
- * @param eventResponsePairs 事件响应配置
670
- */
671
- createWebSocket(name: string, clientOption: ExtendedClientOption, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>): WrapperSocialGameClient;
672
- register(client: WrapperSocialGameClient): void;
673
- unregister(client: WrapperSocialGameClient): void;
674
- private initGlobalListeners;
675
- private handleGlobalStateChange;
676
- private triggerReconnectAll;
677
- private disconnectAll;
678
- private handleSingleClose;
679
- private handleSingleReconnect;
680
- private handleSingleKick;
681
- }
682
-
683
- /**
684
- * @describe 游戏资管理
685
- * @author 游金宇(KM)
686
- * @date 2023-08-03 17:40:51
687
- */
688
-
689
- type ProgressCallback = (completedCount: number, totalCount: number, item: any) => void;
690
- type CompleteCallback<T> = ((err: Error | null, data: T) => void) | null;
691
- type IRemoteOptions = {
692
- [k: string]: any;
693
- ext?: string;
694
- };
695
- type AssetType<T = Asset> = Constructor<T>;
696
- declare class ResLoader {
697
- /**
698
- * 获取资源
699
- * @param path 资源路径
700
- * @param type 资源类型
701
- * @param bundleName 远程资源包名
702
- */
703
- get: <T extends Asset>(path: string, type?: AssetType<T> | null, bundleName?: string) => T | null;
704
- /**
705
- * 获取资源类型
706
- */
707
- isAssetType: <T>(value: any) => value is AssetType<T>;
708
- /**
709
- * 获取资源
710
- * @param bundleName 远程包名
711
- * @param paths 资源路径
712
- * @param type 资源类型-
713
- * @param onProgress 加载进度回调
714
- * @param onComplete 加载完成回调
715
- */
716
- load<T extends Asset>(paths: string | string[]): void;
717
- load<T extends Asset>(paths: string | string[], type: AssetType<T>): void;
718
- load<T extends Asset>(paths: string, onComplete: CompleteCallback<T>): void;
719
- load<T extends Asset>(paths: string, type: AssetType<T>, onComplete: CompleteCallback<T>): void;
720
- load<T extends Asset>(paths: string, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
721
- load<T extends Asset>(paths: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
722
- load<T extends Asset>(paths: string[], onComplete: CompleteCallback<T[]>): void;
723
- load<T extends Asset>(paths: string[], onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
724
- load<T extends Asset>(paths: string[], type: AssetType<T>, onComplete: CompleteCallback<T[]>): void;
725
- load<T extends Asset>(paths: string[], type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
726
- load<T extends Asset>(bundleName: string, paths: string | string[]): void;
727
- load<T extends Asset>(bundleName: string, paths: string | string[], type: AssetType<T>): void;
728
- load<T extends Asset>(bundleName: string, paths: string, onComplete: CompleteCallback<T>): void;
729
- load<T extends Asset>(bundleName: string, paths: string[], onComplete: CompleteCallback<T[]>): void;
730
- load<T extends Asset>(bundleName: string, paths: string, type: AssetType<T>, onComplete: CompleteCallback<T>): void;
731
- load<T extends Asset>(bundleName: string, paths: string[], type: AssetType<T>, onComplete: CompleteCallback<T[]>): void;
732
- load<T extends Asset>(bundleName: string, paths: string, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
733
- load<T extends Asset>(bundleName: string, paths: string[], onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
734
- load<T extends Asset>(bundleName: string, paths: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
735
- load<T extends Asset>(bundleName: string, paths: string[], type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
736
- /**
737
- * 加载文件夹
738
- * @param bundleName 远程包名
739
- * @param dir 文件夹名
740
- * @param type 资源类型
741
- * @param onProgress 加载进度回调
742
- * @param onComplete 加载完成回调
743
- */
744
- loadDir<T extends Asset>(dir: string): void;
745
- loadDir<T extends Asset>(dir: string, type: AssetType<T>): void;
746
- loadDir<T extends Asset>(dir: string, onComplete: CompleteCallback<T[]>): void;
747
- loadDir<T extends Asset>(dir: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
748
- loadDir<T extends Asset>(bundleName: string, dir: string): void;
749
- loadDir<T extends Asset>(bundleName: string, dir: string, type: AssetType<T>): void;
750
- loadDir<T extends Asset>(bundleName: string, dir: string, onComplete: CompleteCallback<T[]>): void;
751
- loadDir<T extends Asset>(bundleName: string, dir: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
752
- /**
753
- * 加载远程资源
754
- * @param url 资源地址
755
- * @param options 资源参数,例:{ ext: ".png" }
756
- * @param onComplete 加载完成回调
757
- *
758
- * res.ResLoader.loadRemote(params.iconv, (err: Error, imageAsset: ImageAsset) => {
759
- if (err) return error(err)
760
- if (isValid(this.itemSp)) {
761
- this.itemSp.spriteFrame = SpriteFrame.createWithImage(imageAsset)
762
- }
763
- })
764
- */
765
- loadRemote<T extends Asset>(url: string, options: IRemoteOptions, onComplete?: CompleteCallback<T>): void;
766
- loadRemote<T extends Asset>(url: string, onComplete?: CompleteCallback<T>): void;
767
- /**
768
- * 加载bundle
769
- * @param url 资源地址 <远程路径或者bundleName>
770
- * @param complete 完成事件
771
- * @param v 资源版本号
772
- * @example
773
- */
774
- loadBundle: (url: string, version?: string) => Promise<AssetManager.Bundle>;
775
- /** 释放预制依赖资源 */
776
- releasePrefabtDepsRecursively: (uuid: string) => void;
777
- /**
778
- * 通过资源相对路径释放资源
779
- * @param path 资源路径
780
- * @param bundleName 远程资源包名
781
- */
782
- release: (path: string, bundleName?: string) => void;
783
- /**
784
- * 通过相对文件夹路径删除所有文件夹中资源
785
- * @param path 资源文件夹路径
786
- * @param bundleName 远程资源包名
787
- */
788
- releaseDir: (path: string, bundleName?: string) => void;
789
- /** 打印缓存中所有资源信息 */
790
- dump: () => void;
791
- /**
792
- * 加载分包中的资源并提供进度反馈。
793
- * @param bundle - 已加载的分包。
794
- * @param onProgress - 进度回调函数。
795
- * @returns Promise<void> - 加载完成后的Promise。
796
- */
797
- loadAssetsWithProgress(bundle: AssetManager.Bundle, onProgress: (progress: number) => void): Promise<void>;
798
- }
799
-
800
- /**
801
- * @describe 基本数据
802
- * @author 游金宇(KM)
803
- * @date 2024-09-12 11:35:02
804
- */
805
-
806
- declare class BaseStore {
807
- protected rootStore: CoreStore;
808
- constructor(rootStore: CoreStore);
809
- }
810
-
811
- declare class CoreStore extends BaseManager {
812
- }
813
-
814
- /**
815
- * MD5加密
816
- * @param msg 加密信息
817
- */
818
- declare const md5: (msg: string) => string;
819
- /** 初始化加密库 */
820
- declare const initCrypto: (key: string, iv: string) => void;
821
- /**
822
- * AES 加密
823
- * @param msg 加密信息
824
- * @param key aes加密的key
825
- * @param iv aes加密的iv
826
- */
827
- declare const aesEncrypt: (msg: string, key: string, iv: string) => string;
828
- /**
829
- * AES 解密
830
- * @param str 解密字符串
831
- * @param key aes加密的key
832
- * @param iv aes加密的iv
833
- */
834
- declare const aesDecrypt: (str: string, key: string, iv: string) => string;
835
- declare const JsonFormatter: {
836
- stringify: (cipherParams: any) => string;
837
- parse: (jsonStr: string) => crypto_es_lib_cipher_core.CipherParams;
838
- };
839
-
840
- declare const EncryptUtil_JsonFormatter: typeof JsonFormatter;
841
- declare const EncryptUtil_aesDecrypt: typeof aesDecrypt;
842
- declare const EncryptUtil_aesEncrypt: typeof aesEncrypt;
843
- declare const EncryptUtil_initCrypto: typeof initCrypto;
844
- declare const EncryptUtil_md5: typeof md5;
845
- declare namespace EncryptUtil {
846
- export {
847
- EncryptUtil_JsonFormatter as JsonFormatter,
848
- EncryptUtil_aesDecrypt as aesDecrypt,
849
- EncryptUtil_aesEncrypt as aesEncrypt,
850
- EncryptUtil_initCrypto as initCrypto,
851
- EncryptUtil_md5 as md5,
852
- };
853
- }
854
-
855
- /**
856
- * @describe 工具类
857
- * @author 游金宇(KM)
858
- * @date 2023-08-02 20:16:42
859
- */
860
-
861
- declare class CoreUtil extends BaseManager {
862
- encryptUtil: typeof EncryptUtil;
863
- }
864
-
865
- /**
866
- * @describe 本地存储管理
867
- * @author 游金宇(KM)
868
- * @date 2023-08-03 17:58:51
869
- */
870
-
871
- declare class StorageManager extends BaseManager {
872
- private _key;
873
- private _iv;
874
- private _id;
875
- /**
876
- * 初始化密钥
877
- * @param key aes加密的key
878
- * @param iv aes加密的iv
879
- */
880
- init(key: string, iv: string): void;
881
- /**
882
- * 设置用户唯一标识
883
- * @param id
884
- */
885
- setUser(id: string): void;
886
- /**
887
- * 存储本地数据
888
- * @param key 存储key
889
- * @param value 存储值
890
- * @returns
891
- */
892
- set(key: string, value: any): void;
893
- /**
894
- * 获取指定关键字的数据
895
- * @param key 获取的关键字
896
- * @param defaultValue 获取的默认值
897
- * @returns
898
- */
899
- get(key: string, defaultValue?: any): string;
900
- /** 获取指定关键字的数值 */
901
- getNumber(key: string, defaultValue?: number): number;
902
- /** 获取指定关键字的布尔值 */
903
- getBoolean(key: string): boolean;
904
- /** 获取指定关键字的JSON对象 */
905
- getJson(key: string, defaultValue?: any): any;
906
- /**
907
- * 删除指定关键字的数据
908
- * @param key 需要移除的关键字
909
- * @returns
910
- */
911
- remove(key: string): void;
912
- /** 清空整个本地存储 */
913
- clear(): void;
914
- }
915
-
916
- /**
917
- * @describe 管理类
918
- * @author 游金宇(KM)
919
- * @date 2024-09-12 11:49:44
920
- */
921
-
922
- declare class Manager {
923
- #private;
924
- static get instance(): Manager;
925
- /**APP初始化事务 */
926
- readonly onAppInitDelegate: AsyncDelegate<() => (Promise<void> | void)>;
927
- /**插件初始化事务 */
928
- readonly onPlugInInitDelegate: AsyncDelegate<() => (Promise<void> | void)>;
929
- /**音频管理 */
930
- get audio(): AudioManager;
931
- /**全局事件管理 */
932
- get event(): EventEmitter<string | symbol, any>;
933
- /**gui管理 */
934
- get gui(): Gui;
935
- /**本地存储管理 */
936
- get storage(): StorageManager;
937
- /**资源管理 */
938
- get res(): ResLoader;
939
- /**工具类管理 */
940
- get util(): CoreUtil;
941
- /**社交游戏类 */
942
- get socialGameClient(): SocialGameClientManager;
943
- /**数据存储 */
944
- get store(): CoreStore;
945
- /**GUI bundle 名称 */
946
- get gui_bundle_name(): string;
947
- /**音效本地存储key */
948
- get audio_local_store_key(): string;
949
- /**默认音效路径 */
950
- get default_audio_effect(): string;
951
- /**GUI资源配置 */
952
- setConfig: ({ default_audio_effect, gui_bundleName, audio_local_store_key }?: {
953
- gui_bundleName?: string;
954
- audio_local_store_key?: string;
955
- default_audio_effect?: string;
956
- }) => this;
957
- /**启动 */
958
- boot(): Promise<void>;
959
- /**合并对象 */
960
- merge<K extends keyof Manager, T extends object>(target: K, source: T): this;
961
- /**
962
- * 注册一个“插件级”初始化回调
963
- * - 如果已初始化,立即执行
964
- * - 否则排队到 onPlugInInitDelegate 中
965
- */
966
- appendPlugInInitDelegate(cb: () => Promise<void> | void): this;
967
- }
968
-
969
- declare enum AudioEventConstant {
970
- /**音乐开 */
971
- MUSIC_ON = "AudioEventConstant/MUSIC_ON",
972
- /**音乐关 */
973
- MUSIC_OFF = "AudioEventConstant/MUSIC_OFF",
974
- /**音效开 */
975
- EFFECT_ON = "AudioEventConstant/EFFECT_ON",
976
- /**音效关 */
977
- EFFECT_OFF = "AudioEventConstant/EFFECT_OFF",
978
- /**暂停音频 */
979
- PAUSE_AUDIO = "AudioEventConstant/PAUSE_AUDIO",
980
- /**恢复音频 */
981
- RESUME_AUDIO = "AudioEventConstant/RESUME_AUDIO"
982
- }
983
-
984
- /**
985
- * @describe 全局事件监听方法
986
- * @author 游金宇(KM)
987
- * @date 2023-08-03 18:13:36
988
- */
989
- declare enum GlobalEventConstant {
990
- /** 游戏从后台进入 */
991
- EVENT_SHOW = "GlobalEventConstant/EVENT_SHOW",
992
- /** 游戏切到后台 */
993
- EVENT_HIDE = "GlobalEventConstant/EVENT_HIDE",
994
- /** 游戏画笔尺寸变化事件 */
995
- GAME_RESIZE = "GlobalEventConstant/GAME_RESIZE",
996
- /**游戏关闭时间 */
997
- EVENT_CLOSE = "GlobalEventConstant/EVENT_CLOSE",
998
- /**网络连接 */
999
- ONLINE = "GlobalEventConstant/ONLINE",
1000
- /**网络断开 */
1001
- OFFLINE = "GlobalEventConstant/OFFLINE",
1002
- /**ROOT_MASK更新 */
1003
- ROOT_MASK_UPDATE = "GlobalEventConstant/ROOT_MASK_UPDATE",
1004
- /**ROOT_MASK更新变化 */
1005
- ROOT_MASK_CHANGE = "GlobalEventConstant/ROOT_MASK_CHANGE"
1006
- }
1007
-
1008
- type CoreUIModalProps = {
1009
- content: string | SpriteFrame | null;
1010
- confirmCB: () => void;
1011
- cancelCB: () => void;
1012
- onDestroy?: () => void;
1013
- title?: SpriteFrame;
1014
- style?: {
1015
- confirm?: SpriteFrame;
1016
- cancel?: SpriteFrame;
1017
- } | null;
1018
- };
1019
- /**
1020
- * @describe 模态框
1021
- * @author 游金宇(KM)
1022
- * @date 2024-09-12 11:49:51
1023
- */
1024
- declare class CoreUIModal extends UILayer<CoreUIModalProps> {
1025
- default_title: SpriteFrame;
1026
- title: Sprite;
1027
- prompt_content_str: Label;
1028
- prompt_content_spriteFrame: Sprite;
1029
- btn_confirm: Button;
1030
- confirm_spriteFrame: SpriteFrame;
1031
- btn_cancel: Button;
1032
- cancel_spriteFrame: SpriteFrame;
1033
- btn_close: Button;
1034
- isConfirm: boolean;
1035
- props: CoreUIModalProps;
1036
- protected onLoad(): void;
1037
- private close;
1038
- private onCancelHandler;
1039
- private onConfirmHandler;
1040
- onDestroy(): void;
1041
- private onCloseHandler;
1042
- }
1043
-
1044
- type CoreReconnectionProps = {
1045
- content: ReconnectPrompt | null;
1046
- };
1047
- /**
1048
- * @describe 重连框
1049
- * @author 游金宇(KM)
1050
- * @date 2024-09-12 11:49:51
1051
- */
1052
- declare class CoreReconnection extends RootUILayer<CoreReconnectionProps> {
1053
- common_prompt_text: Label;
1054
- btn_confirm: Button;
1055
- btn_close: Button;
1056
- protected is_close: boolean;
1057
- props: CoreReconnectionProps;
1058
- protected initUI(): void;
1059
- protected onLoad(): void;
1060
- onDestroy(): void;
1061
- updateProps(props: ReconnectPrompt): void;
1062
- /**更新提示文案 */
1063
- protected updatePromptText(text: ReconnectPrompt, isAnim?: boolean): void;
1064
- protected onConfirmHandler(): void;
1065
- }
1066
-
1067
- type TimerCallback = (executionTime: number) => void;
1068
- declare class TimerManager extends BaseManager {
1069
- private timers;
1070
- private lastUpdateTime;
1071
- constructor(cat: Manager);
1072
- private onHandleAppBackground;
1073
- private onHandleAppForeground;
1074
- /**
1075
- * 注册一个计时器
1076
- * @param tag 注册计时器的对象
1077
- * @param interval 间隔时间(毫秒)
1078
- * @param callback 计时器回调函数
1079
- * @returns 计时器的唯一标识
1080
- */
1081
- registerInterval(tag: any, interval: number, callback: TimerCallback): void;
1082
- /**
1083
- * 注册一个延时器
1084
- * @param tag 注册延时器的对象
1085
- * @param delay 延时时间(毫秒)
1086
- * @param callback 延时器回调函数
1087
- * @returns 延时器的唯一标识
1088
- */
1089
- registerDelay(tag: any, delay: number, callback: TimerCallback): void;
1090
- /**
1091
- * 取消一个计时器或延时器
1092
- * @param tag 计时器或延时器的唯一标识
1093
- */
1094
- unregister(tag: any): void;
1095
- /**是否拥有定时器 */
1096
- has(object: any): boolean;
1097
- /**
1098
- * 更新计时器状态
1099
- * @param dt 间隔时间(毫秒)
1100
- */
1101
- private update;
1102
- }
1103
-
1104
- declare const AudioEffect: <T extends string>(effect?: T, callBackFun?: Function) => MethodDecorator;
1105
- declare const ButtonLock: (lockTime?: number, callBackFun?: Function) => (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
1106
-
1107
- declare global {
1108
- var _cat: Manager;
1109
- }
1110
- declare const cat: Manager;
1111
-
1112
- export { AudioEffect, AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, BaseStore, ButtonLock, CoreBlackMask, CoreNotice, CoreReconnection, CoreShowLoading, CoreStore, CoreToast, CoreUIContainer, CoreUIModal, CoreUtil, GlobalEventConstant, Gui, GuiManager, LayerType, Manager, ReconnectPrompt, RootUILayer, SceneLayer, TimerManager, ToastType, UILayer, WrapperSocialGameClient, cat };
1113
- export type { CoreNoticeProps, CoreShowLoadingProps, CoreUIModalProps, HOOK, ICloseOptions, IDirection, IOpenOptions, IUIOption, SceneComponentType, SceneDataType, ScenePropsType, ToastProps, UIComponentType };
1
+ import { Component, Node, Prefab, Vec3, Quat, math, Layers, AudioClip, AudioSource, Label, Button, Scene, SceneAsset, AsyncDelegate, Asset, Constructor, AssetManager, SpriteFrame, Sprite } from 'cc';
2
+ import EventEmitter from 'eventemitter3';
3
+ import { IReactionPublic, IReactionOptions } from '@shimotsuki/mobx';
4
+ import { SocialGameClient, SocialGameClientOption, AllEventResponsePairs, ClientOption, MessageFns, AudienceOptions } from 'sgc';
5
+ import { BinaryWriter } from '@bufbuild/protobuf/wire';
6
+ import * as crypto_es_lib_cipher_core from 'crypto-es/lib/cipher-core';
7
+
8
+ /**
9
+ * @describe 基础管理类
10
+ * @author 游金宇(KM)
11
+ * @date 2024-09-12 11:49:30
12
+ */
13
+
14
+ declare class BaseManager {
15
+ protected cat: Manager;
16
+ constructor(manager: Manager);
17
+ }
18
+
19
+ /**
20
+ * 音频管理
21
+ */
22
+ declare class AudioManager extends BaseManager {
23
+ local_data: any;
24
+ private music;
25
+ private effect;
26
+ private _volume_music;
27
+ private _volume_effect;
28
+ private _switch_music;
29
+ private _switch_effect;
30
+ private local_store_key;
31
+ extra: {
32
+ [key: string]: any;
33
+ };
34
+ constructor(cat: Manager);
35
+ /**
36
+ * 设置背景音乐播放完成回调
37
+ * @param callback 背景音乐播放完成回调
38
+ */
39
+ setMusicComplete(callback?: Function | null): void;
40
+ /**
41
+ * 播放背景音乐
42
+ * @param url 资源地址
43
+ * @param callback 音乐播放完成事件
44
+ */
45
+ playMusic(url: string): Promise<void>;
46
+ playMusic(bundleName: string, url: string): Promise<void>;
47
+ /**
48
+ * 停止音乐
49
+ */
50
+ stopMusic(): void;
51
+ /**暂停音乐 */
52
+ pauseMusic(): void;
53
+ /**恢复音乐 */
54
+ resumeMusic(): void;
55
+ /**
56
+ * 获取背景音乐播放进度
57
+ */
58
+ get progressMusic(): number;
59
+ /**
60
+ * 设置背景乐播放进度
61
+ * @param value 播放进度值
62
+ */
63
+ set progressMusic(value: number);
64
+ /**
65
+ * 获取背景音乐音量
66
+ */
67
+ get volumeMusic(): number;
68
+ /**
69
+ * 设置背景音乐音量
70
+ * @param value 音乐音量值
71
+ */
72
+ set volumeMusic(value: number);
73
+ /**
74
+ * 获取背景音乐开关值
75
+ */
76
+ get switchMusic(): boolean;
77
+ /**
78
+ * 设置背景音乐开关值
79
+ * @param value 开关值
80
+ */
81
+ set switchMusic(value: boolean);
82
+ /**
83
+ * 播放音效
84
+ * @param url 资源地址
85
+ */
86
+ playEffect(url: string): Promise<void>;
87
+ playEffect(bundleName: string, url: string): Promise<void>;
88
+ /**
89
+ * 停止音效
90
+ */
91
+ stopEffect(): void;
92
+ /**
93
+ * 获取音效音量
94
+ */
95
+ get volumeEffect(): number;
96
+ /**
97
+ * 设置获取音效音量
98
+ * @param value 音效音量值
99
+ */
100
+ set volumeEffect(value: number);
101
+ /**
102
+ * 获取音效开关值
103
+ */
104
+ get switchEffect(): boolean;
105
+ /**
106
+ * 设置音效开关值
107
+ * @param value 音效开关值
108
+ */
109
+ set switchEffect(value: boolean);
110
+ /** 恢复当前暂停的音乐与音效播放 */
111
+ resumeAll(): void;
112
+ /** 暂停当前音乐与音效的播放 */
113
+ pauseAll(): void;
114
+ /** 停止当前音乐与音效的播放 */
115
+ stopAll(): void;
116
+ /** 保存音乐音效的音量、开关配置数据到本地 */
117
+ save(): this;
118
+ /** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */
119
+ load(): void;
120
+ }
121
+
122
+ /**
123
+ * @describe 组件基类
124
+ * @author 游金宇(KM)
125
+ * @date 2023-09-19 12:32:22
126
+ */
127
+
128
+ type HOOK_NAME = 'destroyed' | 'started';
129
+ type HOOK = {
130
+ [key in HOOK_NAME]?: () => void;
131
+ };
132
+ interface IUIOption<T extends object = {}, U extends object = {}> {
133
+ /**组件传值间属性值 */
134
+ props?: T;
135
+ /**组件数据 */
136
+ data?: U;
137
+ /**钩子 */
138
+ hook?: HOOK;
139
+ }
140
+ /**参数 */
141
+ /**initUI->onAutoObserver->onLoad->start */
142
+ declare class BaseComponent<T extends object = {}, K extends object = {}> extends Component {
143
+ /**组件(传值)属性 */
144
+ props: T;
145
+ /**自由属性 */
146
+ data: K;
147
+ cat: typeof globalThis._cat;
148
+ /**autorun销毁 */
149
+ private autorunDisposers;
150
+ /**reaction销毁 */
151
+ private reactionDisposers;
152
+ private eventEmitter;
153
+ hook: HOOK;
154
+ /**初始化UI(可在本函数中进行节点赋值或注册节点事件等...) */
155
+ protected initUI(): void;
156
+ protected __preload(): void;
157
+ constructor();
158
+ /**依赖收集生命周期(可以在该生命周期中注册依赖收集回调) */
159
+ protected onAutoObserver(): void;
160
+ /**添加自动收集 */
161
+ protected addAutorun(cb: (() => void) | (() => void)[]): this;
162
+ /**添加自动收集 */
163
+ protected addReaction<T, FireImmediately extends boolean = false>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: FireImmediately extends true ? T | undefined : T, r: IReactionPublic) => void, opts?: IReactionOptions<T, FireImmediately>): this;
164
+ protected addAudoListener<E extends EventEmitter<any>>(eventEmitter: E): E;
165
+ _onPreDestroy(): void;
166
+ protected onDisable(): void;
167
+ private deleteAllEventByEmitter;
168
+ protected onEnable(): void;
169
+ /**子类继承该方法(全局事件(this.cat.event)注册在components上的事件可以不添加取消监听(自动取消监听了)) */
170
+ protected onEventListener(): void;
171
+ /**子类继承该方法 */
172
+ protected addListener(): void;
173
+ /**子类继承该方法 */
174
+ protected removeListener(): void;
175
+ /**
176
+ * 添加到父节点指定层级
177
+ * @param parent 父节点
178
+ * @param index 插入的层级索引
179
+ * @param options 参数
180
+ * @returns 自身组件
181
+ */
182
+ addToParent(parent: Node | Prefab | Component, index: number, options?: IUIOption<T, K>): this;
183
+ addToParent(parent: Node | Prefab | Component, options?: IUIOption<T, K>): this;
184
+ /**设置属性(覆盖原有属性) */
185
+ setOptions(options?: IUIOption<T, K>): void;
186
+ /**设置data属性(更新) */
187
+ setUpdateData(data: Partial<K>): this | undefined;
188
+ /**设置props属性(更新)*/
189
+ setUpdateProps(props: Partial<T>): this | undefined;
190
+ private toPlainObject;
191
+ /**从父节点移除并销毁 */
192
+ removeAndDestroy(): void;
193
+ /**设置坐标 */
194
+ setPosition(positin: Vec3): this;
195
+ setScale(scale: Vec3): this;
196
+ setAngle(angle: number): this;
197
+ setRotation(rotation: Quat): this;
198
+ setRotationFromEuler(rotation: math.Vec3): this;
199
+ /**显示(同onEnable) */
200
+ protected onShow(): void;
201
+ /**隐藏(同onDisable) */
202
+ protected onHide(): void;
203
+ /**设置节点和子节点的层级 */
204
+ setNodeAndChildrenLayer(layer: string | Layers.Enum): this;
205
+ }
206
+
207
+ /**
208
+ * @describe UI层 所有的UI层需继承自该自组件
209
+ * @author 游金宇(KM)
210
+ * @date 2023-08-04 10:42:26
211
+ */
212
+
213
+ /**
214
+ * left 从左往右
215
+ * right 从右往左
216
+ * top 从上往下
217
+ * bot 从下往上
218
+ * center 中间
219
+ */
220
+ type IDirection = 'left' | 'right' | 'top' | 'bot' | 'center';
221
+ /**开启动画参数选项 */
222
+ interface IOpenOptions<T extends object, U extends object> extends IUIOption<T, U> {
223
+ /**动画 */
224
+ isMotion?: boolean;
225
+ /**动画时间 */
226
+ duration?: number;
227
+ /**方向 */
228
+ direction?: IDirection;
229
+ /**是否回弹 */
230
+ isBounce?: boolean;
231
+ /**回弹时间 */
232
+ bounceDuration?: number;
233
+ }
234
+ /**关闭动画参数选项 */
235
+ interface ICloseOptions<T extends object, U extends object> extends IUIOption<T, U> {
236
+ /**动画 */
237
+ isMotion?: boolean;
238
+ /**动画时间 */
239
+ duration?: number;
240
+ /**方向 */
241
+ direction?: IDirection;
242
+ }
243
+ declare class UILayer<T extends object = {}, U extends object = {}> extends BaseComponent<T, U> {
244
+ /**上次进入的方向 */
245
+ lastEnterDirection: IDirection;
246
+ /**屏幕尺寸 */
247
+ screen: math.Size;
248
+ /**是否正在关闭 */
249
+ isClosing: boolean;
250
+ /**组件所在的UI最顶层(不包含UI) */
251
+ root: Node;
252
+ constructor();
253
+ private _init;
254
+ /**显示动画 */
255
+ showTween<T extends object, U extends object = {}>({ isMotion, direction, duration, isBounce, bounceDuration }: IOpenOptions<T, U>): Promise<void>;
256
+ /**隐藏动画 */
257
+ hideTween<T extends object, U extends object>({ isMotion, direction, duration }: ICloseOptions<T, U>): Promise<void>;
258
+ private handle;
259
+ private deftween;
260
+ }
261
+
262
+ /**
263
+ * @describe 音频组件基类
264
+ * @author 游金宇(KM)
265
+ * @date 2023-12-22 16:20:20
266
+ */
267
+
268
+ /**
269
+ * EFFECT 音效
270
+ * BGM 音乐
271
+ */
272
+ declare enum AudioTypeEnum {
273
+ EFFECT = 0,
274
+ BGM = 1
275
+ }
276
+ declare class AudioSourceBaseComponent<T extends object = {}, K extends object = {}> extends BaseComponent<T, K> {
277
+ type: AudioTypeEnum;
278
+ clip: AudioClip;
279
+ loop: boolean;
280
+ volume: number;
281
+ playOnAwake: boolean;
282
+ audioSource: AudioSource;
283
+ onEnable(): void;
284
+ __preload(): void;
285
+ protected start(): void;
286
+ protected stopAudio(): void;
287
+ protected playAudio(): void;
288
+ protected onPlayEffectHandler(): void;
289
+ protected onStopEffectHandler(): void;
290
+ protected onPlayMusicHandler(): void;
291
+ protected onStopMusicHandler(): void;
292
+ _onPreDestroy(): void;
293
+ }
294
+
295
+ /**带有音频通道的UIlayer组件 */
296
+ declare class AudioSourceUILayer<T extends object, U extends object = {}> extends UILayer<T, U> {
297
+ type: AudioTypeEnum;
298
+ clip: AudioClip;
299
+ loop: boolean;
300
+ volume: number;
301
+ playOnAwake: boolean;
302
+ audioSource: AudioSource;
303
+ onEnable(): void;
304
+ __preload(): void;
305
+ protected stopAudio(): void;
306
+ protected playAudio(): void;
307
+ protected onPlayEffectHandler(): void;
308
+ protected onStopEffectHandler(): void;
309
+ protected onPlayMusicHandler(): void;
310
+ protected onStopMusicHandler(): void;
311
+ _onPreDestroy(): void;
312
+ }
313
+
314
+ /**
315
+ * @describe TOAST弹窗组件
316
+ * @author 游金宇(KM)
317
+ * @date 2024-09-12 11:42:29
318
+ */
319
+
320
+ declare enum ToastType {
321
+ FIXED = 0,
322
+ SLIDE = 1
323
+ }
324
+ type ToastProps = {
325
+ title: string;
326
+ type?: ToastType;
327
+ fixed_time?: number;
328
+ };
329
+ declare class CoreToast extends BaseComponent<ToastProps> {
330
+ fixed_node: Node;
331
+ slide_node: Node;
332
+ fixed_label: Label;
333
+ slide_label: Label;
334
+ onLoad(): void;
335
+ protected start(): void;
336
+ show(): Promise<void>;
337
+ private playAnim;
338
+ onDestroy(): void;
339
+ }
340
+
341
+ /**
342
+ * @describe 根级别的UI层 所有的ROOT UI层需继承自该自组件
343
+ * @author 游金宇(KM)
344
+ * @date 2023-08-04 10:42:26
345
+ */
346
+
347
+ declare class RootUILayer<T extends object> extends UILayer<T> {
348
+ protected onEnable(): void;
349
+ protected onDisable(): void;
350
+ private updateMask;
351
+ }
352
+
353
+ type CoreShowLoadingProps = {
354
+ /**标题 */
355
+ title?: string;
356
+ /**阻挡 */
357
+ mask?: boolean;
358
+ /**显示黑色(弹窗存在公共的遮罩,这里不需要重复设置) */
359
+ black?: boolean;
360
+ };
361
+ /**
362
+ * @describe 加载框
363
+ * @author 游金宇(KM)
364
+ * @date 2024-09-12 11:49:51
365
+ */
366
+ declare class CoreShowLoading extends RootUILayer<CoreShowLoadingProps> {
367
+ title: Label;
368
+ loadingTween: Node;
369
+ private loading_rotate;
370
+ protected onAutoObserver(): void;
371
+ update(deltaTime: number): void;
372
+ }
373
+
374
+ type CoreNoticeProps = {
375
+ text: string;
376
+ confrim?: () => void;
377
+ };
378
+ /**
379
+ * @describe 通知框
380
+ * @author 游金宇(KM)
381
+ * @date 2024-09-12 11:49:51
382
+ */
383
+ declare class CoreNotice<T extends CoreNoticeProps = CoreNoticeProps> extends RootUILayer<T> {
384
+ text: Label;
385
+ btn_confirm: Button;
386
+ btn_close: Button;
387
+ protected onLoad(): void;
388
+ start(): void;
389
+ protected onConfrimHandler(): void;
390
+ updateProps(props: CoreNoticeProps): void;
391
+ }
392
+
393
+ /**
394
+ * @describe Scene层 所有的UI层需继承自该自组件
395
+ * @author 游金宇(KM)
396
+ * @date 2023-08-04 10:42:26
397
+ */
398
+
399
+ type SceneType<T> = T extends SceneLayer<infer U, infer K> ? {
400
+ props: U;
401
+ data: K;
402
+ } : {
403
+ props: object;
404
+ data: object;
405
+ };
406
+ type ScenePropsType<T> = SceneType<T> extends {
407
+ props: infer U extends object;
408
+ data: infer K extends object;
409
+ } ? U : never;
410
+ type SceneDataType<T> = SceneType<T> extends {
411
+ props: infer U extends object;
412
+ data: infer K extends object;
413
+ } ? K : never;
414
+ declare class SceneLayer<T extends object = Object, K extends object = {}> extends BaseComponent<T, K> {
415
+ /**是否为重新加载场景 */
416
+ isReload: boolean;
417
+ }
418
+
419
+ declare enum ReconnectPrompt {
420
+ RECONNECTED = "\u91CD\u8FDE\u6210\u529F",
421
+ RECONNECTING = "\u6B63\u5728\u91CD\u8FDE",
422
+ MAX_RECONNECT = "\u91CD\u8FDE\u6B21\u6570\u8D85\u51FA\u9650\u5236,\u8BF7\u68C0\u67E5\u7F51\u7EDC",
423
+ RECONNECTED_ERROR = "\u91CD\u8FDE\u5931\u8D25,\u8BF7\u68C0\u67E5\u7F51\u7EDC",
424
+ CONNECT_PARAM_ERROR = "\u6E38\u620F\u53C2\u6570\u9519\u8BEF,\u8BF7\u91CD\u65B0\u52A0\u8F7D",
425
+ KICK = "\u8D26\u53F7\u5DF2\u4E0B\u7EBF",
426
+ OFFLINE = "\u7F51\u7EDC\u5DF2\u65AD\u5F00",
427
+ ONLINE = "\u7F51\u7EDC\u5DF2\u8FDE\u63A5",
428
+ GAME_ERROR = "\u8FDE\u63A5\u6E38\u620F\u670D\u9519\u8BEF"
429
+ }
430
+
431
+ /**
432
+ * @describe GUI组件类
433
+ * @author 游金宇(KM)
434
+ * @date 2024-09-12 11:46:22
435
+ */
436
+
437
+ type UIComponentType$1<T> = T extends UILayer<infer U, infer K> ? {
438
+ props: U;
439
+ data: K;
440
+ } : {
441
+ props: object;
442
+ data: object;
443
+ };
444
+ type PropsType<T> = UIComponentType$1<T> extends {
445
+ props: infer U extends object;
446
+ data: infer K extends object;
447
+ } ? U : never;
448
+ type DataType<T> = UIComponentType$1<T> extends {
449
+ props: infer U extends object;
450
+ data: infer K extends object;
451
+ } ? K : never;
452
+ declare enum LayerType {
453
+ UI = 0,
454
+ /**加载 */
455
+ LOADING = 1,
456
+ /**提示 */
457
+ TOAST = 2,
458
+ /**断线重连 */
459
+ RECONNECTTION = 3,
460
+ /**系统服务通知(停机维护) */
461
+ NOTICE = 4
462
+ }
463
+ /**Gui */
464
+ declare class Gui extends BaseComponent {
465
+ reconnection_ui_prefab: Prefab;
466
+ toast_ui_prefab: Prefab;
467
+ loading_ui_prefab: Prefab;
468
+ notice_ui_prefab: Prefab;
469
+ ui_prefab: Prefab;
470
+ root_ui: Node;
471
+ root_toast: Node;
472
+ root_mask: Node;
473
+ /**场景中的UI层 */
474
+ private ui_container_component;
475
+ /**断线重连UI弹窗 */
476
+ private reconnection_ui_component;
477
+ /**公告UI弹窗组件 */
478
+ private notice_ui_component;
479
+ /**加载UI弹窗 */
480
+ private loading_ui_component;
481
+ /**提示UI弹窗 */
482
+ private toast_ui_component;
483
+ /**当前场景对象名 */
484
+ currentScene: string;
485
+ protected onEventListener(): void;
486
+ init(cat: Manager): this;
487
+ protected start(): void;
488
+ private toastQueue;
489
+ private isScheduling;
490
+ private minInterval;
491
+ showToast(props: ToastProps): void;
492
+ private processQueueWithInterval;
493
+ /** 隐藏并清除所有提示 */
494
+ hideToast(): this;
495
+ /**显示Loading */
496
+ showLoading({ title, mask, black }?: CoreShowLoadingProps): this;
497
+ /**隐藏Loading */
498
+ hideLoading(): this;
499
+ /**
500
+ * 显示断线重连
501
+ * @param option 状态提示文案
502
+ */
503
+ showReconnect(option: ReconnectPrompt): this;
504
+ /**隐藏断线重连 */
505
+ hideReconnect(): this;
506
+ /**
507
+ * 显示公告
508
+ * @param option 参数
509
+ */
510
+ showNotice(option: CoreNoticeProps): this;
511
+ /**隐藏公告 */
512
+ hideNotice(): this;
513
+ /**
514
+ * 加载并切换游戏场景
515
+ * @param sceneName 场景名称、场景实例或场景资源,用于指定要加载的场景
516
+ * @param options 可选参数,可以是场景加载的配置选项,或者是一个表示是否重新加载的布尔值
517
+ * @param isReload 可选参数,明确指示是否重新加载场景(当options为布尔值时,此参数被忽略)
518
+ * @returns 返回当前实例,支持链式调用
519
+ */
520
+ loadScene<T>(sceneName: string): this;
521
+ loadScene<T>(sceneName: string, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>): this;
522
+ loadScene<T>(sceneName: string, isReload: boolean): this;
523
+ loadScene<T>(sceneName: string, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>, isReload: boolean): this;
524
+ loadScene<T>(scene: Scene | SceneAsset): this;
525
+ loadScene<T>(scene: Scene | SceneAsset, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>): this;
526
+ loadScene<T>(scene: Scene | SceneAsset, isReload: boolean): this;
527
+ loadScene<T>(scene: Scene | SceneAsset, options: IUIOption<ScenePropsType<T>, SceneDataType<T>>, isReload: boolean): this;
528
+ /**重置场景(清除当前默认当前场景) */
529
+ resetScene(sceneName?: string): this;
530
+ /**清除场景 */
531
+ cleanScene(): void;
532
+ /**
533
+ * 场景变化
534
+ * @param scene 场景
535
+ * @param options 选项
536
+ * @param isReload 是否重新加载
537
+ */
538
+ changeScene<T>(scene: Scene, options?: IUIOption<ScenePropsType<T>, SceneDataType<T>>, isReload?: boolean): void;
539
+ private createUILayer;
540
+ /**重新加载当前场景 */
541
+ reloadScene(): void;
542
+ /**关闭UI */
543
+ closeUI<T extends UILayer<object>, U extends object>(ui: Node | T, options?: ICloseOptions<T, U>): Promise<void>;
544
+ /**
545
+ * 打开ui
546
+ * @param ui 界面的节点或组件
547
+ * @param options 动画参数选项
548
+ */
549
+ openUI<T extends UILayer>(ui: Node, options?: IOpenOptions<PropsType<T>, DataType<T>>): Promise<void>;
550
+ /**根据节点或组件 查询根UI层(继承自UILayer的)节点或组件 */
551
+ private findUIBaseLayer;
552
+ /**根层的变化 */
553
+ private onRootUpdate;
554
+ }
555
+
556
+ declare class CoreBlackMask extends BaseComponent {
557
+ tween: Node;
558
+ }
559
+
560
+ /**
561
+ * @describe UI容器管理 在场景节点下 会随着场景销毁(非常驻节点)
562
+ * @author 游金宇(KM)
563
+ * @date 2024-09-12 11:45:31
564
+ */
565
+
566
+ declare class CoreUIContainer extends UILayer {
567
+ scene_mask_node: Node;
568
+ ui_container: Node;
569
+ gui: Gui;
570
+ protected onLoad(): void;
571
+ get scene_mask(): CoreBlackMask;
572
+ get brother(): Node[];
573
+ get tweenChildren(): Node[];
574
+ protected onEventListener(): void;
575
+ /**增加层级 */
576
+ addMask(): void;
577
+ /**减少层级 */
578
+ subMask(): void;
579
+ blockMaskSiblingIndexChanged(): void;
580
+ /**
581
+ * 将UI节点挂载在tween上执行动画
582
+ * @param node 节点
583
+ */
584
+ addNodeToTween(node: Node): this;
585
+ show(): void;
586
+ hide(): void;
587
+ setGui(gui: Gui): this;
588
+ /**根层的变化 */
589
+ uiMaskChanged(): void;
590
+ setSceneMaskActive(active: boolean): void;
591
+ }
592
+
593
+ /**
594
+ * @describe 层级界面管理
595
+ * @author 游金宇(KM)
596
+ * @date 2023-08-03 20:02:45
597
+ */
598
+
599
+ type UIComponentType<T> = T extends UILayer<infer U> ? U : void;
600
+ type SceneComponentType<T> = T extends SceneLayer<infer U> ? U : void;
601
+ /**预制体路径 */
602
+ declare enum BasePrefab {
603
+ Root = "prefabs/root",
604
+ Toast = "prefabs/toast",
605
+ BlackMask = "prefabs/black-mask",
606
+ Loading = "prefabs/loading",
607
+ Notice = "prefabs/notice",
608
+ Reconnection = "prefabs/reconnection"
609
+ }
610
+ declare class GuiManager extends BaseManager {
611
+ #private;
612
+ /**常驻顶层UI节点层级 */
613
+ gui: Gui;
614
+ /**
615
+ * 获取预制体
616
+ * @param type 类型
617
+ * @returns
618
+ */
619
+ private getGuiPrefabByType;
620
+ /**初始化 */
621
+ init(): Promise<this>;
622
+ }
623
+
624
+ /**
625
+ * @describe 基于社交游戏封装的游戏基础ws类
626
+ * @author 游金宇(KM)
627
+ * @date 2024-09-12 11:47:51
628
+ */
629
+
630
+ type ExtendedClientOption = ClientOption & {
631
+ /** 是否弹出请求错误信息 */
632
+ showRequestErrInfo?: boolean;
633
+ };
634
+ declare class WrapperSocialGameClient extends SocialGameClient {
635
+ /**是否弹出请求错误信息 */
636
+ protected showRequestErrInfo: boolean;
637
+ /**日志黑名单 */
638
+ protected logBlackList: string[];
639
+ ignore: (route: string) => boolean;
640
+ constructor(name: string, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>, clientOption?: ExtendedClientOption);
641
+ destroy(): void;
642
+ GameRequest<U>(route: string, req: BinaryWriter, res: MessageFns<U>, { forwardReq, forwardResp }?: AudienceOptions): Promise<U>;
643
+ subscribe<T>(route: string, respType: MessageFns<T>, fn?: (data: T) => void): this;
644
+ }
645
+
646
+ declare class SocialGameClientManager extends BaseManager {
647
+ private managedClients;
648
+ /**在线 */
649
+ private isGlobalOnline;
650
+ /**在后台 */
651
+ private isInBackground;
652
+ /**正在重连 */
653
+ private reconnecting;
654
+ /**后台委托 */
655
+ readonly onEventHideDelegate: AsyncDelegate<() => (Promise<void> | void)>;
656
+ /**前台委托 */
657
+ readonly onEventShowDelegate: AsyncDelegate<() => (Promise<void> | void)>;
658
+ /**重载场景委托 */
659
+ readonly onEventReloadSceneDelegate: AsyncDelegate<() => (Promise<void> | void)>;
660
+ /**重连定时器 */
661
+ private reconnectTimer;
662
+ private scheduleReconnect;
663
+ get activeClients(): WrapperSocialGameClient[];
664
+ constructor(cat: Manager);
665
+ /**
666
+ * 创建并注册WebSocket客户端
667
+ * @param name 客户端唯一标识(如"game", "room")
668
+ * @param clientOption 客户端配置选项
669
+ * @param opts 社交游戏选项
670
+ * @param eventResponsePairs 事件响应配置
671
+ */
672
+ createWebSocket(name: string, clientOption: ExtendedClientOption, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>): WrapperSocialGameClient;
673
+ register(client: WrapperSocialGameClient): void;
674
+ unregister(client: WrapperSocialGameClient): void;
675
+ private initGlobalListeners;
676
+ private handleGlobalStateChange;
677
+ private triggerReconnectAll;
678
+ private disconnectAll;
679
+ private handleSingleClose;
680
+ private handleSingleReconnect;
681
+ private handleSingleKick;
682
+ }
683
+
684
+ /**
685
+ * @describe 游戏资管理
686
+ * @author 游金宇(KM)
687
+ * @date 2023-08-03 17:40:51
688
+ */
689
+
690
+ type ProgressCallback = (completedCount: number, totalCount: number, item: any) => void;
691
+ type CompleteCallback<T> = ((err: Error | null, data: T) => void) | null;
692
+ type IRemoteOptions = {
693
+ [k: string]: any;
694
+ ext?: string;
695
+ };
696
+ type AssetType<T = Asset> = Constructor<T>;
697
+ declare class ResLoader {
698
+ /**
699
+ * 获取资源
700
+ * @param path 资源路径
701
+ * @param type 资源类型
702
+ * @param bundleName 远程资源包名
703
+ */
704
+ get: <T extends Asset>(path: string, type?: AssetType<T> | null, bundleName?: string) => T | null;
705
+ /**
706
+ * 获取资源类型
707
+ */
708
+ isAssetType: <T>(value: any) => value is AssetType<T>;
709
+ /**
710
+ * 获取资源
711
+ * @param bundleName 远程包名
712
+ * @param paths 资源路径
713
+ * @param type 资源类型-
714
+ * @param onProgress 加载进度回调
715
+ * @param onComplete 加载完成回调
716
+ */
717
+ load<T extends Asset>(paths: string | string[]): void;
718
+ load<T extends Asset>(paths: string | string[], type: AssetType<T>): void;
719
+ load<T extends Asset>(paths: string, onComplete: CompleteCallback<T>): void;
720
+ load<T extends Asset>(paths: string, type: AssetType<T>, onComplete: CompleteCallback<T>): void;
721
+ load<T extends Asset>(paths: string, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
722
+ load<T extends Asset>(paths: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
723
+ load<T extends Asset>(paths: string[], onComplete: CompleteCallback<T[]>): void;
724
+ load<T extends Asset>(paths: string[], onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
725
+ load<T extends Asset>(paths: string[], type: AssetType<T>, onComplete: CompleteCallback<T[]>): void;
726
+ load<T extends Asset>(paths: string[], type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
727
+ load<T extends Asset>(bundleName: string, paths: string | string[]): void;
728
+ load<T extends Asset>(bundleName: string, paths: string | string[], type: AssetType<T>): void;
729
+ load<T extends Asset>(bundleName: string, paths: string, onComplete: CompleteCallback<T>): void;
730
+ load<T extends Asset>(bundleName: string, paths: string[], onComplete: CompleteCallback<T[]>): void;
731
+ load<T extends Asset>(bundleName: string, paths: string, type: AssetType<T>, onComplete: CompleteCallback<T>): void;
732
+ load<T extends Asset>(bundleName: string, paths: string[], type: AssetType<T>, onComplete: CompleteCallback<T[]>): void;
733
+ load<T extends Asset>(bundleName: string, paths: string, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
734
+ load<T extends Asset>(bundleName: string, paths: string[], onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
735
+ load<T extends Asset>(bundleName: string, paths: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T>): void;
736
+ load<T extends Asset>(bundleName: string, paths: string[], type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
737
+ /**
738
+ * 加载文件夹
739
+ * @param bundleName 远程包名
740
+ * @param dir 文件夹名
741
+ * @param type 资源类型
742
+ * @param onProgress 加载进度回调
743
+ * @param onComplete 加载完成回调
744
+ */
745
+ loadDir<T extends Asset>(dir: string): void;
746
+ loadDir<T extends Asset>(dir: string, type: AssetType<T>): void;
747
+ loadDir<T extends Asset>(dir: string, onComplete: CompleteCallback<T[]>): void;
748
+ loadDir<T extends Asset>(dir: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
749
+ loadDir<T extends Asset>(bundleName: string, dir: string): void;
750
+ loadDir<T extends Asset>(bundleName: string, dir: string, type: AssetType<T>): void;
751
+ loadDir<T extends Asset>(bundleName: string, dir: string, onComplete: CompleteCallback<T[]>): void;
752
+ loadDir<T extends Asset>(bundleName: string, dir: string, type: AssetType<T>, onProgress: ProgressCallback, onComplete: CompleteCallback<T[]>): void;
753
+ /**
754
+ * 加载远程资源
755
+ * @param url 资源地址
756
+ * @param options 资源参数,例:{ ext: ".png" }
757
+ * @param onComplete 加载完成回调
758
+ *
759
+ * res.ResLoader.loadRemote(params.iconv, (err: Error, imageAsset: ImageAsset) => {
760
+ if (err) return error(err)
761
+ if (isValid(this.itemSp)) {
762
+ this.itemSp.spriteFrame = SpriteFrame.createWithImage(imageAsset)
763
+ }
764
+ })
765
+ */
766
+ loadRemote<T extends Asset>(url: string, options: IRemoteOptions, onComplete?: CompleteCallback<T>): void;
767
+ loadRemote<T extends Asset>(url: string, onComplete?: CompleteCallback<T>): void;
768
+ /**
769
+ * 加载bundle
770
+ * @param url 资源地址 <远程路径或者bundleName>
771
+ * @param complete 完成事件
772
+ * @param v 资源版本号
773
+ * @example
774
+ */
775
+ loadBundle: (url: string, version?: string) => Promise<AssetManager.Bundle>;
776
+ /** 释放预制依赖资源 */
777
+ releasePrefabtDepsRecursively: (uuid: string) => void;
778
+ /**
779
+ * 通过资源相对路径释放资源
780
+ * @param path 资源路径
781
+ * @param bundleName 远程资源包名
782
+ */
783
+ release: (path: string, bundleName?: string) => void;
784
+ /**
785
+ * 通过相对文件夹路径删除所有文件夹中资源
786
+ * @param path 资源文件夹路径
787
+ * @param bundleName 远程资源包名
788
+ */
789
+ releaseDir: (path: string, bundleName?: string) => void;
790
+ /** 打印缓存中所有资源信息 */
791
+ dump: () => void;
792
+ /**
793
+ * 加载分包中的资源并提供进度反馈。
794
+ * @param bundle - 已加载的分包。
795
+ * @param onProgress - 进度回调函数。
796
+ * @returns Promise<void> - 加载完成后的Promise。
797
+ */
798
+ loadAssetsWithProgress(bundle: AssetManager.Bundle, onProgress: (progress: number) => void): Promise<void>;
799
+ }
800
+
801
+ /**
802
+ * @describe 基本数据
803
+ * @author 游金宇(KM)
804
+ * @date 2024-09-12 11:35:02
805
+ */
806
+
807
+ declare class BaseStore {
808
+ protected rootStore: CoreStore;
809
+ constructor(rootStore: CoreStore);
810
+ }
811
+
812
+ declare class CoreStore extends BaseManager {
813
+ }
814
+
815
+ /**
816
+ * MD5加密
817
+ * @param msg 加密信息
818
+ */
819
+ declare const md5: (msg: string) => string;
820
+ /** 初始化加密库 */
821
+ declare const initCrypto: (key: string, iv: string) => void;
822
+ /**
823
+ * AES 加密
824
+ * @param msg 加密信息
825
+ * @param key aes加密的key
826
+ * @param iv aes加密的iv
827
+ */
828
+ declare const aesEncrypt: (msg: string, key: string, iv: string) => string;
829
+ /**
830
+ * AES 解密
831
+ * @param str 解密字符串
832
+ * @param key aes加密的key
833
+ * @param iv aes加密的iv
834
+ */
835
+ declare const aesDecrypt: (str: string, key: string, iv: string) => string;
836
+ declare const JsonFormatter: {
837
+ stringify: (cipherParams: any) => string;
838
+ parse: (jsonStr: string) => crypto_es_lib_cipher_core.CipherParams;
839
+ };
840
+
841
+ declare const EncryptUtil_JsonFormatter: typeof JsonFormatter;
842
+ declare const EncryptUtil_aesDecrypt: typeof aesDecrypt;
843
+ declare const EncryptUtil_aesEncrypt: typeof aesEncrypt;
844
+ declare const EncryptUtil_initCrypto: typeof initCrypto;
845
+ declare const EncryptUtil_md5: typeof md5;
846
+ declare namespace EncryptUtil {
847
+ export {
848
+ EncryptUtil_JsonFormatter as JsonFormatter,
849
+ EncryptUtil_aesDecrypt as aesDecrypt,
850
+ EncryptUtil_aesEncrypt as aesEncrypt,
851
+ EncryptUtil_initCrypto as initCrypto,
852
+ EncryptUtil_md5 as md5,
853
+ };
854
+ }
855
+
856
+ /**
857
+ * @describe 工具类
858
+ * @author 游金宇(KM)
859
+ * @date 2023-08-02 20:16:42
860
+ */
861
+
862
+ declare class CoreUtil extends BaseManager {
863
+ encryptUtil: typeof EncryptUtil;
864
+ }
865
+
866
+ /**
867
+ * @describe 本地存储管理
868
+ * @author 游金宇(KM)
869
+ * @date 2023-08-03 17:58:51
870
+ */
871
+
872
+ declare class StorageManager extends BaseManager {
873
+ private _key;
874
+ private _iv;
875
+ private _id;
876
+ /**
877
+ * 初始化密钥
878
+ * @param key aes加密的key
879
+ * @param iv aes加密的iv
880
+ */
881
+ init(key: string, iv: string): void;
882
+ /**
883
+ * 设置用户唯一标识
884
+ * @param id
885
+ */
886
+ setUser(id: string): void;
887
+ /**
888
+ * 存储本地数据
889
+ * @param key 存储key
890
+ * @param value 存储值
891
+ * @returns
892
+ */
893
+ set(key: string, value: any): void;
894
+ /**
895
+ * 获取指定关键字的数据
896
+ * @param key 获取的关键字
897
+ * @param defaultValue 获取的默认值
898
+ * @returns
899
+ */
900
+ get(key: string, defaultValue?: any): string;
901
+ /** 获取指定关键字的数值 */
902
+ getNumber(key: string, defaultValue?: number): number;
903
+ /** 获取指定关键字的布尔值 */
904
+ getBoolean(key: string): boolean;
905
+ /** 获取指定关键字的JSON对象 */
906
+ getJson(key: string, defaultValue?: any): any;
907
+ /**
908
+ * 删除指定关键字的数据
909
+ * @param key 需要移除的关键字
910
+ * @returns
911
+ */
912
+ remove(key: string): void;
913
+ /** 清空整个本地存储 */
914
+ clear(): void;
915
+ }
916
+
917
+ /**
918
+ * @describe 管理类
919
+ * @author 游金宇(KM)
920
+ * @date 2024-09-12 11:49:44
921
+ */
922
+
923
+ declare class Manager {
924
+ #private;
925
+ static get instance(): Manager;
926
+ /**APP初始化事务 */
927
+ readonly onAppInitDelegate: AsyncDelegate<() => (Promise<void> | void)>;
928
+ /**插件初始化事务 */
929
+ readonly onPlugInInitDelegate: AsyncDelegate<() => (Promise<void> | void)>;
930
+ /**音频管理 */
931
+ get audio(): AudioManager;
932
+ /**全局事件管理 */
933
+ get event(): EventEmitter<string | symbol, any>;
934
+ /**gui管理 */
935
+ get gui(): Gui;
936
+ /**本地存储管理 */
937
+ get storage(): StorageManager;
938
+ /**资源管理 */
939
+ get res(): ResLoader;
940
+ /**工具类管理 */
941
+ get util(): CoreUtil;
942
+ /**社交游戏类 */
943
+ get socialGameClient(): SocialGameClientManager;
944
+ /**数据存储 */
945
+ get store(): CoreStore;
946
+ /**GUI bundle 名称 */
947
+ get gui_bundle_name(): string;
948
+ /**音效本地存储key */
949
+ get audio_local_store_key(): string;
950
+ /**默认音效路径 */
951
+ get default_audio_effect(): string;
952
+ /**GUI资源配置 */
953
+ setConfig: ({ default_audio_effect, gui_bundleName, audio_local_store_key }?: {
954
+ gui_bundleName?: string;
955
+ audio_local_store_key?: string;
956
+ default_audio_effect?: string;
957
+ }) => this;
958
+ /**启动 */
959
+ boot(): Promise<void>;
960
+ /**合并对象 */
961
+ merge<K extends keyof Manager, T extends object>(target: K, source: T): this;
962
+ /**
963
+ * 注册一个“插件级”初始化回调
964
+ * - 如果已初始化,立即执行
965
+ * - 否则排队到 onPlugInInitDelegate 中
966
+ */
967
+ appendPlugInInitDelegate(cb: () => Promise<void> | void): this;
968
+ }
969
+
970
+ declare enum AudioEventConstant {
971
+ /**音乐开 */
972
+ MUSIC_ON = "AudioEventConstant/MUSIC_ON",
973
+ /**音乐关 */
974
+ MUSIC_OFF = "AudioEventConstant/MUSIC_OFF",
975
+ /**音效开 */
976
+ EFFECT_ON = "AudioEventConstant/EFFECT_ON",
977
+ /**音效关 */
978
+ EFFECT_OFF = "AudioEventConstant/EFFECT_OFF",
979
+ /**暂停音频 */
980
+ PAUSE_AUDIO = "AudioEventConstant/PAUSE_AUDIO",
981
+ /**恢复音频 */
982
+ RESUME_AUDIO = "AudioEventConstant/RESUME_AUDIO"
983
+ }
984
+
985
+ /**
986
+ * @describe 全局事件监听方法
987
+ * @author 游金宇(KM)
988
+ * @date 2023-08-03 18:13:36
989
+ */
990
+ declare enum GlobalEventConstant {
991
+ /** 游戏从后台进入 */
992
+ EVENT_SHOW = "GlobalEventConstant/EVENT_SHOW",
993
+ /** 游戏切到后台 */
994
+ EVENT_HIDE = "GlobalEventConstant/EVENT_HIDE",
995
+ /** 游戏画笔尺寸变化事件 */
996
+ GAME_RESIZE = "GlobalEventConstant/GAME_RESIZE",
997
+ /**游戏关闭时间 */
998
+ EVENT_CLOSE = "GlobalEventConstant/EVENT_CLOSE",
999
+ /**网络连接 */
1000
+ ONLINE = "GlobalEventConstant/ONLINE",
1001
+ /**网络断开 */
1002
+ OFFLINE = "GlobalEventConstant/OFFLINE",
1003
+ /**ROOT_MASK更新 */
1004
+ ROOT_MASK_UPDATE = "GlobalEventConstant/ROOT_MASK_UPDATE",
1005
+ /**ROOT_MASK更新变化 */
1006
+ ROOT_MASK_CHANGE = "GlobalEventConstant/ROOT_MASK_CHANGE"
1007
+ }
1008
+
1009
+ type CoreUIModalProps = {
1010
+ content: string | SpriteFrame | null;
1011
+ confirmCB: () => void;
1012
+ cancelCB: () => void;
1013
+ onDestroy?: () => void;
1014
+ title?: SpriteFrame;
1015
+ style?: {
1016
+ confirm?: SpriteFrame;
1017
+ cancel?: SpriteFrame;
1018
+ } | null;
1019
+ };
1020
+ /**
1021
+ * @describe 模态框
1022
+ * @author 游金宇(KM)
1023
+ * @date 2024-09-12 11:49:51
1024
+ */
1025
+ declare class CoreUIModal extends UILayer<CoreUIModalProps> {
1026
+ default_title: SpriteFrame;
1027
+ title: Sprite;
1028
+ prompt_content_str: Label;
1029
+ prompt_content_spriteFrame: Sprite;
1030
+ btn_confirm: Button;
1031
+ confirm_spriteFrame: SpriteFrame;
1032
+ btn_cancel: Button;
1033
+ cancel_spriteFrame: SpriteFrame;
1034
+ btn_close: Button;
1035
+ isConfirm: boolean;
1036
+ props: CoreUIModalProps;
1037
+ protected onLoad(): void;
1038
+ private close;
1039
+ private onCancelHandler;
1040
+ private onConfirmHandler;
1041
+ onDestroy(): void;
1042
+ private onCloseHandler;
1043
+ }
1044
+
1045
+ type CoreReconnectionProps = {
1046
+ content: ReconnectPrompt | null;
1047
+ };
1048
+ /**
1049
+ * @describe 重连框
1050
+ * @author 游金宇(KM)
1051
+ * @date 2024-09-12 11:49:51
1052
+ */
1053
+ declare class CoreReconnection extends RootUILayer<CoreReconnectionProps> {
1054
+ common_prompt_text: Label;
1055
+ btn_confirm: Button;
1056
+ btn_close: Button;
1057
+ protected is_close: boolean;
1058
+ props: CoreReconnectionProps;
1059
+ protected initUI(): void;
1060
+ protected onLoad(): void;
1061
+ onDestroy(): void;
1062
+ updateProps(props: ReconnectPrompt): void;
1063
+ /**更新提示文案 */
1064
+ protected updatePromptText(text: ReconnectPrompt, isAnim?: boolean): void;
1065
+ protected onConfirmHandler(): void;
1066
+ }
1067
+
1068
+ type TimerCallback = (executionTime: number) => void;
1069
+ declare class TimerManager extends BaseManager {
1070
+ private timers;
1071
+ private lastUpdateTime;
1072
+ constructor(cat: Manager);
1073
+ private onHandleAppBackground;
1074
+ private onHandleAppForeground;
1075
+ /**
1076
+ * 注册一个计时器
1077
+ * @param tag 注册计时器的对象
1078
+ * @param interval 间隔时间(毫秒)
1079
+ * @param callback 计时器回调函数
1080
+ * @returns 计时器的唯一标识
1081
+ */
1082
+ registerInterval(tag: any, interval: number, callback: TimerCallback): void;
1083
+ /**
1084
+ * 注册一个延时器
1085
+ * @param tag 注册延时器的对象
1086
+ * @param delay 延时时间(毫秒)
1087
+ * @param callback 延时器回调函数
1088
+ * @returns 延时器的唯一标识
1089
+ */
1090
+ registerDelay(tag: any, delay: number, callback: TimerCallback): void;
1091
+ /**
1092
+ * 取消一个计时器或延时器
1093
+ * @param tag 计时器或延时器的唯一标识
1094
+ */
1095
+ unregister(tag: any): void;
1096
+ /**是否拥有定时器 */
1097
+ has(object: any): boolean;
1098
+ /**
1099
+ * 更新计时器状态
1100
+ * @param dt 间隔时间(毫秒)
1101
+ */
1102
+ private update;
1103
+ }
1104
+
1105
+ declare const AudioEffect: <T extends string>(effect?: T, callBackFun?: Function) => MethodDecorator;
1106
+ declare const ButtonLock: (lockTime?: number, callBackFun?: Function) => (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
1107
+
1108
+ declare global {
1109
+ var _cat: Manager;
1110
+ }
1111
+ declare const cat: Manager;
1112
+
1113
+ export { AudioEffect, AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, BaseStore, ButtonLock, CoreBlackMask, CoreNotice, CoreReconnection, CoreShowLoading, CoreStore, CoreToast, CoreUIContainer, CoreUIModal, CoreUtil, GlobalEventConstant, Gui, GuiManager, LayerType, Manager, ReconnectPrompt, RootUILayer, SceneLayer, TimerManager, ToastType, UILayer, WrapperSocialGameClient, cat };
1114
+ export type { CoreNoticeProps, CoreShowLoadingProps, CoreUIModalProps, HOOK, ICloseOptions, IDirection, IOpenOptions, IUIOption, SceneComponentType, SceneDataType, ScenePropsType, ToastProps, UIComponentType };