@shimotsuki/core 2.0.54 → 2.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Component, Node, Prefab, Vec3, Quat, math, Layers, AudioSource, Label, Button, Scene, Asset, AssetManager, Constructor, AsyncDelegate, SpriteFrame, Sprite } from 'cc';
1
+ import { Component, Node, Prefab, Vec3, Quat, math, Layers, AudioClip, AudioSource, Label, Button, Scene, Asset, AssetManager, Constructor, AsyncDelegate, SpriteFrame, Sprite } from 'cc';
2
2
  import { IReactionPublic, IReactionOptions } from '@shimotsuki/mobx';
3
3
  import EventEmitter, { EventEmitter as EventEmitter$1 } from 'eventemitter3';
4
4
  import * as crypto_es_lib_cipher_core from 'crypto-es/lib/cipher-core';
@@ -231,9 +231,9 @@ declare class BaseComponent<T extends object = {}, K extends object = {}> extend
231
231
  /**设置属性(覆盖原有属性) */
232
232
  setOptions(options?: IUIOption<T, K>): void;
233
233
  /**设置data属性(更新) */
234
- setUpdateData(data: K): this;
234
+ setUpdateData(data: Partial<K>): this;
235
235
  /**设置props属性(更新)*/
236
- setUpdateProps(props: T): this;
236
+ setUpdateProps(props: Partial<T>): this;
237
237
  /**从父节点移除并销毁 */
238
238
  removeAndDestroy(): void;
239
239
  /**设置坐标 */
@@ -321,7 +321,7 @@ declare enum AudioTypeEnum {
321
321
  }
