@shimotsuki/core 2.0.21 → 2.0.22
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 +5 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -805,6 +805,9 @@ declare class SocialGameClientManager extends BaseManager {
|
|
|
805
805
|
private handleSingleKick;
|
|
806
806
|
}
|
|
807
807
|
|
|
808
|
+
declare class Store extends BaseManager {
|
|
809
|
+
}
|
|
810
|
+
|
|
808
811
|
declare enum AudioEventConstant {
|
|
809
812
|
/**音乐开 */
|
|
810
813
|
MUSIC_ON = "AudioEventConstant/MUSIC_ON",
|
|
@@ -1008,6 +1011,8 @@ declare class Manager {
|
|
|
1008
1011
|
util: CoreUtil;
|
|
1009
1012
|
/**类 */
|
|
1010
1013
|
socialGameClient: SocialGameClientManager;
|
|
1014
|
+
/**数据存储 */
|
|
1015
|
+
store: Store;
|
|
1011
1016
|
/**GUI */
|
|
1012
1017
|
gui_bundle_name: string;
|
|
1013
1018
|
/**音效本地存储key */
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,AsyncDelegate as N,Game as M,SpriteFrame as x,Sprite as D}from"cc";import{PREVIEW as R,WECHAT as F,DEBUG as U}from"cc/env";import{makeObservable as P,observable as L,autorun as H,reaction as B}from"@shimotsuki/mobx";import G from"crypto-es";import{clone as $}from"@bufbuild/protobuf";import{SocketConnectStatus as j}from"pitayaclient";import{SocialGameClient as K}from"sgc";import{EventEmitter as V}from"eventemitter3";import"core-js/es/array/index.js";class W extends t{cat;initAudio(t){return this.cat=t,this}}const{ccclass:Q,menu:J}=e;class X extends W{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:q,menu:z}=e;class Z extends W{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 Y{cat;constructor(t){this.cat=t}}var tt;!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"}(tt||(tt={}));class et extends Y{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(X).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?tt.MUSIC_ON:tt.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?tt.EFFECT_ON:tt.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 it extends Y{_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(R||(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+="");R||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}`,R||(t=this.cat.util.encryptUtil.md5(t));let i=a.localStorage.getItem(t);return null==i||""===i||R||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}`,R||(t=this.cat.util.encryptUtil.md5(t)),a.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function st(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 ot(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class nt extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),P(this,{props:L,data:L})}onAutoObserver(){}addAutorun(t){return(Array.isArray(t)?t:[t]).forEach((t=>{const e=H(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===de.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(de.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 rt(this.node,t),this}}const rt=(t,e)=>{t.layer="string"==typeof e?2**d.nameToLayer(e):e,t?.children.forEach((t=>{rt(t,e)}))};class at extends nt{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:ct,property:lt}=e;var ht;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(ht||(ht={}));class pt extends nt{type=ht.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,de.event.on(tt.EFFECT_ON,this.onPlayEffectHandler,this).on(tt.EFFECT_OFF,this.onStopEffectHandler,this).on(tt.MUSIC_ON,this.onPlayMusicHandler,this).on(tt.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=de.audio;this.audioSource.volume=this.type===ht.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=de.audio;this.audioSource.playing||!(this.type===ht.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}st([lt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(ht)}),ot("design:type",Object)],pt.prototype,"type",void 0),st([lt({tooltip:"音源",type:i}),ot("design:type",Object)],pt.prototype,"clip",void 0),st([lt({tooltip:"循环"}),ot("design:type",Object)],pt.prototype,"loop",void 0),st([lt({tooltip:"音量"}),ot("design:type",Object)],pt.prototype,"volume",void 0),st([lt({tooltip:"是否启用自动播放"}),ot("design:type",Object)],pt.prototype,"playOnAwake",void 0);const{ccclass:dt,property:ut}=e;class _t extends at{type=ht.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),de.event.on(tt.EFFECT_ON,this.onPlayEffectHandler,this).on(tt.EFFECT_OFF,this.onStopEffectHandler,this).on(tt.MUSIC_ON,this.onPlayMusicHandler,this).on(tt.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}=de.audio;this.audioSource.volume=this.type===ht.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=de.audio;this.audioSource.playing||!(this.type===ht.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}st([ut({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(ht)}),ot("design:type",Object)],_t.prototype,"type",void 0),st([ut({tooltip:"音源",type:i}),ot("design:type",Object)],_t.prototype,"clip",void 0),st([ut({tooltip:"循环"}),ot("design:type",Object)],_t.prototype,"loop",void 0),st([ut({tooltip:"音量"}),ot("design:type",Object)],_t.prototype,"volume",void 0),st([ut({tooltip:"是否启用自动播放"}),ot("design:type",Object)],_t.prototype,"playOnAwake",void 0);const{ccclass:mt,property:ft,menu:gt}=e;var yt;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(yt||(yt={}));let vt=class extends nt{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==yt.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 Et;st([ft({type:o,tooltip:"固定节点"}),ot("design:type",o)],vt.prototype,"fixed_node",void 0),st([ft({type:o,tooltip:"滑动节点"}),ot("design:type",o)],vt.prototype,"slide_node",void 0),st([ft({type:b,tooltip:"固定标签节点"}),ot("design:type",b)],vt.prototype,"fixed_label",void 0),st([ft({type:b,tooltip:"滑动标签节点"}),ot("design:type",b)],vt.prototype,"slide_label",void 0),vt=st([mt("CoreToast"),gt("CATCORE/CoreToast")],vt),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"}(Et||(Et={}));const{ccclass:Ct,property:bt,menu:St}=e;let wt=class extends at{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Jt)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){de.event.on(Et.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}};st([bt({type:o}),ot("design:type",o)],wt.prototype,"scene_mask_node",void 0),st([bt({type:o}),ot("design:type",o)],wt.prototype,"ui_container",void 0),wt=st([Ct("CoreUIContainer"),St("CATCORE/CoreUIContainer")],wt);class Ot extends at{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){de.event.emit(Et.ROOT_MASK_UPDATE)}}const{ccclass:At,property:Tt,menu:kt}=e;let It=class extends Ot{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)}};st([Tt({type:b,tooltip:"标题"}),ot("design:type",b)],It.prototype,"title",void 0),st([Tt({type:o,tooltip:"动画"}),ot("design:type",o)],It.prototype,"loadingTween",void 0),It=st([At("CoreShowLoading"),kt("CATCORE/CoreShowLoading")],It);const{ccclass:Nt,property:Mt,menu:xt}=e;var Dt;!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="连接游戏服错误"}(Dt||(Dt={}));let Rt=class extends Ot{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==Dt.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,de.gui.hideReconnect()}};st([Mt({type:b,tooltip:"通用提示文本"}),ot("design:type",b)],Rt.prototype,"common_prompt_text",void 0),st([Mt({type:w,tooltip:"确定按钮"}),ot("design:type",w)],Rt.prototype,"btn_confirm",void 0),Rt=st([Nt("CoreReconnection"),xt("CATCORE/CoreReconnection")],Rt);const{ccclass:Ft,property:Ut,menu:Pt}=e;let Lt=class extends Ot{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?.(),de.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};st([Ut({type:b,tooltip:"提示文本"}),ot("design:type",b)],Lt.prototype,"text",void 0),st([Ut({type:w,tooltip:"确定按钮"}),ot("design:type",w)],Lt.prototype,"btn_confirm",void 0),Lt=st([Ft("CoreNotice"),Pt("CATCORE/CoreNotice")],Lt);class Ht extends nt{isReload}const{ccclass:Bt,property:Gt,menu:$t}=e;var jt;!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"}(jt||(jt={}));let Kt=class extends nt{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(Et.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(vt).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(vt)?.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(It).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(Lt).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(Ht);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(wt).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(at),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 at));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(Et.ROOT_MASK_CHANGE)}};st([Gt({type:l,tooltip:"断线重连UI预制体"}),ot("design:type",l)],Kt.prototype,"reconnection_ui_prefab",void 0),st([Gt({type:l,tooltip:"提示UI预制体"}),ot("design:type",l)],Kt.prototype,"toast_ui_prefab",void 0),st([Gt({type:l,tooltip:"加载UI预制体"}),ot("design:type",l)],Kt.prototype,"loading_ui_prefab",void 0),st([Gt({type:l,tooltip:"公告UI预制体"}),ot("design:type",l)],Kt.prototype,"notice_ui_prefab",void 0),st([Gt({type:l,tooltip:"UI层预制体"}),ot("design:type",l)],Kt.prototype,"ui_prefab",void 0),st([Gt({type:o,tooltip:"root-UI层"}),ot("design:type",o)],Kt.prototype,"root_ui",void 0),st([Gt({type:o,tooltip:"root-组件层"}),ot("design:type",o)],Kt.prototype,"root_toast",void 0),st([Gt({type:o,tooltip:"root-mask"}),ot("design:type",o)],Kt.prototype,"root_mask",void 0),Kt=st([Bt("Gui"),$t("CATCORE/Gui")],Kt);const{ccclass:Vt,property:Wt,menu:Qt}=e;let Jt=class extends nt{tween};var Xt;st([Wt({type:o,tooltip:"动画节点"}),ot("design:type",o)],Jt.prototype,"tween",void 0),Jt=st([Vt("CoreBlackMask"),Qt("CATCORE/CoreBlackMask")],Jt),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"}(Xt||(Xt={}));class qt extends Y{gui;#t="resources";getGuiPrefabByType=(t,e)=>new Promise(((i,s)=>{r(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,Xt.Root),e=h(t);return this.gui=e.getComponent(Kt).init(this.cat),n.addPersistRootNode(e),this}}class zt{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 Yt={stringify:t=>{const e={ct:t.ciphertext.toString(G.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=G.lib.CipherParams.create({ciphertext:G.enc.Base64.parse(e.ct)});return e.iv&&(i.iv=G.enc.Hex.parse(e.iv)),e.s&&(i.salt=G.enc.Hex.parse(e.s)),i}};var te=Object.freeze({__proto__:null,JsonFormatter:Yt,aesDecrypt:(t,e,i)=>G.AES.decrypt(t,e,{iv:Zt,format:Yt}).toString(G.enc.Utf8),aesEncrypt:(t,e,i)=>G.AES.encrypt(t,e,{iv:Zt,format:Yt}).toString(),initCrypto:(t,e)=>{Zt=G.enc.Hex.parse(e)},md5:t=>G.MD5(t).toString()});class ee extends Y{encryptUtil=te}class ie extends K{logBlackList=[];ignore=t=>this.logBlackList.includes(t);constructor(t,e,i,s){super(e,i,s,t)}destroy(){this.disconnect(!0),de.socialGameClient.unregister(this)}async GameRequest(t,e,i,s){return new Promise(((o,n)=>{super.GameRequest(t,e,i,s).then((e=>{U&&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",$(i,e)),o(e)}),(t=>{de.gui.showToast({title:t.msg}),n(t)}))}))}subscribe(t,e,i){return super.subscribe(t,e,(s=>{U&&!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",$(e,s)),de.event.emit(t,$(e,s)),i?.(s)})),this}}class se extends Y{managedClients=new Map;isGlobalOnline=!0;isInBackground=!1;onEventHideDelegate=new N;onEventShowDelegate=new N;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 ie(t,i,s,Object.assign({reconnectMaxAttempts:1/0},{...e,isAutoConnect:!1,isArrayBuffer:F}));return this.register(o),o}register(t){t.on("reconnected",this.handleSingleReconnect),t.on("kick",this.handleSingleKick),this.managedClients.set(t.name,t)}unregister(t){t.off("reconnected",this.handleSingleReconnect),t.off("kick",this.handleSingleKick),this.managedClients.delete(t.name)}initGlobalListeners(){this.cat.event.on(Et.ONLINE,(()=>this.handleGlobalStateChange("online")),this).on(Et.OFFLINE,(()=>this.handleGlobalStateChange("offline")),this),y.on(M.EVENT_SHOW,(()=>this.handleGlobalStateChange("show"))),y.on(M.EVENT_HIDE,(()=>this.handleGlobalStateChange("hide")))}async 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,await this.triggerReconnectAll(),await this.onEventHideDelegate.dispatch();break;case"hide":await this.onEventShowDelegate.dispatch(),this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(!this.isGlobalOnline||this.isInBackground)return;if(0===this.managedClients.size)return void r("没有任何WS需要重连");de.gui.showLoading({title:"正在重连"}),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.reconnectPromise()}catch(e){s(`${t.name}服重连失败`,e),de.gui.showToast({title:`${t.name}服重连失败`})}try{await t.connectRequest()}catch(e){s(`${t.name}服登录错误`,e),de.gui.showToast({title:`登录${t.name}服错误`})}})));const t=this.activeClients.filter((t=>t.socketConnectStatus!==j.CONNECTED));t.length>0&&(console.error("部分WS重连失败:",t.map((t=>t))),setTimeout((()=>{this.triggerReconnectAll()}),2e3))}disconnectAll(t){this.managedClients.forEach((e=>{r("断开连接",e.name,t,e.socket),e.disconnect(t)}))}handleSingleReconnect=()=>{this.activeClients.every((t=>t.socketConnectStatus===j.CONNECTED))&&(r("单个WS重连成功回调===",this.managedClients),de.gui.hideLoading().reloadScene())};handleSingleKick(){de.gui.showReconnect(Dt.KICK)}}const{ccclass:oe,property:ne,menu:re}=e;let ae=class extends at{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 x?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(D).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(D).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),de.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var ce;st([ne({type:x,tooltip:"默认标题"}),ot("design:type",x)],ae.prototype,"default_title",void 0),st([ne({type:D,tooltip:"标题节点"}),ot("design:type",D)],ae.prototype,"title",void 0),st([ne({type:b,tooltip:"字符串内容按钮"}),ot("design:type",b)],ae.prototype,"prompt_content_str",void 0),st([ne({type:D,tooltip:"图片精灵内容按钮"}),ot("design:type",D)],ae.prototype,"prompt_content_spriteFrame",void 0),st([ne({type:w,tooltip:"确认按钮"}),ot("design:type",w)],ae.prototype,"btn_confirm",void 0),st([ne({type:x,tooltip:"确认按钮精灵图"}),ot("design:type",x)],ae.prototype,"confirm_spriteFrame",void 0),st([ne({type:w,tooltip:"取消按钮"}),ot("design:type",w)],ae.prototype,"btn_cancel",void 0),st([ne({type:x,tooltip:"取消按钮精灵图"}),ot("design:type",x)],ae.prototype,"cancel_spriteFrame",void 0),st([ne({type:w,tooltip:"关闭按钮"}),ot("design:type",w)],ae.prototype,"btn_close",void 0),ae=st([oe("CoreUIModal"),re("CATCORE/CoreUIModal")],ae),function(t){t[t.Delay=0]="Delay",t[t.Interval=1]="Interval"}(ce||(ce={}));class le{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 he extends Y{timers=new Map;lastUpdateTime=Date.now();constructor(t){super(t),t.event.on(Et.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(Et.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 le(t,ce.Interval,e,i);this.timers.set(t,o)}registerDelay(t,e,i){if(this.has(t))return s(`${t}延时器已存在,请勿重复注册`);const o=new le(t,ce.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===ce.Interval&&(i.executionTime+=i.initialTime),i.callback(i.executionTime),i.type===ce.Interval?i.remainingTime=i.initialTime:t.push(e));for(const e of t)this.timers.delete(e)}}class pe{static#e;static get instance(){return this.#e||(this.#e=new pe),this.#e}onAppInitDelegate=new N;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 zt,this.util=new ee(this),this.storage=new it(this),this.event=new V,this.audio=new et(this),this.socialGameClient=new se(this),this.gui=(await new qt(this).init()).gui}}const de=pe.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]"),await de.boot(),await de.onAppInitDelegate.dispatch(),console.timeEnd("[Init App]")}));export{tt as AudioEventConstant,et as AudioManager,pt as AudioSourceBaseComponent,_t as AudioSourceUILayer,ht as AudioTypeEnum,nt as BaseComponent,Y as BaseManager,Xt as BasePrefab,Jt as CoreBlackMask,Lt as CoreNotice,Rt as CoreReconnection,It as CoreShowLoading,vt as CoreToast,wt as CoreUIContainer,ae as CoreUIModal,ee as CoreUtil,Et as GlobalEventConstant,Kt as Gui,qt as GuiManager,jt as LayerType,pe as Manager,Dt as ReconnectPrompt,Ot as RootUILayer,Ht as SceneLayer,he as TimerManager,yt as ToastType,at as UILayer,ie as WrapperSocialGameClient,de 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,AsyncDelegate as N,Game as M,SpriteFrame as x,Sprite as D}from"cc";import{PREVIEW as R,WECHAT as F,DEBUG as U}from"cc/env";import{makeObservable as P,observable as L,autorun as H,reaction as B}from"@shimotsuki/mobx";import G from"crypto-es";import{clone as $}from"@bufbuild/protobuf";import{SocketConnectStatus as j}from"pitayaclient";import{SocialGameClient as K}from"sgc";import{EventEmitter as V}from"eventemitter3";import"core-js/es/array/index.js";class W extends t{cat;initAudio(t){return this.cat=t,this}}const{ccclass:Q,menu:J}=e;class X extends W{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:q,menu:z}=e;class Z extends W{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 Y{cat;constructor(t){this.cat=t}}var tt;!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"}(tt||(tt={}));class et extends Y{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(X).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?tt.MUSIC_ON:tt.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?tt.EFFECT_ON:tt.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 it extends Y{_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(R||(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+="");R||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}`,R||(t=this.cat.util.encryptUtil.md5(t));let i=a.localStorage.getItem(t);return null==i||""===i||R||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}`,R||(t=this.cat.util.encryptUtil.md5(t)),a.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function st(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 ot(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class nt extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),P(this,{props:L,data:L})}onAutoObserver(){}addAutorun(t){return(Array.isArray(t)?t:[t]).forEach((t=>{const e=H(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===ue.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(ue.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 rt(this.node,t),this}}const rt=(t,e)=>{t.layer="string"==typeof e?2**d.nameToLayer(e):e,t?.children.forEach((t=>{rt(t,e)}))};class at extends nt{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:ct,property:lt}=e;var ht;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(ht||(ht={}));class pt extends nt{type=ht.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,ue.event.on(tt.EFFECT_ON,this.onPlayEffectHandler,this).on(tt.EFFECT_OFF,this.onStopEffectHandler,this).on(tt.MUSIC_ON,this.onPlayMusicHandler,this).on(tt.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=ue.audio;this.audioSource.volume=this.type===ht.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=ue.audio;this.audioSource.playing||!(this.type===ht.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}st([lt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(ht)}),ot("design:type",Object)],pt.prototype,"type",void 0),st([lt({tooltip:"音源",type:i}),ot("design:type",Object)],pt.prototype,"clip",void 0),st([lt({tooltip:"循环"}),ot("design:type",Object)],pt.prototype,"loop",void 0),st([lt({tooltip:"音量"}),ot("design:type",Object)],pt.prototype,"volume",void 0),st([lt({tooltip:"是否启用自动播放"}),ot("design:type",Object)],pt.prototype,"playOnAwake",void 0);const{ccclass:dt,property:ut}=e;class _t extends at{type=ht.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),ue.event.on(tt.EFFECT_ON,this.onPlayEffectHandler,this).on(tt.EFFECT_OFF,this.onStopEffectHandler,this).on(tt.MUSIC_ON,this.onPlayMusicHandler,this).on(tt.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}=ue.audio;this.audioSource.volume=this.type===ht.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=ue.audio;this.audioSource.playing||!(this.type===ht.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}st([ut({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(ht)}),ot("design:type",Object)],_t.prototype,"type",void 0),st([ut({tooltip:"音源",type:i}),ot("design:type",Object)],_t.prototype,"clip",void 0),st([ut({tooltip:"循环"}),ot("design:type",Object)],_t.prototype,"loop",void 0),st([ut({tooltip:"音量"}),ot("design:type",Object)],_t.prototype,"volume",void 0),st([ut({tooltip:"是否启用自动播放"}),ot("design:type",Object)],_t.prototype,"playOnAwake",void 0);const{ccclass:mt,property:ft,menu:gt}=e;var yt;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(yt||(yt={}));let vt=class extends nt{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==yt.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 Et;st([ft({type:o,tooltip:"固定节点"}),ot("design:type",o)],vt.prototype,"fixed_node",void 0),st([ft({type:o,tooltip:"滑动节点"}),ot("design:type",o)],vt.prototype,"slide_node",void 0),st([ft({type:b,tooltip:"固定标签节点"}),ot("design:type",b)],vt.prototype,"fixed_label",void 0),st([ft({type:b,tooltip:"滑动标签节点"}),ot("design:type",b)],vt.prototype,"slide_label",void 0),vt=st([mt("CoreToast"),gt("CATCORE/CoreToast")],vt),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"}(Et||(Et={}));const{ccclass:Ct,property:bt,menu:St}=e;let wt=class extends at{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Jt)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){ue.event.on(Et.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}};st([bt({type:o}),ot("design:type",o)],wt.prototype,"scene_mask_node",void 0),st([bt({type:o}),ot("design:type",o)],wt.prototype,"ui_container",void 0),wt=st([Ct("CoreUIContainer"),St("CATCORE/CoreUIContainer")],wt);class Ot extends at{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){ue.event.emit(Et.ROOT_MASK_UPDATE)}}const{ccclass:At,property:Tt,menu:kt}=e;let It=class extends Ot{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)}};st([Tt({type:b,tooltip:"标题"}),ot("design:type",b)],It.prototype,"title",void 0),st([Tt({type:o,tooltip:"动画"}),ot("design:type",o)],It.prototype,"loadingTween",void 0),It=st([At("CoreShowLoading"),kt("CATCORE/CoreShowLoading")],It);const{ccclass:Nt,property:Mt,menu:xt}=e;var Dt;!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="连接游戏服错误"}(Dt||(Dt={}));let Rt=class extends Ot{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==Dt.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,ue.gui.hideReconnect()}};st([Mt({type:b,tooltip:"通用提示文本"}),ot("design:type",b)],Rt.prototype,"common_prompt_text",void 0),st([Mt({type:w,tooltip:"确定按钮"}),ot("design:type",w)],Rt.prototype,"btn_confirm",void 0),Rt=st([Nt("CoreReconnection"),xt("CATCORE/CoreReconnection")],Rt);const{ccclass:Ft,property:Ut,menu:Pt}=e;let Lt=class extends Ot{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?.(),ue.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};st([Ut({type:b,tooltip:"提示文本"}),ot("design:type",b)],Lt.prototype,"text",void 0),st([Ut({type:w,tooltip:"确定按钮"}),ot("design:type",w)],Lt.prototype,"btn_confirm",void 0),Lt=st([Ft("CoreNotice"),Pt("CATCORE/CoreNotice")],Lt);class Ht extends nt{isReload}const{ccclass:Bt,property:Gt,menu:$t}=e;var jt;!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"}(jt||(jt={}));let Kt=class extends nt{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(Et.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(vt).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(vt)?.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(It).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(Lt).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(Ht);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(wt).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(at),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 at));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(Et.ROOT_MASK_CHANGE)}};st([Gt({type:l,tooltip:"断线重连UI预制体"}),ot("design:type",l)],Kt.prototype,"reconnection_ui_prefab",void 0),st([Gt({type:l,tooltip:"提示UI预制体"}),ot("design:type",l)],Kt.prototype,"toast_ui_prefab",void 0),st([Gt({type:l,tooltip:"加载UI预制体"}),ot("design:type",l)],Kt.prototype,"loading_ui_prefab",void 0),st([Gt({type:l,tooltip:"公告UI预制体"}),ot("design:type",l)],Kt.prototype,"notice_ui_prefab",void 0),st([Gt({type:l,tooltip:"UI层预制体"}),ot("design:type",l)],Kt.prototype,"ui_prefab",void 0),st([Gt({type:o,tooltip:"root-UI层"}),ot("design:type",o)],Kt.prototype,"root_ui",void 0),st([Gt({type:o,tooltip:"root-组件层"}),ot("design:type",o)],Kt.prototype,"root_toast",void 0),st([Gt({type:o,tooltip:"root-mask"}),ot("design:type",o)],Kt.prototype,"root_mask",void 0),Kt=st([Bt("Gui"),$t("CATCORE/Gui")],Kt);const{ccclass:Vt,property:Wt,menu:Qt}=e;let Jt=class extends nt{tween};var Xt;st([Wt({type:o,tooltip:"动画节点"}),ot("design:type",o)],Jt.prototype,"tween",void 0),Jt=st([Vt("CoreBlackMask"),Qt("CATCORE/CoreBlackMask")],Jt),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"}(Xt||(Xt={}));class qt extends Y{gui;#t="resources";getGuiPrefabByType=(t,e)=>new Promise(((i,s)=>{r(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,Xt.Root),e=h(t);return this.gui=e.getComponent(Kt).init(this.cat),n.addPersistRootNode(e),this}}class zt{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 Yt={stringify:t=>{const e={ct:t.ciphertext.toString(G.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=G.lib.CipherParams.create({ciphertext:G.enc.Base64.parse(e.ct)});return e.iv&&(i.iv=G.enc.Hex.parse(e.iv)),e.s&&(i.salt=G.enc.Hex.parse(e.s)),i}};var te=Object.freeze({__proto__:null,JsonFormatter:Yt,aesDecrypt:(t,e,i)=>G.AES.decrypt(t,e,{iv:Zt,format:Yt}).toString(G.enc.Utf8),aesEncrypt:(t,e,i)=>G.AES.encrypt(t,e,{iv:Zt,format:Yt}).toString(),initCrypto:(t,e)=>{Zt=G.enc.Hex.parse(e)},md5:t=>G.MD5(t).toString()});class ee extends Y{encryptUtil=te}class ie extends K{logBlackList=[];ignore=t=>this.logBlackList.includes(t);constructor(t,e,i,s){super(e,i,s,t)}destroy(){this.disconnect(!0),ue.socialGameClient.unregister(this)}async GameRequest(t,e,i,s){return new Promise(((o,n)=>{super.GameRequest(t,e,i,s).then((e=>{U&&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",$(i,e)),o(e)}),(t=>{ue.gui.showToast({title:t.msg}),n(t)}))}))}subscribe(t,e,i){return super.subscribe(t,e,(s=>{U&&!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",$(e,s)),ue.event.emit(t,$(e,s)),i?.(s)})),this}}class se extends Y{managedClients=new Map;isGlobalOnline=!0;isInBackground=!1;onEventHideDelegate=new N;onEventShowDelegate=new N;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 ie(t,i,s,Object.assign({reconnectMaxAttempts:1/0},{...e,isAutoConnect:!1,isArrayBuffer:F}));return this.register(o),o}register(t){t.on("reconnected",this.handleSingleReconnect),t.on("kick",this.handleSingleKick),this.managedClients.set(t.name,t)}unregister(t){t.off("reconnected",this.handleSingleReconnect),t.off("kick",this.handleSingleKick),this.managedClients.delete(t.name)}initGlobalListeners(){this.cat.event.on(Et.ONLINE,(()=>this.handleGlobalStateChange("online")),this).on(Et.OFFLINE,(()=>this.handleGlobalStateChange("offline")),this),y.on(M.EVENT_SHOW,(()=>this.handleGlobalStateChange("show"))),y.on(M.EVENT_HIDE,(()=>this.handleGlobalStateChange("hide")))}async 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,await this.triggerReconnectAll(),await this.onEventHideDelegate.dispatch();break;case"hide":await this.onEventShowDelegate.dispatch(),this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(!this.isGlobalOnline||this.isInBackground)return;if(0===this.managedClients.size)return void r("没有任何WS需要重连");ue.gui.showLoading({title:"正在重连"}),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.reconnectPromise()}catch(e){s(`${t.name}服重连失败`,e),ue.gui.showToast({title:`${t.name}服重连失败`})}try{await t.connectRequest()}catch(e){s(`${t.name}服登录错误`,e),ue.gui.showToast({title:`登录${t.name}服错误`})}})));const t=this.activeClients.filter((t=>t.socketConnectStatus!==j.CONNECTED));t.length>0&&(console.error("部分WS重连失败:",t.map((t=>t))),setTimeout((()=>{this.triggerReconnectAll()}),2e3))}disconnectAll(t){this.managedClients.forEach((e=>{r("断开连接",e.name,t,e.socket),e.disconnect(t)}))}handleSingleReconnect=()=>{this.activeClients.every((t=>t.socketConnectStatus===j.CONNECTED))&&(r("单个WS重连成功回调===",this.managedClients),ue.gui.hideLoading().reloadScene())};handleSingleKick(){ue.gui.showReconnect(Dt.KICK)}}class oe extends Y{}const{ccclass:ne,property:re,menu:ae}=e;let ce=class extends at{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 x?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(D).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(D).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),ue.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var le;st([re({type:x,tooltip:"默认标题"}),ot("design:type",x)],ce.prototype,"default_title",void 0),st([re({type:D,tooltip:"标题节点"}),ot("design:type",D)],ce.prototype,"title",void 0),st([re({type:b,tooltip:"字符串内容按钮"}),ot("design:type",b)],ce.prototype,"prompt_content_str",void 0),st([re({type:D,tooltip:"图片精灵内容按钮"}),ot("design:type",D)],ce.prototype,"prompt_content_spriteFrame",void 0),st([re({type:w,tooltip:"确认按钮"}),ot("design:type",w)],ce.prototype,"btn_confirm",void 0),st([re({type:x,tooltip:"确认按钮精灵图"}),ot("design:type",x)],ce.prototype,"confirm_spriteFrame",void 0),st([re({type:w,tooltip:"取消按钮"}),ot("design:type",w)],ce.prototype,"btn_cancel",void 0),st([re({type:x,tooltip:"取消按钮精灵图"}),ot("design:type",x)],ce.prototype,"cancel_spriteFrame",void 0),st([re({type:w,tooltip:"关闭按钮"}),ot("design:type",w)],ce.prototype,"btn_close",void 0),ce=st([ne("CoreUIModal"),ae("CATCORE/CoreUIModal")],ce),function(t){t[t.Delay=0]="Delay",t[t.Interval=1]="Interval"}(le||(le={}));class he{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 pe extends Y{timers=new Map;lastUpdateTime=Date.now();constructor(t){super(t),t.event.on(Et.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(Et.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 he(t,le.Interval,e,i);this.timers.set(t,o)}registerDelay(t,e,i){if(this.has(t))return s(`${t}延时器已存在,请勿重复注册`);const o=new he(t,le.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===le.Interval&&(i.executionTime+=i.initialTime),i.callback(i.executionTime),i.type===le.Interval?i.remainingTime=i.initialTime:t.push(e));for(const e of t)this.timers.delete(e)}}class de{static#e;static get instance(){return this.#e||(this.#e=new de),this.#e}onAppInitDelegate=new N;audio;event;gui;storage;res;util;socialGameClient;store;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.store=new oe(this),this.res=new zt,this.util=new ee(this),this.storage=new it(this),this.event=new V,this.audio=new et(this),this.socialGameClient=new se(this),this.gui=(await new qt(this).init()).gui}}const ue=de.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]"),await ue.boot(),await ue.onAppInitDelegate.dispatch(),console.timeEnd("[Init App]")}));export{tt as AudioEventConstant,et as AudioManager,pt as AudioSourceBaseComponent,_t as AudioSourceUILayer,ht as AudioTypeEnum,nt as BaseComponent,Y as BaseManager,Xt as BasePrefab,Jt as CoreBlackMask,Lt as CoreNotice,Rt as CoreReconnection,It as CoreShowLoading,vt as CoreToast,wt as CoreUIContainer,ce as CoreUIModal,ee as CoreUtil,Et as GlobalEventConstant,Kt as Gui,qt as GuiManager,jt as LayerType,de as Manager,Dt as ReconnectPrompt,Ot as RootUILayer,Ht as SceneLayer,pe as TimerManager,yt as ToastType,at as UILayer,ie as WrapperSocialGameClient,ue as cat};
|