@shimotsuki/core 1.0.14 → 1.0.16
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 +103 -64
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ declare class AudioManager extends BaseManager {
|
|
|
25
25
|
private effect;
|
|
26
26
|
private _volume_music;
|
|
27
27
|
private _volume_effect;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
_switch_music: boolean;
|
|
29
|
+
_switch_effect: boolean;
|
|
30
30
|
constructor(cat: Manager);
|
|
31
31
|
/**
|
|
32
32
|
* 设置背景音乐播放完成回调
|
|
@@ -111,6 +111,16 @@ declare class AudioManager extends BaseManager {
|
|
|
111
111
|
protected save(): void;
|
|
112
112
|
/** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */
|
|
113
113
|
protected load(): void;
|
|
114
|
+
/**autorun销毁 */
|
|
115
|
+
private autorunDisposers;
|
|
116
|
+
/**reaction销毁 */
|
|
117
|
+
private reactionDisposers;
|
|
118
|
+
/**添加自动收集 */
|
|
119
|
+
protected addAutorun(cb: (() => void) | (() => void)[]): this;
|
|
120
|
+
/**添加自动收集 */
|
|
121
|
+
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;
|
|
122
|
+
removeAutorun(): void;
|
|
123
|
+
removeReaction(): void;
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
/**
|
|
@@ -164,6 +174,63 @@ declare class StorageManager extends BaseManager {
|
|
|
164
174
|
clear(): void;
|
|
165
175
|
}
|
|
166
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @describe 事件消息管理
|
|
179
|
+
* @author 游金宇(KM)
|
|
180
|
+
* @date 2023-08-03 18:15:38
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
type ListenerFunc = (data: any, event: string | number) => void;
|
|
184
|
+
type EventKeyType = string | number;
|
|
185
|
+
interface EventBase {
|
|
186
|
+
/**注册事件 */
|
|
187
|
+
on(event: string, listener: ListenerFunc, obj: object): void;
|
|
188
|
+
/**取消所有事件 */
|
|
189
|
+
offAll(): void;
|
|
190
|
+
/**注册单次触发事件 */
|
|
191
|
+
once(event: string, listener: ListenerFunc, obj: object): void;
|
|
192
|
+
/**取消单个事件 */
|
|
193
|
+
off(event: string, listener: Function, obj: object): void;
|
|
194
|
+
/**调用事件 */
|
|
195
|
+
dispatchEvent<T>(event: string, args: Record<string, T>): void;
|
|
196
|
+
}
|
|
197
|
+
declare class MessageManager implements EventBase {
|
|
198
|
+
private events;
|
|
199
|
+
/**
|
|
200
|
+
* 注册全局事件
|
|
201
|
+
* @param event 事件名
|
|
202
|
+
* @param listener 处理事件的侦听器函数
|
|
203
|
+
* @param obj 侦听函数绑定的作用域对象
|
|
204
|
+
*/
|
|
205
|
+
on<T extends EventKeyType>(event: T, listener: ListenerFunc | null, obj: object): this;
|
|
206
|
+
/**
|
|
207
|
+
* 监听一次事件,事件响应后,该监听自动移除
|
|
208
|
+
* @param event 事件名
|
|
209
|
+
* @param listener 事件触发回调方法
|
|
210
|
+
* @param obj 侦听函数绑定的作用域对象
|
|
211
|
+
*/
|
|
212
|
+
once<T extends EventKeyType>(event: T, listener: ListenerFunc, obj: object | Symbol): void;
|
|
213
|
+
/**
|
|
214
|
+
* 移除单个事件
|
|
215
|
+
* @param event 事件名
|
|
216
|
+
* @param listener 处理事件的侦听器函数
|
|
217
|
+
* @param obj 侦听函数绑定的作用域对象
|
|
218
|
+
*/
|
|
219
|
+
off<T extends EventKeyType>(event: T, listener: Function | null, obj: object): this;
|
|
220
|
+
/**
|
|
221
|
+
* 触发全局事件
|
|
222
|
+
* @param event(string) 事件名
|
|
223
|
+
* @param args(any) 事件参数
|
|
224
|
+
*/
|
|
225
|
+
dispatchEvent<T extends EventKeyType>(event: T, args?: any): this;
|
|
226
|
+
/**移除所有事件 */
|
|
227
|
+
offAll(): void;
|
|
228
|
+
/**是否存在事件 */
|
|
229
|
+
has(event: EventKeyType): boolean;
|
|
230
|
+
/**删除事件通过组件 */
|
|
231
|
+
deleteEventByComponent(component: Component): void;
|
|
232
|
+
}
|
|
233
|
+
|
|
167
234
|
/**
|
|
168
235
|
* @describe 组件基类
|
|
169
236
|
* @author 游金宇(KM)
|
|
@@ -182,6 +249,36 @@ interface IUIOption<T extends object = {}, U extends object = {}> {
|
|
|
182
249
|
/**钩子 */
|
|
183
250
|
hook?: HOOK;
|
|
184
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* left 从左往右
|
|
254
|
+
* right 从右往左
|
|
255
|
+
* top 从上往下
|
|
256
|
+
* bot 从下往上
|
|
257
|
+
* center 中间
|
|
258
|
+
*/
|
|
259
|
+
type IDirection$1 = 'left' | 'right' | 'top' | 'bot' | 'center';
|
|
260
|
+
/**开启动画参数选项 */
|
|
261
|
+
interface IOpenOptions$1<T extends object = {}, U extends object = {}> extends IUIOption<T, U> {
|
|
262
|
+
/**动画 */
|
|
263
|
+
isMotion?: boolean;
|
|
264
|
+
/**动画时间 */
|
|
265
|
+
duration?: number;
|
|
266
|
+
/**方向 */
|
|
267
|
+
direction?: IDirection$1;
|
|
268
|
+
/**是否回弹 */
|
|
269
|
+
isBounce?: boolean;
|
|
270
|
+
/**回弹时间 */
|
|
271
|
+
bounceDuration?: number;
|
|
272
|
+
}
|
|
273
|
+
/**关闭动画参数选项 */
|
|
274
|
+
interface ICloseOptions$1<T extends object = {}, U extends object = {}> extends IUIOption<T, U> {
|
|
275
|
+
/**动画 */
|
|
276
|
+
isMotion?: boolean;
|
|
277
|
+
/**动画时间 */
|
|
278
|
+
duration?: number;
|
|
279
|
+
/**方向 */
|
|
280
|
+
direction?: IDirection$1;
|
|
281
|
+
}
|
|
185
282
|
/**参数 */
|
|
186
283
|
declare class BaseComponent<T extends object = {}, K extends object = {}> extends Component {
|
|
187
284
|
/**组件(传值)属性 */
|
|
@@ -192,11 +289,10 @@ declare class BaseComponent<T extends object = {}, K extends object = {}> extend
|
|
|
192
289
|
private autorunDisposers;
|
|
193
290
|
/**reaction销毁 */
|
|
194
291
|
private reactionDisposers;
|
|
292
|
+
private messageManagers;
|
|
195
293
|
hook: HOOK;
|
|
196
294
|
/**初始化UI(可在本函数中进行节点赋值或注册节点事件等...) */
|
|
197
295
|
protected initUI(): void;
|
|
198
|
-
/**添加到父节点(动画结束) */
|
|
199
|
-
protected added(): void;
|
|
200
296
|
protected __preload(): void;
|
|
201
297
|
constructor();
|
|
202
298
|
/**依赖收集生命周期(可以在该生命周期中注册依赖收集回调) */
|
|
@@ -205,10 +301,11 @@ declare class BaseComponent<T extends object = {}, K extends object = {}> extend
|
|
|
205
301
|
protected addAutorun(cb: (() => void) | (() => void)[]): this;
|
|
206
302
|
/**添加自动收集 */
|
|
207
303
|
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;
|
|
304
|
+
protected addAudoListener(messageManager: MessageManager): MessageManager;
|
|
208
305
|
_onPreDestroy(): void;
|
|
209
306
|
protected onDisable(): void;
|
|
210
307
|
protected onEnable(): void;
|
|
211
|
-
/**子类继承该方法(注册在components上的事件可以不添加取消监听(自动取消监听了)) */
|
|
308
|
+
/**子类继承该方法(全局事件(cat.event)注册在components上的事件可以不添加取消监听(自动取消监听了)) */
|
|
212
309
|
protected onEventListener(): void;
|
|
213
310
|
/**子类继承该方法 */
|
|
214
311
|
protected addListener(): void;
|
|
@@ -709,63 +806,6 @@ declare class ResLoader {
|
|
|
709
806
|
dump: () => void;
|
|
710
807
|
}
|
|
711
808
|
|
|
712
|
-
/**
|
|
713
|
-
* @describe 事件消息管理
|
|
714
|
-
* @author 游金宇(KM)
|
|
715
|
-
* @date 2023-08-03 18:15:38
|
|
716
|
-
*/
|
|
717
|
-
|
|
718
|
-
type ListenerFunc = (data: any, event: string | number) => void;
|
|
719
|
-
type EventKeyType = string | number;
|
|
720
|
-
interface EventBase {
|
|
721
|
-
/**注册事件 */
|
|
722
|
-
on(event: string, listener: ListenerFunc, obj: object): void;
|
|
723
|
-
/**取消所有事件 */
|
|
724
|
-
offAll(): void;
|
|
725
|
-
/**注册单次触发事件 */
|
|
726
|
-
once(event: string, listener: ListenerFunc, obj: object): void;
|
|
727
|
-
/**取消单个事件 */
|
|
728
|
-
off(event: string, listener: Function, obj: object): void;
|
|
729
|
-
/**调用事件 */
|
|
730
|
-
dispatchEvent<T>(event: string, args: Record<string, T>): void;
|
|
731
|
-
}
|
|
732
|
-
declare class MessageManager implements EventBase {
|
|
733
|
-
private events;
|
|
734
|
-
/**
|
|
735
|
-
* 注册全局事件
|
|
736
|
-
* @param event 事件名
|
|
737
|
-
* @param listener 处理事件的侦听器函数
|
|
738
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
739
|
-
*/
|
|
740
|
-
on<T extends EventKeyType>(event: T, listener: ListenerFunc | null, obj: object): this;
|
|
741
|
-
/**
|
|
742
|
-
* 监听一次事件,事件响应后,该监听自动移除
|
|
743
|
-
* @param event 事件名
|
|
744
|
-
* @param listener 事件触发回调方法
|
|
745
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
746
|
-
*/
|
|
747
|
-
once<T extends EventKeyType>(event: T, listener: ListenerFunc, obj: object | Symbol): void;
|
|
748
|
-
/**
|
|
749
|
-
* 移除单个事件
|
|
750
|
-
* @param event 事件名
|
|
751
|
-
* @param listener 处理事件的侦听器函数
|
|
752
|
-
* @param obj 侦听函数绑定的作用域对象
|
|
753
|
-
*/
|
|
754
|
-
off<T extends EventKeyType>(event: T, listener: Function | null, obj: object): this;
|
|
755
|
-
/**
|
|
756
|
-
* 触发全局事件
|
|
757
|
-
* @param event(string) 事件名
|
|
758
|
-
* @param args(any) 事件参数
|
|
759
|
-
*/
|
|
760
|
-
dispatchEvent<T extends EventKeyType>(event: T, args?: any): this;
|
|
761
|
-
/**移除所有事件 */
|
|
762
|
-
offAll(): void;
|
|
763
|
-
/**是否存在事件 */
|
|
764
|
-
has(event: EventKeyType): boolean;
|
|
765
|
-
/**删除事件通过组件 */
|
|
766
|
-
deleteEventByComponent(component: Component): void;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
809
|
/**
|
|
770
810
|
* MD5加密
|
|
771
811
|
* @param msg 加密信息
|
|
@@ -943,7 +983,6 @@ declare class CoreUIModal extends UILayer<CoreUIModalProps> {
|
|
|
943
983
|
|
|
944
984
|
declare class CoreBlackMask extends BaseComponent {
|
|
945
985
|
tween: Node;
|
|
946
|
-
black_mask: Node;
|
|
947
986
|
}
|
|
948
987
|
|
|
949
988
|
/**
|
|
@@ -1077,4 +1116,4 @@ declare class Manager {
|
|
|
1077
1116
|
}
|
|
1078
1117
|
declare const cat: Manager;
|
|
1079
1118
|
|
|
1080
|
-
export { AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, CoreBlackMask, CoreNotice, type CoreNoticeProps, CoreReconnection, CoreShowLoading, type CoreShowLoadingProps, CoreToast, CoreUIContainer, CoreUIModal, type CoreUIModalProps, CoreUtil, type EventKeyType, GlobalEventConstant, Gui, GuiManager, type HOOK, type ICloseOptions
|
|
1119
|
+
export { AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, CoreBlackMask, CoreNotice, type CoreNoticeProps, CoreReconnection, CoreShowLoading, type CoreShowLoadingProps, CoreToast, CoreUIContainer, CoreUIModal, type CoreUIModalProps, CoreUtil, type EventKeyType, GlobalEventConstant, Gui, GuiManager, type HOOK, type ICloseOptions$1 as ICloseOptions, type IOpenOptions$1 as IOpenOptions, type IUIOption, LayerType, type ListenerFunc, Manager, MessageManager, ReconnectPrompt, type SceneComponentType, type SceneDataType, SceneLayer, type ScenePropsType, TimerManager, type ToastProps, ToastType, type UIComponentType, 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 m,Enum as g,game as y,UITransform as v,UIOpacity as E,Tween as b,Label as w,BlockInputEvents as C,Button as k,Director as O,warn as x,assetManager as S,Asset as T,resources as N,SpriteFrame as R,Sprite as A,AsyncDelegate as I}from"cc";import{PREVIEW as D,DEBUG as M}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";class q extends e{cat;initAudio(e){return this.cat=e,this}}const{ccclass:K,menu:V}=t;class J 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:W,menu:X}=t;class z 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 Q;!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"}(Q||(Q={}));const Y="game_audio";class ee extends Z{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;constructor(e){super(e);var t=new o("UIAudioManager");n.addPersistRootNode(t);var s=new o("UIMusic");s.parent=t,this.music=s.addComponent(z).initAudio(e);var i=new o("UIEffect");i.parent=t,this.effect=i.addComponent(J).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?Q.MUSIC_ON:Q.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?Q.EFFECT_ON:Q.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;let e=JSON.stringify(this.local_data);this.cat.storage.set(Y,e)}load(){try{let e=this.cat.storage.get(Y);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}catch(e){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}class te 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(D||(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+="");D||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}`,D||(e=this.cat.util.encryptUtil.md5(e));let s=a.localStorage.getItem(e);return null==s||""===s||D||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}`,D||(e=this.cat.util.encryptUtil.md5(e)),a.localStorage.removeItem(e)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function se(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 ie(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;class oe extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}added(){}__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}_onPreDestroy(){this.autorunDisposers.forEach((e=>{e()})),this.reactionDisposers.forEach((e=>{e()})),this.autorunDisposers=[],this.reactionDisposers=[],super._onPreDestroy()}onDisable(){this.onHide(),it.event.deleteEventByComponent(this),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.added(),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}onShow(){}onHide(){}setNodeAndChildrenLayer(e){return ne(this.node,e),this}}const ne=(e,t)=>{e.layer="string"==typeof t?2**p.nameToLayer(t):t,e?.children.forEach((e=>{ne(e,t)}))};class re extends oe{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,m(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)=>{m(this.node).to(e,t).call((()=>{s()})).start()}))}}const{ccclass:ae,property:ce}=t;var le;!function(e){e[e.EFFECT=0]="EFFECT",e[e.BGM=1]="BGM"}(le||(le={}));class he extends oe{type=le.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,it.event.on(Q.EFFECT_ON,this.onPlayEffectHandler,this).on(Q.EFFECT_OFF,this.onStopEffectHandler,this).on(Q.MUSIC_ON,this.onPlayMusicHandler,this).on(Q.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:e,volumeMusic:t}=it.audio;this.audioSource.volume=this.type===le.BGM?t:e}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=it.audio;this.audioSource.playing||!(this.type===le.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}se([ce({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(le)}),ie("design:type",Object)],he.prototype,"type",void 0),se([ce({tooltip:"音源",type:s}),ie("design:type",Object)],he.prototype,"clip",void 0),se([ce({tooltip:"循环"}),ie("design:type",Object)],he.prototype,"loop",void 0),se([ce({tooltip:"音量"}),ie("design:type",Object)],he.prototype,"volume",void 0),se([ce({tooltip:"是否启用自动播放"}),ie("design:type",Object)],he.prototype,"playOnAwake",void 0);const{ccclass:de,property:pe}=t;class ue extends re{type=le.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new e;onEnable(){super.onEnable(),it.event.on(Q.EFFECT_ON,this.onPlayEffectHandler,this).on(Q.EFFECT_OFF,this.onStopEffectHandler,this).on(Q.MUSIC_ON,this.onPlayMusicHandler,this).on(Q.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}=it.audio;this.audioSource.volume=this.type===le.BGM?t:e}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=it.audio;this.audioSource.playing||!(this.type===le.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}se([pe({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(le)}),ie("design:type",Object)],ue.prototype,"type",void 0),se([pe({tooltip:"音源",type:s}),ie("design:type",Object)],ue.prototype,"clip",void 0),se([pe({tooltip:"循环"}),ie("design:type",Object)],ue.prototype,"loop",void 0),se([pe({tooltip:"音量"}),ie("design:type",Object)],ue.prototype,"volume",void 0),se([pe({tooltip:"是否启用自动播放"}),ie("design:type",Object)],ue.prototype,"playOnAwake",void 0);const{ccclass:fe,property:_e}=t;var me;!function(e){e[e.FIXED=0]="FIXED",e[e.SLIDE=1]="SLIDE"}(me||(me={}));let ge=class extends oe{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==me.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=m(i).delay(1.2).to(.5,{opacity:0}).call((()=>{b.stopAllByTarget(e),this.node.destroy(),t()}));m(e).by(.5,{position:_(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){b.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var ye;se([_e({type:o,tooltip:"固定节点"}),ie("design:type",o)],ge.prototype,"fixed_node",void 0),se([_e({type:o,tooltip:"滑动节点"}),ie("design:type",o)],ge.prototype,"slide_node",void 0),se([_e({type:w,tooltip:"固定标签节点"}),ie("design:type",w)],ge.prototype,"fixed_label",void 0),se([_e({type:w,tooltip:"滑动标签节点"}),ie("design:type",w)],ge.prototype,"slide_label",void 0),ge=se([fe("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"}(ye||(ye={}));const{ccclass:ve,property:Ee}=t;let be=class extends re{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Be)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){it.event.on(ye.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 this.scene_mask?(this.scene_mask.tween.addChild(e),this):(console.error("scene_mask is null"),this)}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(e){return this.gui=e,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(e){this.scene_mask.black_mask.active=!this.gui.root_mask.active&&e}};se([Ee({type:o}),ie("design:type",o)],be.prototype,"scene_mask_node",void 0),se([Ee({type:o}),ie("design:type",o)],be.prototype,"ui_container",void 0),be=se([ve("CoreUIContainer")],be);class we extends re{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){it.event.dispatchEvent(ye.ROOT_MASK_UPDATE)}}const{ccclass:Ce,property:ke}=t;let Oe=class extends we{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(C).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)}};se([ke({type:w,tooltip:"标题"}),ie("design:type",w)],Oe.prototype,"title",void 0),se([ke({type:o,tooltip:"动画"}),ie("design:type",o)],Oe.prototype,"loadingTween",void 0),Oe=se([Ce("CoreShowLoading")],Oe);const{ccclass:xe,property:Se}=t;var Te;!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="连接游戏服错误"}(Te||(Te={}));let Ne=class extends we{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==Te.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,it.gui.hideReconnect()}};se([Se({type:w,tooltip:"通用提示文本"}),ie("design:type",w)],Ne.prototype,"common_prompt_text",void 0),se([Se({type:k,tooltip:"确定按钮"}),ie("design:type",k)],Ne.prototype,"btn_confirm",void 0),Ne=se([xe("CoreReconnection")],Ne);const{ccclass:Re,property:Ae}=t;let Ie=class extends we{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?.(),it.gui.hideNotice()}updateProps(e){this.text.string=`${e.text}`}};se([Ae({type:w,tooltip:"提示文本"}),ie("design:type",w)],Ie.prototype,"text",void 0),se([Ae({type:k,tooltip:"确定按钮"}),ie("design:type",k)],Ie.prototype,"btn_confirm",void 0),Ie=se([Re("CoreNotice")],Ie);class De extends oe{isReload}const{ccclass:Me,property:Fe}=t;var Ue;!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"}(Ue||(Ue={}));let He=class extends oe{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(ye.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()}showToast({title:e="",type:t=me.SLIDE,fixed_time:s=2}){const i=h(this.toast_ui_prefab);return r("showToast",e),this.toast_ui_component=i.getComponent(ge).addToParent(this.root_toast,{props:{title:e,type:t,fixed_time:s}}),this}hideToast(){return this.toast_ui_component?.removeAndDestroy(),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(Oe).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(Ne).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(Ie).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(De);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(be).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(re),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 re));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.length;if(this.root_mask.active=e>1,e>1){const t=this.root_ui.children[e-2];this.root_mask.setSiblingIndex(t.getSiblingIndex())}this.cat.event.dispatchEvent(ye.ROOT_MASK_CHANGE)}};se([Fe({type:l,tooltip:"断线重连UI预制体"}),ie("design:type",l)],He.prototype,"reconnection_ui_prefab",void 0),se([Fe({type:l,tooltip:"提示UI预制体"}),ie("design:type",l)],He.prototype,"toast_ui_prefab",void 0),se([Fe({type:l,tooltip:"加载UI预制体"}),ie("design:type",l)],He.prototype,"loading_ui_prefab",void 0),se([Fe({type:l,tooltip:"公告UI预制体"}),ie("design:type",l)],He.prototype,"notice_ui_prefab",void 0),se([Fe({type:l,tooltip:"UI层预制体"}),ie("design:type",l)],He.prototype,"ui_prefab",void 0),se([Fe({type:o,tooltip:"root-UI层"}),ie("design:type",o)],He.prototype,"root_ui",void 0),se([Fe({type:o,tooltip:"root-组件层"}),ie("design:type",o)],He.prototype,"root_toast",void 0),se([Fe({type:o,tooltip:"root-mask"}),ie("design:type",o)],He.prototype,"root_mask",void 0),He=se([Me("Gui")],He);const{ccclass:Pe,property:Le}=t;let Be=class extends oe{tween;black_mask};var Ge;se([Le({type:o,tooltip:"动画节点"}),ie("design:type",o)],Be.prototype,"tween",void 0),se([Le({type:o,tooltip:"遮罩节点"}),ie("design:type",o)],Be.prototype,"black_mask",void 0),Be=se([Pe("CoreBlackMask")],Be),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"}(Ge||(Ge={}));class $e 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(e="resources"){this.#e=e;const t=await this.getGuiPrefabByType(this.#e,Ge.Root),s=h(t);return this.gui=s.getComponent(He).init(this.cat),n.addPersistRootNode(s),this}}class je{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 qe{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 Ke=null;const Ve={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 Je=Object.freeze({__proto__:null,JsonFormatter:Ve,aesDecrypt:(e,t,s)=>L.AES.decrypt(e,t,{iv:Ke,format:Ve}).toString(L.enc.Utf8),aesEncrypt:(e,t,s)=>L.AES.encrypt(e,t,{iv:Ke,format:Ve}).toString(),initCrypto:(e,t)=>{Ke=L.enc.Hex.parse(t)},md5:e=>L.MD5(e).toString()});class We extends Z{encryptUtil=Je}class Xe 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}))),it.event.on(ye.EVENT_SHOW,this.onShowHandler,this).on(ye.EVENT_HIDE,this.onHideHandler,this).on(ye.ONLINE,this.onOnlineHandler,this).on(ye.OFFLINE,this.onOfflineHandler,this)}removeEvent(){this.removeAllListeners(),it.event.off(ye.EVENT_SHOW,this.onShowHandler,this).off(ye.EVENT_HIDE,this.onHideHandler,this).off(ye.ONLINE,this.onOnlineHandler,this).off(ye.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 "),it.gui.showToast({title:Te.RECONNECTED}),it.gui.hideReconnect().hideLoading(),it.gui.reloadScene()}catch(e){console.error(e),it.gui.showReconnect(Te.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),it.gui.showReconnect(Te.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"),it.gui.showReconnect(Te.KICK),this.handleEvent({type:"destroy"});break;case"reconnecting":r("正在重连状态 reconnecting"),this.isOnline&&this.isInBackground;break;case"maxReconnect":r("超出最大重连状态 maxReconnect"),it.gui.showReconnect(Te.MAX_RECONNECT);break;case"error":this.isOnline&&(r("ws报错状态 error",e.ev),"string"==typeof e.ev&&it.gui.showToast({title:e.ev}),it.gui.showReconnect(Te.RECONNECTED_ERROR));break;case"online":it.gui.showReconnect(Te.ONLINE),r("在线状态 online"),this.handleEvent({type:"reconnect"});break;case"offline":this.disconnect(!0),r("离线状态 offline"),this.isNeedReconnect=!0,it.gui.showReconnect(Te.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&&(it.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 M&&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=>{M&&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 M&&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=>{M&&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=>{it.gui.showToast({title:e.msg}),n(e)}))}))}async gameRequest(e,t,s){return M&&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=G(j,{forwardReq:!1,forwardResp:!1}),show_log:i=!0}={})=>{this.isSocketConnected&&(M&&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,s))};subscribe(e,t,s){return super.subscribe(e,t,(i=>{M&&!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)),it.event.dispatchEvent(e,B(t,i)),s?.(i)})),this}onData(e){super.onData(e)}}const{ccclass:ze,property:Ze}=t;let Qe=class extends re{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 R?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(A).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(A).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),it.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var Ye;se([Ze({type:R,tooltip:"默认标题"}),ie("design:type",R)],Qe.prototype,"default_title",void 0),se([Ze({type:A,tooltip:"标题节点"}),ie("design:type",A)],Qe.prototype,"title",void 0),se([Ze({type:w,tooltip:"字符串内容按钮"}),ie("design:type",w)],Qe.prototype,"prompt_content_str",void 0),se([Ze({type:A,tooltip:"图片精灵内容按钮"}),ie("design:type",A)],Qe.prototype,"prompt_content_spriteFrame",void 0),se([Ze({type:k,tooltip:"确认按钮"}),ie("design:type",k)],Qe.prototype,"btn_confirm",void 0),se([Ze({type:R,tooltip:"确认按钮精灵图"}),ie("design:type",R)],Qe.prototype,"confirm_spriteFrame",void 0),se([Ze({type:k,tooltip:"取消按钮"}),ie("design:type",k)],Qe.prototype,"btn_cancel",void 0),se([Ze({type:R,tooltip:"取消按钮精灵图"}),ie("design:type",R)],Qe.prototype,"cancel_spriteFrame",void 0),se([Ze({type:k,tooltip:"关闭按钮"}),ie("design:type",k)],Qe.prototype,"btn_close",void 0),Qe=se([ze("CoreUIModal")],Qe),function(e){e[e.Delay=0]="Delay",e[e.Interval=1]="Interval"}(Ye||(Ye={}));class et{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 tt extends Z{timers=new Map;lastUpdateTime=Date.now();constructor(e){super(e),e.event.on(ye.EVENT_HIDE,this.onHandleAppBackground,this),e.event.on(ye.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 et(e,Ye.Interval,t,s);this.timers.set(e,o)}registerDelay(e,t,s){if(this.has(e))return i(`${e}延时器已存在,请勿重复注册`);const o=new et(e,Ye.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===Ye.Interval&&(s.executionTime+=s.initialTime),s.callback(s.executionTime),s.type===Ye.Interval?s.remainingTime=s.initialTime:e.push(t));for(const t of e)this.timers.delete(t)}}class st{static#t;static get instance(){return this.#t||(this.#t=new st),this.#t}onAppInitDelegate=new I;audio;event;gui;storage;res;util;#s="resources";setConfig=({gui_bundleName:e="resources"}={})=>(this.#s=e,console.log("GUI资源配置",this.#s),this);async boot(){this.res=new je,this.util=new We(this),this.storage=new te(this),this.event=new qe,this.audio=new ee(this),this.gui=(await new $e(this).init(this.#s)).gui}}const it=st.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]"),await it.boot(),await it.onAppInitDelegate.dispatch(),console.timeEnd("[Init App]")}));export{Q as AudioEventConstant,ee as AudioManager,he as AudioSourceBaseComponent,ue as AudioSourceUILayer,le as AudioTypeEnum,oe as BaseComponent,Z as BaseManager,Ge as BasePrefab,Be as CoreBlackMask,Ie as CoreNotice,Ne as CoreReconnection,Oe as CoreShowLoading,ge as CoreToast,be as CoreUIContainer,Qe as CoreUIModal,We as CoreUtil,ye as GlobalEventConstant,He as Gui,$e as GuiManager,Ue as LayerType,st as Manager,qe as MessageManager,Te as ReconnectPrompt,De as SceneLayer,tt as TimerManager,me as ToastType,re as UILayer,Xe as WrapperSocialGameClient,it as cat};
|
|
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 m,Enum as g,game as y,UITransform as v,UIOpacity as E,Tween as b,Label as w,BlockInputEvents as C,Button as k,Director as O,warn as x,assetManager as S,Asset as T,resources as N,SpriteFrame as A,Sprite as R,AsyncDelegate as I}from"cc";import{makeObservable as D,observable as M,autorun as F,reaction as U}from"@shimotsuki/mobx";import{PREVIEW as H,DEBUG as P}from"cc/env";import L from"crypto-es";import{clone as B,create as G}from"@bufbuild/protobuf";import{SocialGameClient as $,AudienceOptionsSchema as j}from"sgc";class q extends e{cat;initAudio(e){return this.cat=e,this}}const{ccclass:K,menu:V}=t;class J 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:W,menu:X}=t;class z 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 Q;!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"}(Q||(Q={}));const Y="game_audio";class ee extends Z{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;constructor(e){super(e),D(this,{_switch_music:M,_switch_effect:M});var t=new o("UIAudioManager");n.addPersistRootNode(t);var s=new o("UIMusic");s.parent=t,this.music=s.addComponent(z).initAudio(e);var i=new o("UIEffect");i.parent=t,this.effect=i.addComponent(J).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?Q.MUSIC_ON:Q.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?Q.EFFECT_ON:Q.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;let e=JSON.stringify(this.local_data);this.cat.storage.set(Y,e)}load(){try{let e=this.cat.storage.get(Y);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}catch(e){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}autorunDisposers=[];reactionDisposers=[];addAutorun(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=F(e);this.autorunDisposers.push(t)})),this}addReaction(e,t,s){const i=U(e,t,s);return this.reactionDisposers.push(i),this}removeAutorun(){this.autorunDisposers.forEach((e=>{e()})),this.autorunDisposers=[]}removeReaction(){this.reactionDisposers.forEach((e=>{e()})),this.reactionDisposers=[]}}class te 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(H||(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+="");H||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}`,H||(e=this.cat.util.encryptUtil.md5(e));let s=a.localStorage.getItem(e);return null==s||""===s||H||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}`,H||(e=this.cat.util.encryptUtil.md5(e)),a.localStorage.removeItem(e)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function se(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 ie(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;class oe extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];messageManagers=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),D(this,{props:M,data:M})}onAutoObserver(){}addAutorun(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=F(e);this.autorunDisposers.push(t)})),this}addReaction(e,t,s){const i=U(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(),it.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}onShow(){}onHide(){}setNodeAndChildrenLayer(e){return ne(this.node,e),this}}const ne=(e,t)=>{e.layer="string"==typeof t?2**p.nameToLayer(t):t,e?.children.forEach((e=>{ne(e,t)}))};class re extends oe{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,m(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)=>{m(this.node).to(e,t).call((()=>{s()})).start()}))}}const{ccclass:ae,property:ce}=t;var le;!function(e){e[e.EFFECT=0]="EFFECT",e[e.BGM=1]="BGM"}(le||(le={}));class he extends oe{type=le.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,it.event.on(Q.EFFECT_ON,this.onPlayEffectHandler,this).on(Q.EFFECT_OFF,this.onStopEffectHandler,this).on(Q.MUSIC_ON,this.onPlayMusicHandler,this).on(Q.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:e,volumeMusic:t}=it.audio;this.audioSource.volume=this.type===le.BGM?t:e}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=it.audio;this.audioSource.playing||!(this.type===le.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}se([ce({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(le)}),ie("design:type",Object)],he.prototype,"type",void 0),se([ce({tooltip:"音源",type:s}),ie("design:type",Object)],he.prototype,"clip",void 0),se([ce({tooltip:"循环"}),ie("design:type",Object)],he.prototype,"loop",void 0),se([ce({tooltip:"音量"}),ie("design:type",Object)],he.prototype,"volume",void 0),se([ce({tooltip:"是否启用自动播放"}),ie("design:type",Object)],he.prototype,"playOnAwake",void 0);const{ccclass:de,property:pe}=t;class ue extends re{type=le.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new e;onEnable(){super.onEnable(),it.event.on(Q.EFFECT_ON,this.onPlayEffectHandler,this).on(Q.EFFECT_OFF,this.onStopEffectHandler,this).on(Q.MUSIC_ON,this.onPlayMusicHandler,this).on(Q.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}=it.audio;this.audioSource.volume=this.type===le.BGM?t:e}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=it.audio;this.audioSource.playing||!(this.type===le.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}se([pe({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(le)}),ie("design:type",Object)],ue.prototype,"type",void 0),se([pe({tooltip:"音源",type:s}),ie("design:type",Object)],ue.prototype,"clip",void 0),se([pe({tooltip:"循环"}),ie("design:type",Object)],ue.prototype,"loop",void 0),se([pe({tooltip:"音量"}),ie("design:type",Object)],ue.prototype,"volume",void 0),se([pe({tooltip:"是否启用自动播放"}),ie("design:type",Object)],ue.prototype,"playOnAwake",void 0);const{ccclass:fe,property:_e}=t;var me;!function(e){e[e.FIXED=0]="FIXED",e[e.SLIDE=1]="SLIDE"}(me||(me={}));let ge=class extends oe{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==me.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=m(i).delay(1.2).to(.5,{opacity:0}).call((()=>{b.stopAllByTarget(e),this.node.destroy(),t()}));m(e).by(.5,{position:_(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){b.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var ye;se([_e({type:o,tooltip:"固定节点"}),ie("design:type",o)],ge.prototype,"fixed_node",void 0),se([_e({type:o,tooltip:"滑动节点"}),ie("design:type",o)],ge.prototype,"slide_node",void 0),se([_e({type:w,tooltip:"固定标签节点"}),ie("design:type",w)],ge.prototype,"fixed_label",void 0),se([_e({type:w,tooltip:"滑动标签节点"}),ie("design:type",w)],ge.prototype,"slide_label",void 0),ge=se([fe("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"}(ye||(ye={}));const{ccclass:ve,property:Ee}=t;let be=class extends re{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Be)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){it.event.on(ye.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=!this.gui.root_mask.active&&e}};se([Ee({type:o}),ie("design:type",o)],be.prototype,"scene_mask_node",void 0),se([Ee({type:o}),ie("design:type",o)],be.prototype,"ui_container",void 0),be=se([ve("CoreUIContainer")],be);class we extends re{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){it.event.dispatchEvent(ye.ROOT_MASK_UPDATE)}}const{ccclass:Ce,property:ke}=t;let Oe=class extends we{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(C).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)}};se([ke({type:w,tooltip:"标题"}),ie("design:type",w)],Oe.prototype,"title",void 0),se([ke({type:o,tooltip:"动画"}),ie("design:type",o)],Oe.prototype,"loadingTween",void 0),Oe=se([Ce("CoreShowLoading")],Oe);const{ccclass:xe,property:Se}=t;var Te;!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="连接游戏服错误"}(Te||(Te={}));let Ne=class extends we{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==Te.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,it.gui.hideReconnect()}};se([Se({type:w,tooltip:"通用提示文本"}),ie("design:type",w)],Ne.prototype,"common_prompt_text",void 0),se([Se({type:k,tooltip:"确定按钮"}),ie("design:type",k)],Ne.prototype,"btn_confirm",void 0),Ne=se([xe("CoreReconnection")],Ne);const{ccclass:Ae,property:Re}=t;let Ie=class extends we{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?.(),it.gui.hideNotice()}updateProps(e){this.text.string=`${e.text}`}};se([Re({type:w,tooltip:"提示文本"}),ie("design:type",w)],Ie.prototype,"text",void 0),se([Re({type:k,tooltip:"确定按钮"}),ie("design:type",k)],Ie.prototype,"btn_confirm",void 0),Ie=se([Ae("CoreNotice")],Ie);class De extends oe{isReload}const{ccclass:Me,property:Fe}=t;var Ue;!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"}(Ue||(Ue={}));let He=class extends oe{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(ye.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()}showToast({title:e="",type:t=me.SLIDE,fixed_time:s=2}){const i=h(this.toast_ui_prefab);return r("showToast",e),this.toast_ui_component=i.getComponent(ge).addToParent(this.root_toast,{props:{title:e,type:t,fixed_time:s}}),this}hideToast(){return this.toast_ui_component?.removeAndDestroy(),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(Oe).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(Ne).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(Ie).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(De);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(be).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(re),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 re));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.length;if(this.root_mask.active=e>1,e>1){const t=this.root_ui.children[e-2];this.root_mask.setSiblingIndex(t.getSiblingIndex())}this.cat.event.dispatchEvent(ye.ROOT_MASK_CHANGE)}};se([Fe({type:l,tooltip:"断线重连UI预制体"}),ie("design:type",l)],He.prototype,"reconnection_ui_prefab",void 0),se([Fe({type:l,tooltip:"提示UI预制体"}),ie("design:type",l)],He.prototype,"toast_ui_prefab",void 0),se([Fe({type:l,tooltip:"加载UI预制体"}),ie("design:type",l)],He.prototype,"loading_ui_prefab",void 0),se([Fe({type:l,tooltip:"公告UI预制体"}),ie("design:type",l)],He.prototype,"notice_ui_prefab",void 0),se([Fe({type:l,tooltip:"UI层预制体"}),ie("design:type",l)],He.prototype,"ui_prefab",void 0),se([Fe({type:o,tooltip:"root-UI层"}),ie("design:type",o)],He.prototype,"root_ui",void 0),se([Fe({type:o,tooltip:"root-组件层"}),ie("design:type",o)],He.prototype,"root_toast",void 0),se([Fe({type:o,tooltip:"root-mask"}),ie("design:type",o)],He.prototype,"root_mask",void 0),He=se([Me("Gui")],He);const{ccclass:Pe,property:Le}=t;let Be=class extends oe{tween};var Ge;se([Le({type:o,tooltip:"动画节点"}),ie("design:type",o)],Be.prototype,"tween",void 0),Be=se([Pe("CoreBlackMask")],Be),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"}(Ge||(Ge={}));class $e 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(e="resources"){this.#e=e;const t=await this.getGuiPrefabByType(this.#e,Ge.Root),s=h(t);return this.gui=s.getComponent(He).init(this.cat),n.addPersistRootNode(s),this}}class je{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 qe{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 Ke=null;const Ve={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 Je=Object.freeze({__proto__:null,JsonFormatter:Ve,aesDecrypt:(e,t,s)=>L.AES.decrypt(e,t,{iv:Ke,format:Ve}).toString(L.enc.Utf8),aesEncrypt:(e,t,s)=>L.AES.encrypt(e,t,{iv:Ke,format:Ve}).toString(),initCrypto:(e,t)=>{Ke=L.enc.Hex.parse(t)},md5:e=>L.MD5(e).toString()});class We extends Z{encryptUtil=Je}class Xe 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}))),it.event.on(ye.EVENT_SHOW,this.onShowHandler,this).on(ye.EVENT_HIDE,this.onHideHandler,this).on(ye.ONLINE,this.onOnlineHandler,this).on(ye.OFFLINE,this.onOfflineHandler,this)}removeEvent(){this.removeAllListeners(),it.event.off(ye.EVENT_SHOW,this.onShowHandler,this).off(ye.EVENT_HIDE,this.onHideHandler,this).off(ye.ONLINE,this.onOnlineHandler,this).off(ye.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 "),it.gui.showToast({title:Te.RECONNECTED}),it.gui.hideReconnect().hideLoading(),it.gui.reloadScene()}catch(e){console.error(e),it.gui.showReconnect(Te.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),it.gui.showReconnect(Te.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"),it.gui.showReconnect(Te.KICK),this.handleEvent({type:"destroy"});break;case"reconnecting":r("正在重连状态 reconnecting"),this.isOnline&&this.isInBackground;break;case"maxReconnect":r("超出最大重连状态 maxReconnect"),it.gui.showReconnect(Te.MAX_RECONNECT);break;case"error":this.isOnline&&(r("ws报错状态 error",e.ev),"string"==typeof e.ev&&it.gui.showToast({title:e.ev}),it.gui.showReconnect(Te.RECONNECTED_ERROR));break;case"online":it.gui.showReconnect(Te.ONLINE),r("在线状态 online"),this.handleEvent({type:"reconnect"});break;case"offline":this.disconnect(!0),r("离线状态 offline"),this.isNeedReconnect=!0,it.gui.showReconnect(Te.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&&(it.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 P&&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=>{P&&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 P&&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=>{P&&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=>{it.gui.showToast({title:e.msg}),n(e)}))}))}async gameRequest(e,t,s){return P&&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=G(j,{forwardReq:!1,forwardResp:!1}),show_log:i=!0}={})=>{this.isSocketConnected&&(P&&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,s))};subscribe(e,t,s){return super.subscribe(e,t,(i=>{P&&!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)),it.event.dispatchEvent(e,B(t,i)),s?.(i)})),this}onData(e){super.onData(e)}}const{ccclass:ze,property:Ze}=t;let Qe=class extends re{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 A?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?.(),it.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var Ye;se([Ze({type:A,tooltip:"默认标题"}),ie("design:type",A)],Qe.prototype,"default_title",void 0),se([Ze({type:R,tooltip:"标题节点"}),ie("design:type",R)],Qe.prototype,"title",void 0),se([Ze({type:w,tooltip:"字符串内容按钮"}),ie("design:type",w)],Qe.prototype,"prompt_content_str",void 0),se([Ze({type:R,tooltip:"图片精灵内容按钮"}),ie("design:type",R)],Qe.prototype,"prompt_content_spriteFrame",void 0),se([Ze({type:k,tooltip:"确认按钮"}),ie("design:type",k)],Qe.prototype,"btn_confirm",void 0),se([Ze({type:A,tooltip:"确认按钮精灵图"}),ie("design:type",A)],Qe.prototype,"confirm_spriteFrame",void 0),se([Ze({type:k,tooltip:"取消按钮"}),ie("design:type",k)],Qe.prototype,"btn_cancel",void 0),se([Ze({type:A,tooltip:"取消按钮精灵图"}),ie("design:type",A)],Qe.prototype,"cancel_spriteFrame",void 0),se([Ze({type:k,tooltip:"关闭按钮"}),ie("design:type",k)],Qe.prototype,"btn_close",void 0),Qe=se([ze("CoreUIModal")],Qe),function(e){e[e.Delay=0]="Delay",e[e.Interval=1]="Interval"}(Ye||(Ye={}));class et{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 tt extends Z{timers=new Map;lastUpdateTime=Date.now();constructor(e){super(e),e.event.on(ye.EVENT_HIDE,this.onHandleAppBackground,this),e.event.on(ye.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 et(e,Ye.Interval,t,s);this.timers.set(e,o)}registerDelay(e,t,s){if(this.has(e))return i(`${e}延时器已存在,请勿重复注册`);const o=new et(e,Ye.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===Ye.Interval&&(s.executionTime+=s.initialTime),s.callback(s.executionTime),s.type===Ye.Interval?s.remainingTime=s.initialTime:e.push(t));for(const t of e)this.timers.delete(t)}}class st{static#t;static get instance(){return this.#t||(this.#t=new st),this.#t}onAppInitDelegate=new I;audio;event;gui;storage;res;util;#s="resources";setConfig=({gui_bundleName:e="resources"}={})=>(this.#s=e,console.log("GUI资源配置",this.#s),this);async boot(){this.res=new je,this.util=new We(this),this.storage=new te(this),this.event=new qe,this.audio=new ee(this),this.gui=(await new $e(this).init(this.#s)).gui}}const it=st.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]"),await it.boot(),await it.onAppInitDelegate.dispatch(),console.timeEnd("[Init App]")}));export{Q as AudioEventConstant,ee as AudioManager,he as AudioSourceBaseComponent,ue as AudioSourceUILayer,le as AudioTypeEnum,oe as BaseComponent,Z as BaseManager,Ge as BasePrefab,Be as CoreBlackMask,Ie as CoreNotice,Ne as CoreReconnection,Oe as CoreShowLoading,ge as CoreToast,be as CoreUIContainer,Qe as CoreUIModal,We as CoreUtil,ye as GlobalEventConstant,He as Gui,$e as GuiManager,Ue as LayerType,st as Manager,qe as MessageManager,Te as ReconnectPrompt,De as SceneLayer,tt as TimerManager,me as ToastType,Xe as WrapperSocialGameClient,it as cat};
|