@shimotsuki/core 1.0.44 → 2.0.0
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 +46 -120
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Component, Node, Prefab, Vec3, Quat, math, Layers, AudioSource, Label, Button, Scene, Asset, Constructor, AssetManager, SpriteFrame, Sprite, AsyncDelegate } from 'cc';
|
|
2
2
|
import { IReactionPublic, IReactionOptions } from '@shimotsuki/mobx';
|
|
3
|
+
import EventEmitter, { EventEmitter as EventEmitter$1 } from 'eventemitter3';
|
|
3
4
|
import * as crypto_es_lib_cipher_core from 'crypto-es/lib/cipher-core';
|
|
4
5
|
import { DescMessage, MessageShape } from '@bufbuild/protobuf';
|
|
5
6
|
import { ClientOption } from 'pitayaclient';
|
|
6
|
-
import { SocialGameClient, SocialGameClientOption, AllEventResponsePairs,
|
|
7
|
+
import { SocialGameClient, SocialGameClientOption, AllEventResponsePairs, AudienceOptionsJson } from 'sgc';
|
|
7
8
|
import { ReflectMessage } from '@bufbuild/protobuf/reflect';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -168,63 +169,6 @@ declare class StorageManager extends BaseManager {
|
|
|
168
169
|
clear(): void;
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
/**
|
|
172
|
-
* @describe 事件消息管理
|
|
173
|
-
* @author 游金宇(KM)
|
|
174
|
-
* @date 2023-08-03 18:15:38
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
type ListenerFunc = (data: any, event: string | number) => void;
|
|
178
|
-
type EventKeyType = string | number;
|
|
179
|
-
interface EventBase {
|
|
180
|
-
/**注册事件 */
|
|
181
|
-
on(event: string, listener: ListenerFunc, obj: object): void;
|
|
182
|
-
/**取消所有事件 */
|
|
183
|
-
offAll(): void;
|
|
184
|
-
/**注册单次触发事件 */
|
|
185
|
-
once(event: string, listener: ListenerFunc, obj: object): void;
|
|
186
|
-
/**取消单个事件 */
|
|
187
|
-
off(event: string, listener: Function, obj: object): void;
|
|
188
|
-
/**调用事件 */
|
|
189
|
-
dispatchEvent<T>(event: string, args: Record<string, T>): void;
|
|
190
|
-
}
|
|
191
|
-
declare class MessageManager implements EventBase {
|
|
192
|
-
private events;
|
|
193
|
-
/**
|
|
194
|
-
* 注册全局事件
|
|
195
|
-
* @param event 事件名
|
|
196
|
-
* @param listener 处理事件的侦听器函数
|
|
197
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
198
|
-
*/
|
|
199
|
-
on<T extends EventKeyType>(event: T, listener: ListenerFunc | null, obj: object): this;
|
|
200
|
-
/**
|
|
201
|
-
* 监听一次事件,事件响应后,该监听自动移除
|
|
202
|
-
* @param event 事件名
|
|
203
|
-
* @param listener 事件触发回调方法
|
|
204
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
205
|
-
*/
|
|
206
|
-
once<T extends EventKeyType>(event: T, listener: ListenerFunc, obj: object | Symbol): void;
|
|
207
|
-
/**
|
|
208
|
-
* 移除单个事件
|
|
209
|
-
* @param event 事件名
|
|
210
|
-
* @param listener 处理事件的侦听器函数
|
|
211
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
212
|
-
*/
|
|
213
|
-
off<T extends EventKeyType>(event: T, listener: Function | null, obj: object): this;
|
|
214
|
-
/**
|
|
215
|
-
* 触发全局事件
|
|
216
|
-
* @param event(string) 事件名
|
|
217
|
-
* @param args(any) 事件参数
|
|
218
|
-
*/
|
|
219
|
-
dispatchEvent<T extends EventKeyType>(event: T, args?: any): this;
|
|
220
|
-
/**移除所有事件 */
|
|
221
|
-
offAll(): void;
|
|
222
|
-
/**是否存在事件 */
|
|
223
|
-
has(event: EventKeyType): boolean;
|
|
224
|
-
/**删除事件通过组件 */
|
|
225
|
-
deleteEventByComponent(component: Component): void;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
172
|
/**
|
|
229
173
|
* @describe 组件基类
|
|
230
174
|
* @author 游金宇(KM)
|
|
@@ -253,7 +197,7 @@ declare class BaseComponent<T extends object = {}, K extends object = {}> extend
|
|
|
253
197
|
private autorunDisposers;
|
|
254
198
|
/**reaction销毁 */
|
|
255
199
|
private reactionDisposers;
|
|
256
|
-
private
|
|
200
|
+
private eventEmitter;
|
|
257
201
|
hook: HOOK;
|
|
258
202
|
/**初始化UI(可在本函数中进行节点赋值或注册节点事件等...) */
|
|
259
203
|
protected initUI(): void;
|
|
@@ -265,9 +209,10 @@ declare class BaseComponent<T extends object = {}, K extends object = {}> extend
|
|
|
265
209
|
protected addAutorun(cb: (() => void) | (() => void)[]): this;
|
|
266
210
|
/**添加自动收集 */
|
|
267
211
|
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;
|
|
268
|
-
protected addAudoListener(
|
|
212
|
+
protected addAudoListener(eventEmitter: EventEmitter): EventEmitter<string | symbol, any>;
|
|
269
213
|
_onPreDestroy(): void;
|
|
270
214
|
protected onDisable(): void;
|
|
215
|
+
private deleteAllEventByEmitter;
|
|
271
216
|
protected onEnable(): void;
|
|
272
217
|
/**子类继承该方法(全局事件(cat.event)注册在components上的事件可以不添加取消监听(自动取消监听了)) */
|
|
273
218
|
protected onEventListener(): void;
|
|
@@ -820,6 +765,43 @@ declare class CoreUtil extends BaseManager {
|
|
|
820
765
|
encryptUtil: typeof EncryptUtil;
|
|
821
766
|
}
|
|
822
767
|
|
|
768
|
+
/**
|
|
769
|
+
* @describe 基于社交游戏封装的游戏基础ws类
|
|
770
|
+
* @author 游金宇(KM)
|
|
771
|
+
* @date 2024-09-12 11:47:51
|
|
772
|
+
*/
|
|
773
|
+
declare class WrapperSocialGameClient extends SocialGameClient {
|
|
774
|
+
/**日志黑名单 */
|
|
775
|
+
protected logBlackList: string[];
|
|
776
|
+
ignore: (route: string) => boolean;
|
|
777
|
+
constructor(name: string, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>, clientOption?: ClientOption);
|
|
778
|
+
destroy(): void;
|
|
779
|
+
GameRequest<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resp: U, audOptions?: AudienceOptionsJson): Promise<MessageShape<U>>;
|
|
780
|
+
subscribe<T extends DescMessage>(route: string, respType: T, fn?: (data: MessageShape<T>) => void): this;
|
|
781
|
+
}
|
|
782
|
+
declare class SocialGameClientManager extends BaseManager {
|
|
783
|
+
private managedClients;
|
|
784
|
+
private isGlobalOnline;
|
|
785
|
+
private isInBackground;
|
|
786
|
+
get activeClients(): WrapperSocialGameClient[];
|
|
787
|
+
constructor(cat: Manager);
|
|
788
|
+
/**
|
|
789
|
+
* 创建并注册WebSocket客户端
|
|
790
|
+
* @param name 客户端唯一标识(如"game", "room")
|
|
791
|
+
* @param clientOption 客户端配置选项
|
|
792
|
+
* @param opts 社交游戏选项
|
|
793
|
+
* @param eventResponsePairs 事件响应配置
|
|
794
|
+
*/
|
|
795
|
+
createWebSocket(name: string, clientOption: ClientOption, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>): WrapperSocialGameClient;
|
|
796
|
+
register(client: WrapperSocialGameClient): void;
|
|
797
|
+
unregister(client: WrapperSocialGameClient): void;
|
|
798
|
+
private initGlobalListeners;
|
|
799
|
+
private handleGlobalStateChange;
|
|
800
|
+
private triggerReconnectAll;
|
|
801
|
+
private disconnectAll;
|
|
802
|
+
private handleSingleReconnect;
|
|
803
|
+
}
|
|
804
|
+
|
|
823
805
|
declare enum AudioEventConstant {
|
|
824
806
|
/**音乐开 */
|
|
825
807
|
MUSIC_ON = "AudioEventConstant/MUSIC_ON",
|
|
@@ -859,64 +841,6 @@ declare enum GlobalEventConstant {
|
|
|
859
841
|
ROOT_MASK_CHANGE = "GlobalEventConstant/ROOT_MASK_CHANGE"
|
|
860
842
|
}
|
|
861
843
|
|
|
862
|
-
type GameNotifyType = (route: string, reqReflect: ReflectMessage, options?: {
|
|
863
|
-
audOptions?: {
|
|
864
|
-
forwardReq: false;
|
|
865
|
-
forwardResp: false;
|
|
866
|
-
};
|
|
867
|
-
show_log?: boolean;
|
|
868
|
-
}) => Promise<void>;
|
|
869
|
-
/**
|
|
870
|
-
* @describe 基于社交游戏封装的游戏基础ws类
|
|
871
|
-
* @author 游金宇(KM)
|
|
872
|
-
* @date 2024-09-12 11:47:51
|
|
873
|
-
*/
|
|
874
|
-
declare class WrapperSocialGameClient extends SocialGameClient {
|
|
875
|
-
/**需要重连(标记接下来需要重连) */
|
|
876
|
-
private isNeedReconnect;
|
|
877
|
-
/**网络在线 */
|
|
878
|
-
private isOnline;
|
|
879
|
-
/**在后台 */
|
|
880
|
-
private isInBackground;
|
|
881
|
-
/**状态机运行 */
|
|
882
|
-
private running;
|
|
883
|
-
private index;
|
|
884
|
-
/**日志黑名单 */
|
|
885
|
-
protected logBlackList: string[];
|
|
886
|
-
constructor(opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>, clientOption?: ClientOption);
|
|
887
|
-
/**初始化 */
|
|
888
|
-
addEvent(): void;
|
|
889
|
-
removeEvent(): void;
|
|
890
|
-
private onShowHandler;
|
|
891
|
-
private onHideHandler;
|
|
892
|
-
/**网络在线处理 */
|
|
893
|
-
private onOnlineHandler;
|
|
894
|
-
/**网络断开处理 */
|
|
895
|
-
private onOfflineHandler;
|
|
896
|
-
private handleEvent;
|
|
897
|
-
destroy(): void;
|
|
898
|
-
/**
|
|
899
|
-
* 断开
|
|
900
|
-
* @param activeDisconnect 主动断开
|
|
901
|
-
*/
|
|
902
|
-
disconnect(activeDisconnect?: boolean): void;
|
|
903
|
-
private destroyStateMachine;
|
|
904
|
-
request<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resSchema: U): Promise<MessageShape<U>>;
|
|
905
|
-
Request<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resSchema: U, { audOptions, show_log }?: {
|
|
906
|
-
audOptions?: {
|
|
907
|
-
forwardReq: boolean;
|
|
908
|
-
forwardResp: boolean;
|
|
909
|
-
} | undefined;
|
|
910
|
-
show_log?: boolean | undefined;
|
|
911
|
-
}): Promise<MessageShape<U>>;
|
|
912
|
-
protected GameRequest<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resp: U, audOptions?: AudienceOptions): Promise<MessageShape<U>>;
|
|
913
|
-
protected gameRequest<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resSchema: U): Promise<MessageShape<U>>;
|
|
914
|
-
protected GameNotify: (route: string, reqReflect: ReflectMessage, audOptions?: AudienceOptions) => Promise<void>;
|
|
915
|
-
Notify: GameNotifyType;
|
|
916
|
-
subscribe<T extends DescMessage>(route: string, respType: T, fn?: (data: MessageShape<T>) => void): this;
|
|
917
|
-
onData(body: Uint8Array): void;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
844
|
type CoreUIModalProps = {
|
|
921
845
|
content: string | SpriteFrame | null;
|
|
922
846
|
confirmCB: () => void;
|
|
@@ -1070,7 +994,7 @@ declare class Manager {
|
|
|
1070
994
|
/**音频 */
|
|
1071
995
|
audio: AudioManager;
|
|
1072
996
|
/**事件 */
|
|
1073
|
-
event:
|
|
997
|
+
event: EventEmitter$1;
|
|
1074
998
|
/**gui */
|
|
1075
999
|
gui: Gui;
|
|
1076
1000
|
/**本地存储 */
|
|
@@ -1079,6 +1003,8 @@ declare class Manager {
|
|
|
1079
1003
|
res: ResLoader;
|
|
1080
1004
|
/**工具类 */
|
|
1081
1005
|
util: CoreUtil;
|
|
1006
|
+
/**类 */
|
|
1007
|
+
socialGameClient: SocialGameClientManager;
|
|
1082
1008
|
/**GUI */
|
|
1083
1009
|
gui_bundle_name: string;
|
|
1084
1010
|
/**音效本地存储key */
|
|
@@ -1093,4 +1019,4 @@ declare class Manager {
|
|
|
1093
1019
|
}
|
|
1094
1020
|
declare const cat: Manager;
|
|
1095
1021
|
|
|
1096
|
-
export { AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, CoreBlackMask, CoreNotice, type CoreNoticeProps, CoreReconnection, CoreShowLoading, type CoreShowLoadingProps, CoreToast, CoreUIContainer, CoreUIModal, type CoreUIModalProps, CoreUtil,
|
|
1022
|
+
export { AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, CoreBlackMask, CoreNotice, type CoreNoticeProps, CoreReconnection, CoreShowLoading, type CoreShowLoadingProps, CoreToast, CoreUIContainer, CoreUIModal, type CoreUIModalProps, CoreUtil, GlobalEventConstant, Gui, GuiManager, type HOOK, type ICloseOptions, type IDirection, type IOpenOptions, type IUIOption, LayerType, Manager, ReconnectPrompt, RootUILayer, type SceneComponentType, type SceneDataType, SceneLayer, type ScenePropsType, TimerManager, type ToastProps, ToastType, type UIComponentType, UILayer, WrapperSocialGameClient, cat };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AudioSource as e,_decorator as t,AudioClip as s,error as i,Node as o,director as n,log as r,sys as a,Component as c,Prefab as l,instantiate as h,isValid as d,Layers as p,view as u,Widget as f,v3 as _,tween as g,Enum as m,game as y,UITransform as v,UIOpacity as E,Tween as b,Label as C,BlockInputEvents as w,Button as k,Director as O,warn as x,assetManager as S,Asset as T,resources as N,SpriteFrame as I,Sprite as R,AsyncDelegate as A}from"cc";import{PREVIEW as M,DEBUG as D}from"cc/env";import{makeObservable as F,observable as U,autorun as H,reaction as P}from"@shimotsuki/mobx";import L from"crypto-es";import{clone as B,create as G}from"@bufbuild/protobuf";import{SocialGameClient as $,AudienceOptionsSchema as j}from"sgc";import"core-js/es/array/index.js";class q extends e{cat;initAudio(e){return this.cat=e,this}}const{ccclass:K,menu:V}=t;class W extends q{effects=new Map;load(e){return new Promise(((t,i)=>{this.cat.res.load(e,s,((s,o)=>{if(s)return i(s);this.effects.set(e,o),this.playOneShot(o,this.volume),t(o)}))}))}release(){for(let e in this.effects)this.cat.res.release(e);this.effects.clear()}}const{ccclass:Q,menu:J}=t;class X extends q{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(e){this._progress=e,this.currentTime=e*this.duration}load(e,t){this.cat.res.load(e,s,((s,o)=>{s&&i(s),this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=o,this._url=e,t&&t()}))}update(e){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class z{cat;constructor(e){this.cat=e}}var Z;!function(e){e.MUSIC_ON="AudioEventConstant/MUSIC_ON",e.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",e.EFFECT_ON="AudioEventConstant/EFFECT_ON",e.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",e.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",e.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(Z||(Z={}));class Y extends z{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(e){super(e),this.local_store_key=this.cat.audio_local_store_key;var t=new o("UIAudioManager");n.addPersistRootNode(t);var s=new o("UIMusic");s.parent=t,this.music=s.addComponent(X).initAudio(e);var i=new o("UIEffect");i.parent=t,this.effect=i.addComponent(W).initAudio(e),this.load()}setMusicComplete(e=null){this.music.onComplete=e}playMusic(e,t){this.music.loop=!0,e&&this.music.load(e,(()=>{this._switch_music&&this.music?.play(),t&&t()}))}stopMusic(){0!=this.music.state&&this.music?.stop()}pauseMusic(){1==this.music.state&&this.music?.pause()}resumeMusic(){[0,2].includes(this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(e){this.music.progress=e}get volumeMusic(){return this._volume_music}set volumeMusic(e){this._volume_music=e,this.music.volume=e}get switchMusic(){return this._switch_music}set switchMusic(e){if(r("设置背景音乐开关值",e,this._switch_music),e==this._switch_music)return;this._switch_music=e,e?this.resumeMusic():this.pauseMusic();const t=e?Z.MUSIC_ON:Z.MUSIC_OFF;this.cat.event.has(t)&&this.cat.event.dispatchEvent(t),this.save()}async playEffect(e){this._switch_effect&&e&&await this.effect.load(e).then((()=>{this.effect.play()}))}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(e){this._volume_effect=e,this.effect.volume=e}get switchEffect(){return this._switch_effect}set switchEffect(e){if(e==this._switch_effect)return;this._switch_effect=e,e?this.effect?.play():this.effect?.stop();const t=e?Z.EFFECT_ON:Z.EFFECT_OFF;this.cat.event.has(t)&&this.cat.event.dispatchEvent(t),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let e=JSON.stringify(this.local_data);return this.cat.storage.set(this.local_store_key,e),this}load(){try{let e=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(e),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(e){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}class ee extends z{_key=null;_iv=null;_id="";init(e,t){this.cat.util.encryptUtil.initCrypto(e,t),this._key=this.cat.util.encryptUtil.md5(e),this._iv=this.cat.util.encryptUtil.md5(t)}setUser(e){this._id=e}set(e,t){if(null!=(e=`${e}_${this._id}`)){if(M||(e=this.cat.util.encryptUtil.md5(e)),null==t)return console.warn("存储的值为空,则直接移除该存储"),void this.remove(e);if("function"!=typeof t){if("object"==typeof t)try{t=JSON.stringify(t)}catch(e){return void console.error(`解析失败,str = ${t}`)}else"number"==typeof t&&(t+="");M||null==this._key||null==this._iv||(t=this.cat.util.encryptUtil.aesEncrypt(`${t}`,this._key,this._iv)),a.localStorage.setItem(e,t)}else console.error("储存的值不能为方法")}else console.error("存储的key不能为空")}get(e,t){if(null==e)return console.error("存储的key不能为空"),null;e=`${e}_${this._id}`,M||(e=this.cat.util.encryptUtil.md5(e));let s=a.localStorage.getItem(e);return null==s||""===s||M||null==this._key||null==this._iv||(s=this.cat.util.encryptUtil.aesDecrypt(s,this._key,this._iv)),null===s?t:s}getNumber(e,t=0){var s=this.get(e);return Number(s)||t}getBoolean(e){var t=this.get(e);return Boolean(t)||!1}getJson(e,t){var s=this.get(e);return s&&JSON.parse(s)||t}remove(e){null!=e?(e=`${e}_${this._id}`,M||(e=this.cat.util.encryptUtil.md5(e)),a.localStorage.removeItem(e)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function te(e,t,s,i){var o,n=arguments.length,r=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,s,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(n<3?o(r):n>3?o(t,s,r):o(t,s))||r);return n>3&&r&&Object.defineProperty(t,s,r),r}function se(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;class ie extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];messageManagers=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),F(this,{props:U,data:U})}onAutoObserver(){}addAutorun(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=H(e);this.autorunDisposers.push(t)})),this}addReaction(e,t,s){const i=P(e,t,s);return this.reactionDisposers.push(i),this}addAudoListener(e){return this.messageManagers.includes(e)||this.messageManagers.push(e),e}_onPreDestroy(){this.autorunDisposers.forEach((e=>{e()})),this.reactionDisposers.forEach((e=>{e()})),this.autorunDisposers=[],this.reactionDisposers=[],super._onPreDestroy()}onDisable(){this.onHide(),st.event.deleteEventByComponent(this),this.messageManagers.forEach((e=>{e.deleteEventByComponent(this)})),this.messageManagers=[],this.removeListener()}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(e,t){let s=e instanceof l?h(e):e instanceof c?e.node:e;return this.setOptions(t),s.addChild(this.node),this}setOptions(e){if(e)for(let t in e)switch(t){case"hook":e.hook&&(this.hook=e.hook);break;case"props":null!==e.props&&"object"==typeof e.props&&(this.props=e.props);break;case"data":null!==e.data&&"object"==typeof e.data&&(this.data=e.data)}}setUpdateData(e){return e&&Object.assign(this.data,e),this}setUpdateProps(e){return this.props,e&&Object.assign(this.props,e),this}removeAndDestroy(){d(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(e){return this.node.setPosition(e),this}setScale(e){return this.node.setScale(e),this}setAngle(e){return this.node.angle=e,this}setRotation(e){return this.node.setRotation(e),this}setRotationFromEuler(e){return this.node.setRotationFromEuler(e),this}onShow(){}onHide(){}setNodeAndChildrenLayer(e){return oe(this.node,e),this}}const oe=(e,t)=>{e.layer="string"==typeof t?2**p.nameToLayer(t):t,e?.children.forEach((e=>{oe(e,t)}))};class ne extends ie{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=u.getVisibleSize()}async showTween({isMotion:e=!0,direction:t="center",duration:s=.1,isBounce:i=!0,bounceDuration:o=.05}){if(this.lastEnterDirection=t,e){const e=this.node.getComponent(f);let o,n;e&&(e.updateAlignment(),e.enabled=!1),_(1.1,1.1,1),"center"==t?(o=_(.01,.01,.01),n=_(1,1,1)):(o="left"==t?_(-this.screen.width,0,0):"right"==t?_(this.screen.width,0,0):_(0,"top"==t?this.screen.height:-this.screen.height,0),n=_(0,0,0)),await this.handle(t,s,o,n,i),e&&(e.enabled=!0)}}async hideTween({isMotion:e=!0,direction:t,duration:s=.1}){if(t=t||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,g(this.node).removeSelf(),e){const e=this.node.getComponent(f);let i,o;e&&(e.enabled=!1),"center"==t?(i=this.node.scale,o=_(0,0,0)):(o="left"==t?_(-this.screen.width,0,0):"right"==t?_(this.screen.width,0,0):_(0,"top"==t?this.screen.height:-this.screen.height,0),i=this.node.getPosition()),await this.handle(t,s,i,o,!1)}this.removeAndDestroy()}}async handle(e,t,s,i,o){"center"==e?this.node.setScale(s):this.node.setPosition(s),await this.deftween(t,{["center"==e?"scale":"position"]:i},o)}deftween(e,t,s,i){return new Promise(((s,i)=>{g(this.node).to(e,t).call((()=>{s()})).start()}))}}const{ccclass:re,property:ae}=t;var ce;!function(e){e[e.EFFECT=0]="EFFECT",e[e.BGM=1]="BGM"}(ce||(ce={}));class le extends ie{type=ce.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new e;onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,st.event.on(Z.EFFECT_ON,this.onPlayEffectHandler,this).on(Z.EFFECT_OFF,this.onStopEffectHandler,this).on(Z.MUSIC_ON,this.onPlayMusicHandler,this).on(Z.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:e,volumeMusic:t}=st.audio;this.audioSource.volume=this.type===ce.BGM?t:e}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=st.audio;this.audioSource.playing||!(this.type===ce.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}te([ae({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:m(ce)}),se("design:type",Object)],le.prototype,"type",void 0),te([ae({tooltip:"音源",type:s}),se("design:type",Object)],le.prototype,"clip",void 0),te([ae({tooltip:"循环"}),se("design:type",Object)],le.prototype,"loop",void 0),te([ae({tooltip:"音量"}),se("design:type",Object)],le.prototype,"volume",void 0),te([ae({tooltip:"是否启用自动播放"}),se("design:type",Object)],le.prototype,"playOnAwake",void 0);const{ccclass:he,property:de}=t;class pe extends ne{type=ce.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new e;onEnable(){super.onEnable(),st.event.on(Z.EFFECT_ON,this.onPlayEffectHandler,this).on(Z.EFFECT_OFF,this.onStopEffectHandler,this).on(Z.MUSIC_ON,this.onPlayMusicHandler,this).on(Z.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:e,volumeMusic:t}=st.audio;this.audioSource.volume=this.type===ce.BGM?t:e}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=st.audio;this.audioSource.playing||!(this.type===ce.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}te([de({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:m(ce)}),se("design:type",Object)],pe.prototype,"type",void 0),te([de({tooltip:"音源",type:s}),se("design:type",Object)],pe.prototype,"clip",void 0),te([de({tooltip:"循环"}),se("design:type",Object)],pe.prototype,"loop",void 0),te([de({tooltip:"音量"}),se("design:type",Object)],pe.prototype,"volume",void 0),te([de({tooltip:"是否启用自动播放"}),se("design:type",Object)],pe.prototype,"playOnAwake",void 0);const{ccclass:ue,property:fe}=t;var _e;!function(e){e[e.FIXED=0]="FIXED",e[e.SLIDE=1]="SLIDE"}(_e||(_e={}));let ge=class extends ie{fixed_node;slide_node;fixed_label;slide_label;onLoad(){this.fixed_node.active=this.slide_node.active=!1}start(){this.show()}async show(){return new Promise((async(e,t)=>{const{title:s,type:i,fixed_time:o}=this.props;if(i==_e.FIXED){this.fixed_node.active=!0,this.fixed_label.string=`${s}`,this.fixed_label.updateRenderData(!0);const t=this.fixed_label.node.getComponent(v).height;t-this.fixed_node.getComponent(v).height>0&&(this.fixed_node.getComponent(v).height=t+100),this.scheduleOnce((()=>{this.node.destroy(),e()}),o)}else{this.slide_node.active=!0,this.slide_label.string=`${s}`,this.slide_label.updateRenderData(!0);const t=this.slide_label.node.getComponent(v).width;this.slide_node.getComponent(v).width-t<100&&(this.slide_node.getComponent(v).width=t+100),this.playAnim(this.node).then((()=>{e()}))}}))}playAnim(e){return new Promise(((t,s)=>{const i=this.node.getComponent(E),o=g(i).delay(1.2).to(.5,{opacity:0}).call((()=>{b.stopAllByTarget(e),this.node.destroy(),t()}));g(e).by(.5,{position:_(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){b.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var me;te([fe({type:o,tooltip:"固定节点"}),se("design:type",o)],ge.prototype,"fixed_node",void 0),te([fe({type:o,tooltip:"滑动节点"}),se("design:type",o)],ge.prototype,"slide_node",void 0),te([fe({type:C,tooltip:"固定标签节点"}),se("design:type",C)],ge.prototype,"fixed_label",void 0),te([fe({type:C,tooltip:"滑动标签节点"}),se("design:type",C)],ge.prototype,"slide_label",void 0),ge=te([ue("CoreToast")],ge),function(e){e.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",e.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",e.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",e.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",e.ONLINE="GlobalEventConstant/ONLINE",e.OFFLINE="GlobalEventConstant/OFFLINE",e.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",e.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(me||(me={}));const{ccclass:ye,property:ve}=t;let Ee=class extends ne{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Le)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){st.event.on(me.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const e=this.brother[this.brother.length-1];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const e=this.brother[this.brother.length-2];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(e){return d(this)&&this.scene_mask&&this.scene_mask.tween.addChild(e),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(e){return this.gui=e,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(e){this.scene_mask.node.active=e}};te([ve({type:o}),se("design:type",o)],Ee.prototype,"scene_mask_node",void 0),te([ve({type:o}),se("design:type",o)],Ee.prototype,"ui_container",void 0),Ee=te([ye("CoreUIContainer")],Ee);class be extends ne{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){st.event.dispatchEvent(me.ROOT_MASK_UPDATE)}}const{ccclass:Ce,property:we}=t;let ke=class extends be{title;loadingTween;loading_rotate=0;onAutoObserver(){this.addAutorun([()=>{this.props?.title&&(this.title.string=`${this.props?.title}`),this.title.node.active=!!this.props?.title?.length},()=>{this.getComponent(w).enabled=!!this.props?.mask}])}update(e){this.loading_rotate+=220*e,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};te([we({type:C,tooltip:"标题"}),se("design:type",C)],ke.prototype,"title",void 0),te([we({type:o,tooltip:"动画"}),se("design:type",o)],ke.prototype,"loadingTween",void 0),ke=te([Ce("CoreShowLoading")],ke);const{ccclass:Oe,property:xe}=t;var Se;!function(e){e.RECONNECTED="重连成功",e.RECONNECTING="正在重连",e.MAX_RECONNECT="重连次数超出限制,请检查网络",e.RECONNECTED_ERROR="重连失败,请检查网络",e.CONNECT_PARAM_ERROR="游戏参数错误,请重新加载",e.KICK="账号已下线",e.OFFLINE="网络已断开",e.ONLINE="网络已连接",e.GAME_ERROR="连接游戏服错误"}(Se||(Se={}));let Te=class extends be{common_prompt_text;btn_confirm;is_close=!1;props={content:null};initUI(){this.btn_confirm.node.active=!1}onLoad(){this.btn_confirm.node.on(k.EventType.CLICK,this.onConfirmHandler,this),this.addAutorun([()=>{this.common_prompt_text.string=this.props.content??""}])}onDestroy(){this.unscheduleAllCallbacks()}updateProps(e){this.updatePromptText(e,e==Se.RECONNECTING)}updatePromptText(e,t=!1){if(this.unscheduleAllCallbacks(),this.props.content=e,r("更新提示文案:",e),t){let t=0;const s=()=>{t=(t+1)%4,this.common_prompt_text.string=e+["","·","··","···"][t]};this.schedule(s,.5)}}onConfirmHandler(){this.is_close=!0,st.gui.hideReconnect()}};te([xe({type:C,tooltip:"通用提示文本"}),se("design:type",C)],Te.prototype,"common_prompt_text",void 0),te([xe({type:k,tooltip:"确定按钮"}),se("design:type",k)],Te.prototype,"btn_confirm",void 0),Te=te([Oe("CoreReconnection")],Te);const{ccclass:Ne,property:Ie}=t;let Re=class extends be{text;btn_confirm;onLoad(){this.btn_confirm.node.on(k.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),st.gui.hideNotice()}updateProps(e){this.text.string=`${e.text}`}};te([Ie({type:C,tooltip:"提示文本"}),se("design:type",C)],Re.prototype,"text",void 0),te([Ie({type:k,tooltip:"确定按钮"}),se("design:type",k)],Re.prototype,"btn_confirm",void 0),Re=te([Ne("CoreNotice")],Re);class Ae extends ie{isReload}const{ccclass:Me,property:De}=t;var Fe;!function(e){e[e.UI=0]="UI",e[e.LOADING=1]="LOADING",e[e.TOAST=2]="TOAST",e[e.RECONNECTTION=3]="RECONNECTTION",e[e.NOTICE=4]="NOTICE"}(Fe||(Fe={}));let Ue=class extends ie{reconnection_ui_prefab;toast_ui_prefab;loading_ui_prefab;notice_ui_prefab;ui_prefab;root_ui;root_toast;root_mask;cat;ui_container_component;reconnection_ui_component;notice_ui_component;loading_ui_component;toast_ui_component;currentScene;onEventListener(){this.cat.event.on(me.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(e){this.cat=e;const t=n.getScene();return r("init scene"),t&&this.changeScene(t),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(e){this.toastQueue.push(e),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const e=this.toastQueue.shift(),t=()=>{h(this.toast_ui_prefab).getComponent(ge).addToParent(this.root_toast,{props:e}),this.scheduleOnce((()=>{this.processQueueWithInterval()}),this.minInterval)};0===this.root_toast.children.length?t():this.scheduleOnce(t,this.minInterval)}hideToast(){return this.root_toast&&this.root_toast.children.forEach((e=>{e.getComponent(ge)?.removeAndDestroy()})),this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading({title:e="",mask:t=!0,black:s=!0}={}){if(r("showLoading",e),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:e,mask:t,black:s}});else{const i=h(this.loading_ui_prefab);this.loading_ui_component=i.getComponent(ke).addToParent(this.root_ui,{props:{title:e,mask:t,black:s}})}return this}hideLoading(){return this.loading_ui_component?.removeAndDestroy(),this.loading_ui_component=null,this}showReconnect(e){if(this.reconnection_ui_component)this.reconnection_ui_component.setUpdateProps({content:e});else{const t=h(this.reconnection_ui_prefab);this.reconnection_ui_component=t.getComponent(Te).addToParent(this.root_ui,{props:{content:e}})}return this}hideReconnect(){return this.reconnection_ui_component?.removeAndDestroy(),this.reconnection_ui_component=null,this}showNotice(e){const t=h(this.notice_ui_prefab);return this.notice_ui_component=t.getComponent(Re).addToParent(this.root_ui,{props:e}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}loadScene(e,t,s){r("加载场景",e,t,s);let i={},o=s??!1;return"boolean"==typeof t?o=t:i=t??{},r("当前场景",n.getScene()?.uuid,n.getScene()?.name),n.once(O.EVENT_BEFORE_SCENE_LAUNCH,(e=>{r("Director.EVENT_BEFORE_SCENE_LAUNCH",e),this.changeScene(e,i,o)})),n.loadScene(e),this}resetScene(e=""){return e=e||this.currentScene,this.loadScene(e)}cleanScene(){this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast()}changeScene(e,t,s){this.currentScene=e.name,this.createUILayer(e);const i=e.getComponentInChildren(Ae);i&&(i.isReload=s??!1),i?.setOptions(t)}createUILayer(e){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const t=h(this.ui_prefab);this.ui_container_component=t.getComponent(Ee).setGui(this).addToParent(e)}reloadScene(){this.loadScene(this.currentScene,!0)}async closeUI(e,t){const{component:s}=this.findUIBaseLayer(e,!1);s&&(s.setOptions({...t?.hook??{},...t?.props??{}}),await s.hideTween(t||{}),this.ui_container_component?.subMask())}async openUI(e,t){const{rootNode:s,component:i}=this.findUIBaseLayer(e,!0);s.getComponent(ne),i?.setOptions(t),s&&this.ui_container_component?.addNodeToTween(s).addMask(),i&&await i.showTween(t||{}),this.ui_container_component?.ui_container&&i?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(e,t){let s,n=null;if(e instanceof o){s=e;const t=e.components.filter((e=>e instanceof ne));if(!t.length)return i(`${e.name}节点未找到继承自BaseLayer的组件`),{rootNode:s,component:n};1==t.length?n=t[0]:x(`${e.name}节点存在多个继承自BaseLayer的组件`)}else if(s=e.node,n=e,t){for(;s.parent;)s=s.parent;n.root=s}else s=e.root;return{rootNode:s,component:n}}onRootUpdate(){const e=this.root_ui.children.findLastIndex((e=>e.active&&e!=this.root_mask));if(this.root_mask.active=-1!=e,e>-1){const t=this.root_ui.children[e];this.root_mask.setSiblingIndex(t.getSiblingIndex()-1)}this.cat.event.dispatchEvent(me.ROOT_MASK_CHANGE)}};te([De({type:l,tooltip:"断线重连UI预制体"}),se("design:type",l)],Ue.prototype,"reconnection_ui_prefab",void 0),te([De({type:l,tooltip:"提示UI预制体"}),se("design:type",l)],Ue.prototype,"toast_ui_prefab",void 0),te([De({type:l,tooltip:"加载UI预制体"}),se("design:type",l)],Ue.prototype,"loading_ui_prefab",void 0),te([De({type:l,tooltip:"公告UI预制体"}),se("design:type",l)],Ue.prototype,"notice_ui_prefab",void 0),te([De({type:l,tooltip:"UI层预制体"}),se("design:type",l)],Ue.prototype,"ui_prefab",void 0),te([De({type:o,tooltip:"root-UI层"}),se("design:type",o)],Ue.prototype,"root_ui",void 0),te([De({type:o,tooltip:"root-组件层"}),se("design:type",o)],Ue.prototype,"root_toast",void 0),te([De({type:o,tooltip:"root-mask"}),se("design:type",o)],Ue.prototype,"root_mask",void 0),Ue=te([Me("Gui")],Ue);const{ccclass:He,property:Pe}=t;let Le=class extends ie{tween};var Be;te([Pe({type:o,tooltip:"动画节点"}),se("design:type",o)],Le.prototype,"tween",void 0),Le=te([He("CoreBlackMask")],Le),function(e){e.Root="prefabs/root",e.Toast="prefabs/toast",e.BlackMask="prefabs/black-mask",e.Loading="prefabs/loading",e.Notice="prefabs/notice",e.Reconnection="prefabs/reconnection"}(Be||(Be={}));class Ge extends z{gui;#e="resources";getGuiPrefabByType=(e,t)=>new Promise(((s,i)=>{console.log(e,`${t}`),this.cat.res.load(e,t,((e,t)=>{e?i(e):s(t)}))}));async init(){this.#e=this.cat.gui_bundle_name;const e=await this.getGuiPrefabByType(this.#e,Be.Root),t=h(e);return this.gui=t.getComponent(Ue).init(this.cat),n.addPersistRootNode(t),this}}class $e{get=(e,t,s="resources")=>S.getBundle(s).get(e,t);isAssetType=e=>"function"==typeof e&&e.prototype instanceof T;async load(...e){let t=null,s=null,i=null;"string"==typeof e[0]&&"string"==typeof e[1]&&(t=e.shift());let o=e.shift();this.isAssetType(e[0])&&(s=e.shift()),2==e.length&&(i=e.shift());const n=e.shift();let r=N;if(t&&"resources"!=t){S.bundles.has(t)||await this.loadBundle(t);let e=S.bundles.get(t);e&&(r=e)}i&&n?r.load(o,s,i,n):n?r.load(o,s,n):r.load(o,s)}async loadDir(...e){let t=null,s=null,i=null,o=null;"string"==typeof e[0]&&"string"==typeof e[1]&&(t=e.shift());let n=e.shift();this.isAssetType(e[0])&&(s=e.shift()),2==e.length&&(i=e.shift()),o=e.shift();let r=N;if(t&&"resources"!=t){S.bundles.has(t)||await this.loadBundle(t);let e=S.bundles.get(t);e&&(r=e)}i&&o?r.loadDir(n,s,i,o):o?r.loadDir(n,s,o):r.loadDir(n,s)}loadRemote(e,...t){var s,i=null;2==t.length&&(i=t.shift()),s=t.shift(),S.loadRemote(e,{ext:".png",...i},s)}loadBundle=(e,t)=>new Promise(((s,i)=>{const o=(e,t)=>{if(e)return i(e);s(t)};t?S.loadBundle(e,{version:t},o):S.loadBundle(e,o)}));releasePrefabtDepsRecursively=e=>{var t=S.assets.get(e);(S.releaseAsset(t),t instanceof l)&&S.dependUtil.getDepsRecursively(e).forEach((e=>{S.assets.get(e).decRef()}))};release=(e,t="resources")=>{var s=S.getBundle(t);if(s){var i=s.get(e);i&&this.releasePrefabtDepsRecursively(i._uuid)}};releaseDir=(e,t="resources")=>{var s=S.getBundle(t),i=s?.getDirWithPath(e);i?.map((e=>{this.releasePrefabtDepsRecursively(e.uuid)})),!e&&"resources"!=t&&s&&S.removeBundle(s)};dump=()=>{S.assets.forEach(((e,t)=>{r(S.assets.get(t))})),r(`当前资源总数:${S.assets.count}`)}}class je{events=new Map;on(e,t,s){if(!e||!t)return x(`注册【${e}】事件的侦听器函数为空`),this;const i=this.events.get(e)??this.events.set(e,new Map).get(e);return i.has(s)?(x(`名为【${e}】的事件重复注册侦听器`),this):(i.set(s,t),this)}once(e,t,s){let i=(o,n)=>{this.off(e,i,s),i=null,t.call(s,o,n)};this.on(e,i,s)}off(e,t,s){if(!this.events.get(e)?.has(s))return this;const o=this.events.get(e);return o.get(s)!==t?(i(`${s}注册事件和取消事件不一致`),this):(o.delete(s),this)}dispatchEvent(e,t){if(!this.events.has(e))return this;const s=this.events.get(e);for(const[i,o]of s)o.call(i,t,e);return this}offAll(){this.events.clear()}has(e){return this.events.has(e)}deleteEventByComponent(e){for(const[t,s]of this.events){for(const[t]of s)t===e&&s.delete(t);0===s.size&&this.events.delete(t)}}}let qe=null;const Ke={stringify:e=>{const t={ct:e.ciphertext.toString(L.enc.Base64)};return e.iv&&(t.iv=e.iv.toString()),e.salt&&(t.s=e.salt.toString()),JSON.stringify(t)},parse:e=>{const t=JSON.parse(e),s=L.lib.CipherParams.create({ciphertext:L.enc.Base64.parse(t.ct)});return t.iv&&(s.iv=L.enc.Hex.parse(t.iv)),t.s&&(s.salt=L.enc.Hex.parse(t.s)),s}};var Ve=Object.freeze({__proto__:null,JsonFormatter:Ke,aesDecrypt:(e,t,s)=>L.AES.decrypt(e,t,{iv:qe,format:Ke}).toString(L.enc.Utf8),aesEncrypt:(e,t,s)=>L.AES.encrypt(e,t,{iv:qe,format:Ke}).toString(),initCrypto:(e,t)=>{qe=L.enc.Hex.parse(t)},md5:e=>L.MD5(e).toString()});class We extends z{encryptUtil=Ve}class Qe extends ${isNeedReconnect=!1;isOnline=!0;isInBackground=!1;running=!1;index=0;logBlackList=[];constructor(e,t,s){super(e,t,s),this.running=!0,this.addEvent()}addEvent(){this.on("connected",(()=>this.handleEvent({type:"connected"}))).on("reconnected",(()=>this.handleEvent({type:"reconnected"}))).on("disconnect",(e=>this.handleEvent({type:"disconnect",ev:e}))).on("handshakeError",(e=>this.handleEvent({type:"handshakeError",ret:e}))).on("kick",(()=>this.handleEvent({type:"kick"}))).on("reconnecting",(()=>this.handleEvent({type:"reconnecting"}))).on("maxReconnect",(()=>this.handleEvent({type:"maxReconnect"}))).on("error",(e=>this.handleEvent({type:"error",ev:e}))),st.event.on(me.EVENT_SHOW,this.onShowHandler,this).on(me.EVENT_HIDE,this.onHideHandler,this).on(me.ONLINE,this.onOnlineHandler,this).on(me.OFFLINE,this.onOfflineHandler,this)}removeEvent(){this.removeAllListeners(),st.event.off(me.EVENT_SHOW,this.onShowHandler,this).off(me.EVENT_HIDE,this.onHideHandler,this).off(me.ONLINE,this.onOnlineHandler,this).off(me.OFFLINE,this.onOfflineHandler,this)}onShowHandler(){r("[SHOW]"),this.isInBackground=!1,this.isNeedReconnect&&this.isOnline&&this.handleEvent({type:"show"})}onHideHandler(e){r("[HIDE]"),e().finally((()=>{this.isInBackground=!0,this.handleEvent({type:"hide"})}))}onOnlineHandler(){this.isOnline=!0,r("正在检查网络状态:"+(this.isOnline?"在线":"断开")),this.handleEvent({type:"online"})}onOfflineHandler(){this.isOnline=!1,r("正在检查网络状态:"+(this.isOnline?"在线":"断开")),this.handleEvent({type:"offline"})}async handleEvent(e){if(this.running)switch(e.type){case"init":break;case"connected":r("ws连接成功状态 connected"),this.isNeedReconnect=!1;break;case"reconnected":r("ws重连成功状态 reconnected",this.isSocketConnected),this.isNeedReconnect=!1,r("%c 重连成功状态","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index);try{await this.connectRequest(),r("重连成功状态 connectRequest "),st.gui.showToast({title:Se.RECONNECTED}),st.gui.hideReconnect().hideLoading(),st.gui.reloadScene()}catch(e){console.error(e),st.gui.showReconnect(Se.GAME_ERROR)}break;case"disconnect":r("断开连接状态 disconnect",e.ev),r("%c 断开连接状态","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index),this.isNeedReconnect=!0,this.handleEvent({type:"reconnect"});break;case"handshakeError":r("参数错误状态 handshakeError",e.ret),st.gui.showReconnect(Se.CONNECT_PARAM_ERROR),this.handleEvent({type:"destroy"});break;case"kick":r("%c 被踢出状态","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index),r("被踢出状态 kick"),st.gui.showReconnect(Se.KICK),this.handleEvent({type:"destroy"});break;case"reconnecting":r("正在重连状态 reconnecting"),this.isOnline&&this.isInBackground;break;case"maxReconnect":r("超出最大重连状态 maxReconnect"),st.gui.showReconnect(Se.MAX_RECONNECT);break;case"error":this.isOnline&&(r("ws报错状态 error",e.ev),"string"==typeof e.ev&&st.gui.showToast({title:e.ev}),st.gui.showReconnect(Se.RECONNECTED_ERROR));break;case"online":st.gui.showReconnect(Se.ONLINE),r("在线状态 online"),this.handleEvent({type:"reconnect"});break;case"offline":this.disconnect(!0),r("离线状态 offline"),this.isNeedReconnect=!0,st.gui.showReconnect(Se.OFFLINE);break;case"show":r("前台状态 show"),this.handleEvent({type:"reconnect"});break;case"hide":r("后台状态 hide"),this.disconnect(!0),this.isNeedReconnect=!0;break;case"reconnect":r("重连状态 reconnect"),this.isNeedReconnect&&!this.isInBackground&&this.isOnline&&(st.gui.showLoading({title:"正在重连"}),this.reset(),this.index+=1,r("%c ws重连次数","background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff",this.index),this.reconnectImmediately());break;case"destroy":r("销毁状态 destroy"),this.destroyStateMachine();break;default:r("Unknown event:",e.type)}}destroy(){this.handleEvent({type:"destroy"})}disconnect(e=!1){super.disconnect(e)}destroyStateMachine(){r("Destroying state machine"),this.running=!1,this.removeEvent(),this.disconnect(!0)}request(e,t,s){return D&&r(`%c ws客户端消息 %c [Request][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),new Promise(((o,n)=>{super.request(e,t,s).then((t=>{D&&r(`%c ws服务端消息 %c [Response][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(s,t)),o(t)}),(e=>{i("request err",e),n(e)}))}))}async Request(e,t,s,{audOptions:i={forwardReq:!1,forwardResp:!1},show_log:o=!0}={}){if(!this.isSocketConnected)throw""+(this.isSocketConnected?"未加入战局/观战":"Socket未连接");return D&&o&&r(`%c ws客户端消息 %c [Request][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),this.GameRequest(e,t,s,G(j,i))}async GameRequest(e,t,s,i){return new Promise(((o,n)=>{super.GameRequest(e,t,s,i).then((t=>{D&&r(`%c ws服务端消息 %c [Response][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(s,t)),o(t)}),(e=>{st.gui.showToast({title:e.msg}),n(e)}))}))}async gameRequest(e,t,s){return D&&r(`%c ws客户端消息 %c [Request][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),super.gameRequest(e,t,s)}GameNotify=async(e,t,s)=>{try{super.GameNotify(e,t,s)}catch(t){throw console.error(`Error in connectRequest for route ${e}: `,t),t}};Notify=async(e,t,{audOptions:s={forwardReq:!1,forwardResp:!1},show_log:i=!0}={})=>{this.isSocketConnected&&(D&&i&&r(`%c ws客户端消息 %c[Notify][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7d3d ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t.desc,t.message)),this.GameNotify(e,t,G(j,s)))};subscribe(e,t,s){return super.subscribe(e,t,(i=>{D&&!this.logBlackList.includes(e)&&r(`%c ws服务端消息:[${new Date}] %c ${e} %c`,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#410083 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",B(t,i)),st.event.dispatchEvent(e,B(t,i)),s?.(i)})),this}onData(e){super.onData(e)}}const{ccclass:Je,property:Xe}=t;let ze=class extends ne{default_title=null;title;prompt_content_str;prompt_content_spriteFrame;btn_confirm;confirm_spriteFrame;btn_cancel;cancel_spriteFrame;btn_close;isConfirm=!1;props={title:this.default_title,content:null,confirmCB:()=>{},cancelCB:()=>{},style:null};onLoad(){this.btn_cancel.node.on(k.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(k.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(k.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content instanceof I?this.prompt_content_spriteFrame.spriteFrame=this.props.content:"string"==typeof this.props.content?this.prompt_content_str.string=this.props.content:console.error("未知类型的【UIModal】内容")},()=>{null===this.props?.style?.confirm?this.btn_confirm.node.active=!1:(this.btn_confirm.node.active=!0,this.btn_confirm.getComponent(R).spriteFrame=this.props.style?.confirm||this.confirm_spriteFrame),null===this.props?.style?.cancel?this.btn_cancel.node.active=!1:(this.btn_cancel.node.active=!0,this.btn_cancel.getComponent(R).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),st.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var Ze;te([Xe({type:I,tooltip:"默认标题"}),se("design:type",I)],ze.prototype,"default_title",void 0),te([Xe({type:R,tooltip:"标题节点"}),se("design:type",R)],ze.prototype,"title",void 0),te([Xe({type:C,tooltip:"字符串内容按钮"}),se("design:type",C)],ze.prototype,"prompt_content_str",void 0),te([Xe({type:R,tooltip:"图片精灵内容按钮"}),se("design:type",R)],ze.prototype,"prompt_content_spriteFrame",void 0),te([Xe({type:k,tooltip:"确认按钮"}),se("design:type",k)],ze.prototype,"btn_confirm",void 0),te([Xe({type:I,tooltip:"确认按钮精灵图"}),se("design:type",I)],ze.prototype,"confirm_spriteFrame",void 0),te([Xe({type:k,tooltip:"取消按钮"}),se("design:type",k)],ze.prototype,"btn_cancel",void 0),te([Xe({type:I,tooltip:"取消按钮精灵图"}),se("design:type",I)],ze.prototype,"cancel_spriteFrame",void 0),te([Xe({type:k,tooltip:"关闭按钮"}),se("design:type",k)],ze.prototype,"btn_close",void 0),ze=te([Je("CoreUIModal")],ze),function(e){e[e.Delay=0]="Delay",e[e.Interval=1]="Interval"}(Ze||(Ze={}));class Ye{tag;type;callback;remainingTime;executionTime=0;initialTime;constructor(e,t,s,i){this.tag=e,this.type=t,this.remainingTime=s,this.initialTime=s,this.callback=i}}class et extends z{timers=new Map;lastUpdateTime=Date.now();constructor(e){super(e),e.event.on(me.EVENT_HIDE,this.onHandleAppBackground,this),e.event.on(me.EVENT_SHOW,this.onHandleAppForeground,this),setInterval(this.update.bind(this),1e3)}onHandleAppBackground(){this.lastUpdateTime=Date.now()}onHandleAppForeground(){const e=Date.now(),t=e-this.lastUpdateTime;r("elapsedTime",t);for(const e of this.timers.values())e.remainingTime>0&&(e.remainingTime-=t,e.executionTime+=t);this.lastUpdateTime=e}registerInterval(e,t,s){if(this.has(e))return i(`${e}定时器已存在,请勿重复注册`);const o=new Ye(e,Ze.Interval,t,s);this.timers.set(e,o)}registerDelay(e,t,s){if(this.has(e))return i(`${e}延时器已存在,请勿重复注册`);const o=new Ye(e,Ze.Delay,t,s);this.timers.set(e,o)}unregister(e){this.has(e)&&this.timers.delete(e)}has(e){return this.timers.has(e)}update(){const e=[];for(const[t,s]of this.timers.entries())s.remainingTime-=1e3,s.remainingTime<=0&&(s.type===Ze.Interval&&(s.executionTime+=s.initialTime),s.callback(s.executionTime),s.type===Ze.Interval?s.remainingTime=s.initialTime:e.push(t));for(const t of e)this.timers.delete(t)}}class tt{static#t;static get instance(){return this.#t||(this.#t=new tt),this.#t}onAppInitDelegate=new A;audio;event;gui;storage;res;util;gui_bundle_name="";audio_local_store_key="";setConfig=({gui_bundleName:e="resources",audio_local_store_key:t="game_audio"}={})=>(this.gui_bundle_name=e,this.audio_local_store_key=t,this);async boot(){this.res=new $e,this.util=new We(this),this.storage=new ee(this),this.event=new je,this.audio=new Y(this),this.gui=(await new Ge(this).init()).gui}}const st=tt.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]"),await st.boot(),await st.onAppInitDelegate.dispatch(),console.timeEnd("[Init App]")}));export{Z as AudioEventConstant,Y as AudioManager,le as AudioSourceBaseComponent,pe as AudioSourceUILayer,ce as AudioTypeEnum,ie as BaseComponent,z as BaseManager,Be as BasePrefab,Le as CoreBlackMask,Re as CoreNotice,Te as CoreReconnection,ke as CoreShowLoading,ge as CoreToast,Ee as CoreUIContainer,ze as CoreUIModal,We as CoreUtil,me as GlobalEventConstant,Ue as Gui,Ge as GuiManager,Fe as LayerType,tt as Manager,je as MessageManager,Se as ReconnectPrompt,be as RootUILayer,Ae as SceneLayer,et as TimerManager,_e as ToastType,ne as UILayer,Qe as WrapperSocialGameClient,st as cat};
|
|
1
|
+
import{AudioSource as t,_decorator as e,AudioClip as i,error as s,Node as o,director as n,log as r,sys as a,Component as c,Prefab as l,instantiate as h,isValid as p,Layers as d,view as u,Widget as _,v3 as m,tween as f,Enum as g,game as y,UITransform as v,UIOpacity as E,Tween as C,Label as b,BlockInputEvents as S,Button as w,Director as O,warn as A,assetManager as T,Asset as k,resources as I,Game as N,SpriteFrame as M,Sprite as x,AsyncDelegate as R}from"cc";import{PREVIEW as D,DEBUG as F}from"cc/env";import{makeObservable as U,observable as P,autorun as L,reaction as B}from"@shimotsuki/mobx";import H from"crypto-es";import{clone as G}from"@bufbuild/protobuf";import{SocketConnectStatus as $}from"pitayaclient";import{SocialGameClient as j}from"sgc";import{EventEmitter as K}from"eventemitter3";import"core-js/es/array/index.js";class V extends t{cat;initAudio(t){return this.cat=t,this}}const{ccclass:W,menu:Q}=e;class J extends V{effects=new Map;load(t){return new Promise(((e,s)=>{this.cat.res.load(t,i,((i,o)=>{if(i)return s(i);this.effects.set(t,o),this.playOneShot(o,this.volume),e(o)}))}))}release(){for(let t in this.effects)this.cat.res.release(t);this.effects.clear()}}const{ccclass:X,menu:q}=e;class z extends V{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(t){this._progress=t,this.currentTime=t*this.duration}load(t,e){this.cat.res.load(t,i,((i,o)=>{i&&s(i),this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=o,this._url=t,e&&e()}))}update(t){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class Z{cat;constructor(t){this.cat=t}}var Y;!function(t){t.MUSIC_ON="AudioEventConstant/MUSIC_ON",t.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",t.EFFECT_ON="AudioEventConstant/EFFECT_ON",t.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",t.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",t.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(Y||(Y={}));class tt extends Z{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(t){super(t),this.local_store_key=this.cat.audio_local_store_key;var e=new o("UIAudioManager");n.addPersistRootNode(e);var i=new o("UIMusic");i.parent=e,this.music=i.addComponent(z).initAudio(t);var s=new o("UIEffect");s.parent=e,this.effect=s.addComponent(J).initAudio(t),this.load()}setMusicComplete(t=null){this.music.onComplete=t}playMusic(t,e){this.music.loop=!0,t&&this.music.load(t,(()=>{this._switch_music&&this.music?.play(),e&&e()}))}stopMusic(){0!=this.music.state&&this.music?.stop()}pauseMusic(){1==this.music.state&&this.music?.pause()}resumeMusic(){[0,2].includes(this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(t){this.music.progress=t}get volumeMusic(){return this._volume_music}set volumeMusic(t){this._volume_music=t,this.music.volume=t}get switchMusic(){return this._switch_music}set switchMusic(t){if(r("设置背景音乐开关值",t,this._switch_music),t==this._switch_music)return;this._switch_music=t,t?this.resumeMusic():this.pauseMusic();const e=t?Y.MUSIC_ON:Y.MUSIC_OFF;this.cat.event.emit(e),this.save()}async playEffect(t){this._switch_effect&&t&&await this.effect.load(t).then((()=>{this.effect.play()}))}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(t){this._volume_effect=t,this.effect.volume=t}get switchEffect(){return this._switch_effect}set switchEffect(t){if(t==this._switch_effect)return;this._switch_effect=t,t?this.effect?.play():this.effect?.stop();const e=t?Y.EFFECT_ON:Y.EFFECT_OFF;this.cat.event.emit(e),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let t=JSON.stringify(this.local_data);return this.cat.storage.set(this.local_store_key,t),this}load(){try{let t=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(t),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(t){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}class et extends Z{_key=null;_iv=null;_id="";init(t,e){this.cat.util.encryptUtil.initCrypto(t,e),this._key=this.cat.util.encryptUtil.md5(t),this._iv=this.cat.util.encryptUtil.md5(e)}setUser(t){this._id=t}set(t,e){if(null!=(t=`${t}_${this._id}`)){if(D||(t=this.cat.util.encryptUtil.md5(t)),null==e)return console.warn("存储的值为空,则直接移除该存储"),void this.remove(t);if("function"!=typeof e){if("object"==typeof e)try{e=JSON.stringify(e)}catch(t){return void console.error(`解析失败,str = ${e}`)}else"number"==typeof e&&(e+="");D||null==this._key||null==this._iv||(e=this.cat.util.encryptUtil.aesEncrypt(`${e}`,this._key,this._iv)),a.localStorage.setItem(t,e)}else console.error("储存的值不能为方法")}else console.error("存储的key不能为空")}get(t,e){if(null==t)return console.error("存储的key不能为空"),null;t=`${t}_${this._id}`,D||(t=this.cat.util.encryptUtil.md5(t));let i=a.localStorage.getItem(t);return null==i||""===i||D||null==this._key||null==this._iv||(i=this.cat.util.encryptUtil.aesDecrypt(i,this._key,this._iv)),null===i?e:i}getNumber(t,e=0){var i=this.get(t);return Number(i)||e}getBoolean(t){var e=this.get(t);return Boolean(e)||!1}getJson(t,e){var i=this.get(t);return i&&JSON.parse(i)||e}remove(t){null!=t?(t=`${t}_${this._id}`,D||(t=this.cat.util.encryptUtil.md5(t)),a.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function it(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function st(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class ot extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),U(this,{props:P,data:P})}onAutoObserver(){}addAutorun(t){return(Array.isArray(t)?t:[t]).forEach((t=>{const e=L(t);this.autorunDisposers.push(e)})),this}addReaction(t,e,i){const s=B(t,e,i);return this.reactionDisposers.push(s),this}addAudoListener(t){return this.eventEmitter.includes(t)||t===pe.event||this.eventEmitter.push(t),t}_onPreDestroy(){this.autorunDisposers.forEach((t=>{t()})),this.reactionDisposers.forEach((t=>{t()})),this.autorunDisposers=[],this.reactionDisposers=[],super._onPreDestroy()}onDisable(){this.onHide(),this.deleteAllEventByEmitter(pe.event),this.eventEmitter.forEach((t=>{this.deleteAllEventByEmitter(t)})),this.eventEmitter=[],this.removeListener()}deleteAllEventByEmitter(t){const e=t._events;for(const i in e){let s=e[i];Array.isArray(s)||(s=[s]),s.forEach((e=>{e.context===this&&t.off(i,e.fn,this)}))}}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(t,e){let i=t instanceof l?h(t):t instanceof c?t.node:t;return this.setOptions(e),i.addChild(this.node),this}setOptions(t){if(t)for(let e in t)switch(e){case"hook":t.hook&&(this.hook=t.hook);break;case"props":null!==t.props&&"object"==typeof t.props&&(this.props=t.props);break;case"data":null!==t.data&&"object"==typeof t.data&&(this.data=t.data)}}setUpdateData(t){return t&&Object.assign(this.data,t),this}setUpdateProps(t){return this.props,t&&Object.assign(this.props,t),this}removeAndDestroy(){p(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(t){return this.node.setPosition(t),this}setScale(t){return this.node.setScale(t),this}setAngle(t){return this.node.angle=t,this}setRotation(t){return this.node.setRotation(t),this}setRotationFromEuler(t){return this.node.setRotationFromEuler(t),this}onShow(){}onHide(){}setNodeAndChildrenLayer(t){return nt(this.node,t),this}}const nt=(t,e)=>{t.layer="string"==typeof e?2**d.nameToLayer(e):e,t?.children.forEach((t=>{nt(t,e)}))};class rt extends ot{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=u.getVisibleSize()}async showTween({isMotion:t=!0,direction:e="center",duration:i=.1,isBounce:s=!0,bounceDuration:o=.05}){if(this.lastEnterDirection=e,t){const t=this.node.getComponent(_);let o,n;t&&(t.updateAlignment(),t.enabled=!1),m(1.1,1.1,1),"center"==e?(o=m(.01,.01,.01),n=m(1,1,1)):(o="left"==e?m(-this.screen.width,0,0):"right"==e?m(this.screen.width,0,0):m(0,"top"==e?this.screen.height:-this.screen.height,0),n=m(0,0,0)),await this.handle(e,i,o,n,s),t&&(t.enabled=!0)}}async hideTween({isMotion:t=!0,direction:e,duration:i=.1}){if(e=e||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,f(this.node).removeSelf(),t){const t=this.node.getComponent(_);let s,o;t&&(t.enabled=!1),"center"==e?(s=this.node.scale,o=m(0,0,0)):(o="left"==e?m(-this.screen.width,0,0):"right"==e?m(this.screen.width,0,0):m(0,"top"==e?this.screen.height:-this.screen.height,0),s=this.node.getPosition()),await this.handle(e,i,s,o,!1)}this.removeAndDestroy()}}async handle(t,e,i,s,o){"center"==t?this.node.setScale(i):this.node.setPosition(i),await this.deftween(e,{["center"==t?"scale":"position"]:s},o)}deftween(t,e,i,s){return new Promise(((i,s)=>{f(this.node).to(t,e).call((()=>{i()})).start()}))}}const{ccclass:at,property:ct}=e;var lt;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(lt||(lt={}));class ht extends ot{type=lt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,pe.event.on(Y.EFFECT_ON,this.onPlayEffectHandler,this).on(Y.EFFECT_OFF,this.onStopEffectHandler,this).on(Y.MUSIC_ON,this.onPlayMusicHandler,this).on(Y.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=pe.audio;this.audioSource.volume=this.type===lt.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=pe.audio;this.audioSource.playing||!(this.type===lt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}it([ct({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(lt)}),st("design:type",Object)],ht.prototype,"type",void 0),it([ct({tooltip:"音源",type:i}),st("design:type",Object)],ht.prototype,"clip",void 0),it([ct({tooltip:"循环"}),st("design:type",Object)],ht.prototype,"loop",void 0),it([ct({tooltip:"音量"}),st("design:type",Object)],ht.prototype,"volume",void 0),it([ct({tooltip:"是否启用自动播放"}),st("design:type",Object)],ht.prototype,"playOnAwake",void 0);const{ccclass:pt,property:dt}=e;class ut extends rt{type=lt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),pe.event.on(Y.EFFECT_ON,this.onPlayEffectHandler,this).on(Y.EFFECT_OFF,this.onStopEffectHandler,this).on(Y.MUSIC_ON,this.onPlayMusicHandler,this).on(Y.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:t,volumeMusic:e}=pe.audio;this.audioSource.volume=this.type===lt.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=pe.audio;this.audioSource.playing||!(this.type===lt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}it([dt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(lt)}),st("design:type",Object)],ut.prototype,"type",void 0),it([dt({tooltip:"音源",type:i}),st("design:type",Object)],ut.prototype,"clip",void 0),it([dt({tooltip:"循环"}),st("design:type",Object)],ut.prototype,"loop",void 0),it([dt({tooltip:"音量"}),st("design:type",Object)],ut.prototype,"volume",void 0),it([dt({tooltip:"是否启用自动播放"}),st("design:type",Object)],ut.prototype,"playOnAwake",void 0);const{ccclass:_t,property:mt,menu:ft}=e;var gt;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(gt||(gt={}));let yt=class extends ot{fixed_node;slide_node;fixed_label;slide_label;onLoad(){this.fixed_node.active=this.slide_node.active=!1}start(){this.show()}async show(){return new Promise((async(t,e)=>{const{title:i,type:s,fixed_time:o}=this.props;if(s==gt.FIXED){this.fixed_node.active=!0,this.fixed_label.string=`${i}`,this.fixed_label.updateRenderData(!0);const e=this.fixed_label.node.getComponent(v).height;e-this.fixed_node.getComponent(v).height>0&&(this.fixed_node.getComponent(v).height=e+100),this.scheduleOnce((()=>{this.node.destroy(),t()}),o)}else{this.slide_node.active=!0,this.slide_label.string=`${i}`,this.slide_label.updateRenderData(!0);const e=this.slide_label.node.getComponent(v).width;this.slide_node.getComponent(v).width-e<100&&(this.slide_node.getComponent(v).width=e+100),this.playAnim(this.node).then((()=>{t()}))}}))}playAnim(t){return new Promise(((e,i)=>{const s=this.node.getComponent(E),o=f(s).delay(1.2).to(.5,{opacity:0}).call((()=>{C.stopAllByTarget(t),this.node.destroy(),e()}));f(t).by(.5,{position:m(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){C.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var vt;it([mt({type:o,tooltip:"固定节点"}),st("design:type",o)],yt.prototype,"fixed_node",void 0),it([mt({type:o,tooltip:"滑动节点"}),st("design:type",o)],yt.prototype,"slide_node",void 0),it([mt({type:b,tooltip:"固定标签节点"}),st("design:type",b)],yt.prototype,"fixed_label",void 0),it([mt({type:b,tooltip:"滑动标签节点"}),st("design:type",b)],yt.prototype,"slide_label",void 0),yt=it([_t("CoreToast"),ft("CATCORE/CoreToast")],yt),function(t){t.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",t.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",t.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",t.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",t.ONLINE="GlobalEventConstant/ONLINE",t.OFFLINE="GlobalEventConstant/OFFLINE",t.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",t.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(vt||(vt={}));const{ccclass:Et,property:Ct,menu:bt}=e;let St=class extends rt{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Qt)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){pe.event.on(vt.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const t=this.brother[this.brother.length-1];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const t=this.brother[this.brother.length-2];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(t){return p(this)&&this.scene_mask&&this.scene_mask.tween.addChild(t),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(t){return this.gui=t,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(t){this.scene_mask.node.active=t}};it([Ct({type:o}),st("design:type",o)],St.prototype,"scene_mask_node",void 0),it([Ct({type:o}),st("design:type",o)],St.prototype,"ui_container",void 0),St=it([Et("CoreUIContainer"),bt("CATCORE/CoreUIContainer")],St);class wt extends rt{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){pe.event.emit(vt.ROOT_MASK_UPDATE)}}const{ccclass:Ot,property:At,menu:Tt}=e;let kt=class extends wt{title;loadingTween;loading_rotate=0;onAutoObserver(){this.addAutorun([()=>{this.props?.title&&(this.title.string=`${this.props?.title}`),this.title.node.active=!!this.props?.title?.length},()=>{this.getComponent(S).enabled=!!this.props?.mask}])}update(t){this.loading_rotate+=220*t,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};it([At({type:b,tooltip:"标题"}),st("design:type",b)],kt.prototype,"title",void 0),it([At({type:o,tooltip:"动画"}),st("design:type",o)],kt.prototype,"loadingTween",void 0),kt=it([Ot("CoreShowLoading"),Tt("CATCORE/CoreShowLoading")],kt);const{ccclass:It,property:Nt,menu:Mt}=e;var xt;!function(t){t.RECONNECTED="重连成功",t.RECONNECTING="正在重连",t.MAX_RECONNECT="重连次数超出限制,请检查网络",t.RECONNECTED_ERROR="重连失败,请检查网络",t.CONNECT_PARAM_ERROR="游戏参数错误,请重新加载",t.KICK="账号已下线",t.OFFLINE="网络已断开",t.ONLINE="网络已连接",t.GAME_ERROR="连接游戏服错误"}(xt||(xt={}));let Rt=class extends wt{common_prompt_text;btn_confirm;is_close=!1;props={content:null};initUI(){this.btn_confirm.node.active=!1}onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.addAutorun([()=>{this.common_prompt_text.string=this.props.content??""}])}onDestroy(){this.unscheduleAllCallbacks()}updateProps(t){this.updatePromptText(t,t==xt.RECONNECTING)}updatePromptText(t,e=!1){if(this.unscheduleAllCallbacks(),this.props.content=t,r("更新提示文案:",t),e){let e=0;const i=()=>{e=(e+1)%4,this.common_prompt_text.string=t+["","·","··","···"][e]};this.schedule(i,.5)}}onConfirmHandler(){this.is_close=!0,pe.gui.hideReconnect()}};it([Nt({type:b,tooltip:"通用提示文本"}),st("design:type",b)],Rt.prototype,"common_prompt_text",void 0),it([Nt({type:w,tooltip:"确定按钮"}),st("design:type",w)],Rt.prototype,"btn_confirm",void 0),Rt=it([It("CoreReconnection"),Mt("CATCORE/CoreReconnection")],Rt);const{ccclass:Dt,property:Ft,menu:Ut}=e;let Pt=class extends wt{text;btn_confirm;onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),pe.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};it([Ft({type:b,tooltip:"提示文本"}),st("design:type",b)],Pt.prototype,"text",void 0),it([Ft({type:w,tooltip:"确定按钮"}),st("design:type",w)],Pt.prototype,"btn_confirm",void 0),Pt=it([Dt("CoreNotice"),Ut("CATCORE/CoreNotice")],Pt);class Lt extends ot{isReload}const{ccclass:Bt,property:Ht,menu:Gt}=e;var $t;!function(t){t[t.UI=0]="UI",t[t.LOADING=1]="LOADING",t[t.TOAST=2]="TOAST",t[t.RECONNECTTION=3]="RECONNECTTION",t[t.NOTICE=4]="NOTICE"}($t||($t={}));let jt=class extends ot{reconnection_ui_prefab;toast_ui_prefab;loading_ui_prefab;notice_ui_prefab;ui_prefab;root_ui;root_toast;root_mask;cat;ui_container_component;reconnection_ui_component;notice_ui_component;loading_ui_component;toast_ui_component;currentScene;onEventListener(){this.cat.event.on(vt.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(t){this.cat=t;const e=n.getScene();return r("init scene"),e&&this.changeScene(e),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(t){this.toastQueue.push(t),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const t=this.toastQueue.shift(),e=()=>{h(this.toast_ui_prefab).getComponent(yt).addToParent(this.root_toast,{props:t}),this.scheduleOnce((()=>{this.processQueueWithInterval()}),this.minInterval)};0===this.root_toast.children.length?e():this.scheduleOnce(e,this.minInterval)}hideToast(){return this.root_toast&&this.root_toast.children.forEach((t=>{t.getComponent(yt)?.removeAndDestroy()})),this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading({title:t="",mask:e=!0,black:i=!0}={}){if(r("showLoading",t),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:t,mask:e,black:i}});else{const s=h(this.loading_ui_prefab);this.loading_ui_component=s.getComponent(kt).addToParent(this.root_ui,{props:{title:t,mask:e,black:i}})}return this}hideLoading(){return this.loading_ui_component?.removeAndDestroy(),this.loading_ui_component=null,this}showReconnect(t){if(this.reconnection_ui_component)this.reconnection_ui_component.setUpdateProps({content:t});else{const e=h(this.reconnection_ui_prefab);this.reconnection_ui_component=e.getComponent(Rt).addToParent(this.root_ui,{props:{content:t}})}return this}hideReconnect(){return this.reconnection_ui_component?.removeAndDestroy(),this.reconnection_ui_component=null,this}showNotice(t){const e=h(this.notice_ui_prefab);return this.notice_ui_component=e.getComponent(Pt).addToParent(this.root_ui,{props:t}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}loadScene(t,e,i){r("加载场景",t,e,i);let s={},o=i??!1;return"boolean"==typeof e?o=e:s=e??{},r("当前场景",n.getScene()?.uuid,n.getScene()?.name),n.once(O.EVENT_BEFORE_SCENE_LAUNCH,(t=>{r("Director.EVENT_BEFORE_SCENE_LAUNCH",t),this.changeScene(t,s,o)})),n.loadScene(t),this}resetScene(t=""){return t=t||this.currentScene,this.loadScene(t)}cleanScene(){this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast()}changeScene(t,e,i){this.currentScene=t.name,this.createUILayer(t);const s=t.getComponentInChildren(Lt);s&&(s.isReload=i??!1),s?.setOptions(e)}createUILayer(t){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const e=h(this.ui_prefab);this.ui_container_component=e.getComponent(St).setGui(this).addToParent(t)}reloadScene(){this.loadScene(this.currentScene,!0)}async closeUI(t,e){const{component:i}=this.findUIBaseLayer(t,!1);i&&(i.setOptions({...e?.hook??{},...e?.props??{}}),await i.hideTween(e||{}),this.ui_container_component?.subMask())}async openUI(t,e){const{rootNode:i,component:s}=this.findUIBaseLayer(t,!0);i.getComponent(rt),s?.setOptions(e),i&&this.ui_container_component?.addNodeToTween(i).addMask(),s&&await s.showTween(e||{}),this.ui_container_component?.ui_container&&s?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(t,e){let i,n=null;if(t instanceof o){i=t;const e=t.components.filter((t=>t instanceof rt));if(!e.length)return s(`${t.name}节点未找到继承自BaseLayer的组件`),{rootNode:i,component:n};1==e.length?n=e[0]:A(`${t.name}节点存在多个继承自BaseLayer的组件`)}else if(i=t.node,n=t,e){for(;i.parent;)i=i.parent;n.root=i}else i=t.root;return{rootNode:i,component:n}}onRootUpdate(){const t=this.root_ui.children.findLastIndex((t=>t.active&&t!=this.root_mask));if(this.root_mask.active=-1!=t,t>-1){const e=this.root_ui.children[t];this.root_mask.setSiblingIndex(e.getSiblingIndex()-1)}this.cat.event.emit(vt.ROOT_MASK_CHANGE)}};it([Ht({type:l,tooltip:"断线重连UI预制体"}),st("design:type",l)],jt.prototype,"reconnection_ui_prefab",void 0),it([Ht({type:l,tooltip:"提示UI预制体"}),st("design:type",l)],jt.prototype,"toast_ui_prefab",void 0),it([Ht({type:l,tooltip:"加载UI预制体"}),st("design:type",l)],jt.prototype,"loading_ui_prefab",void 0),it([Ht({type:l,tooltip:"公告UI预制体"}),st("design:type",l)],jt.prototype,"notice_ui_prefab",void 0),it([Ht({type:l,tooltip:"UI层预制体"}),st("design:type",l)],jt.prototype,"ui_prefab",void 0),it([Ht({type:o,tooltip:"root-UI层"}),st("design:type",o)],jt.prototype,"root_ui",void 0),it([Ht({type:o,tooltip:"root-组件层"}),st("design:type",o)],jt.prototype,"root_toast",void 0),it([Ht({type:o,tooltip:"root-mask"}),st("design:type",o)],jt.prototype,"root_mask",void 0),jt=it([Bt("Gui"),Gt("CATCORE/Gui")],jt);const{ccclass:Kt,property:Vt,menu:Wt}=e;let Qt=class extends ot{tween};var Jt;it([Vt({type:o,tooltip:"动画节点"}),st("design:type",o)],Qt.prototype,"tween",void 0),Qt=it([Kt("CoreBlackMask"),Wt("CATCORE/CoreBlackMask")],Qt),function(t){t.Root="prefabs/root",t.Toast="prefabs/toast",t.BlackMask="prefabs/black-mask",t.Loading="prefabs/loading",t.Notice="prefabs/notice",t.Reconnection="prefabs/reconnection"}(Jt||(Jt={}));class Xt extends Z{gui;#t="resources";getGuiPrefabByType=(t,e)=>new Promise(((i,s)=>{console.log(t,`${e}`),this.cat.res.load(t,e,((t,e)=>{t?s(t):i(e)}))}));async init(){this.#t=this.cat.gui_bundle_name;const t=await this.getGuiPrefabByType(this.#t,Jt.Root),e=h(t);return this.gui=e.getComponent(jt).init(this.cat),n.addPersistRootNode(e),this}}class qt{get=(t,e,i="resources")=>T.getBundle(i).get(t,e);isAssetType=t=>"function"==typeof t&&t.prototype instanceof k;async load(...t){let e=null,i=null,s=null;"string"==typeof t[0]&&"string"==typeof t[1]&&(e=t.shift());let o=t.shift();this.isAssetType(t[0])&&(i=t.shift()),2==t.length&&(s=t.shift());const n=t.shift();let r=I;if(e&&"resources"!=e){T.bundles.has(e)||await this.loadBundle(e);let t=T.bundles.get(e);t&&(r=t)}s&&n?r.load(o,i,s,n):n?r.load(o,i,n):r.load(o,i)}async loadDir(...t){let e=null,i=null,s=null,o=null;"string"==typeof t[0]&&"string"==typeof t[1]&&(e=t.shift());let n=t.shift();this.isAssetType(t[0])&&(i=t.shift()),2==t.length&&(s=t.shift()),o=t.shift();let r=I;if(e&&"resources"!=e){T.bundles.has(e)||await this.loadBundle(e);let t=T.bundles.get(e);t&&(r=t)}s&&o?r.loadDir(n,i,s,o):o?r.loadDir(n,i,o):r.loadDir(n,i)}loadRemote(t,...e){var i,s=null;2==e.length&&(s=e.shift()),i=e.shift(),T.loadRemote(t,{ext:".png",...s},i)}loadBundle=(t,e)=>new Promise(((i,s)=>{const o=(t,e)=>{if(t)return s(t);i(e)};e?T.loadBundle(t,{version:e},o):T.loadBundle(t,o)}));releasePrefabtDepsRecursively=t=>{var e=T.assets.get(t);(T.releaseAsset(e),e instanceof l)&&T.dependUtil.getDepsRecursively(t).forEach((t=>{T.assets.get(t).decRef()}))};release=(t,e="resources")=>{var i=T.getBundle(e);if(i){var s=i.get(t);s&&this.releasePrefabtDepsRecursively(s._uuid)}};releaseDir=(t,e="resources")=>{var i=T.getBundle(e),s=i?.getDirWithPath(t);s?.map((t=>{this.releasePrefabtDepsRecursively(t.uuid)})),!t&&"resources"!=e&&i&&T.removeBundle(i)};dump=()=>{T.assets.forEach(((t,e)=>{r(T.assets.get(e))})),r(`当前资源总数:${T.assets.count}`)}}let zt=null;const Zt={stringify:t=>{const e={ct:t.ciphertext.toString(H.enc.Base64)};return t.iv&&(e.iv=t.iv.toString()),t.salt&&(e.s=t.salt.toString()),JSON.stringify(e)},parse:t=>{const e=JSON.parse(t),i=H.lib.CipherParams.create({ciphertext:H.enc.Base64.parse(e.ct)});return e.iv&&(i.iv=H.enc.Hex.parse(e.iv)),e.s&&(i.salt=H.enc.Hex.parse(e.s)),i}};var Yt=Object.freeze({__proto__:null,JsonFormatter:Zt,aesDecrypt:(t,e,i)=>H.AES.decrypt(t,e,{iv:zt,format:Zt}).toString(H.enc.Utf8),aesEncrypt:(t,e,i)=>H.AES.encrypt(t,e,{iv:zt,format:Zt}).toString(),initCrypto:(t,e)=>{zt=H.enc.Hex.parse(e)},md5:t=>H.MD5(t).toString()});class te extends Z{encryptUtil=Yt}class ee extends j{logBlackList=[];ignore=t=>this.logBlackList.includes(t);constructor(t,e,i,s){super(e,i,s),this.name=t}destroy(){this.disconnect(!0),pe.socialGameClient.unregister(this)}async GameRequest(t,e,i,s){return new Promise(((o,n)=>{super.GameRequest(t,e,i,s).then((e=>{F&&r(`%c ws服务端消息 %c [Response][${new Date}] %c ${t} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(i,e)),o(e)}),(t=>{pe.gui.showToast({title:t.msg}),n(t)}))}))}subscribe(t,e,i){return super.subscribe(t,e,(s=>{F&&!this.ignore(t)&&r(`%c ws服务端消息:[${new Date}] %c ${t} %c`,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#410083 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(e,s)),pe.event.emit(t,G(e,s)),i?.(s)})),this}}class ie extends Z{managedClients=new Map;isGlobalOnline=!0;isInBackground=!1;get activeClients(){return Array.from(this.managedClients).map((([t,e])=>e)).filter((t=>t.socket))}constructor(t){super(t),this.initGlobalListeners()}createWebSocket(t,e,i,s){if(this.managedClients.has(t)){this.managedClients.get(t).destroy(),r(`清理旧的 ${t} 客户端`)}const o=new ee(t,i,s,Object.assign({reconnectMaxAttempts:1/0},{...e,isAutoConnect:!1}));return this.register(o),o}register(t){t.on("reconnected",this.handleSingleReconnect),this.managedClients.set(t.name,t)}unregister(t){t.off("reconnected",this.handleSingleReconnect),this.managedClients.delete(t.name)}initGlobalListeners(){this.cat.event.on(vt.ONLINE,(()=>this.handleGlobalStateChange("online")),this).on(vt.OFFLINE,(()=>this.handleGlobalStateChange("offline")),this),y.on(N.EVENT_SHOW,(()=>this.handleGlobalStateChange("show"))),y.on(N.EVENT_HIDE,(()=>this.handleGlobalStateChange("hide")))}handleGlobalStateChange(t){switch(t){case"online":this.isGlobalOnline=!0,this.triggerReconnectAll();break;case"offline":this.isGlobalOnline=!1,this.disconnectAll(!0);break;case"show":this.isInBackground=!1,this.triggerReconnectAll();break;case"hide":this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(!this.isGlobalOnline||this.isInBackground)return;if(0===this.managedClients.size)return void console.log("没有任何WS需要重连");pe.gui.showLoading({title:"正在重连"}),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.reconnectPromise()}catch(e){s(`${t.name}服重连失败`,e),pe.gui.showToast({title:`${t.name}服重连失败`})}try{await t.connectRequest()}catch(e){s(`${t.name}服登录错误`,e),pe.gui.showToast({title:`登录${t.name}服错误`})}})));const t=this.activeClients.filter((t=>t.socketConnectStatus!==$.CONNECTED));t.length>0&&(console.error("部分WS重连失败:",t.map((t=>t))),setTimeout((()=>{this.triggerReconnectAll()}),2e3))}disconnectAll(t){this.managedClients.forEach((e=>{console.log("断开连接",e.name,t,e.socket),e.disconnect(t)}))}handleSingleReconnect=()=>{this.activeClients.every((t=>t.socketConnectStatus===$.CONNECTED))&&(console.log("单个WS重连成功回调===",this.managedClients),pe.gui.hideLoading().reloadScene())}}const{ccclass:se,property:oe,menu:ne}=e;let re=class extends rt{default_title=null;title;prompt_content_str;prompt_content_spriteFrame;btn_confirm;confirm_spriteFrame;btn_cancel;cancel_spriteFrame;btn_close;isConfirm=!1;props={title:this.default_title,content:null,confirmCB:()=>{},cancelCB:()=>{},style:null};onLoad(){this.btn_cancel.node.on(w.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(w.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content instanceof M?this.prompt_content_spriteFrame.spriteFrame=this.props.content:"string"==typeof this.props.content?this.prompt_content_str.string=this.props.content:console.error("未知类型的【UIModal】内容")},()=>{null===this.props?.style?.confirm?this.btn_confirm.node.active=!1:(this.btn_confirm.node.active=!0,this.btn_confirm.getComponent(x).spriteFrame=this.props.style?.confirm||this.confirm_spriteFrame),null===this.props?.style?.cancel?this.btn_cancel.node.active=!1:(this.btn_cancel.node.active=!0,this.btn_cancel.getComponent(x).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),pe.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var ae;it([oe({type:M,tooltip:"默认标题"}),st("design:type",M)],re.prototype,"default_title",void 0),it([oe({type:x,tooltip:"标题节点"}),st("design:type",x)],re.prototype,"title",void 0),it([oe({type:b,tooltip:"字符串内容按钮"}),st("design:type",b)],re.prototype,"prompt_content_str",void 0),it([oe({type:x,tooltip:"图片精灵内容按钮"}),st("design:type",x)],re.prototype,"prompt_content_spriteFrame",void 0),it([oe({type:w,tooltip:"确认按钮"}),st("design:type",w)],re.prototype,"btn_confirm",void 0),it([oe({type:M,tooltip:"确认按钮精灵图"}),st("design:type",M)],re.prototype,"confirm_spriteFrame",void 0),it([oe({type:w,tooltip:"取消按钮"}),st("design:type",w)],re.prototype,"btn_cancel",void 0),it([oe({type:M,tooltip:"取消按钮精灵图"}),st("design:type",M)],re.prototype,"cancel_spriteFrame",void 0),it([oe({type:w,tooltip:"关闭按钮"}),st("design:type",w)],re.prototype,"btn_close",void 0),re=it([se("CoreUIModal"),ne("CATCORE/CoreUIModal")],re),function(t){t[t.Delay=0]="Delay",t[t.Interval=1]="Interval"}(ae||(ae={}));class ce{tag;type;callback;remainingTime;executionTime=0;initialTime;constructor(t,e,i,s){this.tag=t,this.type=e,this.remainingTime=i,this.initialTime=i,this.callback=s}}class le extends Z{timers=new Map;lastUpdateTime=Date.now();constructor(t){super(t),t.event.on(vt.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(vt.EVENT_SHOW,this.onHandleAppForeground,this),setInterval(this.update.bind(this),1e3)}onHandleAppBackground(){this.lastUpdateTime=Date.now()}onHandleAppForeground(){const t=Date.now(),e=t-this.lastUpdateTime;r("elapsedTime",e);for(const t of this.timers.values())t.remainingTime>0&&(t.remainingTime-=e,t.executionTime+=e);this.lastUpdateTime=t}registerInterval(t,e,i){if(this.has(t))return s(`${t}定时器已存在,请勿重复注册`);const o=new ce(t,ae.Interval,e,i);this.timers.set(t,o)}registerDelay(t,e,i){if(this.has(t))return s(`${t}延时器已存在,请勿重复注册`);const o=new ce(t,ae.Delay,e,i);this.timers.set(t,o)}unregister(t){this.has(t)&&this.timers.delete(t)}has(t){return this.timers.has(t)}update(){const t=[];for(const[e,i]of this.timers.entries())i.remainingTime-=1e3,i.remainingTime<=0&&(i.type===ae.Interval&&(i.executionTime+=i.initialTime),i.callback(i.executionTime),i.type===ae.Interval?i.remainingTime=i.initialTime:t.push(e));for(const e of t)this.timers.delete(e)}}class he{static#e;static get instance(){return this.#e||(this.#e=new he),this.#e}onAppInitDelegate=new R;audio;event;gui;storage;res;util;socialGameClient;gui_bundle_name="";audio_local_store_key="";setConfig=({gui_bundleName:t="resources",audio_local_store_key:e="game_audio"}={})=>(this.gui_bundle_name=t,this.audio_local_store_key=e,this);async boot(){this.res=new qt,this.util=new te(this),this.storage=new et(this),this.event=new K,this.audio=new tt(this),this.socialGameClient=new ie(this),this.gui=(await new Xt(this).init()).gui}}const pe=he.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]"),await pe.boot(),await pe.onAppInitDelegate.dispatch(),console.timeEnd("[Init App]")}));export{Y as AudioEventConstant,tt as AudioManager,ht as AudioSourceBaseComponent,ut as AudioSourceUILayer,lt as AudioTypeEnum,ot as BaseComponent,Z as BaseManager,Jt as BasePrefab,Qt as CoreBlackMask,Pt as CoreNotice,Rt as CoreReconnection,kt as CoreShowLoading,yt as CoreToast,St as CoreUIContainer,re as CoreUIModal,te as CoreUtil,vt as GlobalEventConstant,jt as Gui,Xt as GuiManager,$t as LayerType,he as Manager,xt as ReconnectPrompt,wt as RootUILayer,Lt as SceneLayer,le as TimerManager,gt as ToastType,rt as UILayer,ee as WrapperSocialGameClient,pe as cat};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shimotsuki/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@bufbuild/protobuf": "^2.
|
|
27
|
+
"@bufbuild/protobuf": "^2.2.5",
|
|
28
28
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
29
29
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
30
30
|
"@shimotsuki/mobx": "^1.0.1",
|
|
31
31
|
"core-js": "^3.41.0",
|
|
32
32
|
"crypto-es": "^2.1.0",
|
|
33
|
+
"eventemitter3": "^5.0.1",
|
|
33
34
|
"rollup": "^4.18.1",
|
|
34
35
|
"rollup-plugin-copy": "^3.5.0",
|
|
35
36
|
"rollup-plugin-dts": "^6.1.1",
|