322
322
  declare class AudioSourceBaseComponent<T extends object = {}, K extends object = {}> extends BaseComponent<T, K> {
323
323
  type: AudioTypeEnum;
324
- clip: never;
324
+ clip: AudioClip;
325
325
  loop: boolean;
326
326
  volume: number;
327
327
  playOnAwake: boolean;
@@ -341,7 +341,7 @@ declare class AudioSourceBaseComponent<T extends object = {}, K extends object =
341
341
  /**带有音频通道的UIlayer组件 */
342
342
  declare class AudioSourceUILayer<T extends object, U extends object = {}> extends UILayer<T, U> {
343
343
  type: AudioTypeEnum;
344
- clip: never;
344
+ clip: AudioClip;
345
345
  loop: boolean;
346
346
  volume: number;
347
347
  playOnAwake: boolean;
@@ -1 +1 @@
1
- import{AudioSource as t,AudioClip as e,error as i,Node as s,director as o,log as n,sys as r,Component as a,Prefab as l,instantiate as c,isValid as h,Layers as p,view as d,Widget as u,v3 as _,tween as m,Enum as f,_decorator as g,game as y,Label as v,UIOpacity as E,Tween as C,BlockInputEvents as b,Button as w,Director as S,warn as A,assetManager as T,Asset as O,resources as k,AsyncDelegate as I,Game as N,SpriteFrame as D,Sprite as M}from"cc";import{PREVIEW as R,DEBUG as x,WECHAT as F}from"cc/env";import{makeObservable as P,observable as U,autorun as L,reaction as H}from"@shimotsuki/mobx";import B from"crypto-es";import{clone as G}from"@bufbuild/protobuf";import{SocketConnectStatus as $}from"pitayaclient";import{SocialGameClient as j}from"sgc";import{EventEmitter as K}from"eventemitter3";import"core-js/es/array/index.js";class V extends t{cat;initAudio(t){return this.cat=t,this}}class W extends V{effects=new Map;load(t){return new Promise(((i,s)=>{this.cat.res.load(t,e,((e,o)=>{if(e)return s(e);this.effects.set(t,o),this.playOneShot(o,this.volume),i(o)}))}))}release(){for(let t in this.effects)this.cat.res.release(t);this.effects.clear()}}class z extends V{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(t){this._progress=t,this.currentTime=t*this.duration}load(t,s){this.cat.res.load(t,e,((e,o)=>{e&&i(e),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,s&&s()}))}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 Q{cat;constructor(t){this.cat=t}}var J;!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"}(J||(J={}));class X extends Q{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 s("UIAudioManager");o.addPersistRootNode(e);var i=new s("UIMusic");i.parent=e,this.music=i.addComponent(z).initAudio(t);var n=new s("UIEffect");n.parent=e,this.effect=n.addComponent(W).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(n("设置背景音乐开关值",t,this._switch_music),t==this._switch_music)return;this._switch_music=t,t?this.resumeMusic():this.pauseMusic();const e=t?J.MUSIC_ON:J.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?J.EFFECT_ON:J.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 q extends Q{_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)),r.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=r.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)),r.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){r.localStorage.clear()}}function Z(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 Y(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class tt extends a{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=H(t,e,i);return this.reactionDisposers.push(s),this}addAudoListener(t){return this.eventEmitter.includes(t)||t===pe.event||this.eventEmitter.push(t),t}_onPreDestroy(){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(pe.event),this.eventEmitter.forEach((t=>{this.deleteAllEventByEmitter(t)})),this.eventEmitter=[],this.removeListener()}deleteAllEventByEmitter(t){const e=t._events;for(const i in e){let s=e[i];Array.isArray(s)||(s=[s]),s.forEach((e=>{e.context===this&&t.off(i,e.fn,this)}))}}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(t,e){let i=t instanceof l?c(t):t instanceof a?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(){h(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 et(this.node,t),this}}const et=(t,e)=>{t.layer="string"==typeof e?2**p.nameToLayer(e):e,t?.children.forEach((t=>{et(t,e)}))};class it extends tt{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=d.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(u);let o,n;t&&(t.updateAlignment(),t.enabled=!1),_(1.1,1.1,1),"center"==e?(o=_(.01,.01,.01),n=_(1,1,1)):(o="left"==e?_(-this.screen.width,0,0):"right"==e?_(this.screen.width,0,0):_(0,"top"==e?this.screen.height:-this.screen.height,0),n=_(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,m(this.node).removeSelf(),t){const t=this.node.getComponent(u);let s,o;t&&(t.enabled=!1),"center"==e?(s=this.node.scale,o=_(0,0,0)):(o="left"==e?_(-this.screen.width,0,0):"right"==e?_(this.screen.width,0,0):_(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)=>{m(this.node).to(t,e).call((()=>{i()})).start()}))}}const{ccclass:st,property:ot}=g;var nt;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(nt||(nt={}));class rt extends tt{type=nt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,pe.event.on(J.EFFECT_ON,this.onPlayEffectHandler,this).on(J.EFFECT_OFF,this.onStopEffectHandler,this).on(J.MUSIC_ON,this.onPlayMusicHandler,this).on(J.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=pe.audio;this.audioSource.volume=this.type===nt.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=pe.audio;this.audioSource.playing||!(this.type===nt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}Z([ot({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:f(nt)}),Y("design:type",Object)],rt.prototype,"type",void 0),Z([ot({tooltip:"音源",type:e}),Y("design:type",Object)],rt.prototype,"clip",void 0),Z([ot({tooltip:"循环"}),Y("design:type",Object)],rt.prototype,"loop",void 0),Z([ot({tooltip:"音量"}),Y("design:type",Object)],rt.prototype,"volume",void 0),Z([ot({tooltip:"是否启用自动播放"}),Y("design:type",Object)],rt.prototype,"playOnAwake",void 0);const{ccclass:at,property:lt}=g;class ct extends it{type=nt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),pe.event.on(J.EFFECT_ON,this.onPlayEffectHandler,this).on(J.EFFECT_OFF,this.onStopEffectHandler,this).on(J.MUSIC_ON,this.onPlayMusicHandler,this).on(J.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:t,volumeMusic:e}=pe.audio;this.audioSource.volume=this.type===nt.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=pe.audio;this.audioSource.playing||!(this.type===nt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}Z([lt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:f(nt)}),Y("design:type",Object)],ct.prototype,"type",void 0),Z([lt({tooltip:"音源",type:e}),Y("design:type",Object)],ct.prototype,"clip",void 0),Z([lt({tooltip:"循环"}),Y("design:type",Object)],ct.prototype,"loop",void 0),Z([lt({tooltip:"音量"}),Y("design:type",Object)],ct.prototype,"volume",void 0),Z([lt({tooltip:"是否启用自动播放"}),Y("design:type",Object)],ct.prototype,"playOnAwake",void 0);const{ccclass:ht,property:pt,menu:dt}=g;var ut;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(ut||(ut={}));let _t=class extends tt{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==ut.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(E),o=m(s).delay(1.2).to(.5,{opacity:0}).call((()=>{C.stopAllByTarget(t),this.node.destroy(),e()}));m(t).by(.5,{position:_(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){C.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var mt;Z([pt({type:s,tooltip:"固定节点"}),Y("design:type",s)],_t.prototype,"fixed_node",void 0),Z([pt({type:s,tooltip:"滑动节点"}),Y("design:type",s)],_t.prototype,"slide_node",void 0),Z([pt({type:v,tooltip:"固定标签节点"}),Y("design:type",v)],_t.prototype,"fixed_label",void 0),Z([pt({type:v,tooltip:"滑动标签节点"}),Y("design:type",v)],_t.prototype,"slide_label",void 0),_t=Z([ht("CoreToast"),dt("CATCORE/CoreToast")],_t),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"}(mt||(mt={}));const{ccclass:ft,property:gt,menu:yt}=g;let vt=class extends it{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(){pe.event.on(mt.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 h(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}};Z([gt({type:s}),Y("design:type",s)],vt.prototype,"scene_mask_node",void 0),Z([gt({type:s}),Y("design:type",s)],vt.prototype,"ui_container",void 0),vt=Z([ft("CoreUIContainer"),yt("CATCORE/CoreUIContainer")],vt);class Et extends it{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){pe.event.emit(mt.ROOT_MASK_UPDATE)}}const{ccclass:Ct,property:bt,menu:wt}=g;let St=class extends Et{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)}};Z([bt({type:v,tooltip:"标题"}),Y("design:type",v)],St.prototype,"title",void 0),Z([bt({type:s,tooltip:"动画"}),Y("design:type",s)],St.prototype,"loadingTween",void 0),St=Z([Ct("CoreShowLoading"),wt("CATCORE/CoreShowLoading")],St);const{ccclass:At,property:Tt,menu:Ot}=g;var kt;!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="连接游戏服错误"}(kt||(kt={}));let It=class extends Et{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==kt.RECONNECTING)}updatePromptText(t,e=!1){if(this.unscheduleAllCallbacks(),this.props.content=t,n("更新提示文案:",t),e){let e=0;const i=()=>{e=(e+1)%4,this.common_prompt_text.string=t+["","·","··","···"][e]};this.schedule(i,.5)}}onConfirmHandler(){this.is_close=!0,pe.gui.hideReconnect()}};Z([Tt({type:v,tooltip:"通用提示文本"}),Y("design:type",v)],It.prototype,"common_prompt_text",void 0),Z([Tt({type:w,tooltip:"确定按钮"}),Y("design:type",w)],It.prototype,"btn_confirm",void 0),Z([Tt({type:w,tooltip:"关闭按钮"}),Y("design:type",w)],It.prototype,"btn_close",void 0),It=Z([At("CoreReconnection"),Ot("CATCORE/CoreReconnection")],It);const{ccclass:Nt,property:Dt,menu:Mt}=g;let Rt=class extends Et{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?.(),pe.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};Z([Dt({type:v,tooltip:"提示文本"}),Y("design:type",v)],Rt.prototype,"text",void 0),Z([Dt({type:w,tooltip:"确定按钮"}),Y("design:type",w)],Rt.prototype,"btn_confirm",void 0),Z([Dt({type:w,tooltip:"关闭按钮"}),Y("design:type",w)],Rt.prototype,"btn_close",void 0),Rt=Z([Nt("CoreNotice"),Mt("CATCORE/CoreNotice")],Rt);class xt extends tt{isReload}const{ccclass:Ft,property:Pt,menu:Ut}=g;var Lt;!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"}(Lt||(Lt={}));let Ht=class extends tt{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(mt.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(t){this.cat=t;const e=o.getScene();return n("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=()=>{c(this.toast_ui_prefab).getComponent(_t).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(_t)?.removeAndDestroy()})),this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading({title:t="",mask:e=!0,black:i=!0}={}){if(n("showLoading",t),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:t,mask:e,black:i}});else{const s=c(this.loading_ui_prefab);this.loading_ui_component=s.getComponent(St).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=c(this.reconnection_ui_prefab);this.reconnection_ui_component=e.getComponent(It).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=c(this.notice_ui_prefab);return this.notice_ui_component=e.getComponent(Rt).addToParent(this.root_ui,{props:t}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}loadScene(t,e,i){n("加载场景",t,e,i);let s={},r=i??!1;return"boolean"==typeof e?r=e:s=e??{},n("当前场景",o.getScene()?.uuid,o.getScene()?.name),o.once(S.EVENT_BEFORE_SCENE_LAUNCH,(t=>{n("Director.EVENT_BEFORE_SCENE_LAUNCH",t),this.changeScene(t,s,r)})),o.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(xt);s&&(s.isReload=i??!1),s?.setOptions(e)}createUILayer(t){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const e=c(this.ui_prefab);this.ui_container_component=e.getComponent(vt).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(it),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 o,n=null;if(t instanceof s){o=t;const e=t.components.filter((t=>t instanceof it));if(!e.length)return i(`${t.name}节点未找到继承自BaseLayer的组件`),{rootNode:o,component:n};1==e.length?n=e[0]:A(`${t.name}节点存在多个继承自BaseLayer的组件`)}else if(o=t.node,n=t,e){for(;o.parent;)o=o.parent;n.root=o}else o=t.root;return{rootNode:o,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(mt.ROOT_MASK_CHANGE)}};Z([Pt({type:l,tooltip:"断线重连UI预制体"}),Y("design:type",l)],Ht.prototype,"reconnection_ui_prefab",void 0),Z([Pt({type:l,tooltip:"提示UI预制体"}),Y("design:type",l)],Ht.prototype,"toast_ui_prefab",void 0),Z([Pt({type:l,tooltip:"加载UI预制体"}),Y("design:type",l)],Ht.prototype,"loading_ui_prefab",void 0),Z([Pt({type:l,tooltip:"公告UI预制体"}),Y("design:type",l)],Ht.prototype,"notice_ui_prefab",void 0),Z([Pt({type:l,tooltip:"UI层预制体"}),Y("design:type",l)],Ht.prototype,"ui_prefab",void 0),Z([Pt({type:s,tooltip:"root-UI层"}),Y("design:type",s)],Ht.prototype,"root_ui",void 0),Z([Pt({type:s,tooltip:"root-组件层"}),Y("design:type",s)],Ht.prototype,"root_toast",void 0),Z([Pt({type:s,tooltip:"root-mask"}),Y("design:type",s)],Ht.prototype,"root_mask",void 0),Ht=Z([Ft("Gui"),Ut("CATCORE/Gui")],Ht);const{ccclass:Bt,property:Gt,menu:$t}=g;let jt=class extends tt{tween};var Kt;Z([Gt({type:s,tooltip:"动画节点"}),Y("design:type",s)],jt.prototype,"tween",void 0),jt=Z([Bt("CoreBlackMask"),$t("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"}(Kt||(Kt={}));class Vt extends Q{gui;#t="core";getGuiPrefabByType=(t,e)=>new Promise(((i,s)=>{n(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,Kt.Root),e=c(t);return this.gui=e.getComponent(Ht).init(this.cat),o.addPersistRootNode(e),this}}class Wt{get=(t,e,i="resources")=>T.getBundle(i).get(t,e);isAssetType=t=>"function"==typeof t&&t.prototype instanceof O;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=k;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=k;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)=>{n(T.assets.get(e))})),n(`当前资源总数:${T.assets.count}`)}}let zt=null;const Qt={stringify:t=>{const e={ct:t.ciphertext.toString(B.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=B.lib.CipherParams.create({ciphertext:B.enc.Base64.parse(e.ct)});return e.iv&&(i.iv=B.enc.Hex.parse(e.iv)),e.s&&(i.salt=B.enc.Hex.parse(e.s)),i}};var Jt=Object.freeze({__proto__:null,md5:t=>B.MD5(t).toString(),initCrypto:(t,e)=>{zt=B.enc.Hex.parse(e)},aesEncrypt:(t,e,i)=>B.AES.encrypt(t,e,{iv:zt,format:Qt}).toString(),aesDecrypt:(t,e,i)=>B.AES.decrypt(t,e,{iv:zt,format:Qt}).toString(B.enc.Utf8),JsonFormatter:Qt});class Xt extends Q{encryptUtil=Jt}class qt extends j{logBlackList=[];ignore=t=>this.logBlackList.includes(t);constructor(t,e,i,s){super(e,i,s,t)}destroy(){this.disconnect(!0),pe.socialGameClient.unregister(this)}async GameRequest(t,e,i,s){return new Promise(((o,r)=>{super.GameRequest(t,e,i,s).then((e=>{x&&n(`%c ws服务端消息 %c [Response][${new Date}] %c ${t} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(i,e)),o(e)}),(t=>{pe.gui.showToast({title:t.msg}),r(t)}))}))}subscribe(t,e,i){return super.subscribe(t,e,(s=>{x&&!this.ignore(t)&&n(`%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)),pe.event.emit(t,G(e,s)),i?.(s)})),this}}class Zt extends Q{managedClients=new Map;isGlobalOnline=!0;isInBackground=!1;onEventHideDelegate=new I;onEventShowDelegate=new I;onEventReloadSceneDelegate=new I;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(),n(`清理旧的 ${t} 客户端`)}const o=new qt(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(mt.ONLINE,(()=>this.handleGlobalStateChange("online")),this).on(mt.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":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.onEventShowDelegate.dispatch();break;case"hide":await this.onEventHideDelegate.dispatch(),this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(!this.isGlobalOnline||this.isInBackground)return;if(0===this.managedClients.size)return void n("没有任何WS需要重连");pe.gui.showLoading({title:"正在重连"}),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.reconnectPromise()}catch(e){i(`${t.name}服重连失败`,e),pe.gui.showToast({title:`${t.name}服重连失败`})}})));const t=this.activeClients.filter((t=>t.socketConnectStatus!==$.CONNECTED));t.length>0&&(console.error("部分WS重连失败:",t.map((t=>t))),setTimeout((()=>{this.triggerReconnectAll()}),2e3))}disconnectAll(t){this.managedClients.forEach((e=>{n("断开连接",e.name,t,e.socket),e.disconnect(t)}))}handleSingleReconnect=async()=>{this.activeClients.every((t=>t.socketConnectStatus===$.CONNECTED))&&(n("单个WS重连成功回调===",this.managedClients),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.connectRequest()}catch(e){i(`${t.name}服登录错误`,e),pe.gui.showToast({title:`登录${t.name}服错误`})}}))),await this.onEventReloadSceneDelegate.dispatch(),pe.gui.hideLoading().reloadScene())};handleSingleKick(){pe.gui.showReconnect(kt.KICK)}}class Yt{rootStore;constructor(t){this.rootStore=t}}class te extends Q{}const{ccclass:ee,property:ie,menu:se}=g;let oe=class extends it{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(M).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(M).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),pe.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var ne;Z([ie({type:D,tooltip:"默认标题"}),Y("design:type",D)],oe.prototype,"default_title",void 0),Z([ie({type:M,tooltip:"标题节点"}),Y("design:type",M)],oe.prototype,"title",void 0),Z([ie({type:v,tooltip:"字符串内容按钮"}),Y("design:type",v)],oe.prototype,"prompt_content_str",void 0),Z([ie({type:M,tooltip:"图片精灵内容按钮"}),Y("design:type",M)],oe.prototype,"prompt_content_spriteFrame",void 0),Z([ie({type:w,tooltip:"确认按钮"}),Y("design:type",w)],oe.prototype,"btn_confirm",void 0),Z([ie({type:D,tooltip:"确认按钮精灵图"}),Y("design:type",D)],oe.prototype,"confirm_spriteFrame",void 0),Z([ie({type:w,tooltip:"取消按钮"}),Y("design:type",w)],oe.prototype,"btn_cancel",void 0),Z([ie({type:D,tooltip:"取消按钮精灵图"}),Y("design:type",D)],oe.prototype,"cancel_spriteFrame",void 0),Z([ie({type:w,tooltip:"关闭按钮"}),Y("design:type",w)],oe.prototype,"btn_close",void 0),oe=Z([ee("CoreUIModal"),se("CATCORE/CoreUIModal")],oe),function(t){t[t.Delay=0]="Delay",t[t.Interval=1]="Interval"}(ne||(ne={}));class re{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 ae extends Q{timers=new Map;lastUpdateTime=Date.now();constructor(t){super(t),t.event.on(mt.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(mt.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;n("elapsedTime",e);for(const t of this.timers.values())t.remainingTime>0&&(t.remainingTime-=e,t.executionTime+=e);this.lastUpdateTime=t}registerInterval(t,e,s){if(this.has(t))return i(`${t}定时器已存在,请勿重复注册`);const o=new re(t,ne.Interval,e,s);this.timers.set(t,o)}registerDelay(t,e,s){if(this.has(t))return i(`${t}延时器已存在,请勿重复注册`);const o=new re(t,ne.Delay,e,s);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===ne.Interval&&(i.executionTime+=i.initialTime),i.callback(i.executionTime),i.type===ne.Interval?i.remainingTime=i.initialTime:t.push(e));for(const e of t)this.timers.delete(e)}}const le=(t,e)=>(i,s,o)=>{let n=o.value;return o.value=function(...i){const s=t??pe.default_audio_effect;s?pe.audio.playEffect(s):console.warn("请添加音效路径参数"),e&&e(),n.apply(this,i)},o},ce=(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 he{static#e=null;#i=!1;static get instance(){return this.#e??(this.#e=new he)}onAppInitDelegate=new I;onPlugInInitDelegate=new I;#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}#l=null;get util(){return this.#l}#c=null;get socialGameClient(){return this.#c}#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 te(this),this.#a=new Wt,this.#l=new Xt(this),this.#r=new q(this),this.#o=new K,this.#s=new X(this),this.#c=new Zt(this),this.#n=(await new Vt(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 pe=he.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]");try{await pe.boot(),await pe.onAppInitDelegate.dispatch(),await pe.onPlugInInitDelegate.dispatch()}catch(t){throw i(`[Init App] 初始化失败: ${t instanceof Error?t.message:String(t)}`),t}finally{console.timeEnd("[Init App]")}}));export{le as AudioEffect,J as AudioEventConstant,X as AudioManager,rt as AudioSourceBaseComponent,ct as AudioSourceUILayer,nt as AudioTypeEnum,tt as BaseComponent,Q as BaseManager,Kt as BasePrefab,Yt as BaseStore,ce as ButtonLock,jt as CoreBlackMask,Rt as CoreNotice,It as CoreReconnection,St as CoreShowLoading,te as CoreStore,_t as CoreToast,vt as CoreUIContainer,oe as CoreUIModal,Xt as CoreUtil,mt as GlobalEventConstant,Ht as Gui,Vt as GuiManager,Lt as LayerType,he as Manager,kt as ReconnectPrompt,Et as RootUILayer,xt as SceneLayer,ae as TimerManager,ut as ToastType,it as UILayer,qt as WrapperSocialGameClient,pe as cat};
1
+ import{AudioSource as t,AudioClip as e,error as i,Node as s,director as o,log as n,sys as r,Component as a,Prefab as l,instantiate as c,isValid as h,Layers as p,view as d,Widget as u,v3 as _,tween as m,Enum as f,_decorator as g,game as y,Label as v,UIOpacity as E,Tween as C,BlockInputEvents as b,Button as w,Director as S,warn as A,assetManager as T,Asset as k,resources as I,AsyncDelegate as O,Game as N,SpriteFrame as D,Sprite as M}from"cc";import{PREVIEW as R,DEBUG as x,WECHAT 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}}class W extends V{effects=new Map;load(t){return new Promise(((i,s)=>{this.cat.res.load(t,e,((e,o)=>{if(e)return s(e);this.effects.set(t,o),this.playOneShot(o,this.volume),i(o)}))}))}release(){for(let t in this.effects)this.cat.res.release(t);this.effects.clear()}}class z extends V{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(t){this._progress=t,this.currentTime=t*this.duration}load(t,s){this.cat.res.load(t,e,((e,o)=>{e&&i(e),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,s&&s()}))}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 Q{cat;constructor(t){this.cat=t}}var J;!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"}(J||(J={}));class X extends Q{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 s("UIAudioManager");o.addPersistRootNode(e);var i=new s("UIMusic");i.parent=e,this.music=i.addComponent(z).initAudio(t);var n=new s("UIEffect");n.parent=e,this.effect=n.addComponent(W).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(n("设置背景音乐开关值",t,this._switch_music),t==this._switch_music)return;this._switch_music=t,t?this.resumeMusic():this.pauseMusic();const e=t?J.MUSIC_ON:J.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?J.EFFECT_ON:J.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 q extends Q{_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)),r.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=r.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)),r.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){r.localStorage.clear()}}function Z(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 Y(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class tt extends a{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===pe.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(pe.event),this.eventEmitter.forEach((t=>{this.deleteAllEventByEmitter(t)})),this.eventEmitter=[],this.removeListener()}deleteAllEventByEmitter(t){const e=t._events;for(const i in e){let s=e[i];Array.isArray(s)||(s=[s]),s.forEach((e=>{e.context===this&&t.off(i,e.fn,this)}))}}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(t,e){let i=t instanceof l?c(t):t instanceof a?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(){h(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 et(this.node,t),this}}const et=(t,e)=>{t.layer="string"==typeof e?2**p.nameToLayer(e):e,t?.children.forEach((t=>{et(t,e)}))};class it extends tt{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=d.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(u);let o,n;t&&(t.updateAlignment(),t.enabled=!1),_(1.1,1.1,1),"center"==e?(o=_(.01,.01,.01),n=_(1,1,1)):(o="left"==e?_(-this.screen.width,0,0):"right"==e?_(this.screen.width,0,0):_(0,"top"==e?this.screen.height:-this.screen.height,0),n=_(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,m(this.node).removeSelf(),t){const t=this.node.getComponent(u);let s,o;t&&(t.enabled=!1),"center"==e?(s=this.node.scale,o=_(0,0,0)):(o="left"==e?_(-this.screen.width,0,0):"right"==e?_(this.screen.width,0,0):_(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)=>{m(this.node).to(t,e).call((()=>{i()})).start()}))}}const{ccclass:st,property:ot}=g;var nt;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(nt||(nt={}));class rt extends tt{type=nt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,pe.event.on(J.EFFECT_ON,this.onPlayEffectHandler,this).on(J.EFFECT_OFF,this.onStopEffectHandler,this).on(J.MUSIC_ON,this.onPlayMusicHandler,this).on(J.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=pe.audio;this.audioSource.volume=this.type===nt.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=pe.audio;this.audioSource.playing||!(this.type===nt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}Z([ot({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:f(nt)}),Y("design:type",Number)],rt.prototype,"type",void 0),Z([ot({tooltip:"音源",type:e}),Y("design:type",e)],rt.prototype,"clip",void 0),Z([ot({tooltip:"循环"}),Y("design:type",Boolean)],rt.prototype,"loop",void 0),Z([ot({tooltip:"音量"}),Y("design:type",Number)],rt.prototype,"volume",void 0),Z([ot({tooltip:"是否启用自动播放"}),Y("design:type",Boolean)],rt.prototype,"playOnAwake",void 0);const{ccclass:at,property:lt}=g;class ct extends it{type=nt.EFFECT;clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=new t;onEnable(){super.onEnable(),pe.event.on(J.EFFECT_ON,this.onPlayEffectHandler,this).on(J.EFFECT_OFF,this.onStopEffectHandler,this).on(J.MUSIC_ON,this.onPlayMusicHandler,this).on(J.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:t,volumeMusic:e}=pe.audio;this.audioSource.volume=this.type===nt.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=pe.audio;this.audioSource.playing||!(this.type===nt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}Z([lt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:f(nt)}),Y("design:type",Number)],ct.prototype,"type",void 0),Z([lt({tooltip:"音源",type:e}),Y("design:type",e)],ct.prototype,"clip",void 0),Z([lt({tooltip:"循环"}),Y("design:type",Boolean)],ct.prototype,"loop",void 0),Z([lt({tooltip:"音量"}),Y("design:type",Number)],ct.prototype,"volume",void 0),Z([lt({tooltip:"是否启用自动播放"}),Y("design:type",Boolean)],ct.prototype,"playOnAwake",void 0);const{ccclass:ht,property:pt,menu:dt}=g;var ut;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(ut||(ut={}));let _t=class extends tt{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==ut.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(E),o=m(s).delay(1.2).to(.5,{opacity:0}).call((()=>{C.stopAllByTarget(t),this.node.destroy(),e()}));m(t).by(.5,{position:_(0,400,0)}).call((()=>{o.start()})).start()}))}onDestroy(){C.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var mt;Z([pt({type:s,tooltip:"固定节点"}),Y("design:type",s)],_t.prototype,"fixed_node",void 0),Z([pt({type:s,tooltip:"滑动节点"}),Y("design:type",s)],_t.prototype,"slide_node",void 0),Z([pt({type:v,tooltip:"固定标签节点"}),Y("design:type",v)],_t.prototype,"fixed_label",void 0),Z([pt({type:v,tooltip:"滑动标签节点"}),Y("design:type",v)],_t.prototype,"slide_label",void 0),_t=Z([ht("CoreToast"),dt("CATCORE/CoreToast")],_t),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"}(mt||(mt={}));const{ccclass:ft,property:gt,menu:yt}=g;let vt=class extends it{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Kt)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){pe.event.on(mt.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 h(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}};Z([gt({type:s}),Y("design:type",s)],vt.prototype,"scene_mask_node",void 0),Z([gt({type:s}),Y("design:type",s)],vt.prototype,"ui_container",void 0),vt=Z([ft("CoreUIContainer"),yt("CATCORE/CoreUIContainer")],vt);class Et extends it{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){pe.event.emit(mt.ROOT_MASK_UPDATE)}}const{ccclass:Ct,property:bt,menu:wt}=g;let St=class extends Et{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)}};Z([bt({type:v,tooltip:"标题"}),Y("design:type",v)],St.prototype,"title",void 0),Z([bt({type:s,tooltip:"动画"}),Y("design:type",s)],St.prototype,"loadingTween",void 0),St=Z([Ct("CoreShowLoading"),wt("CATCORE/CoreShowLoading")],St);const{ccclass:At,property:Tt,menu:kt}=g;var It;!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="连接游戏服错误"}(It||(It={}));let Ot=class extends Et{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==It.RECONNECTING)}updatePromptText(t,e=!1){if(this.unscheduleAllCallbacks(),this.props.content=t,n("更新提示文案:",t),e){let e=0;const i=()=>{e=(e+1)%4,this.common_prompt_text.string=t+["","·","··","···"][e]};this.schedule(i,.5)}}onConfirmHandler(){this.is_close=!0,pe.gui.hideReconnect()}};Z([Tt({type:v,tooltip:"通用提示文本"}),Y("design:type",v)],Ot.prototype,"common_prompt_text",void 0),Z([Tt({type:w,tooltip:"确定按钮"}),Y("design:type",w)],Ot.prototype,"btn_confirm",void 0),Z([Tt({type:w,tooltip:"关闭按钮"}),Y("design:type",w)],Ot.prototype,"btn_close",void 0),Ot=Z([At("CoreReconnection"),kt("CATCORE/CoreReconnection")],Ot);const{ccclass:Nt,property:Dt,menu:Mt}=g;let Rt=class extends Et{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?.(),pe.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};Z([Dt({type:v,tooltip:"提示文本"}),Y("design:type",v)],Rt.prototype,"text",void 0),Z([Dt({type:w,tooltip:"确定按钮"}),Y("design:type",w)],Rt.prototype,"btn_confirm",void 0),Z([Dt({type:w,tooltip:"关闭按钮"}),Y("design:type",w)],Rt.prototype,"btn_close",void 0),Rt=Z([Nt("CoreNotice"),Mt("CATCORE/CoreNotice")],Rt);class xt extends tt{isReload}const{ccclass:Ft,property:Pt,menu:Ut}=g;var Lt;!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"}(Lt||(Lt={}));let Bt=class extends tt{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(mt.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(t){this.cat=t;const e=o.getScene();return n("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=()=>{c(this.toast_ui_prefab).getComponent(_t).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(_t)?.removeAndDestroy()})),this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading({title:t="",mask:e=!0,black:i=!0}={}){if(n("showLoading",t),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:t,mask:e,black:i}});else{const s=c(this.loading_ui_prefab);this.loading_ui_component=s.getComponent(St).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=c(this.reconnection_ui_prefab);this.reconnection_ui_component=e.getComponent(Ot).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=c(this.notice_ui_prefab);return this.notice_ui_component=e.getComponent(Rt).addToParent(this.root_ui,{props:t}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}loadScene(t,e,i){n("加载场景",t,e,i);let s={},r=i??!1;return"boolean"==typeof e?r=e:s=e??{},n("当前场景",o.getScene()?.uuid,o.getScene()?.name),o.once(S.EVENT_BEFORE_SCENE_LAUNCH,(t=>{n("Director.EVENT_BEFORE_SCENE_LAUNCH",t),this.changeScene(t,s,r)})),o.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(xt);s&&(s.isReload=i??!1),s?.setOptions(e)}createUILayer(t){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const e=c(this.ui_prefab);this.ui_container_component=e.getComponent(vt).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(it),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 o,n=null;if(t instanceof s){o=t;const e=t.components.filter((t=>t instanceof it));if(!e.length)return i(`${t.name}节点未找到继承自BaseLayer的组件`),{rootNode:o,component:n};1==e.length?n=e[0]:A(`${t.name}节点存在多个继承自BaseLayer的组件`)}else if(o=t.node,n=t,e){for(;o.parent;)o=o.parent;n.root=o}else o=t.root;return{rootNode:o,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(mt.ROOT_MASK_CHANGE)}};Z([Pt({type:l,tooltip:"断线重连UI预制体"}),Y("design:type",l)],Bt.prototype,"reconnection_ui_prefab",void 0),Z([Pt({type:l,tooltip:"提示UI预制体"}),Y("design:type",l)],Bt.prototype,"toast_ui_prefab",void 0),Z([Pt({type:l,tooltip:"加载UI预制体"}),Y("design:type",l)],Bt.prototype,"loading_ui_prefab",void 0),Z([Pt({type:l,tooltip:"公告UI预制体"}),Y("design:type",l)],Bt.prototype,"notice_ui_prefab",void 0),Z([Pt({type:l,tooltip:"UI层预制体"}),Y("design:type",l)],Bt.prototype,"ui_prefab",void 0),Z([Pt({type:s,tooltip:"root-UI层"}),Y("design:type",s)],Bt.prototype,"root_ui",void 0),Z([Pt({type:s,tooltip:"root-组件层"}),Y("design:type",s)],Bt.prototype,"root_toast",void 0),Z([Pt({type:s,tooltip:"root-mask"}),Y("design:type",s)],Bt.prototype,"root_mask",void 0),Bt=Z([Ft("Gui"),Ut("CATCORE/Gui")],Bt);const{ccclass:Ht,property:Gt,menu:$t}=g;let Kt=class extends tt{tween};var jt;Z([Gt({type:s,tooltip:"动画节点"}),Y("design:type",s)],Kt.prototype,"tween",void 0),Kt=Z([Ht("CoreBlackMask"),$t("CATCORE/CoreBlackMask")],Kt),function(t){t.Root="prefabs/root",t.Toast="prefabs/toast",t.BlackMask="prefabs/black-mask",t.Loading="prefabs/loading",t.Notice="prefabs/notice",t.Reconnection="prefabs/reconnection"}(jt||(jt={}));class Vt extends Q{gui;#t="core";getGuiPrefabByType=(t,e)=>new Promise(((i,s)=>{n(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,jt.Root),e=c(t);return this.gui=e.getComponent(Bt).init(this.cat),o.addPersistRootNode(e),this}}class Wt{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)=>{n(T.assets.get(e))})),n(`当前资源总数:${T.assets.count}`)}}let zt=null;const Qt={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 Jt=Object.freeze({__proto__:null,md5:t=>H.MD5(t).toString(),initCrypto:(t,e)=>{zt=H.enc.Hex.parse(e)},aesEncrypt:(t,e,i)=>H.AES.encrypt(t,e,{iv:zt,format:Qt}).toString(),aesDecrypt:(t,e,i)=>H.AES.decrypt(t,e,{iv:zt,format:Qt}).toString(H.enc.Utf8),JsonFormatter:Qt});class Xt extends Q{encryptUtil=Jt}class qt extends K{logBlackList=[];ignore=t=>this.logBlackList.includes(t);constructor(t,e,i,s){super(e,i,s,t)}destroy(){this.disconnect(!0),pe.socialGameClient.unregister(this)}async GameRequest(t,e,i,s){return new Promise(((o,r)=>{super.GameRequest(t,e,i,s).then((e=>{x&&n(`%c ws服务端消息 %c [Response][${new Date}] %c ${t} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",G(i,e)),o(e)}),(t=>{pe.gui.showToast({title:t.msg}),r(t)}))}))}subscribe(t,e,i){return super.subscribe(t,e,(s=>{x&&!this.ignore(t)&&n(`%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)),pe.event.emit(t,G(e,s)),i?.(s)})),this}}class Zt extends Q{managedClients=new Map;isGlobalOnline=!0;isInBackground=!1;onEventHideDelegate=new O;onEventShowDelegate=new O;onEventReloadSceneDelegate=new O;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(),n(`清理旧的 ${t} 客户端`)}const o=new qt(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(mt.ONLINE,(()=>this.handleGlobalStateChange("online")),this).on(mt.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":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.onEventShowDelegate.dispatch();break;case"hide":await this.onEventHideDelegate.dispatch(),this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(!this.isGlobalOnline||this.isInBackground)return;if(0===this.managedClients.size)return void n("没有任何WS需要重连");pe.gui.showLoading({title:"正在重连"}),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.reconnectPromise()}catch(e){i(`${t.name}服重连失败`,e),pe.gui.showToast({title:`${t.name}服重连失败`})}})));const t=this.activeClients.filter((t=>t.socketConnectStatus!==$.CONNECTED));t.length>0&&(console.error("部分WS重连失败:",t.map((t=>t))),setTimeout((()=>{this.triggerReconnectAll()}),2e3))}disconnectAll(t){this.managedClients.forEach((e=>{n("断开连接",e.name,t,e.socket),e.disconnect(t)}))}handleSingleReconnect=async()=>{this.activeClients.every((t=>t.socketConnectStatus===$.CONNECTED))&&(n("单个WS重连成功回调===",this.managedClients),await Promise.allSettled(this.activeClients.map((async t=>{try{await t.connectRequest()}catch(e){i(`${t.name}服登录错误`,e),pe.gui.showToast({title:`登录${t.name}服错误`})}}))),await this.onEventReloadSceneDelegate.dispatch(),pe.gui.hideLoading().reloadScene())};handleSingleKick(){pe.gui.showReconnect(It.KICK)}}class Yt{rootStore;constructor(t){this.rootStore=t}}class te extends Q{}const{ccclass:ee,property:ie,menu:se}=g;let oe=class extends it{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(M).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(M).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),pe.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var ne;Z([ie({type:D,tooltip:"默认标题"}),Y("design:type",D)],oe.prototype,"default_title",void 0),Z([ie({type:M,tooltip:"标题节点"}),Y("design:type",M)],oe.prototype,"title",void 0),Z([ie({type:v,tooltip:"字符串内容按钮"}),Y("design:type",v)],oe.prototype,"prompt_content_str",void 0),Z([ie({type:M,tooltip:"图片精灵内容按钮"}),Y("design:type",M)],oe.prototype,"prompt_content_spriteFrame",void 0),Z([ie({type:w,tooltip:"确认按钮"}),Y("design:type",w)],oe.prototype,"btn_confirm",void 0),Z([ie({type:D,tooltip:"确认按钮精灵图"}),Y("design:type",D)],oe.prototype,"confirm_spriteFrame",void 0),Z([ie({type:w,tooltip:"取消按钮"}),Y("design:type",w)],oe.prototype,"btn_cancel",void 0),Z([ie({type:D,tooltip:"取消按钮精灵图"}),Y("design:type",D)],oe.prototype,"cancel_spriteFrame",void 0),Z([ie({type:w,tooltip:"关闭按钮"}),Y("design:type",w)],oe.prototype,"btn_close",void 0),oe=Z([ee("CoreUIModal"),se("CATCORE/CoreUIModal")],oe),function(t){t[t.Delay=0]="Delay",t[t.Interval=1]="Interval"}(ne||(ne={}));class re{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 ae extends Q{timers=new Map;lastUpdateTime=Date.now();constructor(t){super(t),t.event.on(mt.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(mt.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;n("elapsedTime",e);for(const t of this.timers.values())t.remainingTime>0&&(t.remainingTime-=e,t.executionTime+=e);this.lastUpdateTime=t}registerInterval(t,e,s){if(this.has(t))return i(`${t}定时器已存在,请勿重复注册`);const o=new re(t,ne.Interval,e,s);this.timers.set(t,o)}registerDelay(t,e,s){if(this.has(t))return i(`${t}延时器已存在,请勿重复注册`);const o=new re(t,ne.Delay,e,s);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===ne.Interval&&(i.executionTime+=i.initialTime),i.callback(i.executionTime),i.type===ne.Interval?i.remainingTime=i.initialTime:t.push(e));for(const e of t)this.timers.delete(e)}}const le=(t,e)=>(i,s,o)=>{let n=o.value;return o.value=function(...i){const s=t??pe.default_audio_effect;s?pe.audio.playEffect(s):console.warn("请添加音效路径参数"),e&&e(),n.apply(this,i)},o},ce=(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 he{static#e=null;#i=!1;static get instance(){return this.#e??(this.#e=new he)}onAppInitDelegate=new O;onPlugInInitDelegate=new O;#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}#l=null;get util(){return this.#l}#c=null;get socialGameClient(){return this.#c}#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 te(this),this.#a=new Wt,this.#l=new Xt(this),this.#r=new q(this),this.#o=new j,this.#s=new X(this),this.#c=new Zt(this),this.#n=(await new Vt(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 pe=he.instance;y.onPostProjectInitDelegate.add((async()=>{console.time("[Init App]");try{await pe.boot(),await pe.onAppInitDelegate.dispatch(),await pe.onPlugInInitDelegate.dispatch()}catch(t){throw i(`[Init App] 初始化失败: ${t instanceof Error?t.message:String(t)}`),t}finally{console.timeEnd("[Init App]")}}));export{le as AudioEffect,J as AudioEventConstant,X as AudioManager,rt as AudioSourceBaseComponent,ct as AudioSourceUILayer,nt as AudioTypeEnum,tt as BaseComponent,Q as BaseManager,jt as BasePrefab,Yt as BaseStore,ce as ButtonLock,Kt as CoreBlackMask,Rt as CoreNotice,Ot as CoreReconnection,St as CoreShowLoading,te as CoreStore,_t as CoreToast,vt as CoreUIContainer,oe as CoreUIModal,Xt as CoreUtil,mt as GlobalEventConstant,Bt as Gui,Vt as GuiManager,Lt as LayerType,he as Manager,It as ReconnectPrompt,Et as RootUILayer,xt as SceneLayer,ae as TimerManager,ut as ToastType,it as UILayer,qt as WrapperSocialGameClient,pe as cat};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shimotsuki/core",
3
- "version": "2.0.54",
3
+ "version": "2.0.55",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "dist/shimotsuki_core.js",