@shimotsuki/core 3.0.21 → 3.0.23
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 +7 -7
- package/dist/shimotsuki_core.js +1 -1
- package/package.json +54 -53
- package/tsconfig.json +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -568,9 +568,9 @@ declare class CoreUIContainer extends UILayer {
|
|
|
568
568
|
ui_container: Node;
|
|
569
569
|
gui: Gui;
|
|
570
570
|
protected onLoad(): void;
|
|
571
|
-
get scene_mask():
|
|
572
|
-
get brother():
|
|
573
|
-
get tweenChildren():
|
|
571
|
+
get scene_mask(): any;
|
|
572
|
+
get brother(): any;
|
|
573
|
+
get tweenChildren(): any;
|
|
574
574
|
protected onEventListener(): void;
|
|
575
575
|
/**增加层级 */
|
|
576
576
|
addMask(): void;
|
|
@@ -652,9 +652,9 @@ declare class SocialGameClientManager extends BaseManager {
|
|
|
652
652
|
/**正在重连 */
|
|
653
653
|
private reconnecting;
|
|
654
654
|
/**后台委托 */
|
|
655
|
-
readonly onEventHideDelegate: AsyncDelegate<() => (Promise<void> | void)>;
|
|
655
|
+
readonly onEventHideDelegate: AsyncDelegate<(option?: WechatMinigame.GeneralCallbackResult | undefined) => (Promise<void> | void)>;
|
|
656
656
|
/**前台委托 */
|
|
657
|
-
readonly onEventShowDelegate: AsyncDelegate<() => (Promise<void> | void)>;
|
|
657
|
+
readonly onEventShowDelegate: AsyncDelegate<(option?: WechatMinigame.OnShowListenerResult | undefined) => (Promise<void> | void)>;
|
|
658
658
|
/**重载场景委托 */
|
|
659
659
|
readonly onEventReloadSceneDelegate: AsyncDelegate<() => (Promise<void> | void)>;
|
|
660
660
|
/**重连定时器 */
|
|
@@ -1079,7 +1079,7 @@ declare class TimerManager extends BaseManager {
|
|
|
1079
1079
|
* @param callback 计时器回调函数
|
|
1080
1080
|
* @returns 计时器的唯一标识
|
|
1081
1081
|
*/
|
|
1082
|
-
registerInterval(tag: any, interval: number, callback: TimerCallback):
|
|
1082
|
+
registerInterval(tag: any, interval: number, callback: TimerCallback): any;
|
|
1083
1083
|
/**
|
|
1084
1084
|
* 注册一个延时器
|
|
1085
1085
|
* @param tag 注册延时器的对象
|
|
@@ -1087,7 +1087,7 @@ declare class TimerManager extends BaseManager {
|
|
|
1087
1087
|
* @param callback 延时器回调函数
|
|
1088
1088
|
* @returns 延时器的唯一标识
|
|
1089
1089
|
*/
|
|
1090
|
-
registerDelay(tag: any, delay: number, callback: TimerCallback):
|
|
1090
|
+
registerDelay(tag: any, delay: number, callback: TimerCallback): any;
|
|
1091
1091
|
/**
|
|
1092
1092
|
* 取消一个计时器或延时器
|
|
1093
1093
|
* @param tag 计时器或延时器的唯一标识
|
package/dist/shimotsuki_core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime-corejs3/core-js/global-this";import{AudioSource as t,_decorator as i,AudioClip as o,error as s,Node as n,director as r,log as a,Component as l,Prefab as c,instantiate as h,isValid as u,Layers as p,view as d,Widget as m,v3 as _,tween as f,Enum as g,game as y,Label as v,UIOpacity as b,Tween as C,BlockInputEvents as E,Button as S,assetManager as w,Director as A,warn as I,AsyncDelegate as T,Game as k,Asset as O,resources as M,sys as R,SpriteFrame as U,Sprite as D}from"cc";import N from"@babel/runtime-corejs3/core-js-stable/reflect/get";import B from"@babel/runtime-corejs3/core-js-stable/reflect/set";import F from"@babel/runtime-corejs3/core-js-stable/object/assign";import L from"@babel/runtime-corejs3/core-js-stable/promise";import x from"eventemitter3";import P from"@babel/runtime-corejs3/core-js-stable/instance/includes";import G from"@babel/runtime-corejs3/core-js-stable/json/stringify";import j from"@babel/runtime-corejs3/core-js-stable/map";import H from"@babel/runtime-corejs3/core-js-stable/instance/for-each";import $ from"@babel/runtime-corejs3/core-js-stable/instance/filter";import K from"@babel/runtime-corejs3/core-js-stable/array/is-array";import W from"@babel/runtime-corejs3/core-js-stable/reflect/own-keys";import V from"@babel/runtime-corejs3/core-js-stable/instance/bind";import{makeObservable as z,observable as q,autorun as Q,reaction as J}from"@shimotsuki/mobx";import X from"@babel/runtime-corejs3/core-js-stable/set-timeout";import Z from"@babel/runtime-corejs3/core-js-stable/instance/map";import Y from"@babel/runtime-corejs3/core-js-stable/array/from";import ee from"@babel/runtime-corejs3/core-js-stable/instance/every";import{SocketConnectStatus as te}from"pitayaclient";import{DEBUG as ie,WECHAT as oe,PREVIEW as se}from"cc/env";import{SocialGameClient as ne}from"sgc";import re from"crypto-es";import ae from"@babel/runtime-corejs3/core-js-stable/date/now";import le from"@babel/runtime-corejs3/core-js-stable/set-interval";import ce from"@babel/runtime-corejs3/core-js-stable/instance/values";import he from"@babel/runtime-corejs3/core-js-stable/instance/entries";class CommonAudio extends t{cat;initAudio(e){return this.cat=e,this}}const{ccclass:ue,menu:pe}=i;let de=class AudioEffect extends CommonAudio{effects=(()=>new j)();load(e,t){return new L((i,s)=>{let n,r=null;void 0!==t?(r=e,n=t):n=e;const a=(e,t)=>{if(e)return s(e);this.effects.set(n,t),this.playOneShot(t,this.volume),i(t)};r?this.cat.res.load(r,n,o,a):this.cat.res.load(n,o,a)})}release(){for(let e in this.effects)this.cat.res.release(e);this.effects.clear()}};const{ccclass:me,menu:_e}=i;class AudioMusic extends CommonAudio{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(e){this._progress=e,this.currentTime=e*this.duration}load(e,t){return new L((i,n)=>{let r,a=null;void 0!==t?(a=e,r=t):r=e;const l=(e,t)=>{if(e)return s(e),n(e);this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=t,this._url=r,i(t)};a?this.cat.res.load(a,r,o,l):this.cat.res.load(r,o,l)})}update(e){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class BaseManager{cat;constructor(e){this.cat=e}}var fe;!function(e){e.MUSIC_ON="AudioEventConstant/MUSIC_ON",e.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",e.EFFECT_ON="AudioEventConstant/EFFECT_ON",e.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",e.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",e.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(fe||(fe={}));class AudioManager extends BaseManager{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(e){super(e),this.local_store_key=this.cat.audio_local_store_key;var t=new n("UIAudioManager");r.addPersistRootNode(t);var i=new n("UIMusic");i.parent=t,this.music=i.addComponent(AudioMusic).initAudio(e);var o=new n("UIEffect");o.parent=t,this.effect=o.addComponent(de).initAudio(e),this.load()}setMusicComplete(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.music.onComplete=e}async playMusic(e,t){let i,o;this.music.loop=!0,void 0!==t?(o=e,i=t):i=e,i.length&&await(o?this.music.load(o,i):this.music.load(i)).then(()=>{this._switch_music&&this.music.play()})}stopMusic(){0!=this.music.state&&this.music?.stop()}pauseMusic(){1==this.music.state&&this.music?.pause()}resumeMusic(){var e;P(e=[0,2]).call(e,this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(e){this.music.progress=e}get volumeMusic(){return this._volume_music}set volumeMusic(e){this._volume_music=e,this.music.volume=e}get switchMusic(){return this._switch_music}set switchMusic(e){if(a("设置背景音乐开关值",e,this._switch_music),e==this._switch_music)return;this._switch_music=e,e?this.resumeMusic():this.pauseMusic();const t=e?fe.MUSIC_ON:fe.MUSIC_OFF;this.cat.event.emit(t),this.save()}async playEffect(e,t){if(!this._switch_effect)return;let i,o;void 0!==t?(o=e,i=t):i=e,i.length&&await(o?this.effect.load(o,i):this.effect.load(i)).then(()=>{this.effect.play()})}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(e){this._volume_effect=e,this.effect.volume=e}get switchEffect(){return this._switch_effect}set switchEffect(e){if(e==this._switch_effect)return;this._switch_effect=e,e?this.effect?.play():this.effect?.stop();const t=e?fe.EFFECT_ON:fe.EFFECT_OFF;this.cat.event.emit(t),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let e=G(this.local_data);return this.cat.storage.set(this.local_store_key,e),this}load(){try{let e=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(e),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(e){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}function ge(e,t,i,o){var s,n=arguments.length,r=n<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(r=(n<3?s(r):n>3?s(t,i,r):s(t,i))||r);return n>3&&r&&Object.defineProperty(t,i,r),r}function ye(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;class BaseComponent extends l{props={};data={};cat=(()=>e._cat)();autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),z(this,{props:q,data:q})}onAutoObserver(){}addAutorun(e){const t=K(e)?e:[e];return H(t).call(t,e=>{const t=Q(e);this.autorunDisposers.push(t)}),this}addReaction(e,t,i){const o=J(e,t,i);return this.reactionDisposers.push(o),this}addAudoListener(e){var t;return P(t=this.eventEmitter).call(t,e)||e===this.cat.event||this.eventEmitter.push(e),e}_onPreDestroy(){var e,t;if(H(e=this.autorunDisposers).call(e,e=>{e()}),H(t=this.reactionDisposers).call(t,e=>{e()}),this.autorunDisposers=[],this.reactionDisposers=[],!super._onPreDestroy)throw new Error("_onPreDestroy已弃用");super._onPreDestroy()}onDisable(){var e;this.onHide(),this.deleteAllEventByEmitter(this.cat.event),H(e=this.eventEmitter).call(e,e=>{this.deleteAllEventByEmitter(e)}),this.eventEmitter=[],this.removeListener()}deleteAllEventByEmitter(e){const t=e._events;for(const i in t){let o=t[i];K(o)||(o=[o]),H(o).call(o,t=>{t.context===this&&e.off(i,t.fn,this)})}}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(e,t,i){const o=e instanceof c?h(e):e instanceof l?e.node:e;if("number"==typeof t){const e=t,s=i;this.setOptions(s),o.insertChild(this.node,e)}else{const e=t;this.setOptions(e),o.addChild(this.node)}return this}setOptions(e){if(e)for(let t in e)switch(t){case"hook":e.hook&&(this.hook=e.hook);break;case"props":null!==e.props&&"object"==typeof e.props&&(this.props=e.props);break;case"data":null!==e.data&&"object"==typeof e.data&&(this.data=e.data)}}setUpdateData(e){if(this.data)return e&&F(this.data,this.toPlainObject(e)),this}setUpdateProps(e){if(this.props)return e&&F(this.props,this.toPlainObject(e)),this}toPlainObject(e){const t={};for(const i of W(e))if("string"==typeof i)try{t[i]=e[i]}catch{}return t}removeAndDestroy(){u(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(e){return this.node.setPosition(e),this}setScale(e){return this.node.setScale(e),this}setAngle(e){return this.node.angle=e,this}setRotation(e){return this.node.setRotation(e),this}setRotationFromEuler(e){return this.node.setRotationFromEuler(e),this}onShow(){}onHide(){}setNodeAndChildrenLayer(e){return ve(this.node,e),this}}const ve=(e,t)=>{var i,o,s;e.layer="string"==typeof t?2**p.nameToLayer(t):t,(null==(i=e)?void 0:V(s=Function.call).call(s,H(o=i.children),o))?.(e=>{ve(e,t)})};class UILayer extends BaseComponent{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=d.getVisibleSize()}async showTween(e){let{isMotion:t=!0,direction:i="center",duration:o=.1,isBounce:s=!0,bounceDuration:n=.05}=e;if(this.lastEnterDirection=i,t){const e=this.node.getComponent(m);let t,n;e&&(e.updateAlignment(),e.enabled=!1),_(1.1,1.1,1),"center"==i?(t=_(.01,.01,.01),n=_(1,1,1)):(t="left"==i?_(-this.screen.width,0,0):"right"==i?_(this.screen.width,0,0):_(0,"top"==i?this.screen.height:-this.screen.height,0),n=_(0,0,0)),await this.handle(i,o,t,n,s),e&&(e.enabled=!0)}}async hideTween(e){let{isMotion:t=!0,direction:i,duration:o=.1}=e;if(i=i||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,f(this.node).removeSelf(),t){const e=this.node.getComponent(m);let t,s;e&&(e.enabled=!1),"center"==i?(t=this.node.scale,s=_(0,0,0)):(s="left"==i?_(-this.screen.width,0,0):"right"==i?_(this.screen.width,0,0):_(0,"top"==i?this.screen.height:-this.screen.height,0),t=this.node.getPosition()),await this.handle(i,o,t,s,!1)}this.removeAndDestroy()}}async handle(e,t,i,o,s){"center"==e?this.node.setScale(i):this.node.setPosition(i),await this.deftween(t,{["center"==e?"scale":"position"]:o},s)}deftween(e,t,i,o){return new L((i,o)=>{f(this.node).to(e,t).call(()=>{i()}).start()})}}const{ccclass:be,property:Ce}=i;var Ee;!function(e){e[e.EFFECT=0]="EFFECT",e[e.BGM=1]="BGM"}(Ee||(Ee={}));class AudioSourceBaseComponent extends BaseComponent{type=(()=>Ee.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,this.cat.event.on(fe.EFFECT_ON,this.onPlayEffectHandler,this).on(fe.EFFECT_OFF,this.onStopEffectHandler,this).on(fe.MUSIC_ON,this.onPlayMusicHandler,this).on(fe.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:e,volumeMusic:t}=this.cat.audio;this.audioSource.volume=this.type===Ee.BGM?t:e}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=this.cat.audio;this.audioSource.playing||!(this.type===Ee.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}ge([Ce({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(Ee)}),ye("design:type",Number)],AudioSourceBaseComponent.prototype,"type",void 0),ge([Ce({tooltip:"音源",type:o}),ye("design:type",o)],AudioSourceBaseComponent.prototype,"clip",void 0),ge([Ce({tooltip:"循环"}),ye("design:type",Boolean)],AudioSourceBaseComponent.prototype,"loop",void 0),ge([Ce({tooltip:"音量"}),ye("design:type",Number)],AudioSourceBaseComponent.prototype,"volume",void 0),ge([Ce({tooltip:"是否启用自动播放"}),ye("design:type",Boolean)],AudioSourceBaseComponent.prototype,"playOnAwake",void 0);const{ccclass:Se,property:we}=i;class AudioSourceUILayer extends UILayer{type=(()=>Ee.EFFECT)();clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=(()=>new t)();onEnable(){super.onEnable(),this.cat.event.on(fe.EFFECT_ON,this.onPlayEffectHandler,this).on(fe.EFFECT_OFF,this.onStopEffectHandler,this).on(fe.MUSIC_ON,this.onPlayMusicHandler,this).on(fe.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:e,volumeMusic:t}=this.cat.audio;this.audioSource.volume=this.type===Ee.BGM?t:e}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=this.cat.audio;this.audioSource.playing||!(this.type===Ee.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}ge([we({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(Ee)}),ye("design:type",Number)],AudioSourceUILayer.prototype,"type",void 0),ge([we({tooltip:"音源",type:o}),ye("design:type",o)],AudioSourceUILayer.prototype,"clip",void 0),ge([we({tooltip:"循环"}),ye("design:type",Boolean)],AudioSourceUILayer.prototype,"loop",void 0),ge([we({tooltip:"音量"}),ye("design:type",Number)],AudioSourceUILayer.prototype,"volume",void 0),ge([we({tooltip:"是否启用自动播放"}),ye("design:type",Boolean)],AudioSourceUILayer.prototype,"playOnAwake",void 0);const{ccclass:Ae,property:Ie,menu:Te}=i;var ke;!function(e){e[e.FIXED=0]="FIXED",e[e.SLIDE=1]="SLIDE"}(ke||(ke={}));let Oe=class CoreToast extends BaseComponent{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 L(async(e,t)=>{const{title:i,type:o,fixed_time:s}=this.props;o==ke.FIXED?(this.fixed_node.active=!0,this.fixed_label.string=`${i}`,this.scheduleOnce(()=>{this.node.destroy(),e()},s)):(this.slide_node.active=!0,this.slide_label.string=`${i}`,this.playAnim(this.node).then(()=>{e()}))})}playAnim(e){return new L((t,i)=>{const o=this.node.getComponent(b),s=f(o).delay(1.2).to(.5,{opacity:0}).call(()=>{C.stopAllByTarget(e),this.node.destroy(),t()});f(e).by(.5,{position:_(0,400,0)}).call(()=>{s.start()}).start()})}onDestroy(){C.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var Me;ge([Ie({type:n,tooltip:"固定节点"}),ye("design:type",n)],Oe.prototype,"fixed_node",void 0),ge([Ie({type:n,tooltip:"滑动节点"}),ye("design:type",n)],Oe.prototype,"slide_node",void 0),ge([Ie({type:v,tooltip:"固定标签节点"}),ye("design:type",v)],Oe.prototype,"fixed_label",void 0),ge([Ie({type:v,tooltip:"滑动标签节点"}),ye("design:type",v)],Oe.prototype,"slide_label",void 0),Oe=ge([Ae("CoreToast"),Te("CATCORE/CoreToast")],Oe),function(e){e.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",e.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",e.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",e.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",e.ONLINE="GlobalEventConstant/ONLINE",e.OFFLINE="GlobalEventConstant/OFFLINE",e.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",e.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(Me||(Me={}));const{ccclass:Re,property:Ue,menu:De}=i;let Ne=class CoreBlackMask extends BaseComponent{tween};ge([Ue({type:n,tooltip:"动画节点"}),ye("design:type",n)],Ne.prototype,"tween",void 0),Ne=ge([Re("CoreBlackMask"),De("CATCORE/CoreBlackMask")],Ne);const{ccclass:Be,property:Fe,menu:Le}=i;let xe=class CoreUIContainer extends UILayer{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Ne)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){this.cat.event.on(Me.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const e=this.brother[this.brother.length-1];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const e=this.brother[this.brother.length-2];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(e){return u(this)&&this.scene_mask&&this.scene_mask.tween.addChild(e),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(e){return this.gui=e,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(e){this.scene_mask.node.active=e}};ge([Fe({type:n}),ye("design:type",n)],xe.prototype,"scene_mask_node",void 0),ge([Fe({type:n}),ye("design:type",n)],xe.prototype,"ui_container",void 0),xe=ge([Be("CoreUIContainer"),Le("CATCORE/CoreUIContainer")],xe);class RootUILayer extends UILayer{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){this.cat.event.emit(Me.ROOT_MASK_UPDATE)}}const{ccclass:Pe,property:Ge,menu:je}=i;let He=class CoreShowLoading extends RootUILayer{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(E).enabled=!!this.props?.mask}])}update(e){this.loading_rotate+=220*e,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};var $e;ge([Ge({type:v,tooltip:"标题"}),ye("design:type",v)],He.prototype,"title",void 0),ge([Ge({type:n,tooltip:"动画"}),ye("design:type",n)],He.prototype,"loadingTween",void 0),He=ge([Pe("CoreShowLoading"),je("CATCORE/CoreShowLoading")],He),function(e){e.RECONNECTED="重连成功",e.RECONNECTING="正在重连",e.MAX_RECONNECT="重连次数超出限制,请检查网络",e.RECONNECTED_ERROR="重连失败,请检查网络",e.CONNECT_PARAM_ERROR="游戏参数错误,请重新加载",e.KICK="账号已下线",e.OFFLINE="网络已断开",e.ONLINE="网络已连接",e.GAME_ERROR="连接游戏服错误"}($e||($e={}));const{ccclass:Ke,property:We,menu:Ve}=i;let ze=class CoreReconnection extends RootUILayer{common_prompt_text;btn_confirm;btn_close;is_close=!1;props={content:null};initUI(){}onLoad(){this.btn_confirm.node.on(S.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(S.EventType.CLICK,this.onConfirmHandler,this),this.addAutorun([()=>{this.common_prompt_text.string=this.props.content??""}])}onDestroy(){this.unscheduleAllCallbacks()}updateProps(e){this.updatePromptText(e,e==$e.RECONNECTING)}updatePromptText(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.unscheduleAllCallbacks(),this.props.content=e,a("更新提示文案:",e),t){let t=0;const i=()=>{t=(t+1)%4,this.common_prompt_text.string=e+["","·","··","···"][t]};this.schedule(i,.5)}}onConfirmHandler(){this.is_close=!0,this.cat.gui.hideReconnect()}};ge([We({type:v,tooltip:"通用提示文本"}),ye("design:type",v)],ze.prototype,"common_prompt_text",void 0),ge([We({type:S,tooltip:"确定按钮"}),ye("design:type",S)],ze.prototype,"btn_confirm",void 0),ge([We({type:S,tooltip:"关闭按钮"}),ye("design:type",S)],ze.prototype,"btn_close",void 0),ze=ge([Ke("CoreReconnection"),Ve("CATCORE/CoreReconnection")],ze);const{ccclass:qe,property:Qe,menu:Je}=i;let Xe=class CoreNotice extends RootUILayer{text;btn_confirm;btn_close;onLoad(){this.btn_confirm.node.on(S.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),this.cat.gui.hideNotice()}updateProps(e){this.text.string=`${e.text}`}};ge([Qe({type:v,tooltip:"提示文本"}),ye("design:type",v)],Xe.prototype,"text",void 0),ge([Qe({type:S,tooltip:"确定按钮"}),ye("design:type",S)],Xe.prototype,"btn_confirm",void 0),ge([Qe({type:S,tooltip:"关闭按钮"}),ye("design:type",S)],Xe.prototype,"btn_close",void 0),Xe=ge([qe("CoreNotice"),Je("CATCORE/CoreNotice")],Xe);class SceneLayer extends BaseComponent{isReload}const{ccclass:Ze,property:Ye,menu:et}=i;var tt;!function(e){e[e.UI=0]="UI",e[e.LOADING=1]="LOADING",e[e.TOAST=2]="TOAST",e[e.RECONNECTTION=3]="RECONNECTTION",e[e.NOTICE=4]="NOTICE"}(tt||(tt={}));let it=class Gui extends BaseComponent{reconnection_ui_prefab;toast_ui_prefab;loading_ui_prefab;notice_ui_prefab;ui_prefab;root_ui;root_toast;root_mask;ui_container_component;reconnection_ui_component;notice_ui_component;loading_ui_component;toast_ui_component;currentScene;currentSceneUUID;onEventListener(){this.cat.event.on(Me.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(e){this.cat=e;const t=r.getScene();return a("init scene"),t&&this.changeScene(t),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(e){this.toastQueue.push(e),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const e=this.toastQueue.shift(),t=()=>{h(this.toast_ui_prefab).getComponent(Oe).addToParent(this.root_toast,{props:e}),this.scheduleOnce(()=>{this.processQueueWithInterval()},this.minInterval)};0===this.root_toast.children.length?t():this.scheduleOnce(t,this.minInterval)}hideToast(){var e;this.root_toast&&H(e=this.root_toast.children).call(e,e=>{e.getComponent(Oe)?.removeAndDestroy()});return this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading(){let{title:e="",mask:t=!0,black:i=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(a("showLoading",e),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:e,mask:t,black:i}});else{const o=h(this.loading_ui_prefab);this.loading_ui_component=o.getComponent(He).addToParent(this.root_ui,{props:{title:e,mask:t,black:i}})}return this}hideLoading(){return this.loading_ui_component?.removeAndDestroy(),this.loading_ui_component=null,this}showReconnect(e){if(this.reconnection_ui_component)this.reconnection_ui_component.setUpdateProps({content:e});else{const t=h(this.reconnection_ui_prefab);this.reconnection_ui_component=t.getComponent(ze).addToParent(this.root_ui,{props:{content:e}})}return this}hideReconnect(){return this.reconnection_ui_component?.removeAndDestroy(),this.reconnection_ui_component=null,this}showNotice(e){const t=h(this.notice_ui_prefab);return this.notice_ui_component=t.getComponent(Xe).addToParent(this.root_ui,{props:e}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}findBundleBySceneUUID(e){const t=w.bundles._map;for(const i in t){const o=t[i],s=o.config?.scenes?._map;if(s)for(const t in s){const i=s[t];if(i?.uuid===e)return o}}return null}findSceneByUUIDFromBundle(e,t){}loadScene(e,t,i){a("[加载场景名][参数][重新加载]",e,t,i);let o={},n=i??!0;if("boolean"==typeof t?n=t:o=t??{},r.once(A.EVENT_BEFORE_SCENE_LAUNCH,e=>{a("Director.EVENT_BEFORE_SCENE_LAUNCH",e),this.changeScene(e,o,n)}),"string"==typeof e){const t=this.findBundleBySceneUUID(e);if(t)if("main"!==t.name)t.loadScene(this.currentScene,(e,t)=>{e?s("loadScene err",e):r.runScene(t)});else{const i=t.getAssetInfo(e);i?.url&&r.loadScene(i?.url)}else r.loadScene(e)}else r.runScene(e);return this}resetScene(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e=e||this.currentScene,this.loadScene(e)}cleanScene(){this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast()}changeScene(e,t,i){this.currentScene=e.name,this.currentSceneUUID=e.uuid,this.createUILayer(e);const o=e.getComponentInChildren(SceneLayer);a("给场景传递属性值=======",o),o&&(o.isReload=i??!0),o?.setOptions(t)}createUILayer(e){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const t=h(this.ui_prefab);this.ui_container_component=t.getComponent(xe),this.ui_container_component?.setGui(this).addToParent(e,this.node.getSiblingIndex())}reloadScene(){a("重新加载当前场景"),this.loadScene(this.currentSceneUUID,!0)}async closeUI(e,t){const{component:i}=this.findUIBaseLayer(e,!1);i&&(i.setOptions({...t?.hook??{},...t?.props??{}}),await i.hideTween(t||{}),this.ui_container_component?.subMask())}async openUI(e,t){const{rootNode:i,component:o}=this.findUIBaseLayer(e,!0);i.getComponent(UILayer),o?.setOptions(t),i&&this.ui_container_component?.addNodeToTween(i).addMask(),o&&await o.showTween(t||{}),this.ui_container_component?.ui_container&&o?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(e,t){let i,o=null;if(e instanceof n){var r;i=e;const t=$(r=e.components).call(r,e=>e instanceof UILayer);if(!t.length)return s(`${e.name}节点未找到继承自BaseLayer的组件`),{rootNode:i,component:o};1==t.length?o=t[0]:I(`${e.name}节点存在多个继承自BaseLayer的组件`)}else if(i=e.node,o=e,t){for(;i.parent;)i=i.parent;o.root=i}else i=e.root;return{rootNode:i,component:o}}onRootUpdate(){const e=this.root_ui.children.findLastIndex(e=>e.active&&e!=this.root_mask);if(this.root_mask.active=-1!=e,e>-1){const t=this.root_ui.children[e].getSiblingIndex()-1;this.root_mask.setSiblingIndex(t<0?0:t)}this.cat.event.emit(Me.ROOT_MASK_CHANGE)}};var ot;ge([Ye({type:c,tooltip:"断线重连UI预制体"}),ye("design:type",c)],it.prototype,"reconnection_ui_prefab",void 0),ge([Ye({type:c,tooltip:"提示UI预制体"}),ye("design:type",c)],it.prototype,"toast_ui_prefab",void 0),ge([Ye({type:c,tooltip:"加载UI预制体"}),ye("design:type",c)],it.prototype,"loading_ui_prefab",void 0),ge([Ye({type:c,tooltip:"公告UI预制体"}),ye("design:type",c)],it.prototype,"notice_ui_prefab",void 0),ge([Ye({type:c,tooltip:"UI层预制体"}),ye("design:type",c)],it.prototype,"ui_prefab",void 0),ge([Ye({type:n,tooltip:"root-UI层"}),ye("design:type",n)],it.prototype,"root_ui",void 0),ge([Ye({type:n,tooltip:"root-组件层"}),ye("design:type",n)],it.prototype,"root_toast",void 0),ge([Ye({type:n,tooltip:"root-mask"}),ye("design:type",n)],it.prototype,"root_mask",void 0),it=ge([Ze("Gui"),et("CATCORE/Gui")],it),function(e){e.Root="prefabs/root",e.Toast="prefabs/toast",e.BlackMask="prefabs/black-mask",e.Loading="prefabs/loading",e.Notice="prefabs/notice",e.Reconnection="prefabs/reconnection"}(ot||(ot={}));class GuiManager extends BaseManager{gui;#e="core";getGuiPrefabByType=(e,t)=>new L((i,o)=>{a(e,`${t}`),this.cat.res.load(e,t,(e,t)=>{e?o(e):i(t)})});async init(){this.cat.gui_bundle_name&&(this.#e=this.cat.gui_bundle_name);const e=await this.getGuiPrefabByType(this.#e,ot.Root),t=h(e);return this.gui=t.getComponent(it).init(this.cat),r.addPersistRootNode(t),this}}class WrapperSocialGameClient extends ne{showRequestErrInfo=!1;logBlackList=[];ignore=e=>{var t;return P(t=this.logBlackList).call(t,e)};constructor(e,t,i,o){super(t,i,o,e),this.showRequestErrInfo=o?.showRequestErrInfo??!1}destroy(){this.disconnect(!0),e._cat.socialGameClient.unregister(this)}async GameRequest(t,i,o){let{forwardReq:n=!1,forwardResp:r=!1}=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return new L((l,c)=>{super.GameRequest(t,i,o,{forwardReq:n,forwardResp:r}).then(e=>{ie&&a(`%c ws服务端消息 %c [Response][${new Date}] %c ${t} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",i),l(e)},t=>{s(t),this.showRequestErrInfo&&t?.msg&&e._cat.gui.showToast({title:t.msg}),c(t)})})}subscribe(t,i,o){return super.subscribe(t,i,i=>{ie&&!this.ignore(t)&&a(`%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",i),e._cat.event.emit(t,i),o?.(i)}),this}}class SocialGameClientManager extends BaseManager{managedClients=(()=>new j)();isGlobalOnline=!0;isInBackground=!1;reconnecting=!1;onEventHideDelegate=(()=>new T)();onEventShowDelegate=(()=>new T)();onEventReloadSceneDelegate=(()=>new T)();reconnectTimer=null;scheduleReconnect(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2e3;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectTimer=X(()=>{this.reconnectTimer=null,this.triggerReconnectAll()},e)}get activeClients(){var e,t;return $(e=Z(t=Y(this.managedClients)).call(t,e=>{let[t,i]=e;return i})).call(e,e=>e.socket)}constructor(e){super(e),this.initGlobalListeners()}createWebSocket(e,t,i,o){if(this.managedClients.has(e)){this.managedClients.get(e).destroy(),a(`清理旧的 ${e} 客户端`)}const s=new WrapperSocialGameClient(e,i,o,F({reconnectMaxAttempts:1/0},{...t,isAutoConnect:!1,isArrayBuffer:oe}));return this.register(s),s}register(e){e.on("reconnected",this.handleSingleReconnect),e.on("close",this.handleSingleClose),e.on("kick",this.handleSingleKick),this.managedClients.set(e.name,e)}unregister(e){e.off("reconnected",this.handleSingleReconnect),e.off("close",this.handleSingleClose),e.off("kick",this.handleSingleKick),this.managedClients.delete(e.name)}initGlobalListeners(){this.cat.event.on(Me.ONLINE,()=>this.handleGlobalStateChange("online"),this).on(Me.OFFLINE,()=>this.handleGlobalStateChange("offline"),this),y.on(k.EVENT_SHOW,()=>this.handleGlobalStateChange("show")),y.on(k.EVENT_HIDE,()=>this.handleGlobalStateChange("hide"))}async handleGlobalStateChange(e){switch(e){case"online":this.cat.gui.hideLoading().showToast({title:$e.ONLINE}),this.isGlobalOnline=!0,this.triggerReconnectAll();break;case"offline":this.isGlobalOnline=!1,this.disconnectAll(!0),this.cat.gui.showLoading({title:$e.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(a("触发所有客户端重连[正在重连][在线][后台][ws数量]",this.reconnecting,this.isGlobalOnline,this.isInBackground,this.managedClients.size),this.reconnecting||!this.isGlobalOnline||this.isInBackground||0===this.managedClients.size)return this.onEventReloadSceneDelegate.dispatch();this.reconnecting=!0,this.cat.gui.showLoading({title:"正在重连"});try{var e,t;await L.allSettled(Z(e=this.activeClients).call(e,async e=>{try{await e.reconnectPromise()}catch(t){s(`${e.name}服重连失败`,t)}}));const i=$(t=this.activeClients).call(t,e=>e.socketConnectStatus!==te.CONNECTED);i.length>0?(Z(i).call(i,e=>{console.error("部分WS重连失败:",e)}),a("2s后重连所有客户端"),this.reconnecting=!1,this.scheduleReconnect()):this.reconnecting=!1}catch(e){throw this.reconnecting=!1,e}}disconnectAll(e){var t;H(t=this.managedClients).call(t,t=>{a("断开连接",t.name,e,t.socket),t.disconnect(e)})}handleSingleClose=()=>{this.reconnecting||(a("3s后重连所有客户端"),this.scheduleReconnect(3e3))};handleSingleReconnect=async()=>{var e,t;ee(e=this.activeClients).call(e,e=>e.socketConnectStatus===te.CONNECTED)&&(a("单个WS重连成功回调===",this.managedClients),await L.allSettled(Z(t=this.activeClients).call(t,async e=>{try{await e.connectRequest()}catch(t){s(`${e.name}服登录错误`,t),this.cat.gui.showToast({title:`登录${e.name}服错误`})}})),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),console.log("执行onEventReloadSceneDelegate前"),await this.onEventReloadSceneDelegate.dispatch(),console.log("执行onEventReloadSceneDelegate后"),this.cat.gui.hideLoading(),r.getScene()?.getComponentInChildren(SceneLayer)?.isReload&&this.cat.gui.reloadScene())};handleSingleKick=()=>{this.cat.gui.showReconnect($e.KICK)}}class ResLoader{get=(()=>function(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"resources";return w.getBundle(i).get(e,t)})();isAssetType=e=>"function"==typeof e&&e.prototype instanceof O;async load(){let e=null,t=null,i=null;for(var o=arguments.length,s=new Array(o),n=0;n<o;n++)s[n]=arguments[n];"string"==typeof s[0]&&"string"==typeof s[1]&&(e=s.shift());let r=s.shift();this.isAssetType(s[0])&&(t=s.shift()),2==s.length&&(i=s.shift());const a=s.shift();let l=M;if(e&&"resources"!=e){w.bundles.has(e)||await this.loadBundle(e);let t=w.bundles.get(e);t&&(l=t)}i&&a?l.load(r,t,i,a):a?l.load(r,t,a):l.load(r,t)}async loadDir(){let e=null,t=null,i=null,o=null;for(var s=arguments.length,n=new Array(s),r=0;r<s;r++)n[r]=arguments[r];"string"==typeof n[0]&&"string"==typeof n[1]&&(e=n.shift());let a=n.shift();this.isAssetType(n[0])&&(t=n.shift()),2==n.length&&(i=n.shift()),o=n.shift();let l=M;if(e&&"resources"!=e){w.bundles.has(e)||await this.loadBundle(e);let t=w.bundles.get(e);t&&(l=t)}i&&o?l.loadDir(a,t,i,o):o?l.loadDir(a,t,o):l.loadDir(a,t)}loadRemote(e){for(var t,i=null,o=arguments.length,s=new Array(o>1?o-1:0),n=1;n<o;n++)s[n-1]=arguments[n];2==s.length&&(i=s.shift()),t=s.shift(),w.loadRemote(e,{ext:".png",...i},t)}loadBundle=(e,t)=>new L((i,o)=>{const s=(e,t)=>{if(e)return o(e);i(t)};t?w.loadBundle(e,{version:t},s):w.loadBundle(e,s)});releasePrefabtDepsRecursively=e=>{var t=w.assets.get(e);if(w.releaseAsset(t),t instanceof c){var i=w.dependUtil.getDepsRecursively(e);H(i).call(i,e=>{w.assets.get(e).decRef()})}};release=(()=>{var e=this;return function(t){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"resources";var o=w.getBundle(i);if(o){var s=o.get(t);s&&e.releasePrefabtDepsRecursively(s._uuid)}}})();releaseDir=(()=>{var e=this;return function(t){var i,o;let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"resources";var n=w.getBundle(s),r=n?.getDirWithPath(t);(null==(i=r)?void 0:V(o=Function.call).call(o,Z(i),i))?.(t=>{e.releasePrefabtDepsRecursively(t.uuid)}),!t&&"resources"!=s&&n&&w.removeBundle(n)}})();dump=()=>{var e;H(e=w.assets).call(e,(e,t)=>{a(w.assets.get(t))}),a(`当前资源总数:${w.assets.count}`)};loadAssetsWithProgress(e,t){return new L((i,o)=>{const s=e.getDirWithPath(""),n=s.length;let r=0;if(0===n)return t(1),void i();H(s).call(s,s=>{e.load(s.path,e=>{e?o(e):(r++,t(r/n),r===n&&i())})})})}}class BaseStore{rootStore;constructor(e){this.rootStore=e}}class CoreStore extends BaseManager{}let st=null;const nt={stringify:e=>{const t={ct:e.ciphertext.toString(re.enc.Base64)};return e.iv&&(t.iv=e.iv.toString()),e.salt&&(t.s=e.salt.toString()),G(t)},parse:e=>{const t=JSON.parse(e),i=re.lib.CipherParams.create({ciphertext:re.enc.Base64.parse(t.ct)});return t.iv&&(i.iv=re.enc.Hex.parse(t.iv)),t.s&&(i.salt=re.enc.Hex.parse(t.s)),i}};var rt=Object.freeze({__proto__:null,JsonFormatter:nt,aesDecrypt:(e,t,i)=>re.AES.decrypt(e,t,{iv:st,format:nt}).toString(re.enc.Utf8),aesEncrypt:(e,t,i)=>re.AES.encrypt(e,t,{iv:st,format:nt}).toString(),initCrypto:(e,t)=>{st=re.enc.Hex.parse(t)},md5:e=>re.MD5(e).toString()});class CoreUtil extends BaseManager{encryptUtil=(()=>rt)()}class StorageManager extends BaseManager{_key=null;_iv=null;_id="";init(e,t){this.cat.util.encryptUtil.initCrypto(e,t),this._key=this.cat.util.encryptUtil.md5(e),this._iv=this.cat.util.encryptUtil.md5(t)}setUser(e){this._id=e}set(e,t){if(null!=(e=`${e}_${this._id}`)){if(se||(e=this.cat.util.encryptUtil.md5(e)),null==t)return console.warn("存储的值为空,则直接移除该存储"),void this.remove(e);if("function"!=typeof t){if("object"==typeof t)try{t=G(t)}catch(e){return void console.error(`解析失败,str = ${t}`)}else"number"==typeof t&&(t+="");se||null==this._key||null==this._iv||(t=this.cat.util.encryptUtil.aesEncrypt(`${t}`,this._key,this._iv)),R.localStorage.setItem(e,t)}else console.error("储存的值不能为方法")}else console.error("存储的key不能为空")}get(e,t){if(null==e)return console.error("存储的key不能为空"),null;e=`${e}_${this._id}`,se||(e=this.cat.util.encryptUtil.md5(e));let i=R.localStorage.getItem(e);return null==i||""===i||se||null==this._key||null==this._iv||(i=this.cat.util.encryptUtil.aesDecrypt(i,this._key,this._iv)),null===i?t:i}getNumber(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;var i=this.get(e);return Number(i)||t}getBoolean(e){var t=this.get(e);return Boolean(t)||!1}getJson(e,t){var i=this.get(e);return i&&JSON.parse(i)||t}remove(e){null!=e?(e=`${e}_${this._id}`,se||(e=this.cat.util.encryptUtil.md5(e)),R.localStorage.removeItem(e)):console.error("存储的key不能为空")}clear(){R.localStorage.clear()}}class Manager{static#t=null;#i=!1;static get instance(){return this.#t??(this.#t=new Manager)}onAppInitDelegate=(()=>new T)();onPlugInInitDelegate=(()=>new T)();#o=null;get audio(){return this.#o}#s=null;get event(){return this.#s}#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}#u="";get gui_bundle_name(){return this.#u}#p="";get audio_local_store_key(){return this.#p}#d="";get default_audio_effect(){return this.#d}setConfig=(()=>{var e=this;return function(){let{default_audio_effect:t="",gui_bundleName:i="resources",audio_local_store_key:o="game_audio"}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.#i)throw new Error("[CAT] 已初始化,无法修改配置");return e.#u=i,e.#p=o,e.#d=t,e}})();async boot(){if(this.#i)throw new Error("[CAT] 已初始化");try{this.#h=new CoreStore(this),this.#a=new ResLoader,this.#l=new CoreUtil(this),this.#r=new StorageManager(this),this.#s=new x,this.#o=new AudioManager(this),this.#c=new SocialGameClientManager(this),this.#n=(await new GuiManager(this).init()).gui,this.#i=!0}catch(e){throw console.error("[CAT] 初始化失败:",e),e}}merge(e,t){if(!this.#i)throw new Error("[CAT] 未初始化");if("string"!=typeof e)throw new Error("merge方法第一个参数应该为string类型");return N(this,e)||B(this,e,t),F(N(this,e),t),this}appendPlugInInitDelegate(e){return this.#i?L.resolve().then(e).catch(e=>{console.error("[CAT] appendPlugInInitDelegate 回调执行失败:",e)}):this.onPlugInInitDelegate.add(e),this}}const{ccclass:at,property:lt,menu:ct}=i;let ht=class CoreUIModal extends UILayer{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(S.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(S.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(S.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content&&(this.props.content instanceof U?this.prompt_content_spriteFrame.spriteFrame=this.props.content:"string"==typeof this.props.content?this.prompt_content_str.string=this.props.content:console.error("未知类型的【UIModal】内容"))},()=>{null===this.props?.style?.confirm?this.btn_confirm.node.active=!1:(this.btn_confirm.node.active=!0,this.btn_confirm.getComponent(D).spriteFrame=this.props.style?.confirm||this.confirm_spriteFrame),null===this.props?.style?.cancel?this.btn_cancel.node.active=!1:(this.btn_cancel.node.active=!0,this.btn_cancel.getComponent(D).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),this.cat.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var ut;ge([lt({type:U,tooltip:"默认标题"}),ye("design:type",U)],ht.prototype,"default_title",void 0),ge([lt({type:D,tooltip:"标题节点"}),ye("design:type",D)],ht.prototype,"title",void 0),ge([lt({type:v,tooltip:"字符串内容按钮"}),ye("design:type",v)],ht.prototype,"prompt_content_str",void 0),ge([lt({type:D,tooltip:"图片精灵内容按钮"}),ye("design:type",D)],ht.prototype,"prompt_content_spriteFrame",void 0),ge([lt({type:S,tooltip:"确认按钮"}),ye("design:type",S)],ht.prototype,"btn_confirm",void 0),ge([lt({type:U,tooltip:"确认按钮精灵图"}),ye("design:type",U)],ht.prototype,"confirm_spriteFrame",void 0),ge([lt({type:S,tooltip:"取消按钮"}),ye("design:type",S)],ht.prototype,"btn_cancel",void 0),ge([lt({type:U,tooltip:"取消按钮精灵图"}),ye("design:type",U)],ht.prototype,"cancel_spriteFrame",void 0),ge([lt({type:S,tooltip:"关闭按钮"}),ye("design:type",S)],ht.prototype,"btn_close",void 0),ht=ge([at("CoreUIModal"),ct("CATCORE/CoreUIModal")],ht),function(e){e[e.Delay=0]="Delay",e[e.Interval=1]="Interval"}(ut||(ut={}));class TimerEntry{tag;type;callback;remainingTime;executionTime=0;initialTime;constructor(e,t,i,o){this.tag=e,this.type=t,this.remainingTime=i,this.initialTime=i,this.callback=o}}class TimerManager extends BaseManager{timers=(()=>new j)();lastUpdateTime=(()=>ae())();constructor(e){var t;super(e),e.event.on(Me.EVENT_HIDE,this.onHandleAppBackground,this),e.event.on(Me.EVENT_SHOW,this.onHandleAppForeground,this),le(V(t=this.update).call(t,this),1e3)}onHandleAppBackground(){this.lastUpdateTime=ae()}onHandleAppForeground(){const e=ae(),t=e-this.lastUpdateTime;a("elapsedTime",t);for(const e of ce(i=this.timers).call(i)){var i;e.remainingTime>0&&(e.remainingTime-=t,e.executionTime+=t)}this.lastUpdateTime=e}registerInterval(e,t,i){if(this.has(e))return s(`${e}定时器已存在,请勿重复注册`);const o=new TimerEntry(e,ut.Interval,t,i);this.timers.set(e,o)}registerDelay(e,t,i){if(this.has(e))return s(`${e}延时器已存在,请勿重复注册`);const o=new TimerEntry(e,ut.Delay,t,i);this.timers.set(e,o)}unregister(e){this.has(e)&&this.timers.delete(e)}has(e){return this.timers.has(e)}update(){const e=[];for(const[i,o]of he(t=this.timers).call(t)){var t;o.remainingTime-=1e3,o.remainingTime<=0&&(o.type===ut.Interval&&(o.executionTime+=o.initialTime),o.callback(o.executionTime),o.type===ut.Interval?o.remainingTime=o.initialTime:e.push(i))}for(const t of e)this.timers.delete(t)}}const pt=(t,i)=>(o,s,n)=>{let r=n.value;return n.value=function(){const o=t??e._cat.default_audio_effect;o?e._cat.audio.playEffect(o):console.warn("请添加音效路径参数"),i&&i();for(var s=arguments.length,n=new Array(s),a=0;a<s;a++)n[a]=arguments[a];r.apply(this,n)},n},dt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1?arguments[1]:void 0;return function(i,o,s){let n=s.value,r=!1;return s.value=function(){if(r)t&&t();else{r=!0,X(()=>{r=!1},1e3*e);for(var i=arguments.length,o=new Array(i),s=0;s<i;s++)o[s]=arguments[s];n.apply(this,o)}},s}},mt=e._cat??=Manager.instance;y.onPostProjectInitDelegate.add(async()=>{console.time("[Init App]");try{await mt.boot(),await mt.onAppInitDelegate.dispatch(),await mt.onPlugInInitDelegate.dispatch()}catch(e){throw s(`[Init App] 初始化失败: ${e instanceof Error?e.message:String(e)}`),e}finally{console.timeEnd("[Init App]")}});export{pt as AudioEffect,fe as AudioEventConstant,AudioManager,AudioSourceBaseComponent,AudioSourceUILayer,Ee as AudioTypeEnum,BaseComponent,BaseManager,ot as BasePrefab,BaseStore,dt as ButtonLock,Ne as CoreBlackMask,Xe as CoreNotice,ze as CoreReconnection,He as CoreShowLoading,CoreStore,Oe as CoreToast,xe as CoreUIContainer,ht as CoreUIModal,CoreUtil,Me as GlobalEventConstant,it as Gui,GuiManager,tt as LayerType,Manager,$e as ReconnectPrompt,RootUILayer,SceneLayer,TimerManager,ke as ToastType,UILayer,WrapperSocialGameClient,mt as cat};
|
|
1
|
+
import e from"@babel/runtime-corejs3/core-js/global-this";import{AudioSource as t,_decorator as i,AudioClip as o,error as n,Node as s,director as r,log as a,Component as c,Prefab as l,instantiate as h,isValid as u,Layers as d,view as p,Widget as f,v3 as m,tween as _,Enum as g,game as y,Label as v,UIOpacity as b,Tween as C,BlockInputEvents as E,Button as S,assetManager as w,Director as A,warn as I,AsyncDelegate as O,Game as T,Asset as k,resources as M,sys as U,SpriteFrame as R,Sprite as N}from"cc";import D from"@babel/runtime-corejs3/core-js-stable/reflect/get";import j from"@babel/runtime-corejs3/core-js-stable/reflect/set";import x from"@babel/runtime-corejs3/core-js-stable/object/assign";import B from"@babel/runtime-corejs3/core-js-stable/promise";import F from"eventemitter3";import L from"@babel/runtime-corejs3/core-js-stable/instance/includes";import P from"@babel/runtime-corejs3/core-js-stable/json/stringify";import G from"@babel/runtime-corejs3/core-js-stable/map";import H from"@babel/runtime-corejs3/core-js-stable/instance/for-each";import $ from"@babel/runtime-corejs3/core-js-stable/instance/filter";import K from"@babel/runtime-corejs3/core-js-stable/array/is-array";import W from"@babel/runtime-corejs3/core-js-stable/reflect/own-keys";import V from"@babel/runtime-corejs3/core-js-stable/instance/bind";import{makeObservable as z,observable as q,autorun as Q,reaction as J}from"@shimotsuki/mobx";import X from"@babel/runtime-corejs3/core-js-stable/set-timeout";import Z from"@babel/runtime-corejs3/core-js-stable/instance/map";import Y from"@babel/runtime-corejs3/core-js-stable/array/from";import ee from"@babel/runtime-corejs3/core-js-stable/instance/every";import{SocketConnectStatus as te}from"pitayaclient";import{DEBUG as ie,WECHAT as oe,PREVIEW as ne}from"cc/env";import{SocialGameClient as se}from"sgc";import re from"crypto-es";import ae from"@babel/runtime-corejs3/core-js-stable/date/now";import ce from"@babel/runtime-corejs3/core-js-stable/set-interval";import le from"@babel/runtime-corejs3/core-js-stable/instance/values";import he from"@babel/runtime-corejs3/core-js-stable/instance/entries";class CommonAudio extends t{cat;initAudio(e){return this.cat=e,this}}const{ccclass:ue,menu:de}=i;let pe=class AudioEffect extends CommonAudio{effects=(()=>new G)();load(e,t){return new B((i,n)=>{let s,r=null;void 0!==t?(r=e,s=t):s=e;const a=(e,t)=>{if(e)return n(e);this.effects.set(s,t),this.playOneShot(t,this.volume),i(t)};r?this.cat.res.load(r,s,o,a):this.cat.res.load(s,o,a)})}release(){for(let e in this.effects)this.cat.res.release(e);this.effects.clear()}};const{ccclass:fe,menu:me}=i;class AudioMusic extends CommonAudio{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(e){this._progress=e,this.currentTime=e*this.duration}load(e,t){return new B((i,s)=>{let r,a=null;void 0!==t?(a=e,r=t):r=e;const c=(e,t)=>{if(e)return n(e),s(e);this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=t,this._url=r,i(t)};a?this.cat.res.load(a,r,o,c):this.cat.res.load(r,o,c)})}update(e){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class BaseManager{cat;constructor(e){this.cat=e}}var _e;!function(e){e.MUSIC_ON="AudioEventConstant/MUSIC_ON",e.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",e.EFFECT_ON="AudioEventConstant/EFFECT_ON",e.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",e.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",e.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(_e||(_e={}));class AudioManager extends BaseManager{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(e){super(e),this.local_store_key=this.cat.audio_local_store_key;var t=new s("UIAudioManager");r.addPersistRootNode(t);var i=new s("UIMusic");i.parent=t,this.music=i.addComponent(AudioMusic).initAudio(e);var o=new s("UIEffect");o.parent=t,this.effect=o.addComponent(pe).initAudio(e),this.load()}setMusicComplete(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.music.onComplete=e}async playMusic(e,t){let i,o;this.music.loop=!0,void 0!==t?(o=e,i=t):i=e,i.length&&await(o?this.music.load(o,i):this.music.load(i)).then(()=>{this._switch_music&&this.music.play()})}stopMusic(){0!=this.music.state&&this.music?.stop()}pauseMusic(){1==this.music.state&&this.music?.pause()}resumeMusic(){var e;L(e=[0,2]).call(e,this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(e){this.music.progress=e}get volumeMusic(){return this._volume_music}set volumeMusic(e){this._volume_music=e,this.music.volume=e}get switchMusic(){return this._switch_music}set switchMusic(e){if(a("设置背景音乐开关值",e,this._switch_music),e==this._switch_music)return;this._switch_music=e,e?this.resumeMusic():this.pauseMusic();const t=e?_e.MUSIC_ON:_e.MUSIC_OFF;this.cat.event.emit(t),this.save()}async playEffect(e,t){if(!this._switch_effect)return;let i,o;void 0!==t?(o=e,i=t):i=e,i.length&&await(o?this.effect.load(o,i):this.effect.load(i)).then(()=>{this.effect.play()})}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(e){this._volume_effect=e,this.effect.volume=e}get switchEffect(){return this._switch_effect}set switchEffect(e){if(e==this._switch_effect)return;this._switch_effect=e,e?this.effect?.play():this.effect?.stop();const t=e?_e.EFFECT_ON:_e.EFFECT_OFF;this.cat.event.emit(t),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let e=P(this.local_data);return this.cat.storage.set(this.local_store_key,e),this}load(){try{let e=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(e),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(e){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}function ge(e,t,i,o){var n,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,o);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(s<3?n(r):s>3?n(t,i,r):n(t,i))||r);return s>3&&r&&Object.defineProperty(t,i,r),r}function ye(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;class BaseComponent extends c{props={};data={};cat=(()=>e._cat)();autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),z(this,{props:q,data:q})}onAutoObserver(){}addAutorun(e){const t=K(e)?e:[e];return H(t).call(t,e=>{const t=Q(e);this.autorunDisposers.push(t)}),this}addReaction(e,t,i){const o=J(e,t,i);return this.reactionDisposers.push(o),this}addAudoListener(e){var t;return L(t=this.eventEmitter).call(t,e)||e===this.cat.event||this.eventEmitter.push(e),e}_onPreDestroy(){var e,t;if(H(e=this.autorunDisposers).call(e,e=>{e()}),H(t=this.reactionDisposers).call(t,e=>{e()}),this.autorunDisposers=[],this.reactionDisposers=[],!super._onPreDestroy)throw new Error("_onPreDestroy已弃用");super._onPreDestroy()}onDisable(){var e;this.onHide(),this.deleteAllEventByEmitter(this.cat.event),H(e=this.eventEmitter).call(e,e=>{this.deleteAllEventByEmitter(e)}),this.eventEmitter=[],this.removeListener()}deleteAllEventByEmitter(e){const t=e._events;for(const i in t){let o=t[i];K(o)||(o=[o]),H(o).call(o,t=>{t.context===this&&e.off(i,t.fn,this)})}}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(e,t,i){const o=e instanceof l?h(e):e instanceof c?e.node:e;if("number"==typeof t){const e=t,n=i;this.setOptions(n),o.insertChild(this.node,e)}else{const e=t;this.setOptions(e),o.addChild(this.node)}return this}setOptions(e){if(e)for(let t in e)switch(t){case"hook":e.hook&&(this.hook=e.hook);break;case"props":null!==e.props&&"object"==typeof e.props&&(this.props=e.props);break;case"data":null!==e.data&&"object"==typeof e.data&&(this.data=e.data)}}setUpdateData(e){if(this.data)return e&&x(this.data,this.toPlainObject(e)),this}setUpdateProps(e){if(this.props)return e&&x(this.props,this.toPlainObject(e)),this}toPlainObject(e){const t={};for(const i of W(e))if("string"==typeof i)try{t[i]=e[i]}catch{}return t}removeAndDestroy(){u(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(e){return this.node.setPosition(e),this}setScale(e){return this.node.setScale(e),this}setAngle(e){return this.node.angle=e,this}setRotation(e){return this.node.setRotation(e),this}setRotationFromEuler(e){return this.node.setRotationFromEuler(e),this}onShow(){}onHide(){}setNodeAndChildrenLayer(e){return ve(this.node,e),this}}const ve=(e,t)=>{var i,o,n;e.layer="string"==typeof t?2**d.nameToLayer(t):t,(null==(i=e)?void 0:V(n=Function.call).call(n,H(o=i.children),o))?.(e=>{ve(e,t)})};class UILayer extends BaseComponent{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=p.getVisibleSize()}async showTween(e){let{isMotion:t=!0,direction:i="center",duration:o=.1,isBounce:n=!0,bounceDuration:s=.05}=e;if(this.lastEnterDirection=i,t){const e=this.node.getComponent(f);let t,s;e&&(e.updateAlignment(),e.enabled=!1),m(1.1,1.1,1),"center"==i?(t=m(.01,.01,.01),s=m(1,1,1)):(t="left"==i?m(-this.screen.width,0,0):"right"==i?m(this.screen.width,0,0):m(0,"top"==i?this.screen.height:-this.screen.height,0),s=m(0,0,0)),await this.handle(i,o,t,s,n),e&&(e.enabled=!0)}}async hideTween(e){let{isMotion:t=!0,direction:i,duration:o=.1}=e;if(i=i||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,_(this.node).removeSelf(),t){const e=this.node.getComponent(f);let t,n;e&&(e.enabled=!1),"center"==i?(t=this.node.scale,n=m(0,0,0)):(n="left"==i?m(-this.screen.width,0,0):"right"==i?m(this.screen.width,0,0):m(0,"top"==i?this.screen.height:-this.screen.height,0),t=this.node.getPosition()),await this.handle(i,o,t,n,!1)}this.removeAndDestroy()}}async handle(e,t,i,o,n){"center"==e?this.node.setScale(i):this.node.setPosition(i),await this.deftween(t,{["center"==e?"scale":"position"]:o},n)}deftween(e,t,i,o){return new B((i,o)=>{_(this.node).to(e,t).call(()=>{i()}).start()})}}var be;const{ccclass:Ce,property:Ee}=i;var Se,we;!function(e){e[e.EFFECT=0]="EFFECT",e[e.BGM=1]="BGM"}(Se||(Se={}));class AudioSourceBaseComponent extends BaseComponent{type=(()=>Se.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,this.cat.event.on(_e.EFFECT_ON,this.onPlayEffectHandler,this).on(_e.EFFECT_OFF,this.onStopEffectHandler,this).on(_e.MUSIC_ON,this.onPlayMusicHandler,this).on(_e.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:e,volumeMusic:t}=this.cat.audio;this.audioSource.volume=this.type===Se.BGM?t:e}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=this.cat.audio;this.audioSource.playing||!(this.type===Se.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}ge([Ee({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(Se)}),ye("design:type",Number)],AudioSourceBaseComponent.prototype,"type",void 0),ge([Ee({tooltip:"音源",type:o}),ye("design:type","function"==typeof(be=void 0!==o&&o)?be:Object)],AudioSourceBaseComponent.prototype,"clip",void 0),ge([Ee({tooltip:"循环"}),ye("design:type",Boolean)],AudioSourceBaseComponent.prototype,"loop",void 0),ge([Ee({tooltip:"音量"}),ye("design:type",Number)],AudioSourceBaseComponent.prototype,"volume",void 0),ge([Ee({tooltip:"是否启用自动播放"}),ye("design:type",Boolean)],AudioSourceBaseComponent.prototype,"playOnAwake",void 0);const{ccclass:Ae,property:Ie}=i;class AudioSourceUILayer extends UILayer{type=(()=>Se.EFFECT)();clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=(()=>new t)();onEnable(){super.onEnable(),this.cat.event.on(_e.EFFECT_ON,this.onPlayEffectHandler,this).on(_e.EFFECT_OFF,this.onStopEffectHandler,this).on(_e.MUSIC_ON,this.onPlayMusicHandler,this).on(_e.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:e,volumeMusic:t}=this.cat.audio;this.audioSource.volume=this.type===Se.BGM?t:e}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:e,switchMusic:t}=this.cat.audio;this.audioSource.playing||!(this.type===Se.BGM?t:e)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}var Oe,Te,ke,Me;ge([Ie({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(Se)}),ye("design:type",Number)],AudioSourceUILayer.prototype,"type",void 0),ge([Ie({tooltip:"音源",type:o}),ye("design:type","function"==typeof(we=void 0!==o&&o)?we:Object)],AudioSourceUILayer.prototype,"clip",void 0),ge([Ie({tooltip:"循环"}),ye("design:type",Boolean)],AudioSourceUILayer.prototype,"loop",void 0),ge([Ie({tooltip:"音量"}),ye("design:type",Number)],AudioSourceUILayer.prototype,"volume",void 0),ge([Ie({tooltip:"是否启用自动播放"}),ye("design:type",Boolean)],AudioSourceUILayer.prototype,"playOnAwake",void 0);const{ccclass:Ue,property:Re,menu:Ne}=i;var De;!function(e){e[e.FIXED=0]="FIXED",e[e.SLIDE=1]="SLIDE"}(De||(De={}));let je=class CoreToast extends BaseComponent{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 B(async(e,t)=>{const{title:i,type:o,fixed_time:n}=this.props;o==De.FIXED?(this.fixed_node.active=!0,this.fixed_label.string=`${i}`,this.scheduleOnce(()=>{this.node.destroy(),e()},n)):(this.slide_node.active=!0,this.slide_label.string=`${i}`,this.playAnim(this.node).then(()=>{e()}))})}playAnim(e){return new B((t,i)=>{const o=this.node.getComponent(b),n=_(o).delay(1.2).to(.5,{opacity:0}).call(()=>{C.stopAllByTarget(e),this.node.destroy(),t()});_(e).by(.5,{position:m(0,400,0)}).call(()=>{n.start()}).start()})}onDestroy(){C.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var xe,Be;ge([Re({type:s,tooltip:"固定节点"}),ye("design:type","function"==typeof(Oe=void 0!==s&&s)?Oe:Object)],je.prototype,"fixed_node",void 0),ge([Re({type:s,tooltip:"滑动节点"}),ye("design:type","function"==typeof(Te=void 0!==s&&s)?Te:Object)],je.prototype,"slide_node",void 0),ge([Re({type:v,tooltip:"固定标签节点"}),ye("design:type","function"==typeof(ke=void 0!==v&&v)?ke:Object)],je.prototype,"fixed_label",void 0),ge([Re({type:v,tooltip:"滑动标签节点"}),ye("design:type","function"==typeof(Me=void 0!==v&&v)?Me:Object)],je.prototype,"slide_label",void 0),je=ge([Ue("CoreToast"),Ne("CATCORE/CoreToast")],je),function(e){e.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",e.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",e.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",e.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",e.ONLINE="GlobalEventConstant/ONLINE",e.OFFLINE="GlobalEventConstant/OFFLINE",e.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",e.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(xe||(xe={}));const{ccclass:Fe,property:Le,menu:Pe}=i;let Ge=class CoreBlackMask extends BaseComponent{tween};var He,$e;ge([Le({type:s,tooltip:"动画节点"}),ye("design:type","function"==typeof(Be=void 0!==s&&s)?Be:Object)],Ge.prototype,"tween",void 0),Ge=ge([Fe("CoreBlackMask"),Pe("CATCORE/CoreBlackMask")],Ge);const{ccclass:Ke,property:We,menu:Ve}=i;let ze=class CoreUIContainer extends UILayer{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Ge)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){this.cat.event.on(xe.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const e=this.brother[this.brother.length-1];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const e=this.brother[this.brother.length-2];e&&this.scene_mask.node.setSiblingIndex(e.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(e){return u(this)&&this.scene_mask&&this.scene_mask.tween.addChild(e),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(e){return this.gui=e,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(e){this.scene_mask.node.active=e}};ge([We({type:s}),ye("design:type","function"==typeof(He=void 0!==s&&s)?He:Object)],ze.prototype,"scene_mask_node",void 0),ge([We({type:s}),ye("design:type","function"==typeof($e=void 0!==s&&s)?$e:Object)],ze.prototype,"ui_container",void 0),ze=ge([Ke("CoreUIContainer"),Ve("CATCORE/CoreUIContainer")],ze);class RootUILayer extends UILayer{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){this.cat.event.emit(xe.ROOT_MASK_UPDATE)}}var qe,Qe;const{ccclass:Je,property:Xe,menu:Ze}=i;let Ye=class CoreShowLoading extends RootUILayer{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(E).enabled=!!this.props?.mask}])}update(e){this.loading_rotate+=220*e,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};var et,tt,it,ot;ge([Xe({type:v,tooltip:"标题"}),ye("design:type","function"==typeof(qe=void 0!==v&&v)?qe:Object)],Ye.prototype,"title",void 0),ge([Xe({type:s,tooltip:"动画"}),ye("design:type","function"==typeof(Qe=void 0!==s&&s)?Qe:Object)],Ye.prototype,"loadingTween",void 0),Ye=ge([Je("CoreShowLoading"),Ze("CATCORE/CoreShowLoading")],Ye),function(e){e.RECONNECTED="重连成功",e.RECONNECTING="正在重连",e.MAX_RECONNECT="重连次数超出限制,请检查网络",e.RECONNECTED_ERROR="重连失败,请检查网络",e.CONNECT_PARAM_ERROR="游戏参数错误,请重新加载",e.KICK="账号已下线",e.OFFLINE="网络已断开",e.ONLINE="网络已连接",e.GAME_ERROR="连接游戏服错误"}(et||(et={}));const{ccclass:nt,property:st,menu:rt}=i;let at=class CoreReconnection extends RootUILayer{common_prompt_text;btn_confirm;btn_close;is_close=!1;props={content:null};initUI(){}onLoad(){this.btn_confirm.node.on(S.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(S.EventType.CLICK,this.onConfirmHandler,this),this.addAutorun([()=>{this.common_prompt_text.string=this.props.content??""}])}onDestroy(){this.unscheduleAllCallbacks()}updateProps(e){this.updatePromptText(e,e==et.RECONNECTING)}updatePromptText(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.unscheduleAllCallbacks(),this.props.content=e,a("更新提示文案:",e),t){let t=0;const i=()=>{t=(t+1)%4,this.common_prompt_text.string=e+["","·","··","···"][t]};this.schedule(i,.5)}}onConfirmHandler(){this.is_close=!0,this.cat.gui.hideReconnect()}};var ct,lt,ht;ge([st({type:v,tooltip:"通用提示文本"}),ye("design:type","function"==typeof(tt=void 0!==v&&v)?tt:Object)],at.prototype,"common_prompt_text",void 0),ge([st({type:S,tooltip:"确定按钮"}),ye("design:type","function"==typeof(it=void 0!==S&&S)?it:Object)],at.prototype,"btn_confirm",void 0),ge([st({type:S,tooltip:"关闭按钮"}),ye("design:type","function"==typeof(ot=void 0!==S&&S)?ot:Object)],at.prototype,"btn_close",void 0),at=ge([nt("CoreReconnection"),rt("CATCORE/CoreReconnection")],at);const{ccclass:ut,property:dt,menu:pt}=i;let ft=class CoreNotice extends RootUILayer{text;btn_confirm;btn_close;onLoad(){this.btn_confirm.node.on(S.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),this.cat.gui.hideNotice()}updateProps(e){this.text.string=`${e.text}`}};ge([dt({type:v,tooltip:"提示文本"}),ye("design:type","function"==typeof(ct=void 0!==v&&v)?ct:Object)],ft.prototype,"text",void 0),ge([dt({type:S,tooltip:"确定按钮"}),ye("design:type","function"==typeof(lt=void 0!==S&&S)?lt:Object)],ft.prototype,"btn_confirm",void 0),ge([dt({type:S,tooltip:"关闭按钮"}),ye("design:type","function"==typeof(ht=void 0!==S&&S)?ht:Object)],ft.prototype,"btn_close",void 0),ft=ge([ut("CoreNotice"),pt("CATCORE/CoreNotice")],ft);class SceneLayer extends BaseComponent{isReload}var mt,_t,gt,yt,vt,bt,Ct,Et;const{ccclass:St,property:wt,menu:At}=i;var It;!function(e){e[e.UI=0]="UI",e[e.LOADING=1]="LOADING",e[e.TOAST=2]="TOAST",e[e.RECONNECTTION=3]="RECONNECTTION",e[e.NOTICE=4]="NOTICE"}(It||(It={}));let Ot=class Gui extends BaseComponent{reconnection_ui_prefab;toast_ui_prefab;loading_ui_prefab;notice_ui_prefab;ui_prefab;root_ui;root_toast;root_mask;ui_container_component;reconnection_ui_component;notice_ui_component;loading_ui_component;toast_ui_component;currentScene;currentSceneUUID;onEventListener(){this.cat.event.on(xe.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(e){this.cat=e;const t=r.getScene();return a("init scene"),t&&this.changeScene(t),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(e){this.toastQueue.push(e),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const e=this.toastQueue.shift(),t=()=>{h(this.toast_ui_prefab).getComponent(je).addToParent(this.root_toast,{props:e}),this.scheduleOnce(()=>{this.processQueueWithInterval()},this.minInterval)};0===this.root_toast.children.length?t():this.scheduleOnce(t,this.minInterval)}hideToast(){var e;this.root_toast&&H(e=this.root_toast.children).call(e,e=>{e.getComponent(je)?.removeAndDestroy()});return this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading(){let{title:e="",mask:t=!0,black:i=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(a("showLoading",e),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:e,mask:t,black:i}});else{const o=h(this.loading_ui_prefab);this.loading_ui_component=o.getComponent(Ye).addToParent(this.root_ui,{props:{title:e,mask:t,black:i}})}return this}hideLoading(){return this.loading_ui_component?.removeAndDestroy(),this.loading_ui_component=null,this}showReconnect(e){if(this.reconnection_ui_component)this.reconnection_ui_component.setUpdateProps({content:e});else{const t=h(this.reconnection_ui_prefab);this.reconnection_ui_component=t.getComponent(at).addToParent(this.root_ui,{props:{content:e}})}return this}hideReconnect(){return this.reconnection_ui_component?.removeAndDestroy(),this.reconnection_ui_component=null,this}showNotice(e){const t=h(this.notice_ui_prefab);return this.notice_ui_component=t.getComponent(ft).addToParent(this.root_ui,{props:e}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}findBundleBySceneUUID(e){const t=w.bundles._map;for(const i in t){const o=t[i],n=o.config?.scenes?._map;if(n)for(const t in n){const i=n[t];if(i?.uuid===e)return o}}return null}findSceneByUUIDFromBundle(e,t){}loadScene(e,t,i){a("[加载场景名][参数][重新加载]",e,t,i);let o={},s=i??!0;if("boolean"==typeof t?s=t:o=t??{},r.once(A.EVENT_BEFORE_SCENE_LAUNCH,e=>{a("Director.EVENT_BEFORE_SCENE_LAUNCH",e),this.changeScene(e,o,s)}),"string"==typeof e){const t=this.findBundleBySceneUUID(e);if(t)if("main"!==t.name)t.loadScene(this.currentScene,(e,t)=>{e?n("loadScene err",e):r.runScene(t)});else{const i=t.getAssetInfo(e);i?.url&&r.loadScene(i?.url)}else r.loadScene(e)}else r.runScene(e);return this}resetScene(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e=e||this.currentScene,this.loadScene(e)}cleanScene(){this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast()}changeScene(e,t,i){this.currentScene=e.name,this.currentSceneUUID=e.uuid,this.createUILayer(e);const o=e.getComponentInChildren(SceneLayer);a("给场景传递属性值=======",o),o&&(o.isReload=i??!0),o?.setOptions(t)}createUILayer(e){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const t=h(this.ui_prefab);this.ui_container_component=t.getComponent(ze),this.ui_container_component?.setGui(this).addToParent(e,this.node.getSiblingIndex())}reloadScene(){a("重新加载当前场景"),this.loadScene(this.currentSceneUUID,!0)}async closeUI(e,t){const{component:i}=this.findUIBaseLayer(e,!1);i&&(i.setOptions({...t?.hook??{},...t?.props??{}}),await i.hideTween(t||{}),this.ui_container_component?.subMask())}async openUI(e,t){const{rootNode:i,component:o}=this.findUIBaseLayer(e,!0);i.getComponent(UILayer),o?.setOptions(t),i&&this.ui_container_component?.addNodeToTween(i).addMask(),o&&await o.showTween(t||{}),this.ui_container_component?.ui_container&&o?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(e,t){let i,o=null;if(e instanceof s){var r;i=e;const t=$(r=e.components).call(r,e=>e instanceof UILayer);if(!t.length)return n(`${e.name}节点未找到继承自BaseLayer的组件`),{rootNode:i,component:o};1==t.length?o=t[0]:I(`${e.name}节点存在多个继承自BaseLayer的组件`)}else if(i=e.node,o=e,t){for(;i.parent;)i=i.parent;o.root=i}else i=e.root;return{rootNode:i,component:o}}onRootUpdate(){const e=this.root_ui.children.findLastIndex(e=>e.active&&e!=this.root_mask);if(this.root_mask.active=-1!=e,e>-1){const t=this.root_ui.children[e].getSiblingIndex()-1;this.root_mask.setSiblingIndex(t<0?0:t)}this.cat.event.emit(xe.ROOT_MASK_CHANGE)}};var Tt;ge([wt({type:l,tooltip:"断线重连UI预制体"}),ye("design:type","function"==typeof(mt=void 0!==l&&l)?mt:Object)],Ot.prototype,"reconnection_ui_prefab",void 0),ge([wt({type:l,tooltip:"提示UI预制体"}),ye("design:type","function"==typeof(_t=void 0!==l&&l)?_t:Object)],Ot.prototype,"toast_ui_prefab",void 0),ge([wt({type:l,tooltip:"加载UI预制体"}),ye("design:type","function"==typeof(gt=void 0!==l&&l)?gt:Object)],Ot.prototype,"loading_ui_prefab",void 0),ge([wt({type:l,tooltip:"公告UI预制体"}),ye("design:type","function"==typeof(yt=void 0!==l&&l)?yt:Object)],Ot.prototype,"notice_ui_prefab",void 0),ge([wt({type:l,tooltip:"UI层预制体"}),ye("design:type","function"==typeof(vt=void 0!==l&&l)?vt:Object)],Ot.prototype,"ui_prefab",void 0),ge([wt({type:s,tooltip:"root-UI层"}),ye("design:type","function"==typeof(bt=void 0!==s&&s)?bt:Object)],Ot.prototype,"root_ui",void 0),ge([wt({type:s,tooltip:"root-组件层"}),ye("design:type","function"==typeof(Ct=void 0!==s&&s)?Ct:Object)],Ot.prototype,"root_toast",void 0),ge([wt({type:s,tooltip:"root-mask"}),ye("design:type","function"==typeof(Et=void 0!==s&&s)?Et:Object)],Ot.prototype,"root_mask",void 0),Ot=ge([St("Gui"),At("CATCORE/Gui")],Ot),function(e){e.Root="prefabs/root",e.Toast="prefabs/toast",e.BlackMask="prefabs/black-mask",e.Loading="prefabs/loading",e.Notice="prefabs/notice",e.Reconnection="prefabs/reconnection"}(Tt||(Tt={}));class GuiManager extends BaseManager{gui;#e="core";getGuiPrefabByType=(e,t)=>new B((i,o)=>{a(e,`${t}`),this.cat.res.load(e,t,(e,t)=>{e?o(e):i(t)})});async init(){this.cat.gui_bundle_name&&(this.#e=this.cat.gui_bundle_name);const e=await this.getGuiPrefabByType(this.#e,Tt.Root),t=h(e);return this.gui=t.getComponent(Ot).init(this.cat),r.addPersistRootNode(t),this}}class WrapperSocialGameClient extends se{showRequestErrInfo=!1;logBlackList=[];ignore=e=>{var t;return L(t=this.logBlackList).call(t,e)};constructor(e,t,i,o){super(t,i,o,e),this.showRequestErrInfo=o?.showRequestErrInfo??!1}destroy(){this.disconnect(!0),e._cat.socialGameClient.unregister(this)}async GameRequest(t,i,o){let{forwardReq:s=!1,forwardResp:r=!1}=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return new B((c,l)=>{super.GameRequest(t,i,o,{forwardReq:s,forwardResp:r}).then(e=>{ie&&a(`%c ws服务端消息 %c [Response][${new Date}] %c ${t} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",i),c(e)},t=>{n(t),this.showRequestErrInfo&&t?.msg&&e._cat.gui.showToast({title:t.msg}),l(t)})})}subscribe(t,i,o){return super.subscribe(t,i,i=>{ie&&!this.ignore(t)&&a(`%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",i),e._cat.event.emit(t,i),o?.(i)}),this}}class SocialGameClientManager extends BaseManager{managedClients=(()=>new G)();isGlobalOnline=!0;isInBackground=!1;reconnecting=!1;onEventHideDelegate=(()=>new O)();onEventShowDelegate=(()=>new O)();onEventReloadSceneDelegate=(()=>new O)();reconnectTimer=null;scheduleReconnect(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2e3;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectTimer=X(()=>{this.reconnectTimer=null,this.triggerReconnectAll()},e)}get activeClients(){var e,t;return $(e=Z(t=Y(this.managedClients)).call(t,e=>{let[t,i]=e;return i})).call(e,e=>e.socket)}constructor(e){super(e),this.initGlobalListeners()}createWebSocket(e,t,i,o){if(this.managedClients.has(e)){this.managedClients.get(e).destroy(),a(`清理旧的 ${e} 客户端`)}const n=new WrapperSocialGameClient(e,i,o,x({reconnectMaxAttempts:1/0},{...t,isAutoConnect:!1,isArrayBuffer:oe}));return this.register(n),n}register(e){e.on("reconnected",this.handleSingleReconnect),e.on("close",this.handleSingleClose),e.on("kick",this.handleSingleKick),this.managedClients.set(e.name,e)}unregister(e){e.off("reconnected",this.handleSingleReconnect),e.off("close",this.handleSingleClose),e.off("kick",this.handleSingleKick),this.managedClients.delete(e.name)}initGlobalListeners(){console.log("设置监听"),this.cat.event.on(xe.ONLINE,()=>this.handleGlobalStateChange("online"),this).on(xe.OFFLINE,()=>this.handleGlobalStateChange("offline"),this),oe?(wx.onShow(e=>{this.handleGlobalStateChange("show",e)}),wx.onHide(e=>{this.handleGlobalStateChange("hide",e)})):(y.on(T.EVENT_SHOW,()=>this.handleGlobalStateChange("show")),y.on(T.EVENT_HIDE,()=>this.handleGlobalStateChange("hide")))}async handleGlobalStateChange(e,t){switch(e){case"online":this.cat.gui.hideLoading().showToast({title:et.ONLINE}),this.isGlobalOnline=!0,this.triggerReconnectAll();break;case"offline":this.isGlobalOnline=!1,this.disconnectAll(!0),this.cat.gui.showLoading({title:et.OFFLINE});break;case"show":this.isInBackground=!1,console.log("监听前台 show"),await this.triggerReconnectAll(),await this.onEventShowDelegate.dispatch(t);break;case"hide":console.log("监听前台 hide"),await this.onEventHideDelegate.dispatch(t),this.isInBackground=!0,this.disconnectAll(!0)}}async triggerReconnectAll(){if(a("触发所有客户端重连[正在重连][在线][后台][ws数量]",this.reconnecting,this.isGlobalOnline,this.isInBackground,this.managedClients.size),this.reconnecting||!this.isGlobalOnline||this.isInBackground||0===this.managedClients.size)return this.onEventReloadSceneDelegate.dispatch();this.reconnecting=!0,this.cat.gui.showLoading({title:"正在重连"});try{var e,t;await B.allSettled(Z(e=this.activeClients).call(e,async e=>{try{await e.reconnectPromise()}catch(t){n(`${e.name}服重连失败`,t)}}));const i=$(t=this.activeClients).call(t,e=>e.socketConnectStatus!==te.CONNECTED);i.length>0?(Z(i).call(i,e=>{console.error("部分WS重连失败:",e)}),a("2s后重连所有客户端"),this.reconnecting=!1,this.scheduleReconnect()):this.reconnecting=!1}catch(e){throw this.reconnecting=!1,e}}disconnectAll(e){var t;H(t=this.managedClients).call(t,t=>{a("断开连接",t.name,e,t.socket),t.disconnect(e)})}handleSingleClose=()=>{this.reconnecting||(a("3s后重连所有客户端"),this.scheduleReconnect(3e3))};handleSingleReconnect=async()=>{var e,t;ee(e=this.activeClients).call(e,e=>e.socketConnectStatus===te.CONNECTED)&&(a("单个WS重连成功回调===",this.managedClients),await B.allSettled(Z(t=this.activeClients).call(t,async e=>{try{await e.connectRequest()}catch(t){n(`${e.name}服登录错误`,t),this.cat.gui.showToast({title:`登录${e.name}服错误`})}})),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),await this.onEventReloadSceneDelegate.dispatch(),this.cat.gui.hideLoading(),r.getScene()?.getComponentInChildren(SceneLayer)?.isReload&&this.cat.gui.reloadScene())};handleSingleKick=()=>{this.cat.gui.showReconnect(et.KICK)}}class ResLoader{get=(()=>function(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"resources";return w.getBundle(i).get(e,t)})();isAssetType=e=>"function"==typeof e&&e.prototype instanceof k;async load(){let e=null,t=null,i=null;for(var o=arguments.length,n=new Array(o),s=0;s<o;s++)n[s]=arguments[s];"string"==typeof n[0]&&"string"==typeof n[1]&&(e=n.shift());let r=n.shift();this.isAssetType(n[0])&&(t=n.shift()),2==n.length&&(i=n.shift());const a=n.shift();let c=M;if(e&&"resources"!=e){w.bundles.has(e)||await this.loadBundle(e);let t=w.bundles.get(e);t&&(c=t)}i&&a?c.load(r,t,i,a):a?c.load(r,t,a):c.load(r,t)}async loadDir(){let e=null,t=null,i=null,o=null;for(var n=arguments.length,s=new Array(n),r=0;r<n;r++)s[r]=arguments[r];"string"==typeof s[0]&&"string"==typeof s[1]&&(e=s.shift());let a=s.shift();this.isAssetType(s[0])&&(t=s.shift()),2==s.length&&(i=s.shift()),o=s.shift();let c=M;if(e&&"resources"!=e){w.bundles.has(e)||await this.loadBundle(e);let t=w.bundles.get(e);t&&(c=t)}i&&o?c.loadDir(a,t,i,o):o?c.loadDir(a,t,o):c.loadDir(a,t)}loadRemote(e){for(var t,i=null,o=arguments.length,n=new Array(o>1?o-1:0),s=1;s<o;s++)n[s-1]=arguments[s];2==n.length&&(i=n.shift()),t=n.shift(),w.loadRemote(e,{ext:".png",...i},t)}loadBundle=(e,t)=>new B((i,o)=>{const n=(e,t)=>{if(e)return o(e);i(t)};t?w.loadBundle(e,{version:t},n):w.loadBundle(e,n)});releasePrefabtDepsRecursively=e=>{var t=w.assets.get(e);if(w.releaseAsset(t),t instanceof l){var i=w.dependUtil.getDepsRecursively(e);H(i).call(i,e=>{w.assets.get(e).decRef()})}};release=(()=>{var e=this;return function(t){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"resources";var o=w.getBundle(i);if(o){var n=o.get(t);n&&e.releasePrefabtDepsRecursively(n._uuid)}}})();releaseDir=(()=>{var e=this;return function(t){var i,o;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"resources";var s=w.getBundle(n),r=s?.getDirWithPath(t);(null==(i=r)?void 0:V(o=Function.call).call(o,Z(i),i))?.(t=>{e.releasePrefabtDepsRecursively(t.uuid)}),!t&&"resources"!=n&&s&&w.removeBundle(s)}})();dump=()=>{var e;H(e=w.assets).call(e,(e,t)=>{a(w.assets.get(t))}),a(`当前资源总数:${w.assets.count}`)};loadAssetsWithProgress(e,t){return new B((i,o)=>{const n=e.getDirWithPath(""),s=n.length;let r=0;if(0===s)return t(1),void i();H(n).call(n,n=>{e.load(n.path,e=>{e?o(e):(r++,t(r/s),r===s&&i())})})})}}class BaseStore{rootStore;constructor(e){this.rootStore=e}}class CoreStore extends BaseManager{}let kt=null;const Mt={stringify:e=>{const t={ct:e.ciphertext.toString(re.enc.Base64)};return e.iv&&(t.iv=e.iv.toString()),e.salt&&(t.s=e.salt.toString()),P(t)},parse:e=>{const t=JSON.parse(e),i=re.lib.CipherParams.create({ciphertext:re.enc.Base64.parse(t.ct)});return t.iv&&(i.iv=re.enc.Hex.parse(t.iv)),t.s&&(i.salt=re.enc.Hex.parse(t.s)),i}};var Ut,Rt,Nt,Dt,jt,xt,Bt,Ft,Lt,Pt=Object.freeze({__proto__:null,JsonFormatter:Mt,aesDecrypt:(e,t,i)=>re.AES.decrypt(e,t,{iv:kt,format:Mt}).toString(re.enc.Utf8),aesEncrypt:(e,t,i)=>re.AES.encrypt(e,t,{iv:kt,format:Mt}).toString(),initCrypto:(e,t)=>{kt=re.enc.Hex.parse(t)},md5:e=>re.MD5(e).toString()});class CoreUtil extends BaseManager{encryptUtil=(()=>Pt)()}class StorageManager extends BaseManager{_key=null;_iv=null;_id="";init(e,t){this.cat.util.encryptUtil.initCrypto(e,t),this._key=this.cat.util.encryptUtil.md5(e),this._iv=this.cat.util.encryptUtil.md5(t)}setUser(e){this._id=e}set(e,t){if(null!=(e=`${e}_${this._id}`)){if(ne||(e=this.cat.util.encryptUtil.md5(e)),null==t)return console.warn("存储的值为空,则直接移除该存储"),void this.remove(e);if("function"!=typeof t){if("object"==typeof t)try{t=P(t)}catch(e){return void console.error(`解析失败,str = ${t}`)}else"number"==typeof t&&(t+="");ne||null==this._key||null==this._iv||(t=this.cat.util.encryptUtil.aesEncrypt(`${t}`,this._key,this._iv)),U.localStorage.setItem(e,t)}else console.error("储存的值不能为方法")}else console.error("存储的key不能为空")}get(e,t){if(null==e)return console.error("存储的key不能为空"),null;e=`${e}_${this._id}`,ne||(e=this.cat.util.encryptUtil.md5(e));let i=U.localStorage.getItem(e);return null==i||""===i||ne||null==this._key||null==this._iv||(i=this.cat.util.encryptUtil.aesDecrypt(i,this._key,this._iv)),null===i?t:i}getNumber(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;var i=this.get(e);return Number(i)||t}getBoolean(e){var t=this.get(e);return Boolean(t)||!1}getJson(e,t){var i=this.get(e);return i&&JSON.parse(i)||t}remove(e){null!=e?(e=`${e}_${this._id}`,ne||(e=this.cat.util.encryptUtil.md5(e)),U.localStorage.removeItem(e)):console.error("存储的key不能为空")}clear(){U.localStorage.clear()}}class Manager{static#t=null;#i=!1;static get instance(){return this.#t??(this.#t=new Manager)}onAppInitDelegate=(()=>new O)();onPlugInInitDelegate=(()=>new O)();#o=null;get audio(){return this.#o}#n=null;get event(){return this.#n}#s=null;get gui(){return this.#s}#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}#u="";get gui_bundle_name(){return this.#u}#d="";get audio_local_store_key(){return this.#d}#p="";get default_audio_effect(){return this.#p}setConfig=(()=>{var e=this;return function(){let{default_audio_effect:t="",gui_bundleName:i="resources",audio_local_store_key:o="game_audio"}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.#i)throw new Error("[CAT] 已初始化,无法修改配置");return e.#u=i,e.#d=o,e.#p=t,e}})();async boot(){if(this.#i)throw new Error("[CAT] 已初始化");try{this.#h=new CoreStore(this),this.#a=new ResLoader,this.#c=new CoreUtil(this),this.#r=new StorageManager(this),this.#n=new F,this.#o=new AudioManager(this),this.#l=new SocialGameClientManager(this),this.#s=(await new GuiManager(this).init()).gui,this.#i=!0}catch(e){throw console.error("[CAT] 初始化失败:",e),e}}merge(e,t){if(!this.#i)throw new Error("[CAT] 未初始化");if("string"!=typeof e)throw new Error("merge方法第一个参数应该为string类型");return D(this,e)||j(this,e,t),x(D(this,e),t),this}appendPlugInInitDelegate(e){return this.#i?B.resolve().then(e).catch(e=>{console.error("[CAT] appendPlugInInitDelegate 回调执行失败:",e)}):this.onPlugInInitDelegate.add(e),this}}const{ccclass:Gt,property:Ht,menu:$t}=i;let Kt=class CoreUIModal extends UILayer{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(S.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(S.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(S.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content&&(this.props.content instanceof R?this.prompt_content_spriteFrame.spriteFrame=this.props.content:"string"==typeof this.props.content?this.prompt_content_str.string=this.props.content:console.error("未知类型的【UIModal】内容"))},()=>{null===this.props?.style?.confirm?this.btn_confirm.node.active=!1:(this.btn_confirm.node.active=!0,this.btn_confirm.getComponent(N).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(N).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),this.cat.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var Wt;ge([Ht({type:R,tooltip:"默认标题"}),ye("design:type","function"==typeof(Ut=void 0!==R&&R)?Ut:Object)],Kt.prototype,"default_title",void 0),ge([Ht({type:N,tooltip:"标题节点"}),ye("design:type","function"==typeof(Rt=void 0!==N&&N)?Rt:Object)],Kt.prototype,"title",void 0),ge([Ht({type:v,tooltip:"字符串内容按钮"}),ye("design:type","function"==typeof(Nt=void 0!==v&&v)?Nt:Object)],Kt.prototype,"prompt_content_str",void 0),ge([Ht({type:N,tooltip:"图片精灵内容按钮"}),ye("design:type","function"==typeof(Dt=void 0!==N&&N)?Dt:Object)],Kt.prototype,"prompt_content_spriteFrame",void 0),ge([Ht({type:S,tooltip:"确认按钮"}),ye("design:type","function"==typeof(jt=void 0!==S&&S)?jt:Object)],Kt.prototype,"btn_confirm",void 0),ge([Ht({type:R,tooltip:"确认按钮精灵图"}),ye("design:type","function"==typeof(xt=void 0!==R&&R)?xt:Object)],Kt.prototype,"confirm_spriteFrame",void 0),ge([Ht({type:S,tooltip:"取消按钮"}),ye("design:type","function"==typeof(Bt=void 0!==S&&S)?Bt:Object)],Kt.prototype,"btn_cancel",void 0),ge([Ht({type:R,tooltip:"取消按钮精灵图"}),ye("design:type","function"==typeof(Ft=void 0!==R&&R)?Ft:Object)],Kt.prototype,"cancel_spriteFrame",void 0),ge([Ht({type:S,tooltip:"关闭按钮"}),ye("design:type","function"==typeof(Lt=void 0!==S&&S)?Lt:Object)],Kt.prototype,"btn_close",void 0),Kt=ge([Gt("CoreUIModal"),$t("CATCORE/CoreUIModal")],Kt),function(e){e[e.Delay=0]="Delay",e[e.Interval=1]="Interval"}(Wt||(Wt={}));class TimerEntry{tag;type;callback;remainingTime;executionTime=0;initialTime;constructor(e,t,i,o){this.tag=e,this.type=t,this.remainingTime=i,this.initialTime=i,this.callback=o}}class TimerManager extends BaseManager{timers=(()=>new G)();lastUpdateTime=(()=>ae())();constructor(e){var t;super(e),e.event.on(xe.EVENT_HIDE,this.onHandleAppBackground,this),e.event.on(xe.EVENT_SHOW,this.onHandleAppForeground,this),ce(V(t=this.update).call(t,this),1e3)}onHandleAppBackground(){this.lastUpdateTime=ae()}onHandleAppForeground(){const e=ae(),t=e-this.lastUpdateTime;a("elapsedTime",t);for(const e of le(i=this.timers).call(i)){var i;e.remainingTime>0&&(e.remainingTime-=t,e.executionTime+=t)}this.lastUpdateTime=e}registerInterval(e,t,i){if(this.has(e))return n(`${e}定时器已存在,请勿重复注册`);const o=new TimerEntry(e,Wt.Interval,t,i);this.timers.set(e,o)}registerDelay(e,t,i){if(this.has(e))return n(`${e}延时器已存在,请勿重复注册`);const o=new TimerEntry(e,Wt.Delay,t,i);this.timers.set(e,o)}unregister(e){this.has(e)&&this.timers.delete(e)}has(e){return this.timers.has(e)}update(){const e=[];for(const[i,o]of he(t=this.timers).call(t)){var t;o.remainingTime-=1e3,o.remainingTime<=0&&(o.type===Wt.Interval&&(o.executionTime+=o.initialTime),o.callback(o.executionTime),o.type===Wt.Interval?o.remainingTime=o.initialTime:e.push(i))}for(const t of e)this.timers.delete(t)}}const Vt=(t,i)=>(o,n,s)=>{let r=s.value;return s.value=function(){const o=t??e._cat.default_audio_effect;o?e._cat.audio.playEffect(o):console.warn("请添加音效路径参数"),i&&i();for(var n=arguments.length,s=new Array(n),a=0;a<n;a++)s[a]=arguments[a];r.apply(this,s)},s},zt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1?arguments[1]:void 0;return function(i,o,n){let s=n.value,r=!1;return n.value=function(){if(r)t&&t();else{r=!0,X(()=>{r=!1},1e3*e);for(var i=arguments.length,o=new Array(i),n=0;n<i;n++)o[n]=arguments[n];s.apply(this,o)}},n}},qt=e._cat??=Manager.instance;y.onPostProjectInitDelegate.add(async()=>{console.time("[Init App]");try{await qt.boot(),await qt.onAppInitDelegate.dispatch(),await qt.onPlugInInitDelegate.dispatch()}catch(e){throw n(`[Init App] 初始化失败: ${e instanceof Error?e.message:String(e)}`),e}finally{console.timeEnd("[Init App]")}});export{Vt as AudioEffect,_e as AudioEventConstant,AudioManager,AudioSourceBaseComponent,AudioSourceUILayer,Se as AudioTypeEnum,BaseComponent,BaseManager,Tt as BasePrefab,BaseStore,zt as ButtonLock,Ge as CoreBlackMask,ft as CoreNotice,at as CoreReconnection,Ye as CoreShowLoading,CoreStore,je as CoreToast,ze as CoreUIContainer,Kt as CoreUIModal,CoreUtil,xe as GlobalEventConstant,Ot as Gui,GuiManager,It as LayerType,Manager,et as ReconnectPrompt,RootUILayer,SceneLayer,TimerManager,De as ToastType,UILayer,WrapperSocialGameClient,qt as cat};
|
package/package.json
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@shimotsuki/core",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"main": "dist/shimotsuki_core.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"repository": "https://gitee.com/shimotsuki_yami/cat-core",
|
|
9
|
-
"author": "shimotsuki <youcunzhou2383@shengtian.com>",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build:dev": "cross-env BUILD=development rollup -c",
|
|
12
|
-
"build:prod": "cross-env BUILD=production rollup -c"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@babel/core": "^7.26.8",
|
|
16
|
-
"@babel/plugin-transform-runtime": "^7.27.4",
|
|
17
|
-
"@babel/preset-env": "^7.26.8",
|
|
18
|
-
"@babel/runtime": "^7.27.6",
|
|
19
|
-
"@rollup/plugin-babel": "^6.0.4",
|
|
20
|
-
"@rollup/plugin-typescript": "^12.1.2",
|
|
21
|
-
"api": "git+ssh://git@gitlab.stnts.com:sparklab/gameapi.git",
|
|
22
|
-
"cross-env": "^10.0.0",
|
|
23
|
-
"
|
|
24
|
-
"rollup-plugin-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@rollup/plugin-
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"rollup
|
|
41
|
-
"rollup-plugin-
|
|
42
|
-
"rollup-plugin-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"./temp/
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@shimotsuki/core",
|
|
3
|
+
"version": "3.0.23",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/shimotsuki_core.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"repository": "https://gitee.com/shimotsuki_yami/cat-core",
|
|
9
|
+
"author": "shimotsuki <youcunzhou2383@shengtian.com>",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build:dev": "cross-env BUILD=development rollup -c",
|
|
12
|
+
"build:prod": "cross-env BUILD=production rollup -c"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@babel/core": "^7.26.8",
|
|
16
|
+
"@babel/plugin-transform-runtime": "^7.27.4",
|
|
17
|
+
"@babel/preset-env": "^7.26.8",
|
|
18
|
+
"@babel/runtime": "^7.27.6",
|
|
19
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
20
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
21
|
+
"api": "git+ssh://git@gitlab.stnts.com:sparklab/gameapi.git",
|
|
22
|
+
"cross-env": "^10.0.0",
|
|
23
|
+
"minigame-api-typings": "^3.8.12",
|
|
24
|
+
"rollup-plugin-delete": "^2.1.0",
|
|
25
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
26
|
+
"tslib": "^2.8.1",
|
|
27
|
+
"typescript": "^5.7.3"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@babel/runtime-corejs3": "^7.27.6",
|
|
32
|
+
"@bufbuild/protobuf": "^2.2.5",
|
|
33
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
34
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
35
|
+
"@shimotsuki/mobx": "^1.0.1",
|
|
36
|
+
"core-js": "^3.41.0",
|
|
37
|
+
"crypto-es": "^2.1.0",
|
|
38
|
+
"eventemitter3": "^5.0.1",
|
|
39
|
+
"pitayaclient": "git+ssh://git@gitlab.stnts.com/sparklab/pitaya-client.git#ts-proto",
|
|
40
|
+
"rollup": "^4.18.1",
|
|
41
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
42
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
43
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
44
|
+
"sgc": "git+ssh://git@gitlab.stnts.com/sparklab/social-gaming-client.git#ts-proto"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"package.json",
|
|
49
|
+
"./temp/tsconfig.cocos.json",
|
|
50
|
+
"./temp/declarations",
|
|
51
|
+
"tsconfig.json",
|
|
52
|
+
"LICENSE"
|
|
53
|
+
]
|
|
54
|
+
}
|