@shimotsuki/core 2.0.65 → 2.0.67
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/shimotsuki_core.js +1 -1
- package/package.json +1 -1
package/dist/shimotsuki_core.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,UIOpacity as v,Tween as E,Label as C,BlockInputEvents as b,Button as w,Director as S,warn as T,assetManager as A,Asset as I,resources as O,AsyncDelegate as k,Game as N,SpriteFrame as D,Sprite as R}from"cc";import{PREVIEW as M,WECHAT as x,DEBUG as F}from"cc/env";import{makeObservable as P,observable as U,autorun as L,reaction as B}from"@shimotsuki/mobx";import H from"crypto-es";import{clone as G}from"@bufbuild/protobuf";import{SocketConnectStatus as $}from"pitayaclient";import{SocialGameClient as K}from"sgc";import{EventEmitter as j}from"eventemitter3";import"core-js/es/array/index.js";class V extends t{cat;initAudio(t){return this.cat=t,this}}const{ccclass:W,menu:z}=e;let Q=class extends V{effects=new Map;load(t){return new Promise(((e,s)=>{this.cat.res.load(t,i,((i,o)=>{if(i)return s(i);this.effects.set(t,o),this.playOneShot(o,this.volume),e(o)}))}))}release(){for(let t in this.effects)this.cat.res.release(t);this.effects.clear()}};const{ccclass:J,menu:X}=e;class q extends V{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(t){this._progress=t,this.currentTime=t*this.duration}load(t,e){this.cat.res.load(t,i,((i,o)=>{i&&s(i),this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=o,this._url=t,e&&e()}))}update(t){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class Z{cat;constructor(t){this.cat=t}}var Y;!function(t){t.MUSIC_ON="AudioEventConstant/MUSIC_ON",t.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",t.EFFECT_ON="AudioEventConstant/EFFECT_ON",t.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",t.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",t.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(Y||(Y={}));class tt extends Z{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(t){super(t),this.local_store_key=this.cat.audio_local_store_key;var e=new o("UIAudioManager");n.addPersistRootNode(e);var i=new o("UIMusic");i.parent=e,this.music=i.addComponent(q).initAudio(t);var s=new o("UIEffect");s.parent=e,this.effect=s.addComponent(Q).initAudio(t),this.load()}setMusicComplete(t=null){this.music.onComplete=t}playMusic(t,e){this.music.loop=!0,t&&this.music.load(t,(()=>{this._switch_music&&this.music?.play(),e&&e()}))}stopMusic(){0!=this.music.state&&this.music?.stop()}pauseMusic(){1==this.music.state&&this.music?.pause()}resumeMusic(){[0,2].includes(this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(t){this.music.progress=t}get volumeMusic(){return this._volume_music}set volumeMusic(t){this._volume_music=t,this.music.volume=t}get switchMusic(){return this._switch_music}set switchMusic(t){if(r("设置背景音乐开关值",t,this._switch_music),t==this._switch_music)return;this._switch_music=t,t?this.resumeMusic():this.pauseMusic();const e=t?Y.MUSIC_ON:Y.MUSIC_OFF;this.cat.event.emit(e),this.save()}async playEffect(t){this._switch_effect&&t&&await this.effect.load(t).then((()=>{this.effect.play()}))}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(t){this._volume_effect=t,this.effect.volume=t}get switchEffect(){return this._switch_effect}set switchEffect(t){if(t==this._switch_effect)return;this._switch_effect=t,t?this.effect?.play():this.effect?.stop();const e=t?Y.EFFECT_ON:Y.EFFECT_OFF;this.cat.event.emit(e),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let t=JSON.stringify(this.local_data);return this.cat.storage.set(this.local_store_key,t),this}load(){try{let t=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(t),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(t){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}class et extends Z{_key=null;_iv=null;_id="";init(t,e){this.cat.util.encryptUtil.initCrypto(t,e),this._key=this.cat.util.encryptUtil.md5(t),this._iv=this.cat.util.encryptUtil.md5(e)}setUser(t){this._id=t}set(t,e){if(null!=(t=`${t}_${this._id}`)){if(M||(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+="");M||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}`,M||(t=this.cat.util.encryptUtil.md5(t));let i=a.localStorage.getItem(t);return null==i||""===i||M||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}`,M||(t=this.cat.util.encryptUtil.md5(t)),a.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function it(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function st(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class ot extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),P(this,{props:U,data:U})}onAutoObserver(){}addAutorun(t){return(Array.isArray(t)?t:[t]).forEach((t=>{const e=L(t);this.autorunDisposers.push(e)})),this}addReaction(t,e,i){const s=B(t,e,i);return this.reactionDisposers.push(s),this}addAudoListener(t){return this.eventEmitter.includes(t)||t===me.event||this.eventEmitter.push(t),t}_onPreDestroy(){if(this.autorunDisposers.forEach((t=>{t()})),this.reactionDisposers.forEach((t=>{t()})),this.autorunDisposers=[],this.reactionDisposers=[],!super._onPreDestroy)throw new Error("_onPreDestroy已弃用");super._onPreDestroy()}onDisable(){this.onHide(),this.deleteAllEventByEmitter(me.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,i){const s=t instanceof l?h(t):t instanceof c?t.node:t;if("number"==typeof e){const t=e,o=i;this.setOptions(o),s.insertChild(this.node,t)}else{const t=e;this.setOptions(t),s.addChild(this.node)}return this}setOptions(t){if(t)for(let e in t)switch(e){case"hook":t.hook&&(this.hook=t.hook);break;case"props":null!==t.props&&"object"==typeof t.props&&(this.props=t.props);break;case"data":null!==t.data&&"object"==typeof t.data&&(this.data=t.data)}}setUpdateData(t){return t&&Object.assign(this.data,t),this}setUpdateProps(t){return this.props,t&&Object.assign(this.props,t),this}removeAndDestroy(){p(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(t){return this.node.setPosition(t),this}setScale(t){return this.node.setScale(t),this}setAngle(t){return this.node.angle=t,this}setRotation(t){return this.node.setRotation(t),this}setRotationFromEuler(t){return this.node.setRotationFromEuler(t),this}onShow(){}onHide(){}setNodeAndChildrenLayer(t){return nt(this.node,t),this}}const nt=(t,e)=>{t.layer="string"==typeof e?2**d.nameToLayer(e):e,t?.children.forEach((t=>{nt(t,e)}))};class rt extends ot{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=u.getVisibleSize()}async showTween({isMotion:t=!0,direction:e="center",duration:i=.1,isBounce:s=!0,bounceDuration:o=.05}){if(this.lastEnterDirection=e,t){const t=this.node.getComponent(_);let o,n;t&&(t.updateAlignment(),t.enabled=!1),m(1.1,1.1,1),"center"==e?(o=m(.01,.01,.01),n=m(1,1,1)):(o="left"==e?m(-this.screen.width,0,0):"right"==e?m(this.screen.width,0,0):m(0,"top"==e?this.screen.height:-this.screen.height,0),n=m(0,0,0)),await this.handle(e,i,o,n,s),t&&(t.enabled=!0)}}async hideTween({isMotion:t=!0,direction:e,duration:i=.1}){if(e=e||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,f(this.node).removeSelf(),t){const t=this.node.getComponent(_);let s,o;t&&(t.enabled=!1),"center"==e?(s=this.node.scale,o=m(0,0,0)):(o="left"==e?m(-this.screen.width,0,0):"right"==e?m(this.screen.width,0,0):m(0,"top"==e?this.screen.height:-this.screen.height,0),s=this.node.getPosition()),await this.handle(e,i,s,o,!1)}this.removeAndDestroy()}}async handle(t,e,i,s,o){"center"==t?this.node.setScale(i):this.node.setPosition(i),await this.deftween(e,{["center"==t?"scale":"position"]:s},o)}deftween(t,e,i,s){return new Promise(((i,s)=>{f(this.node).to(t,e).call((()=>{i()})).start()}))}}const{ccclass:at,property:ct}=e;var lt;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(lt||(lt={}));class ht extends ot{type=lt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,me.event.on(Y.EFFECT_ON,this.onPlayEffectHandler,this).on(Y.EFFECT_OFF,this.onStopEffectHandler,this).on(Y.MUSIC_ON,this.onPlayMusicHandler,this).on(Y.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=me.audio;this.audioSource.volume=this.type===lt.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=me.audio;this.audioSource.playing||!(this.type===lt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}it([ct({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(lt)}),st("design:type",Number)],ht.prototype,"type",void 0),it([ct({tooltip:"音源",type:i}),st("design:type",i)],ht.prototype,"clip",void 0),it([ct({tooltip:"循环"}),st("design:type",Boolean)],ht.prototype,"loop",void 0),it([ct({tooltip:"音量"}),st("design:type",Number)],ht.prototype,"volume",void 0),it([ct({tooltip:"是否启用自动播放"}),st("design:type",Boolean)],ht.prototype,"playOnAwake",void 0);const{ccclass:pt,property:dt}=e;class ut extends rt{type=lt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),me.event.on(Y.EFFECT_ON,this.onPlayEffectHandler,this).on(Y.EFFECT_OFF,this.onStopEffectHandler,this).on(Y.MUSIC_ON,this.onPlayMusicHandler,this).on(Y.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:t,volumeMusic:e}=me.audio;this.audioSource.volume=this.type===lt.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=me.audio;this.audioSource.playing||!(this.type===lt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}it([dt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(lt)}),st("design:type",Number)],ut.prototype,"type",void 0),it([dt({tooltip:"音源",type:i}),st("design:type",i)],ut.prototype,"clip",void 0),it([dt({tooltip:"循环"}),st("design:type",Boolean)],ut.prototype,"loop",void 0),it([dt({tooltip:"音量"}),st("design:type",Number)],ut.prototype,"volume",void 0),it([dt({tooltip:"是否启用自动播放"}),st("design:type",Boolean)],ut.prototype,"playOnAwake",void 0);const{ccclass:_t,property:mt,menu:ft}=e;var gt;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(gt||(gt={}));let yt=class extends ot{fixed_node;slide_node;fixed_label;slide_label;onLoad(){this.fixed_node.active=this.slide_node.active=!1}start(){this.show()}async show(){return new Promise((async(t,e)=>{const{title:i,type:s,fixed_time:o}=this.props;s==gt.FIXED?(this.fixed_node.active=!0,this.fixed_label.string=`${i}`,this.scheduleOnce((()=>{this.node.destroy(),t()}),o)):(this.slide_node.active=!0,this.slide_label.string=`${i}`,this.playAnim(this.node).then((()=>{t()})))}))}playAnim(t){return new Promise(((e,i)=>{const s=this.node.getComponent(v),o=f(s).delay(1.2).to(.5,{opacity:0}).call((()=>{E.stopAllByTarget(t),this.node.destroy(),e()}));f(t).by(.5,{position:m(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){E.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var vt;it([mt({type:o,tooltip:"固定节点"}),st("design:type",o)],yt.prototype,"fixed_node",void 0),it([mt({type:o,tooltip:"滑动节点"}),st("design:type",o)],yt.prototype,"slide_node",void 0),it([mt({type:C,tooltip:"固定标签节点"}),st("design:type",C)],yt.prototype,"fixed_label",void 0),it([mt({type:C,tooltip:"滑动标签节点"}),st("design:type",C)],yt.prototype,"slide_label",void 0),yt=it([_t("CoreToast"),ft("CATCORE/CoreToast")],yt),function(t){t.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",t.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",t.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",t.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",t.ONLINE="GlobalEventConstant/ONLINE",t.OFFLINE="GlobalEventConstant/OFFLINE",t.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",t.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(vt||(vt={}));const{ccclass:Et,property:Ct,menu:bt}=e;let wt=class extends rt{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(zt)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){me.event.on(vt.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const t=this.brother[this.brother.length-1];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const t=this.brother[this.brother.length-2];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(t){return p(this)&&this.scene_mask&&this.scene_mask.tween.addChild(t),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(t){return this.gui=t,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(t){this.scene_mask.node.active=t}};it([Ct({type:o}),st("design:type",o)],wt.prototype,"scene_mask_node",void 0),it([Ct({type:o}),st("design:type",o)],wt.prototype,"ui_container",void 0),wt=it([Et("CoreUIContainer"),bt("CATCORE/CoreUIContainer")],wt);class St extends rt{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){me.event.emit(vt.ROOT_MASK_UPDATE)}}const{ccclass:Tt,property:At,menu:It}=e;let Ot=class extends St{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(b).enabled=!!this.props?.mask}])}update(t){this.loading_rotate+=220*t,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};it([At({type:C,tooltip:"标题"}),st("design:type",C)],Ot.prototype,"title",void 0),it([At({type:o,tooltip:"动画"}),st("design:type",o)],Ot.prototype,"loadingTween",void 0),Ot=it([Tt("CoreShowLoading"),It("CATCORE/CoreShowLoading")],Ot);const{ccclass:kt,property:Nt,menu:Dt}=e;var Rt;!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="连接游戏服错误"}(Rt||(Rt={}));let Mt=class extends St{common_prompt_text;btn_confirm;btn_close;is_close=!1;props={content:null};initUI(){}onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.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==Rt.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,me.gui.hideReconnect()}};it([Nt({type:C,tooltip:"通用提示文本"}),st("design:type",C)],Mt.prototype,"common_prompt_text",void 0),it([Nt({type:w,tooltip:"确定按钮"}),st("design:type",w)],Mt.prototype,"btn_confirm",void 0),it([Nt({type:w,tooltip:"关闭按钮"}),st("design:type",w)],Mt.prototype,"btn_close",void 0),Mt=it([kt("CoreReconnection"),Dt("CATCORE/CoreReconnection")],Mt);const{ccclass:xt,property:Ft,menu:Pt}=e;let Ut=class extends St{text;btn_confirm;btn_close;onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),me.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};it([Ft({type:C,tooltip:"提示文本"}),st("design:type",C)],Ut.prototype,"text",void 0),it([Ft({type:w,tooltip:"确定按钮"}),st("design:type",w)],Ut.prototype,"btn_confirm",void 0),it([Ft({type:w,tooltip:"关闭按钮"}),st("design:type",w)],Ut.prototype,"btn_close",void 0),Ut=it([xt("CoreNotice"),Pt("CATCORE/CoreNotice")],Ut);class Lt extends ot{isReload}const{ccclass:Bt,property:Ht,menu:Gt}=e;var $t;!function(t){t[t.UI=0]="UI",t[t.LOADING=1]="LOADING",t[t.TOAST=2]="TOAST",t[t.RECONNECTTION=3]="RECONNECTTION",t[t.NOTICE=4]="NOTICE"}($t||($t={}));let Kt=class extends ot{reconnection_ui_prefab;toast_ui_prefab;loading_ui_prefab;notice_ui_prefab;ui_prefab;root_ui;root_toast;root_mask;cat;ui_container_component;reconnection_ui_component;notice_ui_component;loading_ui_component;toast_ui_component;currentScene;onEventListener(){this.cat.event.on(vt.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(t){this.cat=t;const e=n.getScene();return r("init scene"),e&&this.changeScene(e),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(t){this.toastQueue.push(t),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const t=this.toastQueue.shift(),e=()=>{h(this.toast_ui_prefab).getComponent(yt).addToParent(this.root_toast,{props:t}),this.scheduleOnce((()=>{this.processQueueWithInterval()}),this.minInterval)};0===this.root_toast.children.length?e():this.scheduleOnce(e,this.minInterval)}hideToast(){return this.root_toast&&this.root_toast.children.forEach((t=>{t.getComponent(yt)?.removeAndDestroy()})),this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading({title:t="",mask:e=!0,black:i=!0}={}){if(r("showLoading",t),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:t,mask:e,black:i}});else{const s=h(this.loading_ui_prefab);this.loading_ui_component=s.getComponent(Ot).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(Mt).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(Ut).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(S.EVENT_BEFORE_SCENE_LAUNCH,(t=>{r("Director.EVENT_BEFORE_SCENE_LAUNCH",t),this.changeScene(t,s,o)})),n.loadScene(t),this}resetScene(t=""){return t=t||this.currentScene,this.loadScene(t)}cleanScene(){this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast()}changeScene(t,e,i){this.currentScene=t.name,this.createUILayer(t);const s=t.getComponentInChildren(Lt);s&&(s.isReload=i??!1),s?.setOptions(e)}createUILayer(t){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const e=h(this.ui_prefab);this.ui_container_component=e.getComponent(wt).setGui(this).addToParent(t,this.node.getSiblingIndex())}reloadScene(){this.loadScene(this.currentScene,!0)}async closeUI(t,e){const{component:i}=this.findUIBaseLayer(t,!1);i&&(i.setOptions({...e?.hook??{},...e?.props??{}}),await i.hideTween(e||{}),this.ui_container_component?.subMask())}async openUI(t,e){const{rootNode:i,component:s}=this.findUIBaseLayer(t,!0);i.getComponent(rt),s?.setOptions(e),i&&this.ui_container_component?.addNodeToTween(i).addMask(),s&&await s.showTween(e||{}),this.ui_container_component?.ui_container&&s?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(t,e){let i,n=null;if(t instanceof o){i=t;const e=t.components.filter((t=>t instanceof rt));if(!e.length)return s(`${t.name}节点未找到继承自BaseLayer的组件`),{rootNode:i,component:n};1==e.length?n=e[0]:T(`${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].getSiblingIndex()-1;this.root_mask.setSiblingIndex(e<0?0:e)}this.cat.event.emit(vt.ROOT_MASK_CHANGE)}};it([Ht({type:l,tooltip:"断线重连UI预制体"}),st("design:type",l)],Kt.prototype,"reconnection_ui_prefab",void 0),it([Ht({type:l,tooltip:"提示UI预制体"}),st("design:type",l)],Kt.prototype,"toast_ui_prefab",void 0),it([Ht({type:l,tooltip:"加载UI预制体"}),st("design:type",l)],Kt.prototype,"loading_ui_prefab",void 0),it([Ht({type:l,tooltip:"公告UI预制体"}),st("design:type",l)],Kt.prototype,"notice_ui_prefab",void 0),it([Ht({type:l,tooltip:"UI层预制体"}),st("design:type",l)],Kt.prototype,"ui_prefab",void 0),it([Ht({type:o,tooltip:"root-UI层"}),st("design:type",o)],Kt.prototype,"root_ui",void 0),it([Ht({type:o,tooltip:"root-组件层"}),st("design:type",o)],Kt.prototype,"root_toast",void 0),it([Ht({type:o,tooltip:"root-mask"}),st("design:type",o)],Kt.prototype,"root_mask",void 0),Kt=it([Bt("Gui"),Gt("CATCORE/Gui")],Kt);const{ccclass:jt,property:Vt,menu:Wt}=e;let zt=class extends ot{tween};var Qt;it([Vt({type:o,tooltip:"动画节点"}),st("design:type",o)],zt.prototype,"tween",void 0),zt=it([jt("CoreBlackMask"),Wt("CATCORE/CoreBlackMask")],zt),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"}(Qt||(Qt={}));class Jt extends Z{gui;#t="core";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.cat.gui_bundle_name&&(this.#t=this.cat.gui_bundle_name);const t=await this.getGuiPrefabByType(this.#t,Qt.Root),e=h(t);return this.gui=e.getComponent(Kt).init(this.cat),n.addPersistRootNode(e),this}}class Xt{get=(t,e,i="resources")=>A.getBundle(i).get(t,e);isAssetType=t=>"function"==typeof t&&t.prototype instanceof I;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=O;if(e&&"resources"!=e){A.bundles.has(e)||await this.loadBundle(e);let t=A.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=O;if(e&&"resources"!=e){A.bundles.has(e)||await this.loadBundle(e);let t=A.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(),A.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?A.loadBundle(t,{version:e},o):A.loadBundle(t,o)}));releasePrefabtDepsRecursively=t=>{var e=A.assets.get(t);(A.releaseAsset(e),e instanceof l)&&A.dependUtil.getDepsRecursively(t).forEach((t=>{A.assets.get(t).decRef()}))};release=(t,e="resources")=>{var i=A.getBundle(e);if(i){var s=i.get(t);s&&this.releasePrefabtDepsRecursively(s._uuid)}};releaseDir=(t,e="resources")=>{var i=A.getBundle(e),s=i?.getDirWithPath(t);s?.map((t=>{this.releasePrefabtDepsRecursively(t.uuid)})),!t&&"resources"!=e&&i&&A.removeBundle(i)};dump=()=>{A.assets.forEach(((t,e)=>{r(A.assets.get(e))})),r(`当前资源总数:${A.assets.count}`)}}let qt=null;const Zt={stringify:t=>{const e={ct:t.ciphertext.toString(H.enc.Base64)};return t.iv&&(e.iv=t.iv.toString()),t.salt&&(e.s=t.salt.toString()),JSON.stringify(e)},parse:t=>{const e=JSON.parse(t),i=H.lib.CipherParams.create({ciphertext:H.enc.Base64.parse(e.ct)});return e.iv&&(i.iv=H.enc.Hex.parse(e.iv)),e.s&&(i.salt=H.enc.Hex.parse(e.s)),i}};var Yt=Object.freeze({__proto__:null,JsonFormatter:Zt,aesDecrypt:(t,e,i)=>H.AES.decrypt(t,e,{iv:qt,format:Zt}).toString(H.enc.Utf8),aesEncrypt:(t,e,i)=>H.AES.encrypt(t,e,{iv:qt,format:Zt}).toString(),initCrypto:(t,e)=>{qt=H.enc.Hex.parse(e)},md5:t=>H.MD5(t).toString()});class te extends Z{encryptUtil=Yt}class ee extends K{logBlackList=[];ignore=t=>this.logBlackList.includes(t);constructor(t,e,i,s){super(e,i,s,t)}destroy(){this.disconnect(!0),me.socialGameClient.unregister(this)}async GameRequest(t,e,i,s){return new Promise(((o,n)=>{super.GameRequest(t,e,i,s).then((e=>{F&&r(`%c ws服务端消息 %c [Response][${new Date}] %c ${t} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(i,e)),o(e)}),(t=>{me.gui.showToast({title:t.msg}),n(t)}))}))}subscribe(t,e,i){return super.subscribe(t,e,(s=>{F&&!this.ignore(t)&&r(`%c ws服务端消息:[subscribe][${new Date}] %c ${t} %c`,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#410083 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(e,s)),me.event.emit(t,G(e,s)),i?.(s)})),this}}class ie extends Z{managedClients=new Map;isGlobalOnline=!0;isInBackground=!1;reconnecting=!1;onEventHideDelegate=new k;onEventShowDelegate=new k;onEventReloadSceneDelegate=new k;reconnectTimer=null;scheduleReconnect(t=2e3){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectTimer=setTimeout((()=>{this.reconnectTimer=null,this.triggerReconnectAll()}),t)}get activeClients(){return Array.from(this.managedClients).map((([t,e])=>e)).filter((t=>t.socket))}constructor(t){super(t),this.initGlobalListeners()}createWebSocket(t,e,i,s){if(this.managedClients.has(t)){this.managedClients.get(t).destroy(),r(`清理旧的 ${t} 客户端`)}const o=new ee(t,i,s,Object.assign({reconnectMaxAttempts:1/0},{...e,isAutoConnect:!1,isArrayBuffer:x}));return this.register(o),o}register(t){t.on("reconnected",this.handleSingleReconnect),t.on("close",this.handleSingleClose),t.on("kick",this.handleSingleKick),this.managedClients.set(t.name,t)}unregister(t){t.off("reconnected",this.handleSingleReconnect),t.off("close",this.handleSingleClose),t.off("kick",this.handleSingleKick),this.managedClients.delete(t.name)}initGlobalListeners(){this.cat.event.on(vt.ONLINE,(()=>this.handleGlobalStateChange("online")),this).on(vt.OFFLINE,(()=>this.handleGlobalStateChange("offline")),this),y.on(N.EVENT_SHOW,(()=>this.handleGlobalStateChange("show"))),y.on(N.EVENT_HIDE,(()=>this.handleGlobalStateChange("hide")))}async handleGlobalStateChange(t){switch(t){case"online":me.gui.showLoading({title:Rt.ONLINE}),this.isGlobalOnline=!0,this.triggerReconnectAll();break;case"offline":this.isGlobalOnline=!1,this.disconnectAll(!0),me.gui.showLoading({title:Rt.OFFLINE});break;case"show":this.isInBackground=!1,await this.triggerReconnectAll(),await this.onEventShowDelegate.dispatch();break;case"hide":await this.onEventHideDelegate.dispatch(),this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(r("触发所有客户端重连",this.reconnecting,!this.isGlobalOnline,this.isInBackground,this.managedClients.size),!this.reconnecting&&this.isGlobalOnline&&!this.isInBackground&&0!==this.managedClients.size){this.reconnecting=!0,me.gui.showLoading({title:"正在重连"});try{await Promise.allSettled(this.activeClients.map((async t=>{try{await t.reconnectPromise()}catch(e){s(`${t.name}服重连失败`,e)}})));const t=this.activeClients.filter((t=>t.socketConnectStatus!==$.CONNECTED));t.length>0?(console.error("部分WS重连失败:",t.map((t=>t))),r("2s后重连所有客户端"),this.reconnecting=!1,this.scheduleReconnect()):this.reconnecting=!1}catch(t){throw this.reconnecting=!1,t}}}disconnectAll(t){this.managedClients.forEach((e=>{r("断开连接",e.name,t,e.socket),e.disconnect(t)}))}handleSingleClose=()=>{this.reconnecting||(r("3s后重连所有客户端"),this.scheduleReconnect(3e3))};handleSingleReconnect=async()=>{this.activeClients.every((t=>t.socketConnectStatus===$.CONNECTED))&&(r("单个WS重连成功回调===",this.managedClients),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.connectRequest()}catch(e){s(`${t.name}服登录错误`,e),me.gui.showToast({title:`登录${t.name}服错误`})}}))),await this.onEventReloadSceneDelegate.dispatch(),me.gui.hideLoading().reloadScene())};handleSingleKick=()=>{me.gui.showReconnect(Rt.KICK)}}class se{rootStore;constructor(t){this.rootStore=t}}class oe extends Z{}const{ccclass:ne,property:re,menu:ae}=e;let ce=class extends rt{default_title=null;title;prompt_content_str;prompt_content_spriteFrame;btn_confirm;confirm_spriteFrame;btn_cancel;cancel_spriteFrame;btn_close;isConfirm=!1;props={title:this.default_title,content:null,confirmCB:()=>{},cancelCB:()=>{},style:null};onLoad(){this.btn_cancel.node.on(w.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(w.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content&&(this.props.content instanceof D?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?.(),me.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var le;it([re({type:D,tooltip:"默认标题"}),st("design:type",D)],ce.prototype,"default_title",void 0),it([re({type:R,tooltip:"标题节点"}),st("design:type",R)],ce.prototype,"title",void 0),it([re({type:C,tooltip:"字符串内容按钮"}),st("design:type",C)],ce.prototype,"prompt_content_str",void 0),it([re({type:R,tooltip:"图片精灵内容按钮"}),st("design:type",R)],ce.prototype,"prompt_content_spriteFrame",void 0),it([re({type:w,tooltip:"确认按钮"}),st("design:type",w)],ce.prototype,"btn_confirm",void 0),it([re({type:D,tooltip:"确认按钮精灵图"}),st("design:type",D)],ce.prototype,"confirm_spriteFrame",void 0),it([re({type:w,tooltip:"取消按钮"}),st("design:type",w)],ce.prototype,"btn_cancel",void 0),it([re({type:D,tooltip:"取消按钮精灵图"}),st("design:type",D)],ce.prototype,"cancel_spriteFrame",void 0),it([re({type:w,tooltip:"关闭按钮"}),st("design:type",w)],ce.prototype,"btn_close",void 0),ce=it([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 Z{timers=new Map;lastUpdateTime=Date.now();constructor(t){super(t),t.event.on(vt.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(vt.EVENT_SHOW,this.onHandleAppForeground,this),setInterval(this.update.bind(this),1e3)}onHandleAppBackground(){this.lastUpdateTime=Date.now()}onHandleAppForeground(){const t=Date.now(),e=t-this.lastUpdateTime;r("elapsedTime",e);for(const t of this.timers.values())t.remainingTime>0&&(t.remainingTime-=e,t.executionTime+=e);this.lastUpdateTime=t}registerInterval(t,e,i){if(this.has(t))return s(`${t}定时器已存在,请勿重复注册`);const o=new 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)}}const de=(t,e)=>(i,s,o)=>{let n=o.value;return o.value=function(...i){const s=t??me.default_audio_effect;s?me.audio.playEffect(s):console.warn("请添加音效路径参数"),e&&e(),n.apply(this,i)},o},ue=(t=1,e)=>function(i,s,o){let n=o.value,r=!1;return o.value=function(...i){r?e&&e():(r=!0,setTimeout((()=>{r=!1}),1e3*t),n.apply(this,i))},o};class _e{static#e=null;#i=!1;static get instance(){return this.#e??(this.#e=new _e)}onAppInitDelegate=new k;onPlugInInitDelegate=new k;#s=null;get audio(){return this.#s}#o=null;get event(){return this.#o}#n=null;get gui(){return this.#n}#r=null;get storage(){return this.#r}#a=null;get res(){return this.#a}#c=null;get util(){return this.#c}#l=null;get socialGameClient(){return this.#l}#h=null;get store(){return this.#h}#p="";get gui_bundle_name(){return this.#p}#d="";get audio_local_store_key(){return this.#d}#u="";get default_audio_effect(){return this.#u}setConfig=({default_audio_effect:t="",gui_bundleName:e="resources",audio_local_store_key:i="game_audio"}={})=>{if(this.#i)throw new Error("[CAT] 已初始化,无法修改配置");return this.#p=e,this.#d=i,this.#u=t,this};async boot(){if(this.#i)throw new Error("[CAT] 已初始化");try{this.#h=new oe(this),this.#a=new Xt,this.#c=new te(this),this.#r=new et(this),this.#o=new j,this.#s=new tt(this),this.#l=new ie(this),this.#n=(await new Jt(this).init()).gui,this.#i=!0}catch(t){throw console.error("[CAT] 初始化失败:",t),t}}merge(t,e){if(!this.#i)throw new Error("[CAT] 未初始化");if("string"!=typeof t)throw new Error("merge方法第一个参数应该为string类型");return Reflect.get(this,t)||Reflect.set(this,t,e),Object.assign(Reflect.get(this,t),e),this}appendPlugInInitDelegate(t){return this.#i?Promise.resolve().then(t).catch((t=>{console.error("[CAT] appendPlugInInitDelegate 回调执行失败:",t)})):this.onPlugInInitDelegate.add(t),this}}const me=_e.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]");try{await me.boot(),await me.onAppInitDelegate.dispatch(),await me.onPlugInInitDelegate.dispatch()}catch(t){throw s(`[Init App] 初始化失败: ${t instanceof Error?t.message:String(t)}`),t}finally{console.timeEnd("[Init App]")}}));export{de as AudioEffect,Y as AudioEventConstant,tt as AudioManager,ht as AudioSourceBaseComponent,ut as AudioSourceUILayer,lt as AudioTypeEnum,ot as BaseComponent,Z as BaseManager,Qt as BasePrefab,se as BaseStore,ue as ButtonLock,zt as CoreBlackMask,Ut as CoreNotice,Mt as CoreReconnection,Ot as CoreShowLoading,oe as CoreStore,yt as CoreToast,wt as CoreUIContainer,ce as CoreUIModal,te as CoreUtil,vt as GlobalEventConstant,Kt as Gui,Jt as GuiManager,$t as LayerType,_e as Manager,Rt as ReconnectPrompt,St as RootUILayer,Lt as SceneLayer,pe as TimerManager,gt as ToastType,rt as UILayer,ee as WrapperSocialGameClient,me 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,UIOpacity as v,Tween as E,Label as C,BlockInputEvents as b,Button as w,Director as S,warn as T,assetManager as A,Asset as I,resources as O,AsyncDelegate as k,Game as N,SpriteFrame as D,Sprite as R}from"cc";import{PREVIEW as M,WECHAT as x,DEBUG as F}from"cc/env";import{makeObservable as P,observable as U,autorun as L,reaction as B}from"@shimotsuki/mobx";import H from"crypto-es";import{clone as G}from"@bufbuild/protobuf";import{SocketConnectStatus as $}from"pitayaclient";import{SocialGameClient as K}from"sgc";import{EventEmitter as j}from"eventemitter3";import"core-js/es/array/index.js";class V extends t{cat;initAudio(t){return this.cat=t,this}}const{ccclass:W,menu:z}=e;let Q=class extends V{effects=new Map;load(t){return new Promise(((e,s)=>{this.cat.res.load(t,i,((i,o)=>{if(i)return s(i);this.effects.set(t,o),this.playOneShot(o,this.volume),e(o)}))}))}release(){for(let t in this.effects)this.cat.res.release(t);this.effects.clear()}};const{ccclass:J,menu:X}=e;class q extends V{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(t){this._progress=t,this.currentTime=t*this.duration}load(t,e){this.cat.res.load(t,i,((i,o)=>{i&&s(i),this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=o,this._url=t,e&&e()}))}update(t){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class Z{cat;constructor(t){this.cat=t}}var Y;!function(t){t.MUSIC_ON="AudioEventConstant/MUSIC_ON",t.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",t.EFFECT_ON="AudioEventConstant/EFFECT_ON",t.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",t.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",t.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(Y||(Y={}));class tt extends Z{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(t){super(t),this.local_store_key=this.cat.audio_local_store_key;var e=new o("UIAudioManager");n.addPersistRootNode(e);var i=new o("UIMusic");i.parent=e,this.music=i.addComponent(q).initAudio(t);var s=new o("UIEffect");s.parent=e,this.effect=s.addComponent(Q).initAudio(t),this.load()}setMusicComplete(t=null){this.music.onComplete=t}playMusic(t,e){this.music.loop=!0,t&&this.music.load(t,(()=>{this._switch_music&&this.music?.play(),e&&e()}))}stopMusic(){0!=this.music.state&&this.music?.stop()}pauseMusic(){1==this.music.state&&this.music?.pause()}resumeMusic(){[0,2].includes(this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(t){this.music.progress=t}get volumeMusic(){return this._volume_music}set volumeMusic(t){this._volume_music=t,this.music.volume=t}get switchMusic(){return this._switch_music}set switchMusic(t){if(r("设置背景音乐开关值",t,this._switch_music),t==this._switch_music)return;this._switch_music=t,t?this.resumeMusic():this.pauseMusic();const e=t?Y.MUSIC_ON:Y.MUSIC_OFF;this.cat.event.emit(e),this.save()}async playEffect(t){this._switch_effect&&t&&await this.effect.load(t).then((()=>{this.effect.play()}))}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(t){this._volume_effect=t,this.effect.volume=t}get switchEffect(){return this._switch_effect}set switchEffect(t){if(t==this._switch_effect)return;this._switch_effect=t,t?this.effect?.play():this.effect?.stop();const e=t?Y.EFFECT_ON:Y.EFFECT_OFF;this.cat.event.emit(e),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let t=JSON.stringify(this.local_data);return this.cat.storage.set(this.local_store_key,t),this}load(){try{let t=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(t),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(t){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}class et extends Z{_key=null;_iv=null;_id="";init(t,e){this.cat.util.encryptUtil.initCrypto(t,e),this._key=this.cat.util.encryptUtil.md5(t),this._iv=this.cat.util.encryptUtil.md5(e)}setUser(t){this._id=t}set(t,e){if(null!=(t=`${t}_${this._id}`)){if(M||(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+="");M||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}`,M||(t=this.cat.util.encryptUtil.md5(t));let i=a.localStorage.getItem(t);return null==i||""===i||M||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}`,M||(t=this.cat.util.encryptUtil.md5(t)),a.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){a.localStorage.clear()}}function it(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function st(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class ot extends c{props={};data={};autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),P(this,{props:U,data:U})}onAutoObserver(){}addAutorun(t){return(Array.isArray(t)?t:[t]).forEach((t=>{const e=L(t);this.autorunDisposers.push(e)})),this}addReaction(t,e,i){const s=B(t,e,i);return this.reactionDisposers.push(s),this}addAudoListener(t){return this.eventEmitter.includes(t)||t===me.event||this.eventEmitter.push(t),t}_onPreDestroy(){if(this.autorunDisposers.forEach((t=>{t()})),this.reactionDisposers.forEach((t=>{t()})),this.autorunDisposers=[],this.reactionDisposers=[],!super._onPreDestroy)throw new Error("_onPreDestroy已弃用");super._onPreDestroy()}onDisable(){this.onHide(),this.deleteAllEventByEmitter(me.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,i){const s=t instanceof l?h(t):t instanceof c?t.node:t;if("number"==typeof e){const t=e,o=i;this.setOptions(o),s.insertChild(this.node,t)}else{const t=e;this.setOptions(t),s.addChild(this.node)}return this}setOptions(t){if(t)for(let e in t)switch(e){case"hook":t.hook&&(this.hook=t.hook);break;case"props":null!==t.props&&"object"==typeof t.props&&(this.props=t.props);break;case"data":null!==t.data&&"object"==typeof t.data&&(this.data=t.data)}}setUpdateData(t){return t&&Object.assign(this.data,t),this}setUpdateProps(t){return this.props,t&&Object.assign(this.props,t),this}removeAndDestroy(){p(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(t){return this.node.setPosition(t),this}setScale(t){return this.node.setScale(t),this}setAngle(t){return this.node.angle=t,this}setRotation(t){return this.node.setRotation(t),this}setRotationFromEuler(t){return this.node.setRotationFromEuler(t),this}onShow(){}onHide(){}setNodeAndChildrenLayer(t){return nt(this.node,t),this}}const nt=(t,e)=>{t.layer="string"==typeof e?2**d.nameToLayer(e):e,t?.children.forEach((t=>{nt(t,e)}))};class rt extends ot{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=u.getVisibleSize()}async showTween({isMotion:t=!0,direction:e="center",duration:i=.1,isBounce:s=!0,bounceDuration:o=.05}){if(this.lastEnterDirection=e,t){const t=this.node.getComponent(_);let o,n;t&&(t.updateAlignment(),t.enabled=!1),m(1.1,1.1,1),"center"==e?(o=m(.01,.01,.01),n=m(1,1,1)):(o="left"==e?m(-this.screen.width,0,0):"right"==e?m(this.screen.width,0,0):m(0,"top"==e?this.screen.height:-this.screen.height,0),n=m(0,0,0)),await this.handle(e,i,o,n,s),t&&(t.enabled=!0)}}async hideTween({isMotion:t=!0,direction:e,duration:i=.1}){if(e=e||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,f(this.node).removeSelf(),t){const t=this.node.getComponent(_);let s,o;t&&(t.enabled=!1),"center"==e?(s=this.node.scale,o=m(0,0,0)):(o="left"==e?m(-this.screen.width,0,0):"right"==e?m(this.screen.width,0,0):m(0,"top"==e?this.screen.height:-this.screen.height,0),s=this.node.getPosition()),await this.handle(e,i,s,o,!1)}this.removeAndDestroy()}}async handle(t,e,i,s,o){"center"==t?this.node.setScale(i):this.node.setPosition(i),await this.deftween(e,{["center"==t?"scale":"position"]:s},o)}deftween(t,e,i,s){return new Promise(((i,s)=>{f(this.node).to(t,e).call((()=>{i()})).start()}))}}const{ccclass:at,property:ct}=e;var lt;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(lt||(lt={}));class ht extends ot{type=lt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,me.event.on(Y.EFFECT_ON,this.onPlayEffectHandler,this).on(Y.EFFECT_OFF,this.onStopEffectHandler,this).on(Y.MUSIC_ON,this.onPlayMusicHandler,this).on(Y.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=me.audio;this.audioSource.volume=this.type===lt.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=me.audio;this.audioSource.playing||!(this.type===lt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}it([ct({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(lt)}),st("design:type",Number)],ht.prototype,"type",void 0),it([ct({tooltip:"音源",type:i}),st("design:type",i)],ht.prototype,"clip",void 0),it([ct({tooltip:"循环"}),st("design:type",Boolean)],ht.prototype,"loop",void 0),it([ct({tooltip:"音量"}),st("design:type",Number)],ht.prototype,"volume",void 0),it([ct({tooltip:"是否启用自动播放"}),st("design:type",Boolean)],ht.prototype,"playOnAwake",void 0);const{ccclass:pt,property:dt}=e;class ut extends rt{type=lt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),me.event.on(Y.EFFECT_ON,this.onPlayEffectHandler,this).on(Y.EFFECT_OFF,this.onStopEffectHandler,this).on(Y.MUSIC_ON,this.onPlayMusicHandler,this).on(Y.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:t,volumeMusic:e}=me.audio;this.audioSource.volume=this.type===lt.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=me.audio;this.audioSource.playing||!(this.type===lt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}it([dt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(lt)}),st("design:type",Number)],ut.prototype,"type",void 0),it([dt({tooltip:"音源",type:i}),st("design:type",i)],ut.prototype,"clip",void 0),it([dt({tooltip:"循环"}),st("design:type",Boolean)],ut.prototype,"loop",void 0),it([dt({tooltip:"音量"}),st("design:type",Number)],ut.prototype,"volume",void 0),it([dt({tooltip:"是否启用自动播放"}),st("design:type",Boolean)],ut.prototype,"playOnAwake",void 0);const{ccclass:_t,property:mt,menu:ft}=e;var gt;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(gt||(gt={}));let yt=class extends ot{fixed_node;slide_node;fixed_label;slide_label;onLoad(){this.fixed_node.active=this.slide_node.active=!1}start(){this.show()}async show(){return new Promise((async(t,e)=>{const{title:i,type:s,fixed_time:o}=this.props;s==gt.FIXED?(this.fixed_node.active=!0,this.fixed_label.string=`${i}`,this.scheduleOnce((()=>{this.node.destroy(),t()}),o)):(this.slide_node.active=!0,this.slide_label.string=`${i}`,this.playAnim(this.node).then((()=>{t()})))}))}playAnim(t){return new Promise(((e,i)=>{const s=this.node.getComponent(v),o=f(s).delay(1.2).to(.5,{opacity:0}).call((()=>{E.stopAllByTarget(t),this.node.destroy(),e()}));f(t).by(.5,{position:m(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){E.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var vt;it([mt({type:o,tooltip:"固定节点"}),st("design:type",o)],yt.prototype,"fixed_node",void 0),it([mt({type:o,tooltip:"滑动节点"}),st("design:type",o)],yt.prototype,"slide_node",void 0),it([mt({type:C,tooltip:"固定标签节点"}),st("design:type",C)],yt.prototype,"fixed_label",void 0),it([mt({type:C,tooltip:"滑动标签节点"}),st("design:type",C)],yt.prototype,"slide_label",void 0),yt=it([_t("CoreToast"),ft("CATCORE/CoreToast")],yt),function(t){t.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",t.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",t.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",t.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",t.ONLINE="GlobalEventConstant/ONLINE",t.OFFLINE="GlobalEventConstant/OFFLINE",t.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",t.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(vt||(vt={}));const{ccclass:Et,property:Ct,menu:bt}=e;let wt=class extends rt{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(zt)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){me.event.on(vt.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const t=this.brother[this.brother.length-1];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const t=this.brother[this.brother.length-2];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(t){return p(this)&&this.scene_mask&&this.scene_mask.tween.addChild(t),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(t){return this.gui=t,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(t){this.scene_mask.node.active=t}};it([Ct({type:o}),st("design:type",o)],wt.prototype,"scene_mask_node",void 0),it([Ct({type:o}),st("design:type",o)],wt.prototype,"ui_container",void 0),wt=it([Et("CoreUIContainer"),bt("CATCORE/CoreUIContainer")],wt);class St extends rt{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){me.event.emit(vt.ROOT_MASK_UPDATE)}}const{ccclass:Tt,property:At,menu:It}=e;let Ot=class extends St{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(b).enabled=!!this.props?.mask}])}update(t){this.loading_rotate+=220*t,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};it([At({type:C,tooltip:"标题"}),st("design:type",C)],Ot.prototype,"title",void 0),it([At({type:o,tooltip:"动画"}),st("design:type",o)],Ot.prototype,"loadingTween",void 0),Ot=it([Tt("CoreShowLoading"),It("CATCORE/CoreShowLoading")],Ot);const{ccclass:kt,property:Nt,menu:Dt}=e;var Rt;!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="连接游戏服错误"}(Rt||(Rt={}));let Mt=class extends St{common_prompt_text;btn_confirm;btn_close;is_close=!1;props={content:null};initUI(){}onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.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==Rt.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,me.gui.hideReconnect()}};it([Nt({type:C,tooltip:"通用提示文本"}),st("design:type",C)],Mt.prototype,"common_prompt_text",void 0),it([Nt({type:w,tooltip:"确定按钮"}),st("design:type",w)],Mt.prototype,"btn_confirm",void 0),it([Nt({type:w,tooltip:"关闭按钮"}),st("design:type",w)],Mt.prototype,"btn_close",void 0),Mt=it([kt("CoreReconnection"),Dt("CATCORE/CoreReconnection")],Mt);const{ccclass:xt,property:Ft,menu:Pt}=e;let Ut=class extends St{text;btn_confirm;btn_close;onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),me.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};it([Ft({type:C,tooltip:"提示文本"}),st("design:type",C)],Ut.prototype,"text",void 0),it([Ft({type:w,tooltip:"确定按钮"}),st("design:type",w)],Ut.prototype,"btn_confirm",void 0),it([Ft({type:w,tooltip:"关闭按钮"}),st("design:type",w)],Ut.prototype,"btn_close",void 0),Ut=it([xt("CoreNotice"),Pt("CATCORE/CoreNotice")],Ut);class Lt extends ot{isReload}const{ccclass:Bt,property:Ht,menu:Gt}=e;var $t;!function(t){t[t.UI=0]="UI",t[t.LOADING=1]="LOADING",t[t.TOAST=2]="TOAST",t[t.RECONNECTTION=3]="RECONNECTTION",t[t.NOTICE=4]="NOTICE"}($t||($t={}));let Kt=class extends ot{reconnection_ui_prefab;toast_ui_prefab;loading_ui_prefab;notice_ui_prefab;ui_prefab;root_ui;root_toast;root_mask;cat;ui_container_component;reconnection_ui_component;notice_ui_component;loading_ui_component;toast_ui_component;currentScene;onEventListener(){this.cat.event.on(vt.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(t){this.cat=t;const e=n.getScene();return r("init scene"),e&&this.changeScene(e),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(t){this.toastQueue.push(t),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const t=this.toastQueue.shift(),e=()=>{h(this.toast_ui_prefab).getComponent(yt).addToParent(this.root_toast,{props:t}),this.scheduleOnce((()=>{this.processQueueWithInterval()}),this.minInterval)};0===this.root_toast.children.length?e():this.scheduleOnce(e,this.minInterval)}hideToast(){return this.root_toast&&this.root_toast.children.forEach((t=>{t.getComponent(yt)?.removeAndDestroy()})),this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading({title:t="",mask:e=!0,black:i=!0}={}){if(r("showLoading",t),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:t,mask:e,black:i}});else{const s=h(this.loading_ui_prefab);this.loading_ui_component=s.getComponent(Ot).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(Mt).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(Ut).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(S.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.hideLoading(),this.createUILayer(t);const s=t.getComponentInChildren(Lt);s&&(s.isReload=i??!1),s?.setOptions(e)}createUILayer(t){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const e=h(this.ui_prefab);this.ui_container_component=e.getComponent(wt).setGui(this).addToParent(t,this.node.getSiblingIndex())}reloadScene(){this.loadScene(this.currentScene,!0)}async closeUI(t,e){const{component:i}=this.findUIBaseLayer(t,!1);i&&(i.setOptions({...e?.hook??{},...e?.props??{}}),await i.hideTween(e||{}),this.ui_container_component?.subMask())}async openUI(t,e){const{rootNode:i,component:s}=this.findUIBaseLayer(t,!0);i.getComponent(rt),s?.setOptions(e),i&&this.ui_container_component?.addNodeToTween(i).addMask(),s&&await s.showTween(e||{}),this.ui_container_component?.ui_container&&s?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(t,e){let i,n=null;if(t instanceof o){i=t;const e=t.components.filter((t=>t instanceof rt));if(!e.length)return s(`${t.name}节点未找到继承自BaseLayer的组件`),{rootNode:i,component:n};1==e.length?n=e[0]:T(`${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].getSiblingIndex()-1;this.root_mask.setSiblingIndex(e<0?0:e)}this.cat.event.emit(vt.ROOT_MASK_CHANGE)}};it([Ht({type:l,tooltip:"断线重连UI预制体"}),st("design:type",l)],Kt.prototype,"reconnection_ui_prefab",void 0),it([Ht({type:l,tooltip:"提示UI预制体"}),st("design:type",l)],Kt.prototype,"toast_ui_prefab",void 0),it([Ht({type:l,tooltip:"加载UI预制体"}),st("design:type",l)],Kt.prototype,"loading_ui_prefab",void 0),it([Ht({type:l,tooltip:"公告UI预制体"}),st("design:type",l)],Kt.prototype,"notice_ui_prefab",void 0),it([Ht({type:l,tooltip:"UI层预制体"}),st("design:type",l)],Kt.prototype,"ui_prefab",void 0),it([Ht({type:o,tooltip:"root-UI层"}),st("design:type",o)],Kt.prototype,"root_ui",void 0),it([Ht({type:o,tooltip:"root-组件层"}),st("design:type",o)],Kt.prototype,"root_toast",void 0),it([Ht({type:o,tooltip:"root-mask"}),st("design:type",o)],Kt.prototype,"root_mask",void 0),Kt=it([Bt("Gui"),Gt("CATCORE/Gui")],Kt);const{ccclass:jt,property:Vt,menu:Wt}=e;let zt=class extends ot{tween};var Qt;it([Vt({type:o,tooltip:"动画节点"}),st("design:type",o)],zt.prototype,"tween",void 0),zt=it([jt("CoreBlackMask"),Wt("CATCORE/CoreBlackMask")],zt),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"}(Qt||(Qt={}));class Jt extends Z{gui;#t="core";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.cat.gui_bundle_name&&(this.#t=this.cat.gui_bundle_name);const t=await this.getGuiPrefabByType(this.#t,Qt.Root),e=h(t);return this.gui=e.getComponent(Kt).init(this.cat),n.addPersistRootNode(e),this}}class Xt{get=(t,e,i="resources")=>A.getBundle(i).get(t,e);isAssetType=t=>"function"==typeof t&&t.prototype instanceof I;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=O;if(e&&"resources"!=e){A.bundles.has(e)||await this.loadBundle(e);let t=A.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=O;if(e&&"resources"!=e){A.bundles.has(e)||await this.loadBundle(e);let t=A.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(),A.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?A.loadBundle(t,{version:e},o):A.loadBundle(t,o)}));releasePrefabtDepsRecursively=t=>{var e=A.assets.get(t);(A.releaseAsset(e),e instanceof l)&&A.dependUtil.getDepsRecursively(t).forEach((t=>{A.assets.get(t).decRef()}))};release=(t,e="resources")=>{var i=A.getBundle(e);if(i){var s=i.get(t);s&&this.releasePrefabtDepsRecursively(s._uuid)}};releaseDir=(t,e="resources")=>{var i=A.getBundle(e),s=i?.getDirWithPath(t);s?.map((t=>{this.releasePrefabtDepsRecursively(t.uuid)})),!t&&"resources"!=e&&i&&A.removeBundle(i)};dump=()=>{A.assets.forEach(((t,e)=>{r(A.assets.get(e))})),r(`当前资源总数:${A.assets.count}`)}}let qt=null;const Zt={stringify:t=>{const e={ct:t.ciphertext.toString(H.enc.Base64)};return t.iv&&(e.iv=t.iv.toString()),t.salt&&(e.s=t.salt.toString()),JSON.stringify(e)},parse:t=>{const e=JSON.parse(t),i=H.lib.CipherParams.create({ciphertext:H.enc.Base64.parse(e.ct)});return e.iv&&(i.iv=H.enc.Hex.parse(e.iv)),e.s&&(i.salt=H.enc.Hex.parse(e.s)),i}};var Yt=Object.freeze({__proto__:null,JsonFormatter:Zt,aesDecrypt:(t,e,i)=>H.AES.decrypt(t,e,{iv:qt,format:Zt}).toString(H.enc.Utf8),aesEncrypt:(t,e,i)=>H.AES.encrypt(t,e,{iv:qt,format:Zt}).toString(),initCrypto:(t,e)=>{qt=H.enc.Hex.parse(e)},md5:t=>H.MD5(t).toString()});class te extends Z{encryptUtil=Yt}class ee extends K{logBlackList=[];ignore=t=>this.logBlackList.includes(t);constructor(t,e,i,s){super(e,i,s,t)}destroy(){this.disconnect(!0),me.socialGameClient.unregister(this)}async GameRequest(t,e,i,s){return new Promise(((o,n)=>{super.GameRequest(t,e,i,s).then((e=>{F&&r(`%c ws服务端消息 %c [Response][${new Date}] %c ${t} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(i,e)),o(e)}),(t=>{me.gui.showToast({title:t.msg}),n(t)}))}))}subscribe(t,e,i){return super.subscribe(t,e,(s=>{F&&!this.ignore(t)&&r(`%c ws服务端消息:[subscribe][${new Date}] %c ${t} %c`,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#410083 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(e,s)),me.event.emit(t,G(e,s)),i?.(s)})),this}}class ie extends Z{managedClients=new Map;isGlobalOnline=!0;isInBackground=!1;reconnecting=!1;onEventHideDelegate=new k;onEventShowDelegate=new k;onEventReloadSceneDelegate=new k;reconnectTimer=null;scheduleReconnect(t=2e3){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectTimer=setTimeout((()=>{this.reconnectTimer=null,this.triggerReconnectAll()}),t)}get activeClients(){return Array.from(this.managedClients).map((([t,e])=>e)).filter((t=>t.socket))}constructor(t){super(t),this.initGlobalListeners()}createWebSocket(t,e,i,s){if(this.managedClients.has(t)){this.managedClients.get(t).destroy(),r(`清理旧的 ${t} 客户端`)}const o=new ee(t,i,s,Object.assign({reconnectMaxAttempts:1/0},{...e,isAutoConnect:!1,isArrayBuffer:x}));return this.register(o),o}register(t){t.on("reconnected",this.handleSingleReconnect),t.on("close",this.handleSingleClose),t.on("kick",this.handleSingleKick),this.managedClients.set(t.name,t)}unregister(t){t.off("reconnected",this.handleSingleReconnect),t.off("close",this.handleSingleClose),t.off("kick",this.handleSingleKick),this.managedClients.delete(t.name)}initGlobalListeners(){this.cat.event.on(vt.ONLINE,(()=>this.handleGlobalStateChange("online")),this).on(vt.OFFLINE,(()=>this.handleGlobalStateChange("offline")),this),y.on(N.EVENT_SHOW,(()=>this.handleGlobalStateChange("show"))),y.on(N.EVENT_HIDE,(()=>this.handleGlobalStateChange("hide")))}async handleGlobalStateChange(t){switch(t){case"online":me.gui.showLoading({title:Rt.ONLINE}),this.isGlobalOnline=!0,this.triggerReconnectAll();break;case"offline":this.isGlobalOnline=!1,this.disconnectAll(!0),me.gui.showLoading({title:Rt.OFFLINE});break;case"show":this.isInBackground=!1,await this.triggerReconnectAll(),await this.onEventShowDelegate.dispatch();break;case"hide":await this.onEventHideDelegate.dispatch(),this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(r("触发所有客户端重连",this.reconnecting,!this.isGlobalOnline,this.isInBackground,this.managedClients.size),!this.reconnecting&&this.isGlobalOnline&&!this.isInBackground&&0!==this.managedClients.size){this.reconnecting=!0,me.gui.showLoading({title:"正在重连"});try{await Promise.allSettled(this.activeClients.map((async t=>{try{await t.reconnectPromise()}catch(e){s(`${t.name}服重连失败`,e)}})));const t=this.activeClients.filter((t=>t.socketConnectStatus!==$.CONNECTED));t.length>0?(console.error("部分WS重连失败:",t.map((t=>t))),r("2s后重连所有客户端"),this.reconnecting=!1,this.scheduleReconnect()):this.reconnecting=!1}catch(t){throw this.reconnecting=!1,t}}}disconnectAll(t){this.managedClients.forEach((e=>{r("断开连接",e.name,t,e.socket),e.disconnect(t)}))}handleSingleClose=()=>{this.reconnecting||(r("3s后重连所有客户端"),this.scheduleReconnect(3e3))};handleSingleReconnect=async()=>{this.activeClients.every((t=>t.socketConnectStatus===$.CONNECTED))&&(r("单个WS重连成功回调===",this.managedClients),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.connectRequest()}catch(e){s(`${t.name}服登录错误`,e),me.gui.showToast({title:`登录${t.name}服错误`})}}))),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),await this.onEventReloadSceneDelegate.dispatch(),me.gui.hideLoading().reloadScene())};handleSingleKick=()=>{me.gui.showReconnect(Rt.KICK)}}class se{rootStore;constructor(t){this.rootStore=t}}class oe extends Z{}const{ccclass:ne,property:re,menu:ae}=e;let ce=class extends rt{default_title=null;title;prompt_content_str;prompt_content_spriteFrame;btn_confirm;confirm_spriteFrame;btn_cancel;cancel_spriteFrame;btn_close;isConfirm=!1;props={title:this.default_title,content:null,confirmCB:()=>{},cancelCB:()=>{},style:null};onLoad(){this.btn_cancel.node.on(w.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(w.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content&&(this.props.content instanceof D?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?.(),me.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var le;it([re({type:D,tooltip:"默认标题"}),st("design:type",D)],ce.prototype,"default_title",void 0),it([re({type:R,tooltip:"标题节点"}),st("design:type",R)],ce.prototype,"title",void 0),it([re({type:C,tooltip:"字符串内容按钮"}),st("design:type",C)],ce.prototype,"prompt_content_str",void 0),it([re({type:R,tooltip:"图片精灵内容按钮"}),st("design:type",R)],ce.prototype,"prompt_content_spriteFrame",void 0),it([re({type:w,tooltip:"确认按钮"}),st("design:type",w)],ce.prototype,"btn_confirm",void 0),it([re({type:D,tooltip:"确认按钮精灵图"}),st("design:type",D)],ce.prototype,"confirm_spriteFrame",void 0),it([re({type:w,tooltip:"取消按钮"}),st("design:type",w)],ce.prototype,"btn_cancel",void 0),it([re({type:D,tooltip:"取消按钮精灵图"}),st("design:type",D)],ce.prototype,"cancel_spriteFrame",void 0),it([re({type:w,tooltip:"关闭按钮"}),st("design:type",w)],ce.prototype,"btn_close",void 0),ce=it([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 Z{timers=new Map;lastUpdateTime=Date.now();constructor(t){super(t),t.event.on(vt.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(vt.EVENT_SHOW,this.onHandleAppForeground,this),setInterval(this.update.bind(this),1e3)}onHandleAppBackground(){this.lastUpdateTime=Date.now()}onHandleAppForeground(){const t=Date.now(),e=t-this.lastUpdateTime;r("elapsedTime",e);for(const t of this.timers.values())t.remainingTime>0&&(t.remainingTime-=e,t.executionTime+=e);this.lastUpdateTime=t}registerInterval(t,e,i){if(this.has(t))return s(`${t}定时器已存在,请勿重复注册`);const o=new 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)}}const de=(t,e)=>(i,s,o)=>{let n=o.value;return o.value=function(...i){const s=t??me.default_audio_effect;s?me.audio.playEffect(s):console.warn("请添加音效路径参数"),e&&e(),n.apply(this,i)},o},ue=(t=1,e)=>function(i,s,o){let n=o.value,r=!1;return o.value=function(...i){r?e&&e():(r=!0,setTimeout((()=>{r=!1}),1e3*t),n.apply(this,i))},o};class _e{static#e=null;#i=!1;static get instance(){return this.#e??(this.#e=new _e)}onAppInitDelegate=new k;onPlugInInitDelegate=new k;#s=null;get audio(){return this.#s}#o=null;get event(){return this.#o}#n=null;get gui(){return this.#n}#r=null;get storage(){return this.#r}#a=null;get res(){return this.#a}#c=null;get util(){return this.#c}#l=null;get socialGameClient(){return this.#l}#h=null;get store(){return this.#h}#p="";get gui_bundle_name(){return this.#p}#d="";get audio_local_store_key(){return this.#d}#u="";get default_audio_effect(){return this.#u}setConfig=({default_audio_effect:t="",gui_bundleName:e="resources",audio_local_store_key:i="game_audio"}={})=>{if(this.#i)throw new Error("[CAT] 已初始化,无法修改配置");return this.#p=e,this.#d=i,this.#u=t,this};async boot(){if(this.#i)throw new Error("[CAT] 已初始化");try{this.#h=new oe(this),this.#a=new Xt,this.#c=new te(this),this.#r=new et(this),this.#o=new j,this.#s=new tt(this),this.#l=new ie(this),this.#n=(await new Jt(this).init()).gui,this.#i=!0}catch(t){throw console.error("[CAT] 初始化失败:",t),t}}merge(t,e){if(!this.#i)throw new Error("[CAT] 未初始化");if("string"!=typeof t)throw new Error("merge方法第一个参数应该为string类型");return Reflect.get(this,t)||Reflect.set(this,t,e),Object.assign(Reflect.get(this,t),e),this}appendPlugInInitDelegate(t){return this.#i?Promise.resolve().then(t).catch((t=>{console.error("[CAT] appendPlugInInitDelegate 回调执行失败:",t)})):this.onPlugInInitDelegate.add(t),this}}const me=_e.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]");try{await me.boot(),await me.onAppInitDelegate.dispatch(),await me.onPlugInInitDelegate.dispatch()}catch(t){throw s(`[Init App] 初始化失败: ${t instanceof Error?t.message:String(t)}`),t}finally{console.timeEnd("[Init App]")}}));export{de as AudioEffect,Y as AudioEventConstant,tt as AudioManager,ht as AudioSourceBaseComponent,ut as AudioSourceUILayer,lt as AudioTypeEnum,ot as BaseComponent,Z as BaseManager,Qt as BasePrefab,se as BaseStore,ue as ButtonLock,zt as CoreBlackMask,Ut as CoreNotice,Mt as CoreReconnection,Ot as CoreShowLoading,oe as CoreStore,yt as CoreToast,wt as CoreUIContainer,ce as CoreUIModal,te as CoreUtil,vt as GlobalEventConstant,Kt as Gui,Jt as GuiManager,$t as LayerType,_e as Manager,Rt as ReconnectPrompt,St as RootUILayer,Lt as SceneLayer,pe as TimerManager,gt as ToastType,rt as UILayer,ee as WrapperSocialGameClient,me as cat};
|