@shimotsuki/core 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shimotsuki_core.js +2964 -1
- package/package.json +1 -1
package/dist/shimotsuki_core.js
CHANGED
|
@@ -1 +1,2964 @@
|
|
|
1
|
-
import t from"@babel/runtime-corejs3/core-js/global-this";import{AudioSource as e,_decorator as i,AudioClip as s,error as o,Node as n,director as r,log as a,Component as l,Prefab as c,instantiate as h,isValid as p,Layers as u,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 E,BlockInputEvents as C,Button as w,Director as S,warn as T,AsyncDelegate as A,Game as I,assetManager as k,Asset as O,resources as N,sys as R,SpriteFrame as D,Sprite as M}from"cc";import F from"@babel/runtime-corejs3/core-js-stable/reflect/get";import x from"@babel/runtime-corejs3/core-js-stable/reflect/set";import U from"@babel/runtime-corejs3/core-js-stable/object/assign";import P from"@babel/runtime-corejs3/core-js-stable/promise";import L from"eventemitter3";import B from"@babel/runtime-corejs3/core-js-stable/instance/includes";import j from"@babel/runtime-corejs3/core-js-stable/json/stringify";import H from"@babel/runtime-corejs3/core-js-stable/map";import G 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 tt from"@babel/runtime-corejs3/core-js-stable/instance/every";import{SocketConnectStatus as et}from"pitayaclient";import{DEBUG as it,WECHAT as st,PREVIEW as ot}from"cc/env";import{SocialGameClient as nt}from"sgc";import rt from"crypto-es";import at from"@babel/runtime-corejs3/core-js-stable/date/now";import lt from"@babel/runtime-corejs3/core-js-stable/set-interval";import ct from"@babel/runtime-corejs3/core-js-stable/instance/values";import ht from"@babel/runtime-corejs3/core-js-stable/instance/entries";class pt extends e{cat;initAudio(t){return this.cat=t,this}}const{ccclass:ut,menu:dt}=i;let mt=class extends pt{effects=(()=>new H)();load(t,e){return new P((i,o)=>{let n,r=null;void 0!==e?(r=t,n=e):n=t;const a=(t,e)=>{if(t)return o(t);this.effects.set(n,e),this.playOneShot(e,this.volume),i(e)};r?this.cat.res.load(r,n,s,a):this.cat.res.load(n,s,a)})}release(){for(let t in this.effects)this.cat.res.release(t);this.effects.clear()}};const{ccclass:_t,menu:ft}=i;class gt extends pt{onComplete=null;_progress=0;_url=null;_isPlay=!1;get progress(){return this.duration>0&&(this._progress=this.currentTime/this.duration),this._progress}set progress(t){this._progress=t,this.currentTime=t*this.duration}load(t,e){return new P((i,n)=>{let r,a=null;void 0!==e?(a=t,r=e):r=t;const l=(t,e)=>{if(t)return o(t),n(t);this.playing&&(this._isPlay=!1,this.stop(),this.cat.res.release(this._url)),this.playOnAwake=!1,this.enabled=!0,this.clip=e,this._url=r,i(e)};a?this.cat.res.load(a,r,s,l):this.cat.res.load(r,s,l)})}update(t){this.currentTime>0&&(this._isPlay=!0),this._isPlay&&0==this.playing&&(this._isPlay=!1,this.enabled=!1,this.onComplete&&this.onComplete())}release(){this._url&&(this.cat.res.release(this._url),this._url=null)}}class yt{cat;constructor(t){this.cat=t}}var vt;!function(t){t.MUSIC_ON="AudioEventConstant/MUSIC_ON",t.MUSIC_OFF="AudioEventConstant/MUSIC_OFF",t.EFFECT_ON="AudioEventConstant/EFFECT_ON",t.EFFECT_OFF="AudioEventConstant/EFFECT_OFF",t.PAUSE_AUDIO="AudioEventConstant/PAUSE_AUDIO",t.RESUME_AUDIO="AudioEventConstant/RESUME_AUDIO"}(vt||(vt={}));class bt extends yt{local_data={};music;effect;_volume_music=1;_volume_effect=1;_switch_music=!0;_switch_effect=!0;local_store_key="game_audio";extra={};constructor(t){super(t),this.local_store_key=this.cat.audio_local_store_key;var e=new n("UIAudioManager");r.addPersistRootNode(e);var i=new n("UIMusic");i.parent=e,this.music=i.addComponent(gt).initAudio(t);var s=new n("UIEffect");s.parent=e,this.effect=s.addComponent(mt).initAudio(t),this.load()}setMusicComplete(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.music.onComplete=t}async playMusic(t,e){if(this.music.loop=!0,!this._switch_music)return;let i,s;void 0!==e?(s=t,i=e):i=t,i.length&&await(s?this.music.load(s,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 t;B(t=[0,2]).call(t,this.music.state)&&this.music?.play()}get progressMusic(){return this.music.progress}set progressMusic(t){this.music.progress=t}get volumeMusic(){return this._volume_music}set volumeMusic(t){this._volume_music=t,this.music.volume=t}get switchMusic(){return this._switch_music}set switchMusic(t){if(a("设置背景音乐开关值",t,this._switch_music),t==this._switch_music)return;this._switch_music=t,t?this.resumeMusic():this.pauseMusic();const e=t?vt.MUSIC_ON:vt.MUSIC_OFF;this.cat.event.emit(e),this.save()}async playEffect(t,e){if(!this._switch_effect)return;let i,s;void 0!==e?(s=t,i=e):i=t,i.length&&await(s?this.effect.load(s,i):this.effect.load(i)).then(()=>{this.effect.play()})}stopEffect(){this.effect?.stop()}get volumeEffect(){return this._volume_effect}set volumeEffect(t){this._volume_effect=t,this.effect.volume=t}get switchEffect(){return this._switch_effect}set switchEffect(t){if(t==this._switch_effect)return;this._switch_effect=t,t?this.effect?.play():this.effect?.stop();const e=t?vt.EFFECT_ON:vt.EFFECT_OFF;this.cat.event.emit(e),this.save()}resumeAll(){this.switchMusic&&this.music?.play(),this.switchEffect&&this.effect?.play()}pauseAll(){this.music?.pause(),this.effect?.pause()}stopAll(){this.music?.stop(),this.effect?.stop()}save(){this.local_data.volume_music=this._volume_music,this.local_data.volume_effect=this._volume_effect,this.local_data.switch_music=this._switch_music,this.local_data.switch_effect=this._switch_effect,this.local_data.extra=this.extra;let t=j(this.local_data);return this.cat.storage.set(this.local_store_key,t),this}load(){try{let t=this.cat.storage.get(this.local_store_key);this.local_data=JSON.parse(t),this._volume_music=this.local_data.volume_music,this._volume_effect=this.local_data.volume_effect,this._switch_music=this.local_data.switch_music,this._switch_effect=this.local_data.switch_effect,this.extra=this.local_data.extra}catch(t){this.local_data={},this._volume_music=.6,this._volume_effect=1,this._switch_music=!0,this._switch_effect=!0,this.extra={}}this.music&&(this.music.volume=this._volume_music),this.effect&&(this.effect.volume=this._volume_effect)}}function Et(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function Ct(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;class wt extends l{props={};data={};cat=(()=>t._cat)();autorunDisposers=[];reactionDisposers=[];eventEmitter=[];hook={destroyed:()=>{},started:()=>{}};initUI(){}__preload(){this.initUI(),this.onAutoObserver()}constructor(){super(),z(this,{props:q,data:q})}onAutoObserver(){}addAutorun(t){const e=K(t)?t:[t];return G(e).call(e,t=>{const e=Q(t);this.autorunDisposers.push(e)}),this}addReaction(t,e,i){const s=J(t,e,i);return this.reactionDisposers.push(s),this}addAudoListener(t){var e;return B(e=this.eventEmitter).call(e,t)||t===this.cat.event||this.eventEmitter.push(t),t}_onPreDestroy(){var t,e;if(G(t=this.autorunDisposers).call(t,t=>{t()}),G(e=this.reactionDisposers).call(e,t=>{t()}),this.autorunDisposers=[],this.reactionDisposers=[],!super._onPreDestroy)throw new Error("_onPreDestroy已弃用");super._onPreDestroy()}onDisable(){var t;this.onHide(),this.deleteAllEventByEmitter(this.cat.event),G(t=this.eventEmitter).call(t,t=>{this.deleteAllEventByEmitter(t)}),this.eventEmitter=[],this.removeListener()}deleteAllEventByEmitter(t){const e=t._events;for(const i in e){let s=e[i];K(s)||(s=[s]),G(s).call(s,e=>{e.context===this&&t.off(i,e.fn,this)})}}onEnable(){this.onShow(),this.addListener(),this.onEventListener()}onEventListener(){}addListener(){}removeListener(){}addToParent(t,e,i){const s=t instanceof c?h(t):t instanceof l?t.node:t;if("number"==typeof e){const t=e,o=i;this.setOptions(o),s.insertChild(this.node,t)}else{const t=e;this.setOptions(t),s.addChild(this.node)}return this}setOptions(t){if(t)for(let e in t)switch(e){case"hook":t.hook&&(this.hook=t.hook);break;case"props":null!==t.props&&"object"==typeof t.props&&(this.props=t.props);break;case"data":null!==t.data&&"object"==typeof t.data&&(this.data=t.data)}}setUpdateData(t){if(this.data)return t&&U(this.data,this.toPlainObject(t)),this}setUpdateProps(t){if(this.props)return t&&U(this.props,this.toPlainObject(t)),this}toPlainObject(t){const e={};for(const i of W(t))if("string"==typeof i)try{e[i]=t[i]}catch{}return e}removeAndDestroy(){p(this?.node)&&(this.node.removeFromParent(),this.node.destroy())}setPosition(t){return this.node.setPosition(t),this}setScale(t){return this.node.setScale(t),this}setAngle(t){return this.node.angle=t,this}setRotation(t){return this.node.setRotation(t),this}setRotationFromEuler(t){return this.node.setRotationFromEuler(t),this}onShow(){}onHide(){}setNodeAndChildrenLayer(t){return St(this.node,t),this}}const St=(t,e)=>{var i,s,o;t.layer="string"==typeof e?2**u.nameToLayer(e):e,(null==(i=t)?void 0:V(o=Function.call).call(o,G(s=i.children),s))?.(t=>{St(t,e)})};class Tt extends wt{lastEnterDirection="center";screen;isClosing=!1;root;constructor(){super(),this._init()}_init(){this.root=this.node,this.screen=d.getVisibleSize()}async showTween(t){let{isMotion:e=!0,direction:i="center",duration:s=.1,isBounce:o=!0,bounceDuration:n=.05}=t;if(this.lastEnterDirection=i,e){const t=this.node.getComponent(m);let e,n;t&&(t.updateAlignment(),t.enabled=!1),_(1.1,1.1,1),"center"==i?(e=_(.01,.01,.01),n=_(1,1,1)):(e="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,s,e,n,o),t&&(t.enabled=!0)}}async hideTween(t){let{isMotion:e=!0,direction:i,duration:s=.1}=t;if(i=i||this.lastEnterDirection,!this.isClosing){if(this.isClosing=!0,f(this.node).removeSelf(),e){const t=this.node.getComponent(m);let e,o;t&&(t.enabled=!1),"center"==i?(e=this.node.scale,o=_(0,0,0)):(o="left"==i?_(-this.screen.width,0,0):"right"==i?_(this.screen.width,0,0):_(0,"top"==i?this.screen.height:-this.screen.height,0),e=this.node.getPosition()),await this.handle(i,s,e,o,!1)}this.removeAndDestroy()}}async handle(t,e,i,s,o){"center"==t?this.node.setScale(i):this.node.setPosition(i),await this.deftween(e,{["center"==t?"scale":"position"]:s},o)}deftween(t,e,i,s){return new P((i,s)=>{f(this.node).to(t,e).call(()=>{i()}).start()})}}const{ccclass:At,property:It}=i;var kt;!function(t){t[t.EFFECT=0]="EFFECT",t[t.BGM=1]="BGM"}(kt||(kt={}));class Ot extends wt{type=(()=>kt.EFFECT)();clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=(()=>new e)();onEnable(){super.onEnable(),this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,this.cat.event.on(vt.EFFECT_ON,this.onPlayEffectHandler,this).on(vt.EFFECT_OFF,this.onStopEffectHandler,this).on(vt.MUSIC_ON,this.onPlayMusicHandler,this).on(vt.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){super.__preload();const{volumeEffect:t,volumeMusic:e}=this.cat.audio;this.audioSource.volume=this.type===kt.BGM?e:t}start(){}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=this.cat.audio;this.audioSource.playing||!(this.type===kt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}Et([It({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(kt)}),Ct("design:type",Number)],Ot.prototype,"type",void 0),Et([It({tooltip:"音源",type:s}),Ct("design:type",s)],Ot.prototype,"clip",void 0),Et([It({tooltip:"循环"}),Ct("design:type",Boolean)],Ot.prototype,"loop",void 0),Et([It({tooltip:"音量"}),Ct("design:type",Number)],Ot.prototype,"volume",void 0),Et([It({tooltip:"是否启用自动播放"}),Ct("design:type",Boolean)],Ot.prototype,"playOnAwake",void 0);const{ccclass:Nt,property:Rt}=i;class Dt extends Tt{type=(()=>kt.EFFECT)();clip=null;loop=!1;volume=1;playOnAwake=!1;audioSource=(()=>new e)();onEnable(){super.onEnable(),this.cat.event.on(vt.EFFECT_ON,this.onPlayEffectHandler,this).on(vt.EFFECT_OFF,this.onStopEffectHandler,this).on(vt.MUSIC_ON,this.onPlayMusicHandler,this).on(vt.MUSIC_OFF,this.onStopMusicHandler,this)}__preload(){this.clip&&(this.audioSource.clip=this.clip),this.audioSource.loop=this.loop,this.audioSource.volume=this.volume,this.audioSource.playOnAwake=this.playOnAwake,super.__preload();const{volumeEffect:t,volumeMusic:e}=this.cat.audio;this.audioSource.volume=this.type===kt.BGM?e:t}stopAudio(){this.audioSource.stop()}playAudio(){const{switchEffect:t,switchMusic:e}=this.cat.audio;this.audioSource.playing||!(this.type===kt.BGM?e:t)||y._paused||this.audioSource.play()}onPlayEffectHandler(){}onStopEffectHandler(){this.stopAudio()}onPlayMusicHandler(){}onStopMusicHandler(){this.stopAudio()}_onPreDestroy(){this.onStopMusicHandler(),super._onPreDestroy()}}Et([Rt({tooltip:"类型:\n EFFECT 音效\n BGM 音乐",type:g(kt)}),Ct("design:type",Number)],Dt.prototype,"type",void 0),Et([Rt({tooltip:"音源",type:s}),Ct("design:type",s)],Dt.prototype,"clip",void 0),Et([Rt({tooltip:"循环"}),Ct("design:type",Boolean)],Dt.prototype,"loop",void 0),Et([Rt({tooltip:"音量"}),Ct("design:type",Number)],Dt.prototype,"volume",void 0),Et([Rt({tooltip:"是否启用自动播放"}),Ct("design:type",Boolean)],Dt.prototype,"playOnAwake",void 0);const{ccclass:Mt,property:Ft,menu:xt}=i;var Ut;!function(t){t[t.FIXED=0]="FIXED",t[t.SLIDE=1]="SLIDE"}(Ut||(Ut={}));let Pt=class extends wt{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 P(async(t,e)=>{const{title:i,type:s,fixed_time:o}=this.props;s==Ut.FIXED?(this.fixed_node.active=!0,this.fixed_label.string=`${i}`,this.scheduleOnce(()=>{this.node.destroy(),t()},o)):(this.slide_node.active=!0,this.slide_label.string=`${i}`,this.playAnim(this.node).then(()=>{t()}))})}playAnim(t){return new P((e,i)=>{const s=this.node.getComponent(b),o=f(s).delay(1.2).to(.5,{opacity:0}).call(()=>{E.stopAllByTarget(t),this.node.destroy(),e()});f(t).by(.5,{position:_(0,400,0)}).call(()=>{o.start()}).start()})}onDestroy(){E.stopAllByTarget(this.node),this.unscheduleAllCallbacks()}};var Lt;Et([Ft({type:n,tooltip:"固定节点"}),Ct("design:type",n)],Pt.prototype,"fixed_node",void 0),Et([Ft({type:n,tooltip:"滑动节点"}),Ct("design:type",n)],Pt.prototype,"slide_node",void 0),Et([Ft({type:v,tooltip:"固定标签节点"}),Ct("design:type",v)],Pt.prototype,"fixed_label",void 0),Et([Ft({type:v,tooltip:"滑动标签节点"}),Ct("design:type",v)],Pt.prototype,"slide_label",void 0),Pt=Et([Mt("CoreToast"),xt("CATCORE/CoreToast")],Pt),function(t){t.EVENT_SHOW="GlobalEventConstant/EVENT_SHOW",t.EVENT_HIDE="GlobalEventConstant/EVENT_HIDE",t.GAME_RESIZE="GlobalEventConstant/GAME_RESIZE",t.EVENT_CLOSE="GlobalEventConstant/EVENT_CLOSE",t.ONLINE="GlobalEventConstant/ONLINE",t.OFFLINE="GlobalEventConstant/OFFLINE",t.ROOT_MASK_UPDATE="GlobalEventConstant/ROOT_MASK_UPDATE",t.ROOT_MASK_CHANGE="GlobalEventConstant/ROOT_MASK_CHANGE"}(Lt||(Lt={}));const{ccclass:Bt,property:jt,menu:Ht}=i;let Gt=class extends wt{tween};Et([jt({type:n,tooltip:"动画节点"}),Ct("design:type",n)],Gt.prototype,"tween",void 0),Gt=Et([Bt("CoreBlackMask"),Ht("CATCORE/CoreBlackMask")],Gt);const{ccclass:$t,property:Kt,menu:Wt}=i;let Vt=class extends Tt{scene_mask_node;ui_container;gui=null;onLoad(){this.setSceneMaskActive(!1)}get scene_mask(){return this.scene_mask_node.getComponent(Gt)}get brother(){return this.ui_container.children||[]}get tweenChildren(){return this.scene_mask.tween.children}onEventListener(){this.cat.event.on(Lt.ROOT_MASK_CHANGE,this.uiMaskChanged,this)}addMask(){const t=this.brother[this.brother.length-1];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}subMask(){const t=this.brother[this.brother.length-2];t&&this.scene_mask.node.setSiblingIndex(t.getSiblingIndex()),this.blockMaskSiblingIndexChanged()}blockMaskSiblingIndexChanged(){this.tweenChildren.length>1||this.brother.length>1?this.show():this.hide()}addNodeToTween(t){return p(this)&&this.scene_mask&&this.scene_mask.tween.addChild(t),this}show(){this.setSceneMaskActive(!0)}hide(){this.setSceneMaskActive(!1)}setGui(t){return this.gui=t,this}uiMaskChanged(){this.blockMaskSiblingIndexChanged()}setSceneMaskActive(t){this.scene_mask.node.active=t}};Et([Kt({type:n}),Ct("design:type",n)],Vt.prototype,"scene_mask_node",void 0),Et([Kt({type:n}),Ct("design:type",n)],Vt.prototype,"ui_container",void 0),Vt=Et([$t("CoreUIContainer"),Wt("CATCORE/CoreUIContainer")],Vt);class zt extends Tt{onEnable(){super.onEnable(),this.updateMask()}onDisable(){super.onDisable(),this.updateMask()}updateMask(){this.cat.event.emit(Lt.ROOT_MASK_UPDATE)}}const{ccclass:qt,property:Qt,menu:Jt}=i;let Xt=class extends zt{title;loadingTween;loading_rotate=0;onAutoObserver(){this.addAutorun([()=>{this.props?.title&&(this.title.string=`${this.props?.title}`),this.title.node.active=!!this.props?.title?.length},()=>{this.getComponent(C).enabled=!!this.props?.mask}])}update(t){this.loading_rotate+=220*t,this.loadingTween.setRotationFromEuler(0,0,-this.loading_rotate%360),this.loading_rotate>360&&(this.loading_rotate-=360)}};var Zt;Et([Qt({type:v,tooltip:"标题"}),Ct("design:type",v)],Xt.prototype,"title",void 0),Et([Qt({type:n,tooltip:"动画"}),Ct("design:type",n)],Xt.prototype,"loadingTween",void 0),Xt=Et([qt("CoreShowLoading"),Jt("CATCORE/CoreShowLoading")],Xt),function(t){t.RECONNECTED="重连成功",t.RECONNECTING="正在重连",t.MAX_RECONNECT="重连次数超出限制,请检查网络",t.RECONNECTED_ERROR="重连失败,请检查网络",t.CONNECT_PARAM_ERROR="游戏参数错误,请重新加载",t.KICK="账号已下线",t.OFFLINE="网络已断开",t.ONLINE="网络已连接",t.GAME_ERROR="连接游戏服错误"}(Zt||(Zt={}));const{ccclass:Yt,property:te,menu:ee}=i;let ie=class extends zt{common_prompt_text;btn_confirm;btn_close;is_close=!1;props={content:null};initUI(){}onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.addAutorun([()=>{this.common_prompt_text.string=this.props.content??""}])}onDestroy(){this.unscheduleAllCallbacks()}updateProps(t){this.updatePromptText(t,t==Zt.RECONNECTING)}updatePromptText(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.unscheduleAllCallbacks(),this.props.content=t,a("更新提示文案:",t),e){let e=0;const i=()=>{e=(e+1)%4,this.common_prompt_text.string=t+["","·","··","···"][e]};this.schedule(i,.5)}}onConfirmHandler(){this.is_close=!0,this.cat.gui.hideReconnect()}};Et([te({type:v,tooltip:"通用提示文本"}),Ct("design:type",v)],ie.prototype,"common_prompt_text",void 0),Et([te({type:w,tooltip:"确定按钮"}),Ct("design:type",w)],ie.prototype,"btn_confirm",void 0),Et([te({type:w,tooltip:"关闭按钮"}),Ct("design:type",w)],ie.prototype,"btn_close",void 0),ie=Et([Yt("CoreReconnection"),ee("CATCORE/CoreReconnection")],ie);const{ccclass:se,property:oe,menu:ne}=i;let re=class extends zt{text;btn_confirm;btn_close;onLoad(){this.btn_confirm.node.on(w.EventType.CLICK,this.onConfrimHandler,this)}start(){this.props&&this.updateProps(this.props)}onConfrimHandler(){this.props?.confrim?.(),this.cat.gui.hideNotice()}updateProps(t){this.text.string=`${t.text}`}};Et([oe({type:v,tooltip:"提示文本"}),Ct("design:type",v)],re.prototype,"text",void 0),Et([oe({type:w,tooltip:"确定按钮"}),Ct("design:type",w)],re.prototype,"btn_confirm",void 0),Et([oe({type:w,tooltip:"关闭按钮"}),Ct("design:type",w)],re.prototype,"btn_close",void 0),re=Et([se("CoreNotice"),ne("CATCORE/CoreNotice")],re);class ae extends wt{isReload}const{ccclass:le,property:ce,menu:he}=i;var pe;!function(t){t[t.UI=0]="UI",t[t.LOADING=1]="LOADING",t[t.TOAST=2]="TOAST",t[t.RECONNECTTION=3]="RECONNECTTION",t[t.NOTICE=4]="NOTICE"}(pe||(pe={}));let ue=class extends wt{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;onEventListener(){this.cat.event.on(Lt.ROOT_MASK_UPDATE,this.onRootUpdate,this)}init(t){this.cat=t;const e=r.getScene();return a("init scene"),e&&this.changeScene(e),this}start(){this.onRootUpdate()}toastQueue=[];isScheduling=!1;minInterval=.2;showToast(t){this.toastQueue.push(t),this.isScheduling||this.processQueueWithInterval()}processQueueWithInterval(){if(0===this.toastQueue.length)return void(this.isScheduling=!1);this.isScheduling=!0;const t=this.toastQueue.shift(),e=()=>{h(this.toast_ui_prefab).getComponent(Pt).addToParent(this.root_toast,{props:t}),this.scheduleOnce(()=>{this.processQueueWithInterval()},this.minInterval)};0===this.root_toast.children.length?e():this.scheduleOnce(e,this.minInterval)}hideToast(){var t;this.root_toast&&G(t=this.root_toast.children).call(t,t=>{t.getComponent(Pt)?.removeAndDestroy()});return this.toastQueue=[],this.unschedule(this.processQueueWithInterval),this.isScheduling=!1,this}showLoading(){let{title:t="",mask:e=!0,black:i=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(a("showLoading",t),this.loading_ui_component)this.loading_ui_component.setOptions({props:{title:t,mask:e,black:i}});else{const s=h(this.loading_ui_prefab);this.loading_ui_component=s.getComponent(Xt).addToParent(this.root_ui,{props:{title:t,mask:e,black:i}})}return this}hideLoading(){return this.loading_ui_component?.removeAndDestroy(),this.loading_ui_component=null,this}showReconnect(t){if(this.reconnection_ui_component)this.reconnection_ui_component.setUpdateProps({content:t});else{const e=h(this.reconnection_ui_prefab);this.reconnection_ui_component=e.getComponent(ie).addToParent(this.root_ui,{props:{content:t}})}return this}hideReconnect(){return this.reconnection_ui_component?.removeAndDestroy(),this.reconnection_ui_component=null,this}showNotice(t){const e=h(this.notice_ui_prefab);return this.notice_ui_component=e.getComponent(re).addToParent(this.root_ui,{props:t}),this}hideNotice(){return this.notice_ui_component?.removeAndDestroy(),this}loadScene(t,e,i){a("[加载场景名][参数][重新加载]",t,e,i);let s={},o=i??!0;return"boolean"==typeof e?o=e:s=e??{},r.once(S.EVENT_BEFORE_SCENE_LAUNCH,t=>{a("Director.EVENT_BEFORE_SCENE_LAUNCH",t),this.changeScene(t,s,o)}),"string"==typeof t?r.loadScene(t):r.runScene(t),this}resetScene(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return t=t||this.currentScene,this.loadScene(t)}cleanScene(){this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast()}changeScene(t,e,i){this.currentScene=t.name,this.createUILayer(t);const s=t.getComponentInChildren(ae);a("给场景传递属性值=======",s),s&&(s.isReload=i??!0),s?.setOptions(e)}createUILayer(t){this.ui_container_component?.removeAndDestroy(),this.ui_container_component=null;const e=h(this.ui_prefab);this.ui_container_component=e.getComponent(Vt),this.ui_container_component?.setGui(this).addToParent(t,this.node.getSiblingIndex())}reloadScene(){a("重新加载当前场景"),this.loadScene(this.currentScene,!0)}async closeUI(t,e){const{component:i}=this.findUIBaseLayer(t,!1);i&&(i.setOptions({...e?.hook??{},...e?.props??{}}),await i.hideTween(e||{}),this.ui_container_component?.subMask())}async openUI(t,e){const{rootNode:i,component:s}=this.findUIBaseLayer(t,!0);i.getComponent(Tt),s?.setOptions(e),i&&this.ui_container_component?.addNodeToTween(i).addMask(),s&&await s.showTween(e||{}),this.ui_container_component?.ui_container&&s?.addToParent(this.ui_container_component.ui_container)}findUIBaseLayer(t,e){let i,s=null;if(t instanceof n){var r;i=t;const e=$(r=t.components).call(r,t=>t instanceof Tt);if(!e.length)return o(`${t.name}节点未找到继承自BaseLayer的组件`),{rootNode:i,component:s};1==e.length?s=e[0]:T(`${t.name}节点存在多个继承自BaseLayer的组件`)}else if(i=t.node,s=t,e){for(;i.parent;)i=i.parent;s.root=i}else i=t.root;return{rootNode:i,component:s}}onRootUpdate(){const t=this.root_ui.children.findLastIndex(t=>t.active&&t!=this.root_mask);if(this.root_mask.active=-1!=t,t>-1){const e=this.root_ui.children[t].getSiblingIndex()-1;this.root_mask.setSiblingIndex(e<0?0:e)}this.cat.event.emit(Lt.ROOT_MASK_CHANGE)}};var de;Et([ce({type:c,tooltip:"断线重连UI预制体"}),Ct("design:type",c)],ue.prototype,"reconnection_ui_prefab",void 0),Et([ce({type:c,tooltip:"提示UI预制体"}),Ct("design:type",c)],ue.prototype,"toast_ui_prefab",void 0),Et([ce({type:c,tooltip:"加载UI预制体"}),Ct("design:type",c)],ue.prototype,"loading_ui_prefab",void 0),Et([ce({type:c,tooltip:"公告UI预制体"}),Ct("design:type",c)],ue.prototype,"notice_ui_prefab",void 0),Et([ce({type:c,tooltip:"UI层预制体"}),Ct("design:type",c)],ue.prototype,"ui_prefab",void 0),Et([ce({type:n,tooltip:"root-UI层"}),Ct("design:type",n)],ue.prototype,"root_ui",void 0),Et([ce({type:n,tooltip:"root-组件层"}),Ct("design:type",n)],ue.prototype,"root_toast",void 0),Et([ce({type:n,tooltip:"root-mask"}),Ct("design:type",n)],ue.prototype,"root_mask",void 0),ue=Et([le("Gui"),he("CATCORE/Gui")],ue),function(t){t.Root="prefabs/root",t.Toast="prefabs/toast",t.BlackMask="prefabs/black-mask",t.Loading="prefabs/loading",t.Notice="prefabs/notice",t.Reconnection="prefabs/reconnection"}(de||(de={}));class me extends yt{gui;#t="core";getGuiPrefabByType=(t,e)=>new P((i,s)=>{a(t,`${e}`),this.cat.res.load(t,e,(t,e)=>{t?s(t):i(e)})});async init(){this.cat.gui_bundle_name&&(this.#t=this.cat.gui_bundle_name);const t=await this.getGuiPrefabByType(this.#t,de.Root),e=h(t);return this.gui=e.getComponent(ue).init(this.cat),r.addPersistRootNode(e),this}}class _e extends nt{showRequestErrInfo=!1;logBlackList=[];ignore=t=>{var e;return B(e=this.logBlackList).call(e,t)};constructor(t,e,i,s){super(e,i,s,t),this.showRequestErrInfo=s?.showRequestErrInfo??!1}destroy(){this.disconnect(!0),t._cat.socialGameClient.unregister(this)}async GameRequest(e,i,s){let{forwardReq:n=!1,forwardResp:r=!1}=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return new P((l,c)=>{super.GameRequest(e,i,s,{forwardReq:n,forwardResp:r}).then(t=>{it&&a(`%c ws服务端消息 %c [Response][${new Date}] %c ${e} %c`,"background:#ff00ff ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#3d7daa ; padding: 1px; color: #fff","background:#ff00ff ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",i),l(t)},e=>{o(e),this.showRequestErrInfo&&e?.msg&&t._cat.gui.showToast({title:e.msg}),c(e)})})}subscribe(e,i,s){return super.subscribe(e,i,i=>{it&&!this.ignore(e)&&a(`%c ws服务端消息:[subscribe][${new Date}] %c ${e} %c`,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#410083 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",i),t._cat.event.emit(e,i),s?.(i)}),this}}class fe extends yt{managedClients=(()=>new H)();isGlobalOnline=!0;isInBackground=!1;reconnecting=!1;onEventHideDelegate=(()=>new A)();onEventShowDelegate=(()=>new A)();onEventReloadSceneDelegate=(()=>new A)();reconnectTimer=null;scheduleReconnect(){let t=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()},t)}get activeClients(){var t,e;return $(t=Z(e=Y(this.managedClients)).call(e,t=>{let[e,i]=t;return i})).call(t,t=>t.socket)}constructor(t){super(t),this.initGlobalListeners()}createWebSocket(t,e,i,s){if(this.managedClients.has(t)){this.managedClients.get(t).destroy(),a(`清理旧的 ${t} 客户端`)}const o=new _e(t,i,s,U({reconnectMaxAttempts:1/0},{...e,isAutoConnect:!1,isArrayBuffer:st}));return this.register(o),o}register(t){t.on("reconnected",this.handleSingleReconnect),t.on("close",this.handleSingleClose),t.on("kick",this.handleSingleKick),this.managedClients.set(t.name,t)}unregister(t){t.off("reconnected",this.handleSingleReconnect),t.off("close",this.handleSingleClose),t.off("kick",this.handleSingleKick),this.managedClients.delete(t.name)}initGlobalListeners(){this.cat.event.on(Lt.ONLINE,()=>this.handleGlobalStateChange("online"),this).on(Lt.OFFLINE,()=>this.handleGlobalStateChange("offline"),this),y.on(I.EVENT_SHOW,()=>this.handleGlobalStateChange("show")),y.on(I.EVENT_HIDE,()=>this.handleGlobalStateChange("hide"))}async handleGlobalStateChange(t){switch(t){case"online":this.cat.gui.hideLoading().showToast({title:Zt.ONLINE}),this.isGlobalOnline=!0,this.triggerReconnectAll();break;case"offline":this.isGlobalOnline=!1,this.disconnectAll(!0),this.cat.gui.showLoading({title:Zt.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 t,e;await P.allSettled(Z(t=this.activeClients).call(t,async t=>{try{await t.reconnectPromise()}catch(e){o(`${t.name}服重连失败`,e)}}));const i=$(e=this.activeClients).call(e,t=>t.socketConnectStatus!==et.CONNECTED);i.length>0?(console.error("部分WS重连失败:",Z(i).call(i,t=>t)),a("2s后重连所有客户端"),this.reconnecting=!1,this.scheduleReconnect()):this.reconnecting=!1}catch(t){throw this.reconnecting=!1,t}}disconnectAll(t){var e;G(e=this.managedClients).call(e,e=>{a("断开连接",e.name,t,e.socket),e.disconnect(t)})}handleSingleClose=()=>{this.reconnecting||(a("3s后重连所有客户端"),this.scheduleReconnect(3e3))};handleSingleReconnect=async()=>{var t,e;tt(t=this.activeClients).call(t,t=>t.socketConnectStatus===et.CONNECTED)&&(a("单个WS重连成功回调===",this.managedClients),await P.allSettled(Z(e=this.activeClients).call(e,async t=>{try{await t.connectRequest()}catch(e){o(`${t.name}服登录错误`,e),this.cat.gui.showToast({title:`登录${t.name}服错误`})}})),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),await this.onEventReloadSceneDelegate.dispatch(),this.cat.gui.hideLoading(),r.getScene()?.getComponentInChildren(ae)?.isReload&&this.cat.gui.reloadScene())};handleSingleKick=()=>{this.cat.gui.showReconnect(Zt.KICK)}}class ge{get=(()=>function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"resources";return k.getBundle(i).get(t,e)})();isAssetType=t=>"function"==typeof t&&t.prototype instanceof O;async load(){let t=null,e=null,i=null;for(var s=arguments.length,o=new Array(s),n=0;n<s;n++)o[n]=arguments[n];"string"==typeof o[0]&&"string"==typeof o[1]&&(t=o.shift());let r=o.shift();this.isAssetType(o[0])&&(e=o.shift()),2==o.length&&(i=o.shift());const a=o.shift();let l=N;if(t&&"resources"!=t){k.bundles.has(t)||await this.loadBundle(t);let e=k.bundles.get(t);e&&(l=e)}i&&a?l.load(r,e,i,a):a?l.load(r,e,a):l.load(r,e)}async loadDir(){let t=null,e=null,i=null,s=null;for(var o=arguments.length,n=new Array(o),r=0;r<o;r++)n[r]=arguments[r];"string"==typeof n[0]&&"string"==typeof n[1]&&(t=n.shift());let a=n.shift();this.isAssetType(n[0])&&(e=n.shift()),2==n.length&&(i=n.shift()),s=n.shift();let l=N;if(t&&"resources"!=t){k.bundles.has(t)||await this.loadBundle(t);let e=k.bundles.get(t);e&&(l=e)}i&&s?l.loadDir(a,e,i,s):s?l.loadDir(a,e,s):l.loadDir(a,e)}loadRemote(t){for(var e,i=null,s=arguments.length,o=new Array(s>1?s-1:0),n=1;n<s;n++)o[n-1]=arguments[n];2==o.length&&(i=o.shift()),e=o.shift(),k.loadRemote(t,{ext:".png",...i},e)}loadBundle=(t,e)=>new P((i,s)=>{const o=(t,e)=>{if(t)return s(t);i(e)};e?k.loadBundle(t,{version:e},o):k.loadBundle(t,o)});releasePrefabtDepsRecursively=t=>{var e=k.assets.get(t);if(k.releaseAsset(e),e instanceof c){var i=k.dependUtil.getDepsRecursively(t);G(i).call(i,t=>{k.assets.get(t).decRef()})}};release=(()=>{var t=this;return function(e){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"resources";var s=k.getBundle(i);if(s){var o=s.get(e);o&&t.releasePrefabtDepsRecursively(o._uuid)}}})();releaseDir=(()=>{var t=this;return function(e){var i,s;let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"resources";var n=k.getBundle(o),r=n?.getDirWithPath(e);(null==(i=r)?void 0:V(s=Function.call).call(s,Z(i),i))?.(e=>{t.releasePrefabtDepsRecursively(e.uuid)}),!e&&"resources"!=o&&n&&k.removeBundle(n)}})();dump=()=>{var t;G(t=k.assets).call(t,(t,e)=>{a(k.assets.get(e))}),a(`当前资源总数:${k.assets.count}`)};loadAssetsWithProgress(t,e){return new P((i,s)=>{const o=t.getDirWithPath(""),n=o.length;let r=0;if(0===n)return e(1),void i();G(o).call(o,o=>{t.load(o.path,t=>{t?s(t):(r++,e(r/n),r===n&&i())})})})}}class ye{rootStore;constructor(t){this.rootStore=t}}class ve extends yt{}let be=null;const Ee={stringify:t=>{const e={ct:t.ciphertext.toString(rt.enc.Base64)};return t.iv&&(e.iv=t.iv.toString()),t.salt&&(e.s=t.salt.toString()),j(e)},parse:t=>{const e=JSON.parse(t),i=rt.lib.CipherParams.create({ciphertext:rt.enc.Base64.parse(e.ct)});return e.iv&&(i.iv=rt.enc.Hex.parse(e.iv)),e.s&&(i.salt=rt.enc.Hex.parse(e.s)),i}};var Ce=Object.freeze({__proto__:null,JsonFormatter:Ee,aesDecrypt:(t,e,i)=>rt.AES.decrypt(t,e,{iv:be,format:Ee}).toString(rt.enc.Utf8),aesEncrypt:(t,e,i)=>rt.AES.encrypt(t,e,{iv:be,format:Ee}).toString(),initCrypto:(t,e)=>{be=rt.enc.Hex.parse(e)},md5:t=>rt.MD5(t).toString()});class we extends yt{encryptUtil=(()=>Ce)()}class Se extends yt{_key=null;_iv=null;_id="";init(t,e){this.cat.util.encryptUtil.initCrypto(t,e),this._key=this.cat.util.encryptUtil.md5(t),this._iv=this.cat.util.encryptUtil.md5(e)}setUser(t){this._id=t}set(t,e){if(null!=(t=`${t}_${this._id}`)){if(ot||(t=this.cat.util.encryptUtil.md5(t)),null==e)return console.warn("存储的值为空,则直接移除该存储"),void this.remove(t);if("function"!=typeof e){if("object"==typeof e)try{e=j(e)}catch(t){return void console.error(`解析失败,str = ${e}`)}else"number"==typeof e&&(e+="");ot||null==this._key||null==this._iv||(e=this.cat.util.encryptUtil.aesEncrypt(`${e}`,this._key,this._iv)),R.localStorage.setItem(t,e)}else console.error("储存的值不能为方法")}else console.error("存储的key不能为空")}get(t,e){if(null==t)return console.error("存储的key不能为空"),null;t=`${t}_${this._id}`,ot||(t=this.cat.util.encryptUtil.md5(t));let i=R.localStorage.getItem(t);return null==i||""===i||ot||null==this._key||null==this._iv||(i=this.cat.util.encryptUtil.aesDecrypt(i,this._key,this._iv)),null===i?e:i}getNumber(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;var i=this.get(t);return Number(i)||e}getBoolean(t){var e=this.get(t);return Boolean(e)||!1}getJson(t,e){var i=this.get(t);return i&&JSON.parse(i)||e}remove(t){null!=t?(t=`${t}_${this._id}`,ot||(t=this.cat.util.encryptUtil.md5(t)),R.localStorage.removeItem(t)):console.error("存储的key不能为空")}clear(){R.localStorage.clear()}}class Te{static#e=null;#i=!1;static get instance(){return this.#e??(this.#e=new Te)}onAppInitDelegate=(()=>new A)();onPlugInInitDelegate=(()=>new A)();#s=null;get audio(){return this.#s}#o=null;get event(){return this.#o}#n=null;get gui(){return this.#n}#r=null;get storage(){return this.#r}#a=null;get res(){return this.#a}#l=null;get util(){return this.#l}#c=null;get socialGameClient(){return this.#c}#h=null;get store(){return this.#h}#p="";get gui_bundle_name(){return this.#p}#u="";get audio_local_store_key(){return this.#u}#d="";get default_audio_effect(){return this.#d}setConfig=(()=>{var t=this;return function(){let{default_audio_effect:e="",gui_bundleName:i="resources",audio_local_store_key:s="game_audio"}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t.#i)throw new Error("[CAT] 已初始化,无法修改配置");return t.#p=i,t.#u=s,t.#d=e,t}})();async boot(){if(this.#i)throw new Error("[CAT] 已初始化");try{this.#h=new ve(this),this.#a=new ge,this.#l=new we(this),this.#r=new Se(this),this.#o=new L,this.#s=new bt(this),this.#c=new fe(this),this.#n=(await new me(this).init()).gui,this.#i=!0}catch(t){throw console.error("[CAT] 初始化失败:",t),t}}merge(t,e){if(!this.#i)throw new Error("[CAT] 未初始化");if("string"!=typeof t)throw new Error("merge方法第一个参数应该为string类型");return F(this,t)||x(this,t,e),U(F(this,t),e),this}appendPlugInInitDelegate(t){return this.#i?P.resolve().then(t).catch(t=>{console.error("[CAT] appendPlugInInitDelegate 回调执行失败:",t)}):this.onPlugInInitDelegate.add(t),this}}const{ccclass:Ae,property:Ie,menu:ke}=i;let Oe=class extends Tt{default_title=null;title;prompt_content_str;prompt_content_spriteFrame;btn_confirm;confirm_spriteFrame;btn_cancel;cancel_spriteFrame;btn_close;isConfirm=!1;props={title:this.default_title,content:null,confirmCB:()=>{},cancelCB:()=>{},style:null};onLoad(){this.btn_cancel.node.on(w.EventType.CLICK,this.onCancelHandler,this),this.btn_confirm.node.on(w.EventType.CLICK,this.onConfirmHandler,this),this.btn_close.node.on(w.EventType.CLICK,this.onCloseHandler,this),this.addAutorun([()=>{this.title.spriteFrame=this.props?.title||this.default_title},()=>{this.props.content&&(this.props.content instanceof D?this.prompt_content_spriteFrame.spriteFrame=this.props.content:"string"==typeof this.props.content?this.prompt_content_str.string=this.props.content:console.error("未知类型的【UIModal】内容"))},()=>{null===this.props?.style?.confirm?this.btn_confirm.node.active=!1:(this.btn_confirm.node.active=!0,this.btn_confirm.getComponent(M).spriteFrame=this.props.style?.confirm||this.confirm_spriteFrame),null===this.props?.style?.cancel?this.btn_cancel.node.active=!1:(this.btn_cancel.node.active=!0,this.btn_cancel.getComponent(M).spriteFrame=this.props.style?.cancel||this.cancel_spriteFrame)}])}close(){this.props.cancelCB?.(),this.cat.gui.closeUI(this)}onCancelHandler(){this.close()}onConfirmHandler(){this.props.confirmCB?.()}onDestroy(){this.isConfirm&&this.props.onDestroy?.()}onCloseHandler(){this.close()}};var Ne;Et([Ie({type:D,tooltip:"默认标题"}),Ct("design:type",D)],Oe.prototype,"default_title",void 0),Et([Ie({type:M,tooltip:"标题节点"}),Ct("design:type",M)],Oe.prototype,"title",void 0),Et([Ie({type:v,tooltip:"字符串内容按钮"}),Ct("design:type",v)],Oe.prototype,"prompt_content_str",void 0),Et([Ie({type:M,tooltip:"图片精灵内容按钮"}),Ct("design:type",M)],Oe.prototype,"prompt_content_spriteFrame",void 0),Et([Ie({type:w,tooltip:"确认按钮"}),Ct("design:type",w)],Oe.prototype,"btn_confirm",void 0),Et([Ie({type:D,tooltip:"确认按钮精灵图"}),Ct("design:type",D)],Oe.prototype,"confirm_spriteFrame",void 0),Et([Ie({type:w,tooltip:"取消按钮"}),Ct("design:type",w)],Oe.prototype,"btn_cancel",void 0),Et([Ie({type:D,tooltip:"取消按钮精灵图"}),Ct("design:type",D)],Oe.prototype,"cancel_spriteFrame",void 0),Et([Ie({type:w,tooltip:"关闭按钮"}),Ct("design:type",w)],Oe.prototype,"btn_close",void 0),Oe=Et([Ae("CoreUIModal"),ke("CATCORE/CoreUIModal")],Oe),function(t){t[t.Delay=0]="Delay",t[t.Interval=1]="Interval"}(Ne||(Ne={}));class Re{tag;type;callback;remainingTime;executionTime=0;initialTime;constructor(t,e,i,s){this.tag=t,this.type=e,this.remainingTime=i,this.initialTime=i,this.callback=s}}class De extends yt{timers=(()=>new H)();lastUpdateTime=(()=>at())();constructor(t){var e;super(t),t.event.on(Lt.EVENT_HIDE,this.onHandleAppBackground,this),t.event.on(Lt.EVENT_SHOW,this.onHandleAppForeground,this),lt(V(e=this.update).call(e,this),1e3)}onHandleAppBackground(){this.lastUpdateTime=at()}onHandleAppForeground(){const t=at(),e=t-this.lastUpdateTime;a("elapsedTime",e);for(const t of ct(i=this.timers).call(i)){var i;t.remainingTime>0&&(t.remainingTime-=e,t.executionTime+=e)}this.lastUpdateTime=t}registerInterval(t,e,i){if(this.has(t))return o(`${t}定时器已存在,请勿重复注册`);const s=new Re(t,Ne.Interval,e,i);this.timers.set(t,s)}registerDelay(t,e,i){if(this.has(t))return o(`${t}延时器已存在,请勿重复注册`);const s=new Re(t,Ne.Delay,e,i);this.timers.set(t,s)}unregister(t){this.has(t)&&this.timers.delete(t)}has(t){return this.timers.has(t)}update(){const t=[];for(const[i,s]of ht(e=this.timers).call(e)){var e;s.remainingTime-=1e3,s.remainingTime<=0&&(s.type===Ne.Interval&&(s.executionTime+=s.initialTime),s.callback(s.executionTime),s.type===Ne.Interval?s.remainingTime=s.initialTime:t.push(i))}for(const e of t)this.timers.delete(e)}}const Me=(e,i)=>(s,o,n)=>{let r=n.value;return n.value=function(){const s=e??t._cat.default_audio_effect;s?t._cat.audio.playEffect(s):console.warn("请添加音效路径参数"),i&&i();for(var o=arguments.length,n=new Array(o),a=0;a<o;a++)n[a]=arguments[a];r.apply(this,n)},n},Fe=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1?arguments[1]:void 0;return function(i,s,o){let n=o.value,r=!1;return o.value=function(){if(r)e&&e();else{r=!0,X(()=>{r=!1},1e3*t);for(var i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];n.apply(this,s)}},o}},xe=t._cat??=Te.instance;y.onPostProjectInitDelegate.add(async()=>{console.time("[Init App]");try{await xe.boot(),await xe.onAppInitDelegate.dispatch(),await xe.onPlugInInitDelegate.dispatch()}catch(t){throw o(`[Init App] 初始化失败: ${t instanceof Error?t.message:String(t)}`),t}finally{console.timeEnd("[Init App]")}});export{Me as AudioEffect,vt as AudioEventConstant,bt as AudioManager,Ot as AudioSourceBaseComponent,Dt as AudioSourceUILayer,kt as AudioTypeEnum,wt as BaseComponent,yt as BaseManager,de as BasePrefab,ye as BaseStore,Fe as ButtonLock,Gt as CoreBlackMask,re as CoreNotice,ie as CoreReconnection,Xt as CoreShowLoading,ve as CoreStore,Pt as CoreToast,Vt as CoreUIContainer,Oe as CoreUIModal,we as CoreUtil,Lt as GlobalEventConstant,ue as Gui,me as GuiManager,pe as LayerType,Te as Manager,Zt as ReconnectPrompt,zt as RootUILayer,ae as SceneLayer,De as TimerManager,Ut as ToastType,Tt as UILayer,_e as WrapperSocialGameClient,xe as cat};
|
|
1
|
+
import _globalThis from '@babel/runtime-corejs3/core-js/global-this';
|
|
2
|
+
import { AudioSource, _decorator, AudioClip, error, Node, director, log, Component, Prefab, instantiate, isValid, Layers, view, Widget, v3, tween, Enum, game, Label, UIOpacity, Tween, BlockInputEvents, Button, Director, warn, AsyncDelegate, Game, assetManager, Asset, resources, sys, SpriteFrame, Sprite } from 'cc';
|
|
3
|
+
import _Reflect$get from '@babel/runtime-corejs3/core-js-stable/reflect/get';
|
|
4
|
+
import _Reflect$set from '@babel/runtime-corejs3/core-js-stable/reflect/set';
|
|
5
|
+
import _Object$assign from '@babel/runtime-corejs3/core-js-stable/object/assign';
|
|
6
|
+
import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
|
|
7
|
+
import EventEmitter from 'eventemitter3';
|
|
8
|
+
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
9
|
+
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
10
|
+
import _Map from '@babel/runtime-corejs3/core-js-stable/map';
|
|
11
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
12
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
13
|
+
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
14
|
+
import _Reflect$ownKeys from '@babel/runtime-corejs3/core-js-stable/reflect/own-keys';
|
|
15
|
+
import _bindInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/bind';
|
|
16
|
+
import { makeObservable, observable, autorun, reaction } from '@shimotsuki/mobx';
|
|
17
|
+
import _setTimeout from '@babel/runtime-corejs3/core-js-stable/set-timeout';
|
|
18
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
19
|
+
import _Array$from from '@babel/runtime-corejs3/core-js-stable/array/from';
|
|
20
|
+
import _everyInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/every';
|
|
21
|
+
import { SocketConnectStatus } from 'pitayaclient';
|
|
22
|
+
import { DEBUG, WECHAT, PREVIEW } from 'cc/env';
|
|
23
|
+
import { SocialGameClient } from 'sgc';
|
|
24
|
+
import CryptoES from 'crypto-es';
|
|
25
|
+
import _Date$now from '@babel/runtime-corejs3/core-js-stable/date/now';
|
|
26
|
+
import _setInterval from '@babel/runtime-corejs3/core-js-stable/set-interval';
|
|
27
|
+
import _valuesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/values';
|
|
28
|
+
import _entriesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/entries';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @describe 音频公共类
|
|
32
|
+
* @author 游金宇(KM)
|
|
33
|
+
* @date 2024-09-12 11:42:58
|
|
34
|
+
*/
|
|
35
|
+
class CommonAudio extends AudioSource {
|
|
36
|
+
cat;
|
|
37
|
+
initAudio(cat) {
|
|
38
|
+
this.cat = cat;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
ccclass: ccclass$b,
|
|
45
|
+
menu: menu$9
|
|
46
|
+
} = _decorator;
|
|
47
|
+
/**
|
|
48
|
+
* 注:用playOneShot播放的音乐效果,在播放期间暂时没办法即时关闭音乐
|
|
49
|
+
*/
|
|
50
|
+
/** 游戏音效 */
|
|
51
|
+
let AudioEffect$1 = class AudioEffect extends CommonAudio {
|
|
52
|
+
effects = (() => new _Map())();
|
|
53
|
+
load(arg1, arg2) {
|
|
54
|
+
return new _Promise((resolve, reject) => {
|
|
55
|
+
let bundleName = null;
|
|
56
|
+
let url;
|
|
57
|
+
if (arg2 !== undefined) {
|
|
58
|
+
bundleName = arg1;
|
|
59
|
+
url = arg2;
|
|
60
|
+
} else {
|
|
61
|
+
url = arg1;
|
|
62
|
+
}
|
|
63
|
+
const cb = (err, data) => {
|
|
64
|
+
if (err) {
|
|
65
|
+
return reject(err);
|
|
66
|
+
}
|
|
67
|
+
this.effects.set(url, data);
|
|
68
|
+
this.playOneShot(data, this.volume);
|
|
69
|
+
resolve(data);
|
|
70
|
+
};
|
|
71
|
+
bundleName ? this.cat.res.load(bundleName, url, AudioClip, cb) : this.cat.res.load(url, AudioClip, cb);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** 释放所有已使用过的音效资源 */
|
|
75
|
+
release() {
|
|
76
|
+
for (let key in this.effects) {
|
|
77
|
+
this.cat.res.release(key);
|
|
78
|
+
}
|
|
79
|
+
this.effects.clear();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
ccclass: ccclass$a,
|
|
85
|
+
menu: menu$8
|
|
86
|
+
} = _decorator;
|
|
87
|
+
/** 背景音乐 */
|
|
88
|
+
class AudioMusic extends CommonAudio {
|
|
89
|
+
/** 背景音乐播放完成回调 */
|
|
90
|
+
onComplete = null;
|
|
91
|
+
_progress = 0;
|
|
92
|
+
_url = null;
|
|
93
|
+
_isPlay = false;
|
|
94
|
+
/** 获取音乐播放进度 */
|
|
95
|
+
get progress() {
|
|
96
|
+
if (this.duration > 0) this._progress = this.currentTime / this.duration;
|
|
97
|
+
return this._progress;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 设置音乐当前播放进度
|
|
101
|
+
* @param value 进度百分比0到1之间
|
|
102
|
+
*/
|
|
103
|
+
set progress(value) {
|
|
104
|
+
this._progress = value;
|
|
105
|
+
this.currentTime = value * this.duration;
|
|
106
|
+
}
|
|
107
|
+
load(arg1, arg2) {
|
|
108
|
+
return new _Promise((resolve, reject) => {
|
|
109
|
+
let bundleName = null;
|
|
110
|
+
let url;
|
|
111
|
+
if (arg2 !== undefined) {
|
|
112
|
+
bundleName = arg1;
|
|
113
|
+
url = arg2;
|
|
114
|
+
} else {
|
|
115
|
+
url = arg1;
|
|
116
|
+
}
|
|
117
|
+
const cb = (err, data) => {
|
|
118
|
+
if (err) {
|
|
119
|
+
error(err);
|
|
120
|
+
return reject(err);
|
|
121
|
+
}
|
|
122
|
+
if (this.playing) {
|
|
123
|
+
this._isPlay = false;
|
|
124
|
+
this.stop();
|
|
125
|
+
this.cat.res.release(this._url);
|
|
126
|
+
}
|
|
127
|
+
this.playOnAwake = false;
|
|
128
|
+
this.enabled = true;
|
|
129
|
+
this.clip = data;
|
|
130
|
+
this._url = url;
|
|
131
|
+
resolve(data);
|
|
132
|
+
};
|
|
133
|
+
bundleName ? this.cat.res.load(bundleName, url, AudioClip, cb) : this.cat.res.load(url, AudioClip, cb);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** cc.Component 生命周期方法,验证背景音乐播放完成逻辑,建议不要主动调用 */
|
|
137
|
+
update(dt) {
|
|
138
|
+
if (this.currentTime > 0) {
|
|
139
|
+
this._isPlay = true;
|
|
140
|
+
}
|
|
141
|
+
if (this._isPlay && this.playing == false) {
|
|
142
|
+
this._isPlay = false;
|
|
143
|
+
this.enabled = false;
|
|
144
|
+
this.onComplete && this.onComplete();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** 释放当前背景音乐资源 */
|
|
148
|
+
release() {
|
|
149
|
+
if (this._url) {
|
|
150
|
+
this.cat.res.release(this._url);
|
|
151
|
+
this._url = null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @describe 基础管理类
|
|
158
|
+
* @author 游金宇(KM)
|
|
159
|
+
* @date 2024-09-12 11:49:30
|
|
160
|
+
*/
|
|
161
|
+
class BaseManager {
|
|
162
|
+
cat;
|
|
163
|
+
constructor(manager) {
|
|
164
|
+
this.cat = manager;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var AudioEventConstant;
|
|
169
|
+
(function (AudioEventConstant) {
|
|
170
|
+
/**音乐开 */
|
|
171
|
+
AudioEventConstant["MUSIC_ON"] = "AudioEventConstant/MUSIC_ON";
|
|
172
|
+
/**音乐关 */
|
|
173
|
+
AudioEventConstant["MUSIC_OFF"] = "AudioEventConstant/MUSIC_OFF";
|
|
174
|
+
/**音效开 */
|
|
175
|
+
AudioEventConstant["EFFECT_ON"] = "AudioEventConstant/EFFECT_ON";
|
|
176
|
+
/**音效关 */
|
|
177
|
+
AudioEventConstant["EFFECT_OFF"] = "AudioEventConstant/EFFECT_OFF";
|
|
178
|
+
/**暂停音频 */
|
|
179
|
+
AudioEventConstant["PAUSE_AUDIO"] = "AudioEventConstant/PAUSE_AUDIO";
|
|
180
|
+
/**恢复音频 */
|
|
181
|
+
AudioEventConstant["RESUME_AUDIO"] = "AudioEventConstant/RESUME_AUDIO";
|
|
182
|
+
})(AudioEventConstant || (AudioEventConstant = {}));
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 音频管理
|
|
186
|
+
*/
|
|
187
|
+
class AudioManager extends BaseManager {
|
|
188
|
+
local_data = {};
|
|
189
|
+
music;
|
|
190
|
+
effect;
|
|
191
|
+
_volume_music = 1;
|
|
192
|
+
_volume_effect = 1;
|
|
193
|
+
_switch_music = true;
|
|
194
|
+
_switch_effect = true;
|
|
195
|
+
local_store_key = 'game_audio';
|
|
196
|
+
extra = {};
|
|
197
|
+
constructor(cat) {
|
|
198
|
+
super(cat);
|
|
199
|
+
this.local_store_key = this.cat.audio_local_store_key;
|
|
200
|
+
var node = new Node('UIAudioManager');
|
|
201
|
+
director.addPersistRootNode(node);
|
|
202
|
+
var music = new Node('UIMusic');
|
|
203
|
+
music.parent = node;
|
|
204
|
+
this.music = music.addComponent(AudioMusic).initAudio(cat);
|
|
205
|
+
var effect = new Node('UIEffect');
|
|
206
|
+
effect.parent = node;
|
|
207
|
+
this.effect = effect.addComponent(AudioEffect$1).initAudio(cat);
|
|
208
|
+
this.load();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 设置背景音乐播放完成回调
|
|
212
|
+
* @param callback 背景音乐播放完成回调
|
|
213
|
+
*/
|
|
214
|
+
setMusicComplete() {
|
|
215
|
+
let callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
216
|
+
this.music.onComplete = callback;
|
|
217
|
+
}
|
|
218
|
+
async playMusic(arg1, arg2) {
|
|
219
|
+
this.music.loop = true;
|
|
220
|
+
if (!this._switch_music) return;
|
|
221
|
+
let url;
|
|
222
|
+
let bundleName;
|
|
223
|
+
if (arg2 !== undefined) {
|
|
224
|
+
bundleName = arg1;
|
|
225
|
+
url = arg2;
|
|
226
|
+
} else {
|
|
227
|
+
url = arg1;
|
|
228
|
+
}
|
|
229
|
+
if (!url.length) return;
|
|
230
|
+
await (bundleName ? this.music.load(bundleName, url) : this.music.load(url)).then(() => {
|
|
231
|
+
if (this._switch_music) {
|
|
232
|
+
this.music.play();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 停止音乐
|
|
238
|
+
*/
|
|
239
|
+
stopMusic() {
|
|
240
|
+
if (this.music.state != 0) this.music?.stop();
|
|
241
|
+
}
|
|
242
|
+
/**暂停音乐 */
|
|
243
|
+
pauseMusic() {
|
|
244
|
+
if (this.music.state == 1) this.music?.pause();
|
|
245
|
+
}
|
|
246
|
+
/**恢复音乐 */
|
|
247
|
+
resumeMusic() {
|
|
248
|
+
var _context;
|
|
249
|
+
if (_includesInstanceProperty(_context = [0, 2]).call(_context, this.music.state)) this.music?.play();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* 获取背景音乐播放进度
|
|
253
|
+
*/
|
|
254
|
+
get progressMusic() {
|
|
255
|
+
return this.music.progress;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* 设置背景乐播放进度
|
|
259
|
+
* @param value 播放进度值
|
|
260
|
+
*/
|
|
261
|
+
set progressMusic(value) {
|
|
262
|
+
this.music.progress = value;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* 获取背景音乐音量
|
|
266
|
+
*/
|
|
267
|
+
get volumeMusic() {
|
|
268
|
+
return this._volume_music;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 设置背景音乐音量
|
|
272
|
+
* @param value 音乐音量值
|
|
273
|
+
*/
|
|
274
|
+
set volumeMusic(value) {
|
|
275
|
+
this._volume_music = value;
|
|
276
|
+
this.music.volume = value;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 获取背景音乐开关值
|
|
280
|
+
*/
|
|
281
|
+
get switchMusic() {
|
|
282
|
+
return this._switch_music;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* 设置背景音乐开关值
|
|
286
|
+
* @param value 开关值
|
|
287
|
+
*/
|
|
288
|
+
set switchMusic(value) {
|
|
289
|
+
log('设置背景音乐开关值', value, this._switch_music);
|
|
290
|
+
if (value == this._switch_music) return;
|
|
291
|
+
this._switch_music = value;
|
|
292
|
+
value ? this.resumeMusic() : this.pauseMusic();
|
|
293
|
+
const nonce = value ? AudioEventConstant.MUSIC_ON : AudioEventConstant.MUSIC_OFF;
|
|
294
|
+
this.cat.event.emit(nonce);
|
|
295
|
+
this.save();
|
|
296
|
+
}
|
|
297
|
+
async playEffect(arg1, arg2) {
|
|
298
|
+
if (!this._switch_effect) return;
|
|
299
|
+
let url;
|
|
300
|
+
let bundleName;
|
|
301
|
+
if (arg2 !== undefined) {
|
|
302
|
+
bundleName = arg1;
|
|
303
|
+
url = arg2;
|
|
304
|
+
} else {
|
|
305
|
+
url = arg1;
|
|
306
|
+
}
|
|
307
|
+
if (!url.length) return;
|
|
308
|
+
await (bundleName ? this.effect.load(bundleName, url) : this.effect.load(url)).then(() => {
|
|
309
|
+
this.effect.play();
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* 停止音效
|
|
314
|
+
*/
|
|
315
|
+
stopEffect() {
|
|
316
|
+
this.effect?.stop();
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* 获取音效音量
|
|
320
|
+
*/
|
|
321
|
+
get volumeEffect() {
|
|
322
|
+
return this._volume_effect;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* 设置获取音效音量
|
|
326
|
+
* @param value 音效音量值
|
|
327
|
+
*/
|
|
328
|
+
set volumeEffect(value) {
|
|
329
|
+
this._volume_effect = value;
|
|
330
|
+
this.effect.volume = value;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 获取音效开关值
|
|
334
|
+
*/
|
|
335
|
+
get switchEffect() {
|
|
336
|
+
return this._switch_effect;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* 设置音效开关值
|
|
340
|
+
* @param value 音效开关值
|
|
341
|
+
*/
|
|
342
|
+
set switchEffect(value) {
|
|
343
|
+
if (value == this._switch_effect) return;
|
|
344
|
+
this._switch_effect = value;
|
|
345
|
+
value ? this.effect?.play() : this.effect?.stop();
|
|
346
|
+
const nonce = value ? AudioEventConstant.EFFECT_ON : AudioEventConstant.EFFECT_OFF;
|
|
347
|
+
this.cat.event.emit(nonce);
|
|
348
|
+
this.save();
|
|
349
|
+
}
|
|
350
|
+
/** 恢复当前暂停的音乐与音效播放 */
|
|
351
|
+
resumeAll() {
|
|
352
|
+
this.switchMusic && this.music?.play();
|
|
353
|
+
this.switchEffect && this.effect?.play();
|
|
354
|
+
}
|
|
355
|
+
/** 暂停当前音乐与音效的播放 */
|
|
356
|
+
pauseAll() {
|
|
357
|
+
this.music?.pause();
|
|
358
|
+
this.effect?.pause();
|
|
359
|
+
}
|
|
360
|
+
/** 停止当前音乐与音效的播放 */
|
|
361
|
+
stopAll() {
|
|
362
|
+
this.music?.stop();
|
|
363
|
+
this.effect?.stop();
|
|
364
|
+
}
|
|
365
|
+
/** 保存音乐音效的音量、开关配置数据到本地 */
|
|
366
|
+
save() {
|
|
367
|
+
this.local_data.volume_music = this._volume_music;
|
|
368
|
+
this.local_data.volume_effect = this._volume_effect;
|
|
369
|
+
this.local_data.switch_music = this._switch_music;
|
|
370
|
+
this.local_data.switch_effect = this._switch_effect;
|
|
371
|
+
this.local_data.extra = this.extra;
|
|
372
|
+
let data = _JSON$stringify(this.local_data);
|
|
373
|
+
this.cat.storage.set(this.local_store_key, data);
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
/** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */
|
|
377
|
+
load() {
|
|
378
|
+
try {
|
|
379
|
+
let data = this.cat.storage.get(this.local_store_key);
|
|
380
|
+
this.local_data = JSON.parse(data);
|
|
381
|
+
this._volume_music = this.local_data.volume_music;
|
|
382
|
+
this._volume_effect = this.local_data.volume_effect;
|
|
383
|
+
this._switch_music = this.local_data.switch_music;
|
|
384
|
+
this._switch_effect = this.local_data.switch_effect;
|
|
385
|
+
this.extra = this.local_data.extra;
|
|
386
|
+
} catch (e) {
|
|
387
|
+
this.local_data = {};
|
|
388
|
+
this._volume_music = 0.6;
|
|
389
|
+
this._volume_effect = 1.0;
|
|
390
|
+
this._switch_music = true;
|
|
391
|
+
this._switch_effect = true;
|
|
392
|
+
this.extra = {};
|
|
393
|
+
}
|
|
394
|
+
if (this.music) this.music.volume = this._volume_music;
|
|
395
|
+
if (this.effect) this.effect.volume = this._volume_effect;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/******************************************************************************
|
|
400
|
+
Copyright (c) Microsoft Corporation.
|
|
401
|
+
|
|
402
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
403
|
+
purpose with or without fee is hereby granted.
|
|
404
|
+
|
|
405
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
406
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
407
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
408
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
409
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
410
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
411
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
412
|
+
***************************************************************************** */
|
|
413
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
function __decorate(decorators, target, key, desc) {
|
|
417
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
418
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
419
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
420
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function __metadata(metadataKey, metadataValue) {
|
|
424
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
428
|
+
var e = new Error(message);
|
|
429
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/**参数 */
|
|
433
|
+
/**initUI->onAutoObserver->onLoad->start */
|
|
434
|
+
class BaseComponent extends Component {
|
|
435
|
+
/**组件(传值)属性 */
|
|
436
|
+
props = {};
|
|
437
|
+
/**自由属性 */
|
|
438
|
+
data = {};
|
|
439
|
+
cat = (() => _globalThis._cat)();
|
|
440
|
+
/**autorun销毁 */
|
|
441
|
+
autorunDisposers = [];
|
|
442
|
+
/**reaction销毁 */
|
|
443
|
+
reactionDisposers = [];
|
|
444
|
+
eventEmitter = [];
|
|
445
|
+
hook = {
|
|
446
|
+
destroyed: () => {},
|
|
447
|
+
started: () => {}
|
|
448
|
+
};
|
|
449
|
+
/**初始化UI(可在本函数中进行节点赋值或注册节点事件等...) */
|
|
450
|
+
initUI() {}
|
|
451
|
+
__preload() {
|
|
452
|
+
this.initUI();
|
|
453
|
+
this.onAutoObserver();
|
|
454
|
+
}
|
|
455
|
+
constructor() {
|
|
456
|
+
super();
|
|
457
|
+
makeObservable(this, {
|
|
458
|
+
props: observable,
|
|
459
|
+
data: observable
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
/**依赖收集生命周期(可以在该生命周期中注册依赖收集回调) */
|
|
463
|
+
onAutoObserver() {}
|
|
464
|
+
/**添加自动收集 */
|
|
465
|
+
addAutorun(cb) {
|
|
466
|
+
const cbs = _Array$isArray(cb) ? cb : [cb];
|
|
467
|
+
_forEachInstanceProperty(cbs).call(cbs, item => {
|
|
468
|
+
const disposer = autorun(item);
|
|
469
|
+
this.autorunDisposers.push(disposer);
|
|
470
|
+
});
|
|
471
|
+
return this;
|
|
472
|
+
}
|
|
473
|
+
/**添加自动收集 */
|
|
474
|
+
addReaction(expression, effect, opts) {
|
|
475
|
+
const disposer = reaction(expression, effect, opts);
|
|
476
|
+
this.reactionDisposers.push(disposer);
|
|
477
|
+
return this;
|
|
478
|
+
}
|
|
479
|
+
// /**添加自动收集 */
|
|
480
|
+
// protected addReaction<T, FireImmediately extends boolean = false>(option: ReactionParameters<T, FireImmediately>) {
|
|
481
|
+
// const disposer = reaction(...option)
|
|
482
|
+
// this.reactionDisposers.push(disposer)
|
|
483
|
+
// return this
|
|
484
|
+
// }
|
|
485
|
+
addAudoListener(eventEmitter) {
|
|
486
|
+
var _context;
|
|
487
|
+
if (!_includesInstanceProperty(_context = this.eventEmitter).call(_context, eventEmitter) && eventEmitter !== this.cat.event) {
|
|
488
|
+
this.eventEmitter.push(eventEmitter);
|
|
489
|
+
}
|
|
490
|
+
return eventEmitter;
|
|
491
|
+
}
|
|
492
|
+
_onPreDestroy() {
|
|
493
|
+
var _context2, _context3;
|
|
494
|
+
_forEachInstanceProperty(_context2 = this.autorunDisposers).call(_context2, item => {
|
|
495
|
+
item();
|
|
496
|
+
});
|
|
497
|
+
_forEachInstanceProperty(_context3 = this.reactionDisposers).call(_context3, item => {
|
|
498
|
+
item();
|
|
499
|
+
});
|
|
500
|
+
this.autorunDisposers = [];
|
|
501
|
+
this.reactionDisposers = [];
|
|
502
|
+
if (!super._onPreDestroy) {
|
|
503
|
+
throw new Error("_onPreDestroy已弃用");
|
|
504
|
+
} else {
|
|
505
|
+
super._onPreDestroy();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
onDisable() {
|
|
509
|
+
var _context4;
|
|
510
|
+
this.onHide();
|
|
511
|
+
// 清理当前组件所有全局注册的事件
|
|
512
|
+
this.deleteAllEventByEmitter(this.cat.event);
|
|
513
|
+
// 移除非全局注册的事件
|
|
514
|
+
_forEachInstanceProperty(_context4 = this.eventEmitter).call(_context4, item => {
|
|
515
|
+
this.deleteAllEventByEmitter(item);
|
|
516
|
+
});
|
|
517
|
+
this.eventEmitter = [];
|
|
518
|
+
this.removeListener();
|
|
519
|
+
}
|
|
520
|
+
deleteAllEventByEmitter(emitter) {
|
|
521
|
+
const events = emitter['_events'];
|
|
522
|
+
for (const key in events) {
|
|
523
|
+
let handlers = events[key];
|
|
524
|
+
if (!_Array$isArray(handlers)) {
|
|
525
|
+
handlers = [handlers]; // 统一处理,单个和数组情况
|
|
526
|
+
}
|
|
527
|
+
_forEachInstanceProperty(handlers).call(handlers, handler => {
|
|
528
|
+
if (handler.context === this) {
|
|
529
|
+
emitter.off(key, handler.fn, this); // 移除事件
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
onEnable() {
|
|
535
|
+
this.onShow();
|
|
536
|
+
this.addListener();
|
|
537
|
+
this.onEventListener();
|
|
538
|
+
}
|
|
539
|
+
/**子类继承该方法(全局事件(this.cat.event)注册在components上的事件可以不添加取消监听(自动取消监听了)) */
|
|
540
|
+
onEventListener() {}
|
|
541
|
+
/**子类继承该方法 */
|
|
542
|
+
addListener() {}
|
|
543
|
+
/**子类继承该方法 */
|
|
544
|
+
removeListener() {}
|
|
545
|
+
addToParent(parent, indexOrOptions, maybeOptions) {
|
|
546
|
+
const _parent = parent instanceof Prefab ? instantiate(parent) : parent instanceof Component ? parent.node : parent;
|
|
547
|
+
if (typeof indexOrOptions === 'number') {
|
|
548
|
+
const index = indexOrOptions;
|
|
549
|
+
const options = maybeOptions;
|
|
550
|
+
this.setOptions(options);
|
|
551
|
+
_parent.insertChild(this.node, index);
|
|
552
|
+
} else {
|
|
553
|
+
const options = indexOrOptions;
|
|
554
|
+
this.setOptions(options);
|
|
555
|
+
_parent.addChild(this.node);
|
|
556
|
+
}
|
|
557
|
+
return this;
|
|
558
|
+
}
|
|
559
|
+
/**设置属性(覆盖原有属性) */
|
|
560
|
+
setOptions(options) {
|
|
561
|
+
// 使用类型断言来确保 options 的正确类型
|
|
562
|
+
if (!options) return;
|
|
563
|
+
// 如果 options 是 IUIOption<T> 类型,则可以安全地访问 props 属性
|
|
564
|
+
for (let key in options) {
|
|
565
|
+
switch (key) {
|
|
566
|
+
case 'hook':
|
|
567
|
+
options.hook && (this.hook = options.hook);
|
|
568
|
+
break;
|
|
569
|
+
case 'props':
|
|
570
|
+
if (options.props !== null && typeof options.props === "object") {
|
|
571
|
+
this.props = options.props;
|
|
572
|
+
}
|
|
573
|
+
break;
|
|
574
|
+
case 'data':
|
|
575
|
+
if (options.data !== null && typeof options.data === "object") {
|
|
576
|
+
this.data = options.data;
|
|
577
|
+
}
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**设置data属性(更新) */
|
|
583
|
+
setUpdateData(data) {
|
|
584
|
+
if (!this.data) return;
|
|
585
|
+
data && _Object$assign(this.data, this.toPlainObject(data));
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
/**设置props属性(更新)*/
|
|
589
|
+
setUpdateProps(props) {
|
|
590
|
+
// this.props的指向有可能变空
|
|
591
|
+
if (!this.props) return;
|
|
592
|
+
props && _Object$assign(this.props, this.toPlainObject(props));
|
|
593
|
+
return this;
|
|
594
|
+
}
|
|
595
|
+
toPlainObject(observableObj) {
|
|
596
|
+
const result = {};
|
|
597
|
+
for (const key of _Reflect$ownKeys(observableObj)) {
|
|
598
|
+
if (typeof key === "string") {
|
|
599
|
+
try {
|
|
600
|
+
result[key] = observableObj[key];
|
|
601
|
+
} catch {}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return result;
|
|
605
|
+
}
|
|
606
|
+
/**从父节点移除并销毁 */
|
|
607
|
+
removeAndDestroy() {
|
|
608
|
+
if (isValid(this?.node)) {
|
|
609
|
+
this.node.removeFromParent();
|
|
610
|
+
this.node.destroy();
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
/**设置坐标 */
|
|
614
|
+
setPosition(positin) {
|
|
615
|
+
this.node.setPosition(positin);
|
|
616
|
+
return this;
|
|
617
|
+
}
|
|
618
|
+
setScale(scale) {
|
|
619
|
+
this.node.setScale(scale);
|
|
620
|
+
return this;
|
|
621
|
+
}
|
|
622
|
+
setAngle(angle) {
|
|
623
|
+
this.node.angle = angle;
|
|
624
|
+
return this;
|
|
625
|
+
}
|
|
626
|
+
setRotation(rotation) {
|
|
627
|
+
this.node.setRotation(rotation);
|
|
628
|
+
return this;
|
|
629
|
+
}
|
|
630
|
+
setRotationFromEuler(rotation) {
|
|
631
|
+
this.node.setRotationFromEuler(rotation);
|
|
632
|
+
return this;
|
|
633
|
+
}
|
|
634
|
+
/**显示(同onEnable) */
|
|
635
|
+
onShow() {}
|
|
636
|
+
/**隐藏(同onDisable) */
|
|
637
|
+
onHide() {}
|
|
638
|
+
/**设置节点和子节点的层级 */
|
|
639
|
+
setNodeAndChildrenLayer(layer) {
|
|
640
|
+
setNodeAndChildrenLayer(this.node, layer);
|
|
641
|
+
return this;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
/**设置节点及子节点的层级 */
|
|
645
|
+
const setNodeAndChildrenLayer = (node, layer) => {
|
|
646
|
+
var _context5, _context6, _context7;
|
|
647
|
+
node.layer = typeof layer === 'string' ? 2 ** Layers.nameToLayer(layer) : layer;
|
|
648
|
+
((_context5 = node) == null ? void 0 : _bindInstanceProperty(_context7 = Function.call).call(_context7, _forEachInstanceProperty(_context6 = _context5.children), _context6))?.(item => {
|
|
649
|
+
setNodeAndChildrenLayer(item, layer);
|
|
650
|
+
});
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
class UILayer extends BaseComponent {
|
|
654
|
+
/**上次进入的方向 */
|
|
655
|
+
lastEnterDirection = 'center';
|
|
656
|
+
/**屏幕尺寸 */
|
|
657
|
+
screen;
|
|
658
|
+
/**是否正在关闭 */
|
|
659
|
+
isClosing = false;
|
|
660
|
+
/**组件所在的UI最顶层(不包含UI) */
|
|
661
|
+
root;
|
|
662
|
+
constructor() {
|
|
663
|
+
super();
|
|
664
|
+
this._init();
|
|
665
|
+
}
|
|
666
|
+
_init() {
|
|
667
|
+
this.root = this.node;
|
|
668
|
+
this.screen = view.getVisibleSize();
|
|
669
|
+
}
|
|
670
|
+
// protected onLoad() {
|
|
671
|
+
// // TODO 预留做弹窗动画
|
|
672
|
+
// this.node.addComponent(BlockInputEvents)
|
|
673
|
+
// }
|
|
674
|
+
/**显示动画 */
|
|
675
|
+
async showTween(_ref) {
|
|
676
|
+
let {
|
|
677
|
+
isMotion = true,
|
|
678
|
+
direction = 'center',
|
|
679
|
+
duration = 0.1,
|
|
680
|
+
isBounce = true,
|
|
681
|
+
bounceDuration = 0.05
|
|
682
|
+
} = _ref;
|
|
683
|
+
this.lastEnterDirection = direction;
|
|
684
|
+
if (isMotion) {
|
|
685
|
+
const widget = this.node.getComponent(Widget);
|
|
686
|
+
if (widget) {
|
|
687
|
+
widget.updateAlignment();
|
|
688
|
+
widget.enabled = false;
|
|
689
|
+
}
|
|
690
|
+
// 起点坐标
|
|
691
|
+
let start;
|
|
692
|
+
// 终点坐标
|
|
693
|
+
let end;
|
|
694
|
+
// 回弹坐标 TODO
|
|
695
|
+
v3(1.1, 1.1, 1);
|
|
696
|
+
if (direction == 'center') {
|
|
697
|
+
// 从中间放大
|
|
698
|
+
start = v3(0.01, 0.01, 0.01);
|
|
699
|
+
end = v3(1, 1, 1);
|
|
700
|
+
} else {
|
|
701
|
+
if (direction == 'left') {
|
|
702
|
+
start = v3(-this.screen.width, 0, 0);
|
|
703
|
+
} else if (direction == 'right') {
|
|
704
|
+
start = v3(this.screen.width, 0, 0);
|
|
705
|
+
} else if (direction == 'top') {
|
|
706
|
+
start = v3(0, this.screen.height, 0);
|
|
707
|
+
} else {
|
|
708
|
+
start = v3(0, -this.screen.height, 0);
|
|
709
|
+
}
|
|
710
|
+
end = v3(0, 0, 0);
|
|
711
|
+
}
|
|
712
|
+
await this.handle(direction, duration, start, end, isBounce);
|
|
713
|
+
if (widget) widget.enabled = true;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
/**隐藏动画 */
|
|
717
|
+
async hideTween(_ref2) {
|
|
718
|
+
let {
|
|
719
|
+
isMotion = true,
|
|
720
|
+
direction,
|
|
721
|
+
duration = 0.1
|
|
722
|
+
} = _ref2;
|
|
723
|
+
direction = direction || this.lastEnterDirection;
|
|
724
|
+
// 避免重复点击关闭
|
|
725
|
+
if (this.isClosing) return;
|
|
726
|
+
this.isClosing = true;
|
|
727
|
+
// 停止当前动画
|
|
728
|
+
tween(this.node).removeSelf();
|
|
729
|
+
if (isMotion) {
|
|
730
|
+
const widget = this.node.getComponent(Widget);
|
|
731
|
+
if (widget) widget.enabled = false;
|
|
732
|
+
// 设置起始坐标
|
|
733
|
+
// 起点坐标
|
|
734
|
+
let start;
|
|
735
|
+
// 终点坐标
|
|
736
|
+
let end;
|
|
737
|
+
if (direction == 'center') {
|
|
738
|
+
// 从中间缩小
|
|
739
|
+
start = this.node.scale;
|
|
740
|
+
end = v3(0, 0, 0);
|
|
741
|
+
} else {
|
|
742
|
+
if (direction == 'left') {
|
|
743
|
+
end = v3(-this.screen.width, 0, 0);
|
|
744
|
+
} else if (direction == 'right') {
|
|
745
|
+
end = v3(this.screen.width, 0, 0);
|
|
746
|
+
} else if (direction == 'top') {
|
|
747
|
+
end = v3(0, this.screen.height, 0);
|
|
748
|
+
} else {
|
|
749
|
+
end = v3(0, -this.screen.height, 0);
|
|
750
|
+
}
|
|
751
|
+
start = this.node.getPosition();
|
|
752
|
+
}
|
|
753
|
+
await this.handle(direction, duration, start, end, false);
|
|
754
|
+
}
|
|
755
|
+
this.removeAndDestroy();
|
|
756
|
+
}
|
|
757
|
+
async handle(direction, duration, start, end, isBounce) {
|
|
758
|
+
if (direction == 'center') {
|
|
759
|
+
// 从中间放大
|
|
760
|
+
this.node.setScale(start);
|
|
761
|
+
} else {
|
|
762
|
+
this.node.setPosition(start);
|
|
763
|
+
}
|
|
764
|
+
await this.deftween(duration, {
|
|
765
|
+
[direction == 'center' ? 'scale' : 'position']: end
|
|
766
|
+
}, isBounce);
|
|
767
|
+
}
|
|
768
|
+
deftween(duration, props, isBounce, cb) {
|
|
769
|
+
return new _Promise((resolve, reject) => {
|
|
770
|
+
tween(this.node).to(duration, props).call(() => {
|
|
771
|
+
// tween_node.removeSelf();
|
|
772
|
+
resolve();
|
|
773
|
+
}).start();
|
|
774
|
+
// if (options.isBounce) {
|
|
775
|
+
// this.node.scale = start;
|
|
776
|
+
// const tween_node = tween(this.node)
|
|
777
|
+
// .to(options.duration, { scale: bounce })
|
|
778
|
+
// .to(options.bounceDuration, { scale: end })
|
|
779
|
+
// .call(() => {
|
|
780
|
+
// tween_node.removeSelf()
|
|
781
|
+
// })
|
|
782
|
+
// .start();
|
|
783
|
+
// }
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* @describe 音频组件基类
|
|
790
|
+
* @author 游金宇(KM)
|
|
791
|
+
* @date 2023-12-22 16:20:20
|
|
792
|
+
*/
|
|
793
|
+
const {
|
|
794
|
+
ccclass: ccclass$9,
|
|
795
|
+
property: property$9
|
|
796
|
+
} = _decorator;
|
|
797
|
+
/**
|
|
798
|
+
* EFFECT 音效
|
|
799
|
+
* BGM 音乐
|
|
800
|
+
*/
|
|
801
|
+
var AudioTypeEnum;
|
|
802
|
+
(function (AudioTypeEnum) {
|
|
803
|
+
AudioTypeEnum[AudioTypeEnum["EFFECT"] = 0] = "EFFECT";
|
|
804
|
+
AudioTypeEnum[AudioTypeEnum["BGM"] = 1] = "BGM";
|
|
805
|
+
})(AudioTypeEnum || (AudioTypeEnum = {}));
|
|
806
|
+
class AudioSourceBaseComponent extends BaseComponent {
|
|
807
|
+
type = (() => AudioTypeEnum.EFFECT)();
|
|
808
|
+
clip = null;
|
|
809
|
+
loop = false;
|
|
810
|
+
volume = 1;
|
|
811
|
+
playOnAwake = false;
|
|
812
|
+
audioSource = (() => new AudioSource())();
|
|
813
|
+
onEnable() {
|
|
814
|
+
super.onEnable();
|
|
815
|
+
this.clip && (this.audioSource.clip = this.clip);
|
|
816
|
+
this.audioSource.loop = this.loop;
|
|
817
|
+
this.audioSource.volume = this.volume;
|
|
818
|
+
this.audioSource.playOnAwake = this.playOnAwake;
|
|
819
|
+
this.cat.event.on(AudioEventConstant.EFFECT_ON, this.onPlayEffectHandler, this).on(AudioEventConstant.EFFECT_OFF, this.onStopEffectHandler, this).on(AudioEventConstant.MUSIC_ON, this.onPlayMusicHandler, this).on(AudioEventConstant.MUSIC_OFF, this.onStopMusicHandler, this);
|
|
820
|
+
}
|
|
821
|
+
__preload() {
|
|
822
|
+
super.__preload();
|
|
823
|
+
const {
|
|
824
|
+
volumeEffect,
|
|
825
|
+
volumeMusic
|
|
826
|
+
} = this.cat.audio;
|
|
827
|
+
this.audioSource.volume = this.type === AudioTypeEnum.BGM ? volumeMusic : volumeEffect;
|
|
828
|
+
}
|
|
829
|
+
start() {}
|
|
830
|
+
stopAudio() {
|
|
831
|
+
this.audioSource.stop();
|
|
832
|
+
}
|
|
833
|
+
playAudio() {
|
|
834
|
+
const {
|
|
835
|
+
switchEffect,
|
|
836
|
+
switchMusic
|
|
837
|
+
} = this.cat.audio;
|
|
838
|
+
// @ts-ignore 保证在游戏运行的时候才播放
|
|
839
|
+
if (!this.audioSource.playing && (this.type === AudioTypeEnum.BGM ? switchMusic : switchEffect) && !game._paused) this.audioSource.play();
|
|
840
|
+
}
|
|
841
|
+
onPlayEffectHandler() {}
|
|
842
|
+
onStopEffectHandler() {
|
|
843
|
+
this.stopAudio();
|
|
844
|
+
}
|
|
845
|
+
onPlayMusicHandler() {}
|
|
846
|
+
onStopMusicHandler() {
|
|
847
|
+
this.stopAudio();
|
|
848
|
+
}
|
|
849
|
+
_onPreDestroy() {
|
|
850
|
+
this.onStopMusicHandler();
|
|
851
|
+
super._onPreDestroy();
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
__decorate([property$9({
|
|
855
|
+
tooltip: `类型:
|
|
856
|
+
EFFECT 音效
|
|
857
|
+
BGM 音乐`,
|
|
858
|
+
type: Enum(AudioTypeEnum)
|
|
859
|
+
}), __metadata("design:type", Number)], AudioSourceBaseComponent.prototype, "type", void 0);
|
|
860
|
+
__decorate([property$9({
|
|
861
|
+
tooltip: '音源',
|
|
862
|
+
type: AudioClip
|
|
863
|
+
}), __metadata("design:type", AudioClip)], AudioSourceBaseComponent.prototype, "clip", void 0);
|
|
864
|
+
__decorate([property$9({
|
|
865
|
+
tooltip: '循环'
|
|
866
|
+
}), __metadata("design:type", Boolean)], AudioSourceBaseComponent.prototype, "loop", void 0);
|
|
867
|
+
__decorate([property$9({
|
|
868
|
+
tooltip: '音量'
|
|
869
|
+
}), __metadata("design:type", Number)], AudioSourceBaseComponent.prototype, "volume", void 0);
|
|
870
|
+
__decorate([property$9({
|
|
871
|
+
tooltip: '是否启用自动播放'
|
|
872
|
+
}), __metadata("design:type", Boolean)], AudioSourceBaseComponent.prototype, "playOnAwake", void 0);
|
|
873
|
+
|
|
874
|
+
const {
|
|
875
|
+
ccclass: ccclass$8,
|
|
876
|
+
property: property$8
|
|
877
|
+
} = _decorator;
|
|
878
|
+
/**带有音频通道的UIlayer组件 */
|
|
879
|
+
class AudioSourceUILayer extends UILayer {
|
|
880
|
+
type = (() => AudioTypeEnum.EFFECT)();
|
|
881
|
+
clip = null;
|
|
882
|
+
loop = false;
|
|
883
|
+
volume = 1;
|
|
884
|
+
playOnAwake = false;
|
|
885
|
+
audioSource = (() => new AudioSource())();
|
|
886
|
+
onEnable() {
|
|
887
|
+
super.onEnable();
|
|
888
|
+
this.cat.event.on(AudioEventConstant.EFFECT_ON, this.onPlayEffectHandler, this).on(AudioEventConstant.EFFECT_OFF, this.onStopEffectHandler, this).on(AudioEventConstant.MUSIC_ON, this.onPlayMusicHandler, this).on(AudioEventConstant.MUSIC_OFF, this.onStopMusicHandler, this);
|
|
889
|
+
}
|
|
890
|
+
__preload() {
|
|
891
|
+
this.clip && (this.audioSource.clip = this.clip);
|
|
892
|
+
this.audioSource.loop = this.loop;
|
|
893
|
+
this.audioSource.volume = this.volume;
|
|
894
|
+
this.audioSource.playOnAwake = this.playOnAwake;
|
|
895
|
+
super.__preload();
|
|
896
|
+
const {
|
|
897
|
+
volumeEffect,
|
|
898
|
+
volumeMusic
|
|
899
|
+
} = this.cat.audio;
|
|
900
|
+
this.audioSource.volume = this.type === AudioTypeEnum.BGM ? volumeMusic : volumeEffect;
|
|
901
|
+
}
|
|
902
|
+
stopAudio() {
|
|
903
|
+
this.audioSource.stop();
|
|
904
|
+
}
|
|
905
|
+
playAudio() {
|
|
906
|
+
const {
|
|
907
|
+
switchEffect,
|
|
908
|
+
switchMusic
|
|
909
|
+
} = this.cat.audio;
|
|
910
|
+
// @ts-ignore 保证在游戏运行的时候才播放
|
|
911
|
+
if (!this.audioSource.playing && (this.type === AudioTypeEnum.BGM ? switchMusic : switchEffect) && !game._paused) this.audioSource.play();
|
|
912
|
+
}
|
|
913
|
+
onPlayEffectHandler() {}
|
|
914
|
+
onStopEffectHandler() {
|
|
915
|
+
this.stopAudio();
|
|
916
|
+
}
|
|
917
|
+
onPlayMusicHandler() {}
|
|
918
|
+
onStopMusicHandler() {
|
|
919
|
+
this.stopAudio();
|
|
920
|
+
}
|
|
921
|
+
_onPreDestroy() {
|
|
922
|
+
this.onStopMusicHandler();
|
|
923
|
+
super._onPreDestroy();
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
__decorate([property$8({
|
|
927
|
+
tooltip: `类型:
|
|
928
|
+
EFFECT 音效
|
|
929
|
+
BGM 音乐`,
|
|
930
|
+
type: Enum(AudioTypeEnum)
|
|
931
|
+
}), __metadata("design:type", Number)], AudioSourceUILayer.prototype, "type", void 0);
|
|
932
|
+
__decorate([property$8({
|
|
933
|
+
tooltip: '音源',
|
|
934
|
+
type: AudioClip
|
|
935
|
+
}), __metadata("design:type", AudioClip)], AudioSourceUILayer.prototype, "clip", void 0);
|
|
936
|
+
__decorate([property$8({
|
|
937
|
+
tooltip: '循环'
|
|
938
|
+
}), __metadata("design:type", Boolean)], AudioSourceUILayer.prototype, "loop", void 0);
|
|
939
|
+
__decorate([property$8({
|
|
940
|
+
tooltip: '音量'
|
|
941
|
+
}), __metadata("design:type", Number)], AudioSourceUILayer.prototype, "volume", void 0);
|
|
942
|
+
__decorate([property$8({
|
|
943
|
+
tooltip: '是否启用自动播放'
|
|
944
|
+
}), __metadata("design:type", Boolean)], AudioSourceUILayer.prototype, "playOnAwake", void 0);
|
|
945
|
+
|
|
946
|
+
const {
|
|
947
|
+
ccclass: ccclass$7,
|
|
948
|
+
property: property$7,
|
|
949
|
+
menu: menu$7
|
|
950
|
+
} = _decorator;
|
|
951
|
+
var ToastType;
|
|
952
|
+
(function (ToastType) {
|
|
953
|
+
ToastType[ToastType["FIXED"] = 0] = "FIXED";
|
|
954
|
+
ToastType[ToastType["SLIDE"] = 1] = "SLIDE";
|
|
955
|
+
})(ToastType || (ToastType = {}));
|
|
956
|
+
let CoreToast = class CoreToast extends BaseComponent {
|
|
957
|
+
fixed_node;
|
|
958
|
+
slide_node;
|
|
959
|
+
fixed_label;
|
|
960
|
+
slide_label;
|
|
961
|
+
onLoad() {
|
|
962
|
+
this.fixed_node.active = this.slide_node.active = false;
|
|
963
|
+
}
|
|
964
|
+
start() {
|
|
965
|
+
this.show();
|
|
966
|
+
}
|
|
967
|
+
async show() {
|
|
968
|
+
return new _Promise(async (resolve, _reject) => {
|
|
969
|
+
const {
|
|
970
|
+
title,
|
|
971
|
+
type,
|
|
972
|
+
fixed_time
|
|
973
|
+
} = this.props;
|
|
974
|
+
if (type == ToastType.FIXED) {
|
|
975
|
+
this.fixed_node.active = true;
|
|
976
|
+
this.fixed_label.string = `${title}`;
|
|
977
|
+
// v2.4
|
|
978
|
+
// this.fixed_label['_forceUpdateRenderData'](true);
|
|
979
|
+
// v3.0
|
|
980
|
+
// this.fixed_label.updateRenderData(true);
|
|
981
|
+
// const fixed_label_height = this.fixed_label.node.getComponent(UITransform)!.height;
|
|
982
|
+
// const fixed_node_height = this.fixed_node.getComponent(UITransform)!.height;
|
|
983
|
+
// if (fixed_label_height - fixed_node_height > 0) {
|
|
984
|
+
// this.fixed_node.getComponent(UITransform)!.height = fixed_label_height + 100;
|
|
985
|
+
// }
|
|
986
|
+
this.scheduleOnce(() => {
|
|
987
|
+
this.node.destroy();
|
|
988
|
+
resolve();
|
|
989
|
+
}, fixed_time);
|
|
990
|
+
} else {
|
|
991
|
+
this.slide_node.active = true;
|
|
992
|
+
this.slide_label.string = `${title}`;
|
|
993
|
+
// v2.4通过LAYOUT组件实现
|
|
994
|
+
// this.slide_label['_forceUpdateRenderData'](true);
|
|
995
|
+
// v3.0
|
|
996
|
+
// this.slide_label.updateRenderData(true);
|
|
997
|
+
// const deslabelW = this.slide_label.node.getComponent(UITransform)!.width;
|
|
998
|
+
// const bgw = this.slide_node.getComponent(UITransform)!.width;
|
|
999
|
+
// if (bgw - deslabelW < 100) {
|
|
1000
|
+
// this.slide_node.getComponent(UITransform)!.width = deslabelW + 100;
|
|
1001
|
+
// }
|
|
1002
|
+
this.playAnim(this.node).then(() => {
|
|
1003
|
+
resolve();
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
playAnim(node) {
|
|
1009
|
+
return new _Promise((resolve, reject) => {
|
|
1010
|
+
const delay = 1.2;
|
|
1011
|
+
const duration = 0.5;
|
|
1012
|
+
const uiOpacity = this.node.getComponent(UIOpacity);
|
|
1013
|
+
const uiOpacityTween = tween(uiOpacity).delay(delay).to(duration, {
|
|
1014
|
+
opacity: 0
|
|
1015
|
+
}).call(() => {
|
|
1016
|
+
Tween.stopAllByTarget(node);
|
|
1017
|
+
this.node.destroy();
|
|
1018
|
+
resolve();
|
|
1019
|
+
});
|
|
1020
|
+
tween(node).by(duration, {
|
|
1021
|
+
position: v3(0, 400, 0)
|
|
1022
|
+
}).call(() => {
|
|
1023
|
+
uiOpacityTween.start();
|
|
1024
|
+
}).start();
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
onDestroy() {
|
|
1028
|
+
Tween.stopAllByTarget(this.node);
|
|
1029
|
+
this.unscheduleAllCallbacks();
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
__decorate([property$7({
|
|
1033
|
+
type: Node,
|
|
1034
|
+
tooltip: '固定节点'
|
|
1035
|
+
}), __metadata("design:type", Node)], CoreToast.prototype, "fixed_node", void 0);
|
|
1036
|
+
__decorate([property$7({
|
|
1037
|
+
type: Node,
|
|
1038
|
+
tooltip: '滑动节点'
|
|
1039
|
+
}), __metadata("design:type", Node)], CoreToast.prototype, "slide_node", void 0);
|
|
1040
|
+
__decorate([property$7({
|
|
1041
|
+
type: Label,
|
|
1042
|
+
tooltip: '固定标签节点'
|
|
1043
|
+
}), __metadata("design:type", Label)], CoreToast.prototype, "fixed_label", void 0);
|
|
1044
|
+
__decorate([property$7({
|
|
1045
|
+
type: Label,
|
|
1046
|
+
tooltip: '滑动标签节点'
|
|
1047
|
+
}), __metadata("design:type", Label)], CoreToast.prototype, "slide_label", void 0);
|
|
1048
|
+
CoreToast = __decorate([ccclass$7('CoreToast'), menu$7("CATCORE/CoreToast")], CoreToast);
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* @describe 全局事件监听方法
|
|
1052
|
+
* @author 游金宇(KM)
|
|
1053
|
+
* @date 2023-08-03 18:13:36
|
|
1054
|
+
*/
|
|
1055
|
+
var GlobalEventConstant;
|
|
1056
|
+
(function (GlobalEventConstant) {
|
|
1057
|
+
/** 游戏从后台进入 */
|
|
1058
|
+
GlobalEventConstant["EVENT_SHOW"] = "GlobalEventConstant/EVENT_SHOW";
|
|
1059
|
+
/** 游戏切到后台 */
|
|
1060
|
+
GlobalEventConstant["EVENT_HIDE"] = "GlobalEventConstant/EVENT_HIDE";
|
|
1061
|
+
/** 游戏画笔尺寸变化事件 */
|
|
1062
|
+
GlobalEventConstant["GAME_RESIZE"] = "GlobalEventConstant/GAME_RESIZE";
|
|
1063
|
+
/**游戏关闭时间 */
|
|
1064
|
+
GlobalEventConstant["EVENT_CLOSE"] = "GlobalEventConstant/EVENT_CLOSE";
|
|
1065
|
+
/**网络连接 */
|
|
1066
|
+
GlobalEventConstant["ONLINE"] = "GlobalEventConstant/ONLINE";
|
|
1067
|
+
/**网络断开 */
|
|
1068
|
+
GlobalEventConstant["OFFLINE"] = "GlobalEventConstant/OFFLINE";
|
|
1069
|
+
/**ROOT_MASK更新 */
|
|
1070
|
+
GlobalEventConstant["ROOT_MASK_UPDATE"] = "GlobalEventConstant/ROOT_MASK_UPDATE";
|
|
1071
|
+
/**ROOT_MASK更新变化 */
|
|
1072
|
+
GlobalEventConstant["ROOT_MASK_CHANGE"] = "GlobalEventConstant/ROOT_MASK_CHANGE";
|
|
1073
|
+
})(GlobalEventConstant || (GlobalEventConstant = {}));
|
|
1074
|
+
|
|
1075
|
+
/**遮罩管理 TODO (每个层级都有一个遮罩 但是同时只能出现1个) */
|
|
1076
|
+
const {
|
|
1077
|
+
ccclass: ccclass$6,
|
|
1078
|
+
property: property$6,
|
|
1079
|
+
menu: menu$6
|
|
1080
|
+
} = _decorator;
|
|
1081
|
+
let CoreBlackMask = class CoreBlackMask extends BaseComponent {
|
|
1082
|
+
tween;
|
|
1083
|
+
};
|
|
1084
|
+
__decorate([property$6({
|
|
1085
|
+
type: Node,
|
|
1086
|
+
tooltip: '动画节点'
|
|
1087
|
+
}), __metadata("design:type", Node)], CoreBlackMask.prototype, "tween", void 0);
|
|
1088
|
+
CoreBlackMask = __decorate([ccclass$6('CoreBlackMask'), menu$6("CATCORE/CoreBlackMask")], CoreBlackMask);
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* @describe UI容器管理 在场景节点下 会随着场景销毁(非常驻节点)
|
|
1092
|
+
* @author 游金宇(KM)
|
|
1093
|
+
* @date 2024-09-12 11:45:31
|
|
1094
|
+
*/
|
|
1095
|
+
const {
|
|
1096
|
+
ccclass: ccclass$5,
|
|
1097
|
+
property: property$5,
|
|
1098
|
+
menu: menu$5
|
|
1099
|
+
} = _decorator;
|
|
1100
|
+
let CoreUIContainer = class CoreUIContainer extends UILayer {
|
|
1101
|
+
scene_mask_node;
|
|
1102
|
+
ui_container;
|
|
1103
|
+
gui = null;
|
|
1104
|
+
onLoad() {
|
|
1105
|
+
this.setSceneMaskActive(false);
|
|
1106
|
+
}
|
|
1107
|
+
get scene_mask() {
|
|
1108
|
+
return this.scene_mask_node.getComponent(CoreBlackMask);
|
|
1109
|
+
}
|
|
1110
|
+
get brother() {
|
|
1111
|
+
return this.ui_container.children || [];
|
|
1112
|
+
}
|
|
1113
|
+
get tweenChildren() {
|
|
1114
|
+
return this.scene_mask.tween.children;
|
|
1115
|
+
}
|
|
1116
|
+
onEventListener() {
|
|
1117
|
+
this.cat.event.on(GlobalEventConstant.ROOT_MASK_CHANGE, this.uiMaskChanged, this);
|
|
1118
|
+
}
|
|
1119
|
+
/**增加层级 */
|
|
1120
|
+
addMask() {
|
|
1121
|
+
const last = this.brother[this.brother.length - 1];
|
|
1122
|
+
last && this.scene_mask.node.setSiblingIndex(last.getSiblingIndex());
|
|
1123
|
+
this.blockMaskSiblingIndexChanged();
|
|
1124
|
+
}
|
|
1125
|
+
/**减少层级 */
|
|
1126
|
+
subMask() {
|
|
1127
|
+
const last = this.brother[this.brother.length - 2];
|
|
1128
|
+
last && this.scene_mask.node.setSiblingIndex(last.getSiblingIndex());
|
|
1129
|
+
this.blockMaskSiblingIndexChanged();
|
|
1130
|
+
}
|
|
1131
|
+
blockMaskSiblingIndexChanged() {
|
|
1132
|
+
this.tweenChildren.length > 1 || this.brother.length > 1 ? this.show() : this.hide();
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* 将UI节点挂载在tween上执行动画
|
|
1136
|
+
* @param node 节点
|
|
1137
|
+
*/
|
|
1138
|
+
addNodeToTween(node) {
|
|
1139
|
+
if (isValid(this) && this.scene_mask) {
|
|
1140
|
+
this.scene_mask.tween.addChild(node);
|
|
1141
|
+
}
|
|
1142
|
+
return this;
|
|
1143
|
+
}
|
|
1144
|
+
show() {
|
|
1145
|
+
this.setSceneMaskActive(true);
|
|
1146
|
+
}
|
|
1147
|
+
hide() {
|
|
1148
|
+
this.setSceneMaskActive(false);
|
|
1149
|
+
}
|
|
1150
|
+
setGui(gui) {
|
|
1151
|
+
this.gui = gui;
|
|
1152
|
+
return this;
|
|
1153
|
+
}
|
|
1154
|
+
/**根层的变化 */
|
|
1155
|
+
uiMaskChanged() {
|
|
1156
|
+
this.blockMaskSiblingIndexChanged();
|
|
1157
|
+
}
|
|
1158
|
+
setSceneMaskActive(active) {
|
|
1159
|
+
this.scene_mask.node.active = active;
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
__decorate([property$5({
|
|
1163
|
+
type: Node
|
|
1164
|
+
}), __metadata("design:type", Node)], CoreUIContainer.prototype, "scene_mask_node", void 0);
|
|
1165
|
+
__decorate([property$5({
|
|
1166
|
+
type: Node
|
|
1167
|
+
}), __metadata("design:type", Node)], CoreUIContainer.prototype, "ui_container", void 0);
|
|
1168
|
+
CoreUIContainer = __decorate([ccclass$5('CoreUIContainer'), menu$5("CATCORE/CoreUIContainer")], CoreUIContainer);
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* @describe 根级别的UI层 所有的ROOT UI层需继承自该自组件
|
|
1172
|
+
* @author 游金宇(KM)
|
|
1173
|
+
* @date 2023-08-04 10:42:26
|
|
1174
|
+
*/
|
|
1175
|
+
class RootUILayer extends UILayer {
|
|
1176
|
+
onEnable() {
|
|
1177
|
+
super.onEnable();
|
|
1178
|
+
this.updateMask();
|
|
1179
|
+
}
|
|
1180
|
+
onDisable() {
|
|
1181
|
+
super.onDisable();
|
|
1182
|
+
this.updateMask();
|
|
1183
|
+
}
|
|
1184
|
+
updateMask() {
|
|
1185
|
+
this.cat.event.emit(GlobalEventConstant.ROOT_MASK_UPDATE);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
const {
|
|
1190
|
+
ccclass: ccclass$4,
|
|
1191
|
+
property: property$4,
|
|
1192
|
+
menu: menu$4
|
|
1193
|
+
} = _decorator;
|
|
1194
|
+
/**
|
|
1195
|
+
* @describe 加载框
|
|
1196
|
+
* @author 游金宇(KM)
|
|
1197
|
+
* @date 2024-09-12 11:49:51
|
|
1198
|
+
*/
|
|
1199
|
+
let CoreShowLoading = class CoreShowLoading extends RootUILayer {
|
|
1200
|
+
title;
|
|
1201
|
+
loadingTween;
|
|
1202
|
+
// @property({ type: Node, tooltip: '遮罩' })
|
|
1203
|
+
// black: Node
|
|
1204
|
+
loading_rotate = 0;
|
|
1205
|
+
onAutoObserver() {
|
|
1206
|
+
this.addAutorun([() => {
|
|
1207
|
+
if (this.props?.title) {
|
|
1208
|
+
this.title.string = `${this.props?.title}`;
|
|
1209
|
+
}
|
|
1210
|
+
this.title.node.active = !!this.props?.title?.length;
|
|
1211
|
+
}, () => {
|
|
1212
|
+
this.getComponent(BlockInputEvents).enabled = !!this.props?.mask;
|
|
1213
|
+
}]);
|
|
1214
|
+
}
|
|
1215
|
+
update(deltaTime) {
|
|
1216
|
+
this.loading_rotate += deltaTime * 220;
|
|
1217
|
+
this.loadingTween.setRotationFromEuler(0, 0, -this.loading_rotate % 360);
|
|
1218
|
+
if (this.loading_rotate > 360) {
|
|
1219
|
+
this.loading_rotate -= 360;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
__decorate([property$4({
|
|
1224
|
+
type: Label,
|
|
1225
|
+
tooltip: '标题'
|
|
1226
|
+
}), __metadata("design:type", Label)], CoreShowLoading.prototype, "title", void 0);
|
|
1227
|
+
__decorate([property$4({
|
|
1228
|
+
type: Node,
|
|
1229
|
+
tooltip: '动画'
|
|
1230
|
+
}), __metadata("design:type", Node
|
|
1231
|
+
// @property({ type: Node, tooltip: '遮罩' })
|
|
1232
|
+
// black: Node
|
|
1233
|
+
)], CoreShowLoading.prototype, "loadingTween", void 0);
|
|
1234
|
+
CoreShowLoading = __decorate([ccclass$4('CoreShowLoading'), menu$4("CATCORE/CoreShowLoading")], CoreShowLoading);
|
|
1235
|
+
|
|
1236
|
+
var ReconnectPrompt;
|
|
1237
|
+
(function (ReconnectPrompt) {
|
|
1238
|
+
ReconnectPrompt["RECONNECTED"] = "\u91CD\u8FDE\u6210\u529F";
|
|
1239
|
+
ReconnectPrompt["RECONNECTING"] = "\u6B63\u5728\u91CD\u8FDE";
|
|
1240
|
+
ReconnectPrompt["MAX_RECONNECT"] = "\u91CD\u8FDE\u6B21\u6570\u8D85\u51FA\u9650\u5236,\u8BF7\u68C0\u67E5\u7F51\u7EDC";
|
|
1241
|
+
ReconnectPrompt["RECONNECTED_ERROR"] = "\u91CD\u8FDE\u5931\u8D25,\u8BF7\u68C0\u67E5\u7F51\u7EDC";
|
|
1242
|
+
ReconnectPrompt["CONNECT_PARAM_ERROR"] = "\u6E38\u620F\u53C2\u6570\u9519\u8BEF,\u8BF7\u91CD\u65B0\u52A0\u8F7D";
|
|
1243
|
+
ReconnectPrompt["KICK"] = "\u8D26\u53F7\u5DF2\u4E0B\u7EBF";
|
|
1244
|
+
ReconnectPrompt["OFFLINE"] = "\u7F51\u7EDC\u5DF2\u65AD\u5F00";
|
|
1245
|
+
ReconnectPrompt["ONLINE"] = "\u7F51\u7EDC\u5DF2\u8FDE\u63A5";
|
|
1246
|
+
ReconnectPrompt["GAME_ERROR"] = "\u8FDE\u63A5\u6E38\u620F\u670D\u9519\u8BEF";
|
|
1247
|
+
})(ReconnectPrompt || (ReconnectPrompt = {}));
|
|
1248
|
+
|
|
1249
|
+
const {
|
|
1250
|
+
ccclass: ccclass$3,
|
|
1251
|
+
property: property$3,
|
|
1252
|
+
menu: menu$3
|
|
1253
|
+
} = _decorator;
|
|
1254
|
+
/**
|
|
1255
|
+
* @describe 重连框
|
|
1256
|
+
* @author 游金宇(KM)
|
|
1257
|
+
* @date 2024-09-12 11:49:51
|
|
1258
|
+
*/
|
|
1259
|
+
let CoreReconnection = class CoreReconnection extends RootUILayer {
|
|
1260
|
+
common_prompt_text;
|
|
1261
|
+
btn_confirm;
|
|
1262
|
+
btn_close;
|
|
1263
|
+
is_close = false;
|
|
1264
|
+
props = {
|
|
1265
|
+
content: null
|
|
1266
|
+
};
|
|
1267
|
+
initUI() {}
|
|
1268
|
+
onLoad() {
|
|
1269
|
+
this.btn_confirm.node.on(Button.EventType.CLICK, this.onConfirmHandler, this);
|
|
1270
|
+
this.btn_close.node.on(Button.EventType.CLICK, this.onConfirmHandler, this);
|
|
1271
|
+
this.addAutorun([() => {
|
|
1272
|
+
this.common_prompt_text.string = this.props.content ?? '';
|
|
1273
|
+
}]);
|
|
1274
|
+
}
|
|
1275
|
+
onDestroy() {
|
|
1276
|
+
this.unscheduleAllCallbacks();
|
|
1277
|
+
// this.is_close && cat.platform.back()
|
|
1278
|
+
}
|
|
1279
|
+
updateProps(props) {
|
|
1280
|
+
this.updatePromptText(props, props == ReconnectPrompt.RECONNECTING);
|
|
1281
|
+
}
|
|
1282
|
+
/**更新提示文案 */
|
|
1283
|
+
updatePromptText(text) {
|
|
1284
|
+
let isAnim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1285
|
+
// 停止之前的动画效果
|
|
1286
|
+
this.unscheduleAllCallbacks();
|
|
1287
|
+
this.props.content = text;
|
|
1288
|
+
log('更新提示文案:', text);
|
|
1289
|
+
// 如果需要应用动画效果
|
|
1290
|
+
if (isAnim) {
|
|
1291
|
+
let index = 0;
|
|
1292
|
+
const updateText = () => {
|
|
1293
|
+
index = (index + 1) % 4;
|
|
1294
|
+
this.common_prompt_text.string = text + ['', '·', '··', '···'][index];
|
|
1295
|
+
};
|
|
1296
|
+
this.schedule(updateText, 0.5);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
onConfirmHandler() {
|
|
1300
|
+
this.is_close = true;
|
|
1301
|
+
// 销毁ws
|
|
1302
|
+
// cat.ws.destroy()
|
|
1303
|
+
// gui.close(this)
|
|
1304
|
+
this.cat.gui.hideReconnect();
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
__decorate([property$3({
|
|
1308
|
+
type: Label,
|
|
1309
|
+
tooltip: '通用提示文本'
|
|
1310
|
+
}), __metadata("design:type", Label)], CoreReconnection.prototype, "common_prompt_text", void 0);
|
|
1311
|
+
__decorate([property$3({
|
|
1312
|
+
type: Button,
|
|
1313
|
+
tooltip: '确定按钮'
|
|
1314
|
+
}), __metadata("design:type", Button)], CoreReconnection.prototype, "btn_confirm", void 0);
|
|
1315
|
+
__decorate([property$3({
|
|
1316
|
+
type: Button,
|
|
1317
|
+
tooltip: '关闭按钮'
|
|
1318
|
+
}), __metadata("design:type", Button)], CoreReconnection.prototype, "btn_close", void 0);
|
|
1319
|
+
CoreReconnection = __decorate([ccclass$3('CoreReconnection'), menu$3("CATCORE/CoreReconnection")], CoreReconnection);
|
|
1320
|
+
|
|
1321
|
+
const {
|
|
1322
|
+
ccclass: ccclass$2,
|
|
1323
|
+
property: property$2,
|
|
1324
|
+
menu: menu$2
|
|
1325
|
+
} = _decorator;
|
|
1326
|
+
/**
|
|
1327
|
+
* @describe 通知框
|
|
1328
|
+
* @author 游金宇(KM)
|
|
1329
|
+
* @date 2024-09-12 11:49:51
|
|
1330
|
+
*/
|
|
1331
|
+
let CoreNotice = class CoreNotice extends RootUILayer {
|
|
1332
|
+
text;
|
|
1333
|
+
btn_confirm;
|
|
1334
|
+
btn_close;
|
|
1335
|
+
onLoad() {
|
|
1336
|
+
this.btn_confirm.node.on(Button.EventType.CLICK, this.onConfrimHandler, this);
|
|
1337
|
+
}
|
|
1338
|
+
start() {
|
|
1339
|
+
this.props && this.updateProps(this.props);
|
|
1340
|
+
}
|
|
1341
|
+
onConfrimHandler() {
|
|
1342
|
+
this.props?.confrim?.();
|
|
1343
|
+
this.cat.gui.hideNotice();
|
|
1344
|
+
}
|
|
1345
|
+
updateProps(props) {
|
|
1346
|
+
this.text.string = `${props.text}`;
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
__decorate([property$2({
|
|
1350
|
+
type: Label,
|
|
1351
|
+
tooltip: '提示文本'
|
|
1352
|
+
}), __metadata("design:type", Label)], CoreNotice.prototype, "text", void 0);
|
|
1353
|
+
__decorate([property$2({
|
|
1354
|
+
type: Button,
|
|
1355
|
+
tooltip: '确定按钮'
|
|
1356
|
+
}), __metadata("design:type", Button)], CoreNotice.prototype, "btn_confirm", void 0);
|
|
1357
|
+
__decorate([property$2({
|
|
1358
|
+
type: Button,
|
|
1359
|
+
tooltip: '关闭按钮'
|
|
1360
|
+
}), __metadata("design:type", Button)], CoreNotice.prototype, "btn_close", void 0);
|
|
1361
|
+
CoreNotice = __decorate([ccclass$2('CoreNotice'), menu$2("CATCORE/CoreNotice")], CoreNotice);
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* @describe Scene层 所有的UI层需继承自该自组件
|
|
1365
|
+
* @author 游金宇(KM)
|
|
1366
|
+
* @date 2023-08-04 10:42:26
|
|
1367
|
+
*/
|
|
1368
|
+
class SceneLayer extends BaseComponent {
|
|
1369
|
+
/**是否为重新加载场景 */
|
|
1370
|
+
isReload;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
const {
|
|
1374
|
+
ccclass: ccclass$1,
|
|
1375
|
+
property: property$1,
|
|
1376
|
+
menu: menu$1
|
|
1377
|
+
} = _decorator;
|
|
1378
|
+
var LayerType;
|
|
1379
|
+
(function (LayerType) {
|
|
1380
|
+
LayerType[LayerType["UI"] = 0] = "UI";
|
|
1381
|
+
/**加载 */
|
|
1382
|
+
LayerType[LayerType["LOADING"] = 1] = "LOADING";
|
|
1383
|
+
/**提示 */
|
|
1384
|
+
LayerType[LayerType["TOAST"] = 2] = "TOAST";
|
|
1385
|
+
/**断线重连 */
|
|
1386
|
+
LayerType[LayerType["RECONNECTTION"] = 3] = "RECONNECTTION";
|
|
1387
|
+
/**系统服务通知(停机维护) */
|
|
1388
|
+
LayerType[LayerType["NOTICE"] = 4] = "NOTICE";
|
|
1389
|
+
})(LayerType || (LayerType = {}));
|
|
1390
|
+
/**Gui层 */
|
|
1391
|
+
let Gui = class Gui extends BaseComponent {
|
|
1392
|
+
reconnection_ui_prefab;
|
|
1393
|
+
toast_ui_prefab;
|
|
1394
|
+
loading_ui_prefab;
|
|
1395
|
+
notice_ui_prefab;
|
|
1396
|
+
ui_prefab;
|
|
1397
|
+
root_ui;
|
|
1398
|
+
root_toast;
|
|
1399
|
+
root_mask;
|
|
1400
|
+
/**场景中的UI层 */
|
|
1401
|
+
ui_container_component;
|
|
1402
|
+
/**断线重连UI弹窗 */
|
|
1403
|
+
reconnection_ui_component;
|
|
1404
|
+
/**公告UI弹窗组件 */
|
|
1405
|
+
notice_ui_component;
|
|
1406
|
+
/**加载UI弹窗 */
|
|
1407
|
+
loading_ui_component;
|
|
1408
|
+
/**提示UI弹窗 */
|
|
1409
|
+
toast_ui_component;
|
|
1410
|
+
/**当前场景对象名 */
|
|
1411
|
+
currentScene;
|
|
1412
|
+
onEventListener() {
|
|
1413
|
+
this.cat.event.on(GlobalEventConstant.ROOT_MASK_UPDATE, this.onRootUpdate, this);
|
|
1414
|
+
}
|
|
1415
|
+
init(cat) {
|
|
1416
|
+
this.cat = cat;
|
|
1417
|
+
const scene = director.getScene();
|
|
1418
|
+
log('init scene');
|
|
1419
|
+
scene && this.changeScene(scene);
|
|
1420
|
+
return this;
|
|
1421
|
+
}
|
|
1422
|
+
start() {
|
|
1423
|
+
this.onRootUpdate();
|
|
1424
|
+
}
|
|
1425
|
+
toastQueue = [];
|
|
1426
|
+
isScheduling = false; // 新增调度锁
|
|
1427
|
+
minInterval = 0.2; // 改为秒单位,与scheduleOnce一致
|
|
1428
|
+
showToast(props) {
|
|
1429
|
+
this.toastQueue.push(props);
|
|
1430
|
+
if (!this.isScheduling) {
|
|
1431
|
+
this.processQueueWithInterval();
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
processQueueWithInterval() {
|
|
1435
|
+
if (this.toastQueue.length === 0) {
|
|
1436
|
+
this.isScheduling = false;
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
this.isScheduling = true;
|
|
1440
|
+
const props = this.toastQueue.shift();
|
|
1441
|
+
// 实际显示逻辑
|
|
1442
|
+
const show = () => {
|
|
1443
|
+
const node = instantiate(this.toast_ui_prefab);
|
|
1444
|
+
const toastComponent = node.getComponent(CoreToast);
|
|
1445
|
+
toastComponent.addToParent(this.root_toast, {
|
|
1446
|
+
props
|
|
1447
|
+
});
|
|
1448
|
+
// 使用游戏时间计算下一个
|
|
1449
|
+
this.scheduleOnce(() => {
|
|
1450
|
+
this.processQueueWithInterval();
|
|
1451
|
+
}, this.minInterval);
|
|
1452
|
+
};
|
|
1453
|
+
// 立即显示第一个
|
|
1454
|
+
if (this.root_toast.children.length === 0) {
|
|
1455
|
+
show();
|
|
1456
|
+
} else {
|
|
1457
|
+
this.scheduleOnce(show, this.minInterval);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
/** 隐藏并清除所有提示 */
|
|
1461
|
+
hideToast() {
|
|
1462
|
+
// 1. 销毁正在显示的Toast
|
|
1463
|
+
if (this.root_toast) {
|
|
1464
|
+
var _context;
|
|
1465
|
+
_forEachInstanceProperty(_context = this.root_toast.children).call(_context, child => {
|
|
1466
|
+
child.getComponent(CoreToast)?.removeAndDestroy();
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
// 2. 清空等待队列
|
|
1470
|
+
this.toastQueue = [];
|
|
1471
|
+
// 3. 取消预定的队列处理
|
|
1472
|
+
this.unschedule(this.processQueueWithInterval);
|
|
1473
|
+
this.isScheduling = false;
|
|
1474
|
+
return this;
|
|
1475
|
+
}
|
|
1476
|
+
/**显示Loading */
|
|
1477
|
+
showLoading() {
|
|
1478
|
+
let {
|
|
1479
|
+
title = '',
|
|
1480
|
+
mask = true,
|
|
1481
|
+
black = true
|
|
1482
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1483
|
+
log('showLoading', title);
|
|
1484
|
+
if (this.loading_ui_component) {
|
|
1485
|
+
this.loading_ui_component.setOptions({
|
|
1486
|
+
props: {
|
|
1487
|
+
title,
|
|
1488
|
+
mask,
|
|
1489
|
+
black
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
} else {
|
|
1493
|
+
const node = instantiate(this.loading_ui_prefab);
|
|
1494
|
+
this.loading_ui_component = node.getComponent(CoreShowLoading).addToParent(this.root_ui, {
|
|
1495
|
+
props: {
|
|
1496
|
+
title,
|
|
1497
|
+
mask,
|
|
1498
|
+
black
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
return this;
|
|
1503
|
+
}
|
|
1504
|
+
/**隐藏Loading */
|
|
1505
|
+
hideLoading() {
|
|
1506
|
+
this.loading_ui_component?.removeAndDestroy();
|
|
1507
|
+
this.loading_ui_component = null;
|
|
1508
|
+
return this;
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* 显示断线重连
|
|
1512
|
+
* @param option 状态提示文案
|
|
1513
|
+
*/
|
|
1514
|
+
showReconnect(option) {
|
|
1515
|
+
if (!this.reconnection_ui_component) {
|
|
1516
|
+
const node = instantiate(this.reconnection_ui_prefab);
|
|
1517
|
+
this.reconnection_ui_component = node.getComponent(CoreReconnection).addToParent(this.root_ui, {
|
|
1518
|
+
props: {
|
|
1519
|
+
content: option
|
|
1520
|
+
}
|
|
1521
|
+
});
|
|
1522
|
+
} else {
|
|
1523
|
+
this.reconnection_ui_component.setUpdateProps({
|
|
1524
|
+
content: option
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
return this;
|
|
1528
|
+
}
|
|
1529
|
+
/**隐藏断线重连 */
|
|
1530
|
+
hideReconnect() {
|
|
1531
|
+
this.reconnection_ui_component?.removeAndDestroy();
|
|
1532
|
+
this.reconnection_ui_component = null;
|
|
1533
|
+
return this;
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* 显示公告
|
|
1537
|
+
* @param option 参数
|
|
1538
|
+
*/
|
|
1539
|
+
showNotice(option) {
|
|
1540
|
+
const node = instantiate(this.notice_ui_prefab);
|
|
1541
|
+
this.notice_ui_component = node.getComponent(CoreNotice).addToParent(this.root_ui, {
|
|
1542
|
+
props: option
|
|
1543
|
+
});
|
|
1544
|
+
return this;
|
|
1545
|
+
}
|
|
1546
|
+
/**隐藏公告 */
|
|
1547
|
+
hideNotice() {
|
|
1548
|
+
this.notice_ui_component?.removeAndDestroy();
|
|
1549
|
+
return this;
|
|
1550
|
+
}
|
|
1551
|
+
loadScene(sceneName, options, isReload) {
|
|
1552
|
+
log('[加载场景名][参数][重新加载]', sceneName, options, isReload);
|
|
1553
|
+
let _options = {};
|
|
1554
|
+
let _isReload = isReload ?? true;
|
|
1555
|
+
if (typeof options === 'boolean') {
|
|
1556
|
+
_isReload = options;
|
|
1557
|
+
} else {
|
|
1558
|
+
_options = options ?? {};
|
|
1559
|
+
}
|
|
1560
|
+
director.once(Director.EVENT_BEFORE_SCENE_LAUNCH, scene => {
|
|
1561
|
+
log('Director.EVENT_BEFORE_SCENE_LAUNCH', scene);
|
|
1562
|
+
this.changeScene(scene, _options, _isReload);
|
|
1563
|
+
});
|
|
1564
|
+
if (typeof sceneName === 'string') {
|
|
1565
|
+
director.loadScene(sceneName);
|
|
1566
|
+
} else {
|
|
1567
|
+
director.runScene(sceneName);
|
|
1568
|
+
}
|
|
1569
|
+
return this;
|
|
1570
|
+
}
|
|
1571
|
+
/**重置场景(清除当前默认当前场景) */
|
|
1572
|
+
resetScene() {
|
|
1573
|
+
let sceneName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1574
|
+
sceneName = sceneName || this.currentScene;
|
|
1575
|
+
return this.loadScene(sceneName);
|
|
1576
|
+
}
|
|
1577
|
+
/**清除场景 */
|
|
1578
|
+
cleanScene() {
|
|
1579
|
+
// 清理全局UI
|
|
1580
|
+
this.resetScene().hideLoading().hideNotice().hideReconnect().hideToast();
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* 场景变化
|
|
1584
|
+
* @param scene 场景
|
|
1585
|
+
* @param options 选项
|
|
1586
|
+
* @param isReload 是否重新加载
|
|
1587
|
+
*/
|
|
1588
|
+
changeScene(scene, options, isReload) {
|
|
1589
|
+
this.currentScene = scene.name;
|
|
1590
|
+
// 获取当前场景
|
|
1591
|
+
// const canvas = scene.getComponentsInChildren(Canvas);
|
|
1592
|
+
// let ui2dCanvas = canvas.find(item => {
|
|
1593
|
+
// // return item.node.layer == Layers.Enum.UI_2D;
|
|
1594
|
+
// // UI_IN_SCENE
|
|
1595
|
+
// return item.node.layer == 2 ** 15;
|
|
1596
|
+
// });
|
|
1597
|
+
// if (!ui2dCanvas) {
|
|
1598
|
+
// ui2dCanvas = canvas.find(item => {
|
|
1599
|
+
// return item.node.layer == Layers.Enum.UI_2D;
|
|
1600
|
+
// });
|
|
1601
|
+
// }
|
|
1602
|
+
// const canvasNode = ui2dCanvas!.node;
|
|
1603
|
+
// 创建UI层
|
|
1604
|
+
this.createUILayer(scene);
|
|
1605
|
+
// 给场景传递属性值
|
|
1606
|
+
const crrentScene = scene.getComponentInChildren(SceneLayer);
|
|
1607
|
+
log('给场景传递属性值=======', crrentScene);
|
|
1608
|
+
if (crrentScene) {
|
|
1609
|
+
crrentScene.isReload = isReload ?? true;
|
|
1610
|
+
}
|
|
1611
|
+
// 更新场景props
|
|
1612
|
+
crrentScene?.setOptions(options);
|
|
1613
|
+
}
|
|
1614
|
+
createUILayer(scene) {
|
|
1615
|
+
this.ui_container_component?.removeAndDestroy();
|
|
1616
|
+
this.ui_container_component = null;
|
|
1617
|
+
const node = instantiate(this.ui_prefab);
|
|
1618
|
+
this.ui_container_component = node.getComponent(CoreUIContainer);
|
|
1619
|
+
this.ui_container_component?.setGui(this).addToParent(scene, this.node.getSiblingIndex());
|
|
1620
|
+
}
|
|
1621
|
+
/**重新加载当前场景 */
|
|
1622
|
+
reloadScene() {
|
|
1623
|
+
log('重新加载当前场景');
|
|
1624
|
+
this.loadScene(this.currentScene, true);
|
|
1625
|
+
}
|
|
1626
|
+
/**关闭UI */
|
|
1627
|
+
async closeUI(ui, options) {
|
|
1628
|
+
const {
|
|
1629
|
+
component
|
|
1630
|
+
} = this.findUIBaseLayer(ui, false);
|
|
1631
|
+
if (component) {
|
|
1632
|
+
component.setOptions({
|
|
1633
|
+
...(options?.hook ?? {}),
|
|
1634
|
+
...(options?.props ?? {})
|
|
1635
|
+
});
|
|
1636
|
+
// 调用uiNode组件下的showTween方法
|
|
1637
|
+
await component.hideTween(options || {});
|
|
1638
|
+
// 移除层级遮罩
|
|
1639
|
+
this.ui_container_component?.subMask();
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* 打开ui层
|
|
1644
|
+
* @param ui 界面的节点或组件
|
|
1645
|
+
* @param options 动画参数选项
|
|
1646
|
+
*/
|
|
1647
|
+
async openUI(ui, options) {
|
|
1648
|
+
// 查询根节点
|
|
1649
|
+
const {
|
|
1650
|
+
rootNode,
|
|
1651
|
+
component
|
|
1652
|
+
} = this.findUIBaseLayer(ui, true);
|
|
1653
|
+
// 获取根组件
|
|
1654
|
+
rootNode.getComponent(UILayer);
|
|
1655
|
+
// 配置选项
|
|
1656
|
+
component?.setOptions(options);
|
|
1657
|
+
// 动画
|
|
1658
|
+
if (rootNode) {
|
|
1659
|
+
// 添加层级遮罩
|
|
1660
|
+
this.ui_container_component?.addNodeToTween(rootNode).addMask();
|
|
1661
|
+
}
|
|
1662
|
+
if (component) {
|
|
1663
|
+
// 调用uiNode组件下的showTween方法
|
|
1664
|
+
await component.showTween(options || {});
|
|
1665
|
+
}
|
|
1666
|
+
// 运动结束之后,添加界面到UI层
|
|
1667
|
+
this.ui_container_component?.ui_container && component?.addToParent(this.ui_container_component.ui_container);
|
|
1668
|
+
}
|
|
1669
|
+
/**根据节点或组件 查询根UI层(继承自UILayer的)节点或组件 */
|
|
1670
|
+
findUIBaseLayer(ui, isOpen) {
|
|
1671
|
+
let rootNode;
|
|
1672
|
+
let component = null;
|
|
1673
|
+
if (ui instanceof Node) {
|
|
1674
|
+
var _context2;
|
|
1675
|
+
// ui为节点
|
|
1676
|
+
rootNode = ui;
|
|
1677
|
+
// 获取组件
|
|
1678
|
+
const extendsBaseLayer = _filterInstanceProperty(_context2 = ui.components).call(_context2, item => {
|
|
1679
|
+
return item instanceof UILayer;
|
|
1680
|
+
});
|
|
1681
|
+
if (extendsBaseLayer.length) {
|
|
1682
|
+
if (extendsBaseLayer.length == 1) {
|
|
1683
|
+
component = extendsBaseLayer[0];
|
|
1684
|
+
} else {
|
|
1685
|
+
warn(`${ui.name}节点存在多个继承自BaseLayer的组件`);
|
|
1686
|
+
}
|
|
1687
|
+
} else {
|
|
1688
|
+
error(`${ui.name}节点未找到继承自BaseLayer的组件`);
|
|
1689
|
+
return {
|
|
1690
|
+
rootNode,
|
|
1691
|
+
component
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
} else {
|
|
1695
|
+
// ui为T组件
|
|
1696
|
+
// 定义一个变量用于保存根节点
|
|
1697
|
+
rootNode = ui.node;
|
|
1698
|
+
component = ui;
|
|
1699
|
+
if (isOpen) {
|
|
1700
|
+
// 循环向上查找根节点,直到找到没有父节点的节点
|
|
1701
|
+
while (rootNode.parent) {
|
|
1702
|
+
rootNode = rootNode.parent;
|
|
1703
|
+
}
|
|
1704
|
+
component.root = rootNode;
|
|
1705
|
+
} else {
|
|
1706
|
+
rootNode = ui.root;
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
return {
|
|
1710
|
+
rootNode,
|
|
1711
|
+
component
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
/**根层的变化 */
|
|
1715
|
+
onRootUpdate() {
|
|
1716
|
+
// 如果根ui节点 没有子节点 则隐藏根遮罩
|
|
1717
|
+
const last_active_index = this.root_ui.children.findLastIndex(item => item.active && item != this.root_mask);
|
|
1718
|
+
// 显示
|
|
1719
|
+
this.root_mask.active = last_active_index != -1;
|
|
1720
|
+
// 调整层级
|
|
1721
|
+
if (last_active_index > -1) {
|
|
1722
|
+
// 更新根遮罩层级
|
|
1723
|
+
const last = this.root_ui.children[last_active_index];
|
|
1724
|
+
const nonce = last.getSiblingIndex() - 1;
|
|
1725
|
+
this.root_mask.setSiblingIndex(nonce < 0 ? 0 : nonce);
|
|
1726
|
+
}
|
|
1727
|
+
// 通知ui层级变化
|
|
1728
|
+
this.cat.event.emit(GlobalEventConstant.ROOT_MASK_CHANGE);
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
__decorate([property$1({
|
|
1732
|
+
type: Prefab,
|
|
1733
|
+
tooltip: '断线重连UI预制体'
|
|
1734
|
+
}), __metadata("design:type", Prefab)], Gui.prototype, "reconnection_ui_prefab", void 0);
|
|
1735
|
+
__decorate([property$1({
|
|
1736
|
+
type: Prefab,
|
|
1737
|
+
tooltip: '提示UI预制体'
|
|
1738
|
+
}), __metadata("design:type", Prefab)], Gui.prototype, "toast_ui_prefab", void 0);
|
|
1739
|
+
__decorate([property$1({
|
|
1740
|
+
type: Prefab,
|
|
1741
|
+
tooltip: '加载UI预制体'
|
|
1742
|
+
}), __metadata("design:type", Prefab)], Gui.prototype, "loading_ui_prefab", void 0);
|
|
1743
|
+
__decorate([property$1({
|
|
1744
|
+
type: Prefab,
|
|
1745
|
+
tooltip: '公告UI预制体'
|
|
1746
|
+
}), __metadata("design:type", Prefab)], Gui.prototype, "notice_ui_prefab", void 0);
|
|
1747
|
+
__decorate([property$1({
|
|
1748
|
+
type: Prefab,
|
|
1749
|
+
tooltip: 'UI层预制体'
|
|
1750
|
+
}), __metadata("design:type", Prefab)], Gui.prototype, "ui_prefab", void 0);
|
|
1751
|
+
__decorate([property$1({
|
|
1752
|
+
type: Node,
|
|
1753
|
+
tooltip: 'root-UI层'
|
|
1754
|
+
}), __metadata("design:type", Node)], Gui.prototype, "root_ui", void 0);
|
|
1755
|
+
__decorate([property$1({
|
|
1756
|
+
type: Node,
|
|
1757
|
+
tooltip: 'root-组件层'
|
|
1758
|
+
}), __metadata("design:type", Node)], Gui.prototype, "root_toast", void 0);
|
|
1759
|
+
__decorate([property$1({
|
|
1760
|
+
type: Node,
|
|
1761
|
+
tooltip: 'root-mask'
|
|
1762
|
+
}), __metadata("design:type", Node
|
|
1763
|
+
/**场景中的UI层 */)], Gui.prototype, "root_mask", void 0);
|
|
1764
|
+
Gui = __decorate([ccclass$1('Gui'), menu$1("CATCORE/Gui")], Gui);
|
|
1765
|
+
|
|
1766
|
+
/**预制体路径 */
|
|
1767
|
+
var BasePrefab;
|
|
1768
|
+
(function (BasePrefab) {
|
|
1769
|
+
BasePrefab["Root"] = "prefabs/root";
|
|
1770
|
+
BasePrefab["Toast"] = "prefabs/toast";
|
|
1771
|
+
BasePrefab["BlackMask"] = "prefabs/black-mask";
|
|
1772
|
+
BasePrefab["Loading"] = "prefabs/loading";
|
|
1773
|
+
BasePrefab["Notice"] = "prefabs/notice";
|
|
1774
|
+
BasePrefab["Reconnection"] = "prefabs/reconnection";
|
|
1775
|
+
})(BasePrefab || (BasePrefab = {}));
|
|
1776
|
+
class GuiManager extends BaseManager {
|
|
1777
|
+
/**常驻顶层UI节点层级 */
|
|
1778
|
+
gui;
|
|
1779
|
+
#bundleName = 'core';
|
|
1780
|
+
/**
|
|
1781
|
+
* 获取预制体
|
|
1782
|
+
* @param type 类型
|
|
1783
|
+
* @returns
|
|
1784
|
+
*/
|
|
1785
|
+
getGuiPrefabByType = (bundleName, type) => {
|
|
1786
|
+
return new _Promise((resolve, reject) => {
|
|
1787
|
+
log(bundleName, `${type}`);
|
|
1788
|
+
this.cat.res.load(bundleName, type, (err, prefab) => {
|
|
1789
|
+
if (err) {
|
|
1790
|
+
reject(err);
|
|
1791
|
+
} else {
|
|
1792
|
+
resolve(prefab);
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
});
|
|
1796
|
+
};
|
|
1797
|
+
/**初始化 */
|
|
1798
|
+
async init() {
|
|
1799
|
+
this.cat.gui_bundle_name && (this.#bundleName = this.cat.gui_bundle_name);
|
|
1800
|
+
// 初始化常驻节点
|
|
1801
|
+
const root_prefab = await this.getGuiPrefabByType(this.#bundleName, BasePrefab.Root);
|
|
1802
|
+
const root = instantiate(root_prefab);
|
|
1803
|
+
this.gui = root.getComponent(Gui).init(this.cat);
|
|
1804
|
+
director.addPersistRootNode(root);
|
|
1805
|
+
// 更新场景
|
|
1806
|
+
return this;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
class WrapperSocialGameClient extends SocialGameClient {
|
|
1811
|
+
/**是否弹出请求错误信息 */
|
|
1812
|
+
showRequestErrInfo = false;
|
|
1813
|
+
/**日志黑名单 */
|
|
1814
|
+
logBlackList = [];
|
|
1815
|
+
ignore = item => {
|
|
1816
|
+
var _context;
|
|
1817
|
+
return _includesInstanceProperty(_context = this.logBlackList).call(_context, item);
|
|
1818
|
+
};
|
|
1819
|
+
constructor(name, opts, eventResponsePairs, clientOption) {
|
|
1820
|
+
super(opts, eventResponsePairs, clientOption, name);
|
|
1821
|
+
this.showRequestErrInfo = clientOption?.showRequestErrInfo ?? false;
|
|
1822
|
+
}
|
|
1823
|
+
destroy() {
|
|
1824
|
+
this.disconnect(true);
|
|
1825
|
+
_globalThis._cat.socialGameClient.unregister(this);
|
|
1826
|
+
}
|
|
1827
|
+
async GameRequest(route, req, res) {
|
|
1828
|
+
let {
|
|
1829
|
+
forwardReq = false,
|
|
1830
|
+
forwardResp = false
|
|
1831
|
+
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1832
|
+
return new _Promise((resolve, reject) => {
|
|
1833
|
+
super.GameRequest(route, req, res, {
|
|
1834
|
+
forwardReq,
|
|
1835
|
+
forwardResp
|
|
1836
|
+
}).then(res => {
|
|
1837
|
+
if (DEBUG) {
|
|
1838
|
+
log(`%c ws服务端消息 %c [Response][${new Date()}] %c ${route} %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', req);
|
|
1839
|
+
}
|
|
1840
|
+
resolve(res);
|
|
1841
|
+
}, err => {
|
|
1842
|
+
error(err);
|
|
1843
|
+
this.showRequestErrInfo && err?.msg && _globalThis._cat.gui.showToast({
|
|
1844
|
+
title: err.msg
|
|
1845
|
+
});
|
|
1846
|
+
reject(err);
|
|
1847
|
+
});
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
subscribe(route, respType, fn) {
|
|
1851
|
+
super.subscribe(route, respType, data => {
|
|
1852
|
+
if (DEBUG && !this.ignore(route)) {
|
|
1853
|
+
log(`%c ws服务端消息:[subscribe][${new Date()}] %c ${route} %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', data);
|
|
1854
|
+
}
|
|
1855
|
+
_globalThis._cat.event.emit(route, data);
|
|
1856
|
+
fn?.(data);
|
|
1857
|
+
});
|
|
1858
|
+
return this;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
// ---------------------- 新增管理类 ----------------------
|
|
1863
|
+
class SocialGameClientManager extends BaseManager {
|
|
1864
|
+
managedClients = (() => new _Map())();
|
|
1865
|
+
/**在线 */
|
|
1866
|
+
isGlobalOnline = true;
|
|
1867
|
+
/**在后台 */
|
|
1868
|
+
isInBackground = false;
|
|
1869
|
+
/**正在重连 */
|
|
1870
|
+
reconnecting = false;
|
|
1871
|
+
/**后台委托 */
|
|
1872
|
+
onEventHideDelegate = (() => new AsyncDelegate())();
|
|
1873
|
+
/**前台委托 */
|
|
1874
|
+
onEventShowDelegate = (() => new AsyncDelegate())();
|
|
1875
|
+
/**重载场景委托 */
|
|
1876
|
+
onEventReloadSceneDelegate = (() => new AsyncDelegate())();
|
|
1877
|
+
/**重连定时器 */
|
|
1878
|
+
reconnectTimer = null;
|
|
1879
|
+
scheduleReconnect() {
|
|
1880
|
+
let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2000;
|
|
1881
|
+
if (this.reconnectTimer) {
|
|
1882
|
+
clearTimeout(this.reconnectTimer);
|
|
1883
|
+
this.reconnectTimer = null;
|
|
1884
|
+
}
|
|
1885
|
+
this.reconnectTimer = _setTimeout(() => {
|
|
1886
|
+
this.reconnectTimer = null;
|
|
1887
|
+
this.triggerReconnectAll();
|
|
1888
|
+
}, delay);
|
|
1889
|
+
}
|
|
1890
|
+
get activeClients() {
|
|
1891
|
+
var _context, _context2;
|
|
1892
|
+
return _filterInstanceProperty(_context = _mapInstanceProperty(_context2 = _Array$from(this.managedClients)).call(_context2, _ref => {
|
|
1893
|
+
let [_, client] = _ref;
|
|
1894
|
+
return client;
|
|
1895
|
+
})).call(_context, client => client.socket);
|
|
1896
|
+
}
|
|
1897
|
+
constructor(cat) {
|
|
1898
|
+
super(cat);
|
|
1899
|
+
this.initGlobalListeners();
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* 创建并注册WebSocket客户端
|
|
1903
|
+
* @param name 客户端唯一标识(如"game", "room")
|
|
1904
|
+
* @param clientOption 客户端配置选项
|
|
1905
|
+
* @param opts 社交游戏选项
|
|
1906
|
+
* @param eventResponsePairs 事件响应配置
|
|
1907
|
+
*/
|
|
1908
|
+
createWebSocket(name, clientOption, opts, eventResponsePairs) {
|
|
1909
|
+
// 清理同名旧客户端
|
|
1910
|
+
if (this.managedClients.has(name)) {
|
|
1911
|
+
const oldClient = this.managedClients.get(name);
|
|
1912
|
+
// 主动断开并销毁
|
|
1913
|
+
oldClient.destroy();
|
|
1914
|
+
log(`清理旧的 ${name} 客户端`);
|
|
1915
|
+
}
|
|
1916
|
+
// 创建客户端实例
|
|
1917
|
+
const client = new WrapperSocialGameClient(name,
|
|
1918
|
+
// 将名称注入配置
|
|
1919
|
+
opts, eventResponsePairs, _Object$assign({
|
|
1920
|
+
reconnectMaxAttempts: Infinity
|
|
1921
|
+
}, {
|
|
1922
|
+
...clientOption,
|
|
1923
|
+
// 强制关闭自动重连,由管理器统一控制
|
|
1924
|
+
isAutoConnect: false,
|
|
1925
|
+
isArrayBuffer: WECHAT
|
|
1926
|
+
}));
|
|
1927
|
+
// 注册并返回
|
|
1928
|
+
this.register(client);
|
|
1929
|
+
return client;
|
|
1930
|
+
}
|
|
1931
|
+
// 注册客户端
|
|
1932
|
+
register(client) {
|
|
1933
|
+
client.on('reconnected', this.handleSingleReconnect);
|
|
1934
|
+
client.on('close', this.handleSingleClose);
|
|
1935
|
+
client.on('kick', this.handleSingleKick);
|
|
1936
|
+
this.managedClients.set(client.name, client);
|
|
1937
|
+
}
|
|
1938
|
+
// 注销客户端
|
|
1939
|
+
unregister(client) {
|
|
1940
|
+
client.off('reconnected', this.handleSingleReconnect);
|
|
1941
|
+
client.off('close', this.handleSingleClose);
|
|
1942
|
+
client.off('kick', this.handleSingleKick);
|
|
1943
|
+
this.managedClients.delete(client.name);
|
|
1944
|
+
}
|
|
1945
|
+
initGlobalListeners() {
|
|
1946
|
+
// 网络状态监听
|
|
1947
|
+
this.cat.event.on(GlobalEventConstant.ONLINE, () => this.handleGlobalStateChange('online'), this).on(GlobalEventConstant.OFFLINE, () => this.handleGlobalStateChange('offline'), this);
|
|
1948
|
+
game.on(Game.EVENT_SHOW, () => this.handleGlobalStateChange('show'));
|
|
1949
|
+
game.on(Game.EVENT_HIDE, () => this.handleGlobalStateChange('hide'));
|
|
1950
|
+
}
|
|
1951
|
+
async handleGlobalStateChange(state) {
|
|
1952
|
+
// 更新全局状态
|
|
1953
|
+
switch (state) {
|
|
1954
|
+
case 'online':
|
|
1955
|
+
this.cat.gui.hideLoading().showToast({
|
|
1956
|
+
title: ReconnectPrompt.ONLINE
|
|
1957
|
+
});
|
|
1958
|
+
this.isGlobalOnline = true;
|
|
1959
|
+
this.triggerReconnectAll();
|
|
1960
|
+
break;
|
|
1961
|
+
case 'offline':
|
|
1962
|
+
this.isGlobalOnline = false;
|
|
1963
|
+
this.disconnectAll(true);
|
|
1964
|
+
this.cat.gui.showLoading({
|
|
1965
|
+
title: ReconnectPrompt.OFFLINE
|
|
1966
|
+
});
|
|
1967
|
+
break;
|
|
1968
|
+
case 'show':
|
|
1969
|
+
this.isInBackground = false;
|
|
1970
|
+
await this.triggerReconnectAll();
|
|
1971
|
+
await this.onEventShowDelegate.dispatch();
|
|
1972
|
+
break;
|
|
1973
|
+
case 'hide':
|
|
1974
|
+
await this.onEventHideDelegate.dispatch();
|
|
1975
|
+
this.isInBackground = true;
|
|
1976
|
+
this.disconnectAll(true);
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
// 统一触发所有WS重连
|
|
1981
|
+
async triggerReconnectAll() {
|
|
1982
|
+
log('触发所有客户端重连[正在重连][在线][后台][ws数量]', this.reconnecting, this.isGlobalOnline, this.isInBackground, this.managedClients.size);
|
|
1983
|
+
// 如果没有任何客户端需要重连,直接返回
|
|
1984
|
+
if (this.reconnecting || !this.isGlobalOnline || this.isInBackground || this.managedClients.size === 0) return this.onEventReloadSceneDelegate.dispatch();
|
|
1985
|
+
this.reconnecting = true;
|
|
1986
|
+
this.cat.gui.showLoading({
|
|
1987
|
+
title: '正在重连'
|
|
1988
|
+
});
|
|
1989
|
+
try {
|
|
1990
|
+
var _context3, _context4;
|
|
1991
|
+
await _Promise.allSettled(_mapInstanceProperty(_context3 = this.activeClients).call(_context3, async client => {
|
|
1992
|
+
try {
|
|
1993
|
+
// 1. 等待物理层重连
|
|
1994
|
+
await client.reconnectPromise();
|
|
1995
|
+
} catch (err) {
|
|
1996
|
+
error(`${client.name}服重连失败`, err);
|
|
1997
|
+
// cat.gui.showToast({ title: `${client.name}服重连失败` });
|
|
1998
|
+
// 不抛出错误,让 Promise.allSettled 收集结果
|
|
1999
|
+
}
|
|
2000
|
+
}));
|
|
2001
|
+
// 检查是否有客户端未成功连接
|
|
2002
|
+
const failedClients = _filterInstanceProperty(_context4 = this.activeClients).call(_context4, client => client.socketConnectStatus !== SocketConnectStatus.CONNECTED);
|
|
2003
|
+
if (failedClients.length > 0) {
|
|
2004
|
+
console.error("部分WS重连失败:", _mapInstanceProperty(failedClients).call(failedClients, name => name));
|
|
2005
|
+
// 可以在一段时间后再次尝试重连
|
|
2006
|
+
log('2s后重连所有客户端');
|
|
2007
|
+
this.reconnecting = false;
|
|
2008
|
+
this.scheduleReconnect();
|
|
2009
|
+
} else {
|
|
2010
|
+
this.reconnecting = false;
|
|
2011
|
+
}
|
|
2012
|
+
} catch (e) {
|
|
2013
|
+
this.reconnecting = false;
|
|
2014
|
+
throw e;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
// 统一断开所有WS
|
|
2018
|
+
disconnectAll(active) {
|
|
2019
|
+
var _context5;
|
|
2020
|
+
_forEachInstanceProperty(_context5 = this.managedClients).call(_context5, client => {
|
|
2021
|
+
log('断开连接', client.name, active, client.socket);
|
|
2022
|
+
client.disconnect(active);
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
handleSingleClose = () => {
|
|
2026
|
+
if (!this.reconnecting) {
|
|
2027
|
+
log('3s后重连所有客户端');
|
|
2028
|
+
this.scheduleReconnect(3000);
|
|
2029
|
+
}
|
|
2030
|
+
};
|
|
2031
|
+
// 单个WS重连成功回调
|
|
2032
|
+
handleSingleReconnect = async () => {
|
|
2033
|
+
var _context6;
|
|
2034
|
+
if (_everyInstanceProperty(_context6 = this.activeClients).call(_context6, client => client.socketConnectStatus === SocketConnectStatus.CONNECTED)) {
|
|
2035
|
+
var _context7;
|
|
2036
|
+
log('单个WS重连成功回调===', this.managedClients);
|
|
2037
|
+
await _Promise.allSettled(_mapInstanceProperty(_context7 = this.activeClients).call(_context7, async client => {
|
|
2038
|
+
// 连接社交游戏服务
|
|
2039
|
+
try {
|
|
2040
|
+
// 2. 执行业务层连接请求
|
|
2041
|
+
await client.connectRequest();
|
|
2042
|
+
} catch (err) {
|
|
2043
|
+
error(`${client.name}服登录错误`, err);
|
|
2044
|
+
this.cat.gui.showToast({
|
|
2045
|
+
title: `登录${client.name}服错误`
|
|
2046
|
+
});
|
|
2047
|
+
}
|
|
2048
|
+
}));
|
|
2049
|
+
if (this.reconnectTimer) {
|
|
2050
|
+
clearTimeout(this.reconnectTimer);
|
|
2051
|
+
this.reconnectTimer = null;
|
|
2052
|
+
}
|
|
2053
|
+
await this.onEventReloadSceneDelegate.dispatch();
|
|
2054
|
+
this.cat.gui.hideLoading();
|
|
2055
|
+
if (director.getScene()?.getComponentInChildren(SceneLayer)?.isReload) this.cat.gui.reloadScene();
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
// 被踢出
|
|
2059
|
+
handleSingleKick = () => {
|
|
2060
|
+
this.cat.gui.showReconnect(ReconnectPrompt.KICK);
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
class ResLoader {
|
|
2065
|
+
/**
|
|
2066
|
+
* 获取资源
|
|
2067
|
+
* @param path 资源路径
|
|
2068
|
+
* @param type 资源类型
|
|
2069
|
+
* @param bundleName 远程资源包名
|
|
2070
|
+
*/
|
|
2071
|
+
get = (() => function (path, type) {
|
|
2072
|
+
let bundleName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'resources';
|
|
2073
|
+
var bundle = assetManager.getBundle(bundleName);
|
|
2074
|
+
return bundle.get(path, type);
|
|
2075
|
+
})();
|
|
2076
|
+
/**
|
|
2077
|
+
* 获取资源类型
|
|
2078
|
+
*/
|
|
2079
|
+
isAssetType = value => {
|
|
2080
|
+
return typeof value === 'function' && value.prototype instanceof Asset;
|
|
2081
|
+
};
|
|
2082
|
+
async load() {
|
|
2083
|
+
let bundleName = null;
|
|
2084
|
+
let type = null;
|
|
2085
|
+
let onProgress = null;
|
|
2086
|
+
// 判断前两个参数是否都为字符串
|
|
2087
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2088
|
+
args[_key] = arguments[_key];
|
|
2089
|
+
}
|
|
2090
|
+
if (typeof args[0] === 'string' && typeof args[1] === 'string') {
|
|
2091
|
+
// 取出包名参数
|
|
2092
|
+
bundleName = args.shift();
|
|
2093
|
+
}
|
|
2094
|
+
// 取出路径参数
|
|
2095
|
+
let paths = args.shift();
|
|
2096
|
+
// 取出类型参数
|
|
2097
|
+
if (this.isAssetType(args[0])) {
|
|
2098
|
+
type = args.shift();
|
|
2099
|
+
}
|
|
2100
|
+
// 取出进度回调参数
|
|
2101
|
+
if (args.length == 2) {
|
|
2102
|
+
onProgress = args.shift();
|
|
2103
|
+
}
|
|
2104
|
+
// 取出完成回调参数
|
|
2105
|
+
const onComplete = args.shift();
|
|
2106
|
+
let nonce = resources;
|
|
2107
|
+
if (bundleName && bundleName != 'resources') {
|
|
2108
|
+
// bundleName不存在
|
|
2109
|
+
if (!assetManager.bundles.has(bundleName)) {
|
|
2110
|
+
await this.loadBundle(bundleName);
|
|
2111
|
+
}
|
|
2112
|
+
let bundle = assetManager.bundles.get(bundleName);
|
|
2113
|
+
if (bundle) {
|
|
2114
|
+
nonce = bundle;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
if (onProgress && onComplete) {
|
|
2118
|
+
nonce.load(paths, type, onProgress, onComplete);
|
|
2119
|
+
} else if (onComplete) {
|
|
2120
|
+
nonce.load(paths, type, onComplete);
|
|
2121
|
+
} else {
|
|
2122
|
+
nonce.load(paths, type);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
async loadDir() {
|
|
2126
|
+
let bundleName = null;
|
|
2127
|
+
let type = null;
|
|
2128
|
+
let onProgress = null;
|
|
2129
|
+
let onComplete = null;
|
|
2130
|
+
// 获取bundleName是否存在
|
|
2131
|
+
// 判断前两个参数是否都为字符串
|
|
2132
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2133
|
+
args[_key2] = arguments[_key2];
|
|
2134
|
+
}
|
|
2135
|
+
if (typeof args[0] === 'string' && typeof args[1] === 'string') {
|
|
2136
|
+
bundleName = args.shift();
|
|
2137
|
+
}
|
|
2138
|
+
let paths = args.shift();
|
|
2139
|
+
if (this.isAssetType(args[0])) {
|
|
2140
|
+
type = args.shift();
|
|
2141
|
+
}
|
|
2142
|
+
if (args.length == 2) {
|
|
2143
|
+
onProgress = args.shift();
|
|
2144
|
+
}
|
|
2145
|
+
onComplete = args.shift();
|
|
2146
|
+
let nonce = resources;
|
|
2147
|
+
if (bundleName && bundleName != 'resources') {
|
|
2148
|
+
// bundleName不存在
|
|
2149
|
+
if (!assetManager.bundles.has(bundleName)) {
|
|
2150
|
+
await this.loadBundle(bundleName);
|
|
2151
|
+
}
|
|
2152
|
+
let bundle = assetManager.bundles.get(bundleName);
|
|
2153
|
+
if (bundle) {
|
|
2154
|
+
nonce = bundle;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
if (onProgress && onComplete) {
|
|
2158
|
+
nonce.loadDir(paths, type, onProgress, onComplete);
|
|
2159
|
+
} else if (onComplete) {
|
|
2160
|
+
nonce.loadDir(paths, type, onComplete);
|
|
2161
|
+
} else {
|
|
2162
|
+
nonce.loadDir(paths, type);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
loadRemote(url) {
|
|
2166
|
+
var options = null;
|
|
2167
|
+
var onComplete = null;
|
|
2168
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
2169
|
+
args[_key3 - 1] = arguments[_key3];
|
|
2170
|
+
}
|
|
2171
|
+
if (args.length == 2) {
|
|
2172
|
+
options = args.shift();
|
|
2173
|
+
}
|
|
2174
|
+
onComplete = args.shift();
|
|
2175
|
+
assetManager.loadRemote(url, {
|
|
2176
|
+
ext: ".png",
|
|
2177
|
+
...options
|
|
2178
|
+
}, onComplete);
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* 加载bundle
|
|
2182
|
+
* @param url 资源地址 <远程路径或者bundleName>
|
|
2183
|
+
* @param complete 完成事件
|
|
2184
|
+
* @param v 资源版本号
|
|
2185
|
+
* @example
|
|
2186
|
+
*/
|
|
2187
|
+
loadBundle = (url, version) => {
|
|
2188
|
+
return new _Promise((resolve, reject) => {
|
|
2189
|
+
const onComplete = (err, bundle) => {
|
|
2190
|
+
if (err) {
|
|
2191
|
+
return reject(err);
|
|
2192
|
+
}
|
|
2193
|
+
resolve(bundle);
|
|
2194
|
+
};
|
|
2195
|
+
version ? assetManager.loadBundle(url, {
|
|
2196
|
+
version
|
|
2197
|
+
}, onComplete) : assetManager.loadBundle(url, onComplete);
|
|
2198
|
+
});
|
|
2199
|
+
};
|
|
2200
|
+
/** 释放预制依赖资源 */
|
|
2201
|
+
releasePrefabtDepsRecursively = uuid => {
|
|
2202
|
+
var asset = assetManager.assets.get(uuid);
|
|
2203
|
+
assetManager.releaseAsset(asset);
|
|
2204
|
+
if (asset instanceof Prefab) {
|
|
2205
|
+
var uuids = assetManager.dependUtil.getDepsRecursively(uuid);
|
|
2206
|
+
_forEachInstanceProperty(uuids).call(uuids, uuid => {
|
|
2207
|
+
var asset = assetManager.assets.get(uuid);
|
|
2208
|
+
asset.decRef();
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
};
|
|
2212
|
+
/**
|
|
2213
|
+
* 通过资源相对路径释放资源
|
|
2214
|
+
* @param path 资源路径
|
|
2215
|
+
* @param bundleName 远程资源包名
|
|
2216
|
+
*/
|
|
2217
|
+
release = (() => {
|
|
2218
|
+
var _this = this;
|
|
2219
|
+
return function (path) {
|
|
2220
|
+
let bundleName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'resources';
|
|
2221
|
+
var bundle = assetManager.getBundle(bundleName);
|
|
2222
|
+
if (bundle) {
|
|
2223
|
+
var asset = bundle.get(path);
|
|
2224
|
+
if (asset) {
|
|
2225
|
+
_this.releasePrefabtDepsRecursively(asset._uuid);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
};
|
|
2229
|
+
})();
|
|
2230
|
+
/**
|
|
2231
|
+
* 通过相对文件夹路径删除所有文件夹中资源
|
|
2232
|
+
* @param path 资源文件夹路径
|
|
2233
|
+
* @param bundleName 远程资源包名
|
|
2234
|
+
*/
|
|
2235
|
+
releaseDir = (() => {
|
|
2236
|
+
var _this2 = this;
|
|
2237
|
+
return function (path) {
|
|
2238
|
+
var _context, _context2;
|
|
2239
|
+
let bundleName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'resources';
|
|
2240
|
+
var bundle = assetManager.getBundle(bundleName);
|
|
2241
|
+
var infos = bundle?.getDirWithPath(path);
|
|
2242
|
+
((_context = infos) == null ? void 0 : _bindInstanceProperty(_context2 = Function.call).call(_context2, _mapInstanceProperty(_context), _context))?.(info => {
|
|
2243
|
+
_this2.releasePrefabtDepsRecursively(info.uuid);
|
|
2244
|
+
});
|
|
2245
|
+
if (!path && bundleName != 'resources' && bundle) {
|
|
2246
|
+
assetManager.removeBundle(bundle);
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
})();
|
|
2250
|
+
/** 打印缓存中所有资源信息 */
|
|
2251
|
+
dump = () => {
|
|
2252
|
+
var _context3;
|
|
2253
|
+
_forEachInstanceProperty(_context3 = assetManager.assets).call(_context3, (value, key) => {
|
|
2254
|
+
log(assetManager.assets.get(key));
|
|
2255
|
+
});
|
|
2256
|
+
log(`当前资源总数:${assetManager.assets.count}`);
|
|
2257
|
+
};
|
|
2258
|
+
/**
|
|
2259
|
+
* 加载分包中的资源并提供进度反馈。
|
|
2260
|
+
* @param bundle - 已加载的分包。
|
|
2261
|
+
* @param onProgress - 进度回调函数。
|
|
2262
|
+
* @returns Promise<void> - 加载完成后的Promise。
|
|
2263
|
+
*/
|
|
2264
|
+
loadAssetsWithProgress(bundle, onProgress) {
|
|
2265
|
+
return new _Promise((resolve, reject) => {
|
|
2266
|
+
const assets = bundle.getDirWithPath('');
|
|
2267
|
+
const totalAssets = assets.length;
|
|
2268
|
+
let loadedAssets = 0;
|
|
2269
|
+
if (totalAssets === 0) {
|
|
2270
|
+
onProgress(1);
|
|
2271
|
+
resolve();
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2274
|
+
_forEachInstanceProperty(assets).call(assets, asset => {
|
|
2275
|
+
bundle.load(asset.path, err => {
|
|
2276
|
+
if (err) {
|
|
2277
|
+
reject(err);
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
loadedAssets++;
|
|
2281
|
+
onProgress(loadedAssets / totalAssets);
|
|
2282
|
+
if (loadedAssets === totalAssets) {
|
|
2283
|
+
resolve();
|
|
2284
|
+
}
|
|
2285
|
+
});
|
|
2286
|
+
});
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
/**
|
|
2292
|
+
* @describe 基本数据
|
|
2293
|
+
* @author 游金宇(KM)
|
|
2294
|
+
* @date 2024-09-12 11:35:02
|
|
2295
|
+
*/
|
|
2296
|
+
class BaseStore {
|
|
2297
|
+
rootStore;
|
|
2298
|
+
constructor(rootStore) {
|
|
2299
|
+
this.rootStore = rootStore;
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
class CoreStore extends BaseManager {}
|
|
2304
|
+
|
|
2305
|
+
let _iv = null;
|
|
2306
|
+
/**
|
|
2307
|
+
* MD5加密
|
|
2308
|
+
* @param msg 加密信息
|
|
2309
|
+
*/
|
|
2310
|
+
const md5 = msg => {
|
|
2311
|
+
return CryptoES.MD5(msg).toString();
|
|
2312
|
+
};
|
|
2313
|
+
/** 初始化加密库 */
|
|
2314
|
+
const initCrypto = (key, iv) => {
|
|
2315
|
+
_iv = CryptoES.enc.Hex.parse(iv);
|
|
2316
|
+
};
|
|
2317
|
+
/**
|
|
2318
|
+
* AES 加密
|
|
2319
|
+
* @param msg 加密信息
|
|
2320
|
+
* @param key aes加密的key
|
|
2321
|
+
* @param iv aes加密的iv
|
|
2322
|
+
*/
|
|
2323
|
+
const aesEncrypt = (msg, key, iv) => {
|
|
2324
|
+
return CryptoES.AES.encrypt(msg, key, {
|
|
2325
|
+
iv: _iv,
|
|
2326
|
+
format: JsonFormatter
|
|
2327
|
+
}).toString();
|
|
2328
|
+
};
|
|
2329
|
+
/**
|
|
2330
|
+
* AES 解密
|
|
2331
|
+
* @param str 解密字符串
|
|
2332
|
+
* @param key aes加密的key
|
|
2333
|
+
* @param iv aes加密的iv
|
|
2334
|
+
*/
|
|
2335
|
+
const aesDecrypt = (str, key, iv) => {
|
|
2336
|
+
const decrypted = CryptoES.AES.decrypt(str, key, {
|
|
2337
|
+
iv: _iv,
|
|
2338
|
+
format: JsonFormatter
|
|
2339
|
+
});
|
|
2340
|
+
return decrypted.toString(CryptoES.enc.Utf8);
|
|
2341
|
+
};
|
|
2342
|
+
const JsonFormatter = {
|
|
2343
|
+
stringify: cipherParams => {
|
|
2344
|
+
const jsonObj = {
|
|
2345
|
+
ct: cipherParams.ciphertext.toString(CryptoES.enc.Base64)
|
|
2346
|
+
};
|
|
2347
|
+
if (cipherParams.iv) {
|
|
2348
|
+
jsonObj.iv = cipherParams.iv.toString();
|
|
2349
|
+
}
|
|
2350
|
+
if (cipherParams.salt) {
|
|
2351
|
+
jsonObj.s = cipherParams.salt.toString();
|
|
2352
|
+
}
|
|
2353
|
+
return _JSON$stringify(jsonObj);
|
|
2354
|
+
},
|
|
2355
|
+
parse: jsonStr => {
|
|
2356
|
+
const jsonObj = JSON.parse(jsonStr);
|
|
2357
|
+
const cipherParams = CryptoES.lib.CipherParams.create({
|
|
2358
|
+
ciphertext: CryptoES.enc.Base64.parse(jsonObj.ct)
|
|
2359
|
+
});
|
|
2360
|
+
if (jsonObj.iv) {
|
|
2361
|
+
cipherParams.iv = CryptoES.enc.Hex.parse(jsonObj.iv);
|
|
2362
|
+
}
|
|
2363
|
+
if (jsonObj.s) {
|
|
2364
|
+
cipherParams.salt = CryptoES.enc.Hex.parse(jsonObj.s);
|
|
2365
|
+
}
|
|
2366
|
+
return cipherParams;
|
|
2367
|
+
}
|
|
2368
|
+
};
|
|
2369
|
+
|
|
2370
|
+
var EncryptUtil = /*#__PURE__*/Object.freeze({
|
|
2371
|
+
__proto__: null,
|
|
2372
|
+
JsonFormatter: JsonFormatter,
|
|
2373
|
+
aesDecrypt: aesDecrypt,
|
|
2374
|
+
aesEncrypt: aesEncrypt,
|
|
2375
|
+
initCrypto: initCrypto,
|
|
2376
|
+
md5: md5
|
|
2377
|
+
});
|
|
2378
|
+
|
|
2379
|
+
/**
|
|
2380
|
+
* @describe 工具类
|
|
2381
|
+
* @author 游金宇(KM)
|
|
2382
|
+
* @date 2023-08-02 20:16:42
|
|
2383
|
+
*/
|
|
2384
|
+
// 扩展 Manager 接口,添加 Util 属性
|
|
2385
|
+
class CoreUtil extends BaseManager {
|
|
2386
|
+
encryptUtil = (() => EncryptUtil)();
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
class StorageManager extends BaseManager {
|
|
2390
|
+
_key = null;
|
|
2391
|
+
_iv = null;
|
|
2392
|
+
_id = '';
|
|
2393
|
+
/**
|
|
2394
|
+
* 初始化密钥
|
|
2395
|
+
* @param key aes加密的key
|
|
2396
|
+
* @param iv aes加密的iv
|
|
2397
|
+
*/
|
|
2398
|
+
init(key, iv) {
|
|
2399
|
+
this.cat.util.encryptUtil.initCrypto(key, iv);
|
|
2400
|
+
this._key = this.cat.util.encryptUtil.md5(key);
|
|
2401
|
+
this._iv = this.cat.util.encryptUtil.md5(iv);
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* 设置用户唯一标识
|
|
2405
|
+
* @param id
|
|
2406
|
+
*/
|
|
2407
|
+
setUser(id) {
|
|
2408
|
+
this._id = id;
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* 存储本地数据
|
|
2412
|
+
* @param key 存储key
|
|
2413
|
+
* @param value 存储值
|
|
2414
|
+
* @returns
|
|
2415
|
+
*/
|
|
2416
|
+
set(key, value) {
|
|
2417
|
+
key = `${key}_${this._id}`;
|
|
2418
|
+
if (null == key) {
|
|
2419
|
+
console.error('存储的key不能为空');
|
|
2420
|
+
return;
|
|
2421
|
+
}
|
|
2422
|
+
if (!PREVIEW) {
|
|
2423
|
+
key = this.cat.util.encryptUtil.md5(key);
|
|
2424
|
+
}
|
|
2425
|
+
if (null == value) {
|
|
2426
|
+
console.warn('存储的值为空,则直接移除该存储');
|
|
2427
|
+
this.remove(key);
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
if (typeof value === 'function') {
|
|
2431
|
+
console.error('储存的值不能为方法');
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
if (typeof value === 'object') {
|
|
2435
|
+
try {
|
|
2436
|
+
value = _JSON$stringify(value);
|
|
2437
|
+
} catch (e) {
|
|
2438
|
+
console.error(`解析失败,str = ${value}`);
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
} else if (typeof value === 'number') {
|
|
2442
|
+
value = value + '';
|
|
2443
|
+
}
|
|
2444
|
+
if (!PREVIEW && null != this._key && null != this._iv) {
|
|
2445
|
+
value = this.cat.util.encryptUtil.aesEncrypt(`${value}`, this._key, this._iv);
|
|
2446
|
+
}
|
|
2447
|
+
sys.localStorage.setItem(key, value);
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* 获取指定关键字的数据
|
|
2451
|
+
* @param key 获取的关键字
|
|
2452
|
+
* @param defaultValue 获取的默认值
|
|
2453
|
+
* @returns
|
|
2454
|
+
*/
|
|
2455
|
+
get(key, defaultValue) {
|
|
2456
|
+
if (null == key) {
|
|
2457
|
+
console.error('存储的key不能为空');
|
|
2458
|
+
return null;
|
|
2459
|
+
}
|
|
2460
|
+
key = `${key}_${this._id}`;
|
|
2461
|
+
if (!PREVIEW) {
|
|
2462
|
+
key = this.cat.util.encryptUtil.md5(key);
|
|
2463
|
+
}
|
|
2464
|
+
let str = sys.localStorage.getItem(key);
|
|
2465
|
+
if (null != str && '' !== str && !PREVIEW && null != this._key && null != this._iv) {
|
|
2466
|
+
str = this.cat.util.encryptUtil.aesDecrypt(str, this._key, this._iv);
|
|
2467
|
+
}
|
|
2468
|
+
if (null === str) {
|
|
2469
|
+
return defaultValue;
|
|
2470
|
+
}
|
|
2471
|
+
return str;
|
|
2472
|
+
}
|
|
2473
|
+
/** 获取指定关键字的数值 */
|
|
2474
|
+
getNumber(key) {
|
|
2475
|
+
let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2476
|
+
var r = this.get(key);
|
|
2477
|
+
return Number(r) || defaultValue;
|
|
2478
|
+
}
|
|
2479
|
+
/** 获取指定关键字的布尔值 */
|
|
2480
|
+
getBoolean(key) {
|
|
2481
|
+
var r = this.get(key);
|
|
2482
|
+
return Boolean(r) || false;
|
|
2483
|
+
}
|
|
2484
|
+
/** 获取指定关键字的JSON对象 */
|
|
2485
|
+
getJson(key, defaultValue) {
|
|
2486
|
+
var r = this.get(key);
|
|
2487
|
+
return r && JSON.parse(r) || defaultValue;
|
|
2488
|
+
}
|
|
2489
|
+
/**
|
|
2490
|
+
* 删除指定关键字的数据
|
|
2491
|
+
* @param key 需要移除的关键字
|
|
2492
|
+
* @returns
|
|
2493
|
+
*/
|
|
2494
|
+
remove(key) {
|
|
2495
|
+
if (null == key) {
|
|
2496
|
+
console.error('存储的key不能为空');
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2499
|
+
key = `${key}_${this._id}`;
|
|
2500
|
+
if (!PREVIEW) {
|
|
2501
|
+
key = this.cat.util.encryptUtil.md5(key);
|
|
2502
|
+
}
|
|
2503
|
+
sys.localStorage.removeItem(key);
|
|
2504
|
+
}
|
|
2505
|
+
/** 清空整个本地存储 */
|
|
2506
|
+
clear() {
|
|
2507
|
+
sys.localStorage.clear();
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
class Manager {
|
|
2512
|
+
static #ins = null;
|
|
2513
|
+
#initialized = false;
|
|
2514
|
+
static get instance() {
|
|
2515
|
+
return this.#ins ?? (this.#ins = new Manager());
|
|
2516
|
+
}
|
|
2517
|
+
/**APP初始化事务 */
|
|
2518
|
+
onAppInitDelegate = (() => new AsyncDelegate())();
|
|
2519
|
+
/**插件初始化事务 */
|
|
2520
|
+
onPlugInInitDelegate = (() => new AsyncDelegate())();
|
|
2521
|
+
#audio = null;
|
|
2522
|
+
/**音频管理 */
|
|
2523
|
+
get audio() {
|
|
2524
|
+
return this.#audio;
|
|
2525
|
+
}
|
|
2526
|
+
#event = null;
|
|
2527
|
+
/**全局事件管理 */
|
|
2528
|
+
get event() {
|
|
2529
|
+
return this.#event;
|
|
2530
|
+
}
|
|
2531
|
+
#gui = null;
|
|
2532
|
+
/**gui管理 */
|
|
2533
|
+
get gui() {
|
|
2534
|
+
return this.#gui;
|
|
2535
|
+
}
|
|
2536
|
+
#storage = null;
|
|
2537
|
+
/**本地存储管理 */
|
|
2538
|
+
get storage() {
|
|
2539
|
+
return this.#storage;
|
|
2540
|
+
}
|
|
2541
|
+
#res = null;
|
|
2542
|
+
/**资源管理 */
|
|
2543
|
+
get res() {
|
|
2544
|
+
return this.#res;
|
|
2545
|
+
}
|
|
2546
|
+
#util = null;
|
|
2547
|
+
/**工具类管理 */
|
|
2548
|
+
get util() {
|
|
2549
|
+
return this.#util;
|
|
2550
|
+
}
|
|
2551
|
+
#socialGameClient = null;
|
|
2552
|
+
/**社交游戏类 */
|
|
2553
|
+
get socialGameClient() {
|
|
2554
|
+
return this.#socialGameClient;
|
|
2555
|
+
}
|
|
2556
|
+
#store = null;
|
|
2557
|
+
/**数据存储 */
|
|
2558
|
+
get store() {
|
|
2559
|
+
return this.#store;
|
|
2560
|
+
}
|
|
2561
|
+
#gui_bundle_name = '';
|
|
2562
|
+
/**GUI bundle 名称 */
|
|
2563
|
+
get gui_bundle_name() {
|
|
2564
|
+
return this.#gui_bundle_name;
|
|
2565
|
+
}
|
|
2566
|
+
#audio_local_store_key = '';
|
|
2567
|
+
/**音效本地存储key */
|
|
2568
|
+
get audio_local_store_key() {
|
|
2569
|
+
return this.#audio_local_store_key;
|
|
2570
|
+
}
|
|
2571
|
+
#default_audio_effect = '';
|
|
2572
|
+
/**默认音效路径 */
|
|
2573
|
+
get default_audio_effect() {
|
|
2574
|
+
return this.#default_audio_effect;
|
|
2575
|
+
}
|
|
2576
|
+
/**GUI资源配置 */
|
|
2577
|
+
setConfig = (() => {
|
|
2578
|
+
var _this = this;
|
|
2579
|
+
return function () {
|
|
2580
|
+
let {
|
|
2581
|
+
default_audio_effect = '',
|
|
2582
|
+
gui_bundleName = 'resources',
|
|
2583
|
+
audio_local_store_key = 'game_audio'
|
|
2584
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2585
|
+
if (_this.#initialized) {
|
|
2586
|
+
throw new Error('[CAT] 已初始化,无法修改配置');
|
|
2587
|
+
}
|
|
2588
|
+
_this.#gui_bundle_name = gui_bundleName;
|
|
2589
|
+
_this.#audio_local_store_key = audio_local_store_key;
|
|
2590
|
+
_this.#default_audio_effect = default_audio_effect;
|
|
2591
|
+
return _this;
|
|
2592
|
+
};
|
|
2593
|
+
})();
|
|
2594
|
+
/**启动 */
|
|
2595
|
+
async boot() {
|
|
2596
|
+
if (this.#initialized) {
|
|
2597
|
+
throw new Error('[CAT] 已初始化');
|
|
2598
|
+
}
|
|
2599
|
+
try {
|
|
2600
|
+
this.#store = new CoreStore(this);
|
|
2601
|
+
this.#res = new ResLoader();
|
|
2602
|
+
this.#util = new CoreUtil(this);
|
|
2603
|
+
this.#storage = new StorageManager(this);
|
|
2604
|
+
this.#event = new EventEmitter();
|
|
2605
|
+
this.#audio = new AudioManager(this);
|
|
2606
|
+
this.#socialGameClient = new SocialGameClientManager(this);
|
|
2607
|
+
this.#gui = (await new GuiManager(this).init()).gui;
|
|
2608
|
+
this.#initialized = true;
|
|
2609
|
+
} catch (err) {
|
|
2610
|
+
console.error(`[CAT] 初始化失败:`, err);
|
|
2611
|
+
throw err;
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
/**合并对象 */
|
|
2615
|
+
merge(target, source) {
|
|
2616
|
+
if (!this.#initialized) throw new Error('[CAT] 未初始化');
|
|
2617
|
+
if (typeof target !== 'string') {
|
|
2618
|
+
throw new Error(`merge方法第一个参数应该为string类型`);
|
|
2619
|
+
}
|
|
2620
|
+
if (!_Reflect$get(this, target)) {
|
|
2621
|
+
_Reflect$set(this, target, source);
|
|
2622
|
+
}
|
|
2623
|
+
_Object$assign(_Reflect$get(this, target), source);
|
|
2624
|
+
return this;
|
|
2625
|
+
}
|
|
2626
|
+
/**
|
|
2627
|
+
* 注册一个“插件级”初始化回调
|
|
2628
|
+
* - 如果已初始化,立即执行
|
|
2629
|
+
* - 否则排队到 onPlugInInitDelegate 中
|
|
2630
|
+
*/
|
|
2631
|
+
appendPlugInInitDelegate(cb) {
|
|
2632
|
+
if (this.#initialized) {
|
|
2633
|
+
// 已经初始化:异步立即执行
|
|
2634
|
+
_Promise.resolve().then(cb).catch(err => {
|
|
2635
|
+
console.error('[CAT] appendPlugInInitDelegate 回调执行失败:', err);
|
|
2636
|
+
});
|
|
2637
|
+
} else {
|
|
2638
|
+
// 未初始化:注册到插件初始化队列
|
|
2639
|
+
this.onPlugInInitDelegate.add(cb);
|
|
2640
|
+
}
|
|
2641
|
+
return this;
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
const {
|
|
2646
|
+
ccclass,
|
|
2647
|
+
property,
|
|
2648
|
+
menu
|
|
2649
|
+
} = _decorator;
|
|
2650
|
+
/**
|
|
2651
|
+
* @describe 模态框
|
|
2652
|
+
* @author 游金宇(KM)
|
|
2653
|
+
* @date 2024-09-12 11:49:51
|
|
2654
|
+
*/
|
|
2655
|
+
let CoreUIModal = class CoreUIModal extends UILayer {
|
|
2656
|
+
default_title = null;
|
|
2657
|
+
title;
|
|
2658
|
+
prompt_content_str;
|
|
2659
|
+
prompt_content_spriteFrame;
|
|
2660
|
+
btn_confirm;
|
|
2661
|
+
confirm_spriteFrame;
|
|
2662
|
+
btn_cancel;
|
|
2663
|
+
cancel_spriteFrame;
|
|
2664
|
+
btn_close;
|
|
2665
|
+
isConfirm = false;
|
|
2666
|
+
props = {
|
|
2667
|
+
title: this.default_title,
|
|
2668
|
+
content: null,
|
|
2669
|
+
confirmCB: () => {},
|
|
2670
|
+
cancelCB: () => {},
|
|
2671
|
+
style: null
|
|
2672
|
+
};
|
|
2673
|
+
onLoad() {
|
|
2674
|
+
this.btn_cancel.node.on(Button.EventType.CLICK, this.onCancelHandler, this);
|
|
2675
|
+
this.btn_confirm.node.on(Button.EventType.CLICK, this.onConfirmHandler, this);
|
|
2676
|
+
this.btn_close.node.on(Button.EventType.CLICK, this.onCloseHandler, this);
|
|
2677
|
+
this.addAutorun([() => {
|
|
2678
|
+
this.title.spriteFrame = this.props?.title || this.default_title;
|
|
2679
|
+
}, () => {
|
|
2680
|
+
if (this.props.content) {
|
|
2681
|
+
if (this.props.content instanceof SpriteFrame) {
|
|
2682
|
+
//图片
|
|
2683
|
+
this.prompt_content_spriteFrame.spriteFrame = this.props.content;
|
|
2684
|
+
} else if (typeof this.props.content === 'string') {
|
|
2685
|
+
this.prompt_content_str.string = this.props.content;
|
|
2686
|
+
} else {
|
|
2687
|
+
console.error('未知类型的【UIModal】内容');
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
}, () => {
|
|
2691
|
+
if (this.props?.style?.confirm === null) {
|
|
2692
|
+
this.btn_confirm.node.active = false;
|
|
2693
|
+
} else {
|
|
2694
|
+
this.btn_confirm.node.active = true;
|
|
2695
|
+
this.btn_confirm.getComponent(Sprite).spriteFrame = this.props.style?.confirm || this.confirm_spriteFrame;
|
|
2696
|
+
}
|
|
2697
|
+
if (this.props?.style?.cancel === null) {
|
|
2698
|
+
this.btn_cancel.node.active = false;
|
|
2699
|
+
} else {
|
|
2700
|
+
this.btn_cancel.node.active = true;
|
|
2701
|
+
this.btn_cancel.getComponent(Sprite).spriteFrame = this.props.style?.cancel || this.cancel_spriteFrame;
|
|
2702
|
+
}
|
|
2703
|
+
}]);
|
|
2704
|
+
}
|
|
2705
|
+
close() {
|
|
2706
|
+
this.props.cancelCB?.();
|
|
2707
|
+
this.cat.gui.closeUI(this);
|
|
2708
|
+
}
|
|
2709
|
+
onCancelHandler() {
|
|
2710
|
+
this.close();
|
|
2711
|
+
}
|
|
2712
|
+
onConfirmHandler() {
|
|
2713
|
+
this.props.confirmCB?.();
|
|
2714
|
+
}
|
|
2715
|
+
onDestroy() {
|
|
2716
|
+
if (this.isConfirm) this.props.onDestroy?.();
|
|
2717
|
+
}
|
|
2718
|
+
onCloseHandler() {
|
|
2719
|
+
this.close();
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
__decorate([property({
|
|
2723
|
+
type: SpriteFrame,
|
|
2724
|
+
tooltip: '默认标题'
|
|
2725
|
+
}), __metadata("design:type", SpriteFrame)], CoreUIModal.prototype, "default_title", void 0);
|
|
2726
|
+
__decorate([property({
|
|
2727
|
+
type: Sprite,
|
|
2728
|
+
tooltip: '标题节点'
|
|
2729
|
+
}), __metadata("design:type", Sprite)], CoreUIModal.prototype, "title", void 0);
|
|
2730
|
+
__decorate([property({
|
|
2731
|
+
type: Label,
|
|
2732
|
+
tooltip: '字符串内容按钮'
|
|
2733
|
+
}), __metadata("design:type", Label)], CoreUIModal.prototype, "prompt_content_str", void 0);
|
|
2734
|
+
__decorate([property({
|
|
2735
|
+
type: Sprite,
|
|
2736
|
+
tooltip: '图片精灵内容按钮'
|
|
2737
|
+
}), __metadata("design:type", Sprite)], CoreUIModal.prototype, "prompt_content_spriteFrame", void 0);
|
|
2738
|
+
__decorate([property({
|
|
2739
|
+
type: Button,
|
|
2740
|
+
tooltip: '确认按钮'
|
|
2741
|
+
}), __metadata("design:type", Button)], CoreUIModal.prototype, "btn_confirm", void 0);
|
|
2742
|
+
__decorate([property({
|
|
2743
|
+
type: SpriteFrame,
|
|
2744
|
+
tooltip: '确认按钮精灵图'
|
|
2745
|
+
}), __metadata("design:type", SpriteFrame)], CoreUIModal.prototype, "confirm_spriteFrame", void 0);
|
|
2746
|
+
__decorate([property({
|
|
2747
|
+
type: Button,
|
|
2748
|
+
tooltip: '取消按钮'
|
|
2749
|
+
}), __metadata("design:type", Button)], CoreUIModal.prototype, "btn_cancel", void 0);
|
|
2750
|
+
__decorate([property({
|
|
2751
|
+
type: SpriteFrame,
|
|
2752
|
+
tooltip: '取消按钮精灵图'
|
|
2753
|
+
}), __metadata("design:type", SpriteFrame)], CoreUIModal.prototype, "cancel_spriteFrame", void 0);
|
|
2754
|
+
__decorate([property({
|
|
2755
|
+
type: Button,
|
|
2756
|
+
tooltip: '关闭按钮'
|
|
2757
|
+
}), __metadata("design:type", Button)], CoreUIModal.prototype, "btn_close", void 0);
|
|
2758
|
+
CoreUIModal = __decorate([ccclass('CoreUIModal'), menu("CATCORE/CoreUIModal")], CoreUIModal);
|
|
2759
|
+
|
|
2760
|
+
/**
|
|
2761
|
+
* @describe 时间管理
|
|
2762
|
+
* @author 游金宇(KM)
|
|
2763
|
+
* @date 2024-09-12 11:49:19
|
|
2764
|
+
*/
|
|
2765
|
+
var TimerType;
|
|
2766
|
+
(function (TimerType) {
|
|
2767
|
+
TimerType[TimerType["Delay"] = 0] = "Delay";
|
|
2768
|
+
TimerType[TimerType["Interval"] = 1] = "Interval";
|
|
2769
|
+
})(TimerType || (TimerType = {}));
|
|
2770
|
+
class TimerEntry {
|
|
2771
|
+
/** 唯一标识符 */
|
|
2772
|
+
tag;
|
|
2773
|
+
/** 计时器类型(计时器或延时器) */
|
|
2774
|
+
type;
|
|
2775
|
+
/** 回调函数 */
|
|
2776
|
+
callback;
|
|
2777
|
+
/** 触发剩余时间(毫秒)*/
|
|
2778
|
+
remainingTime;
|
|
2779
|
+
/** 执行时间(毫秒)*/
|
|
2780
|
+
executionTime = 0;
|
|
2781
|
+
/** 初始时间(仅适用于计时器) */
|
|
2782
|
+
initialTime;
|
|
2783
|
+
/**
|
|
2784
|
+
* 创建一个新的计时器或延时器条目
|
|
2785
|
+
* @param tag 唯一标识符
|
|
2786
|
+
* @param type 计时器类型(计时器或延时器)
|
|
2787
|
+
* @param time 剩余时间(毫秒)
|
|
2788
|
+
* @param callback 回调函数
|
|
2789
|
+
* @param initialTime 初始间隔时间(仅适用于计时器)
|
|
2790
|
+
*/
|
|
2791
|
+
constructor(tag, type, time, callback) {
|
|
2792
|
+
this.tag = tag;
|
|
2793
|
+
this.type = type;
|
|
2794
|
+
this.remainingTime = time;
|
|
2795
|
+
this.initialTime = time; // 新增字段,仅适用于计时器
|
|
2796
|
+
this.callback = callback;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
class TimerManager extends BaseManager {
|
|
2800
|
+
timers = (() => new _Map())();
|
|
2801
|
+
lastUpdateTime = (() => _Date$now())();
|
|
2802
|
+
constructor(cat) {
|
|
2803
|
+
var _context;
|
|
2804
|
+
super(cat);
|
|
2805
|
+
cat.event.on(GlobalEventConstant.EVENT_HIDE, this.onHandleAppBackground, this);
|
|
2806
|
+
cat.event.on(GlobalEventConstant.EVENT_SHOW, this.onHandleAppForeground, this);
|
|
2807
|
+
// 在构造函数中启动一个定时器,以每帧调用 update 方法
|
|
2808
|
+
_setInterval(_bindInstanceProperty(_context = this.update).call(_context, this), 1000);
|
|
2809
|
+
}
|
|
2810
|
+
onHandleAppBackground() {
|
|
2811
|
+
this.lastUpdateTime = _Date$now();
|
|
2812
|
+
}
|
|
2813
|
+
onHandleAppForeground() {
|
|
2814
|
+
const currentTime = _Date$now();
|
|
2815
|
+
const elapsedTime = currentTime - this.lastUpdateTime;
|
|
2816
|
+
log('elapsedTime', elapsedTime);
|
|
2817
|
+
for (const entry of _valuesInstanceProperty(_context2 = this.timers).call(_context2)) {
|
|
2818
|
+
var _context2;
|
|
2819
|
+
if (entry.remainingTime > 0) {
|
|
2820
|
+
entry.remainingTime -= elapsedTime;
|
|
2821
|
+
entry.executionTime += elapsedTime;
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
this.lastUpdateTime = currentTime;
|
|
2825
|
+
}
|
|
2826
|
+
/**
|
|
2827
|
+
* 注册一个计时器
|
|
2828
|
+
* @param tag 注册计时器的对象
|
|
2829
|
+
* @param interval 间隔时间(毫秒)
|
|
2830
|
+
* @param callback 计时器回调函数
|
|
2831
|
+
* @returns 计时器的唯一标识
|
|
2832
|
+
*/
|
|
2833
|
+
registerInterval(tag, interval, callback) {
|
|
2834
|
+
if (this.has(tag)) {
|
|
2835
|
+
return error(`${tag}定时器已存在,请勿重复注册`);
|
|
2836
|
+
}
|
|
2837
|
+
const timerEntry = new TimerEntry(tag, TimerType.Interval, interval, callback);
|
|
2838
|
+
this.timers.set(tag, timerEntry);
|
|
2839
|
+
}
|
|
2840
|
+
/**
|
|
2841
|
+
* 注册一个延时器
|
|
2842
|
+
* @param tag 注册延时器的对象
|
|
2843
|
+
* @param delay 延时时间(毫秒)
|
|
2844
|
+
* @param callback 延时器回调函数
|
|
2845
|
+
* @returns 延时器的唯一标识
|
|
2846
|
+
*/
|
|
2847
|
+
registerDelay(tag, delay, callback) {
|
|
2848
|
+
if (this.has(tag)) {
|
|
2849
|
+
return error(`${tag}延时器已存在,请勿重复注册`);
|
|
2850
|
+
}
|
|
2851
|
+
const timerEntry = new TimerEntry(tag, TimerType.Delay, delay, callback);
|
|
2852
|
+
this.timers.set(tag, timerEntry);
|
|
2853
|
+
}
|
|
2854
|
+
/**
|
|
2855
|
+
* 取消一个计时器或延时器
|
|
2856
|
+
* @param tag 计时器或延时器的唯一标识
|
|
2857
|
+
*/
|
|
2858
|
+
unregister(tag) {
|
|
2859
|
+
if (this.has(tag)) {
|
|
2860
|
+
this.timers.delete(tag);
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
/**是否拥有定时器 */
|
|
2864
|
+
has(object) {
|
|
2865
|
+
return this.timers.has(object);
|
|
2866
|
+
}
|
|
2867
|
+
/**
|
|
2868
|
+
* 更新计时器状态
|
|
2869
|
+
* @param dt 间隔时间(毫秒)
|
|
2870
|
+
*/
|
|
2871
|
+
update() {
|
|
2872
|
+
const entriesToRemove = [];
|
|
2873
|
+
for (const [id, entry] of _entriesInstanceProperty(_context3 = this.timers).call(_context3)) {
|
|
2874
|
+
var _context3;
|
|
2875
|
+
entry.remainingTime -= 1000;
|
|
2876
|
+
if (entry.remainingTime <= 0) {
|
|
2877
|
+
if (entry.type === TimerType.Interval) {
|
|
2878
|
+
entry.executionTime += entry.initialTime;
|
|
2879
|
+
}
|
|
2880
|
+
// 触发回调
|
|
2881
|
+
entry.callback(entry.executionTime);
|
|
2882
|
+
// 如果是计时器,重置剩余时间
|
|
2883
|
+
if (entry.type === TimerType.Interval) {
|
|
2884
|
+
entry.remainingTime = entry.initialTime; // 重置为初始间隔时间
|
|
2885
|
+
} else {
|
|
2886
|
+
// 如果是延时器,标记为待删除
|
|
2887
|
+
entriesToRemove.push(id);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
// 删除已完成的延时器
|
|
2892
|
+
for (const idToRemove of entriesToRemove) {
|
|
2893
|
+
this.timers.delete(idToRemove);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
const AudioEffect = (effect, callBackFun) => {
|
|
2899
|
+
return (_target, _propertyKey, descriptor) => {
|
|
2900
|
+
let oldFun = descriptor.value;
|
|
2901
|
+
descriptor.value = function () {
|
|
2902
|
+
const _effect = effect ?? _globalThis._cat.default_audio_effect;
|
|
2903
|
+
if (_effect) {
|
|
2904
|
+
_globalThis._cat.audio.playEffect(_effect);
|
|
2905
|
+
} else {
|
|
2906
|
+
console.warn(`请添加音效路径参数`);
|
|
2907
|
+
}
|
|
2908
|
+
if (callBackFun) {
|
|
2909
|
+
callBackFun();
|
|
2910
|
+
}
|
|
2911
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2912
|
+
args[_key] = arguments[_key];
|
|
2913
|
+
}
|
|
2914
|
+
oldFun.apply(this, args);
|
|
2915
|
+
};
|
|
2916
|
+
return descriptor;
|
|
2917
|
+
};
|
|
2918
|
+
};
|
|
2919
|
+
const ButtonLock = function () {
|
|
2920
|
+
let lockTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
2921
|
+
let callBackFun = arguments.length > 1 ? arguments[1] : undefined;
|
|
2922
|
+
return function (_target, _propertyKey, descriptor) {
|
|
2923
|
+
let oldFun = descriptor.value;
|
|
2924
|
+
let isLock = false;
|
|
2925
|
+
descriptor.value = function () {
|
|
2926
|
+
if (isLock) {
|
|
2927
|
+
if (callBackFun) {
|
|
2928
|
+
callBackFun();
|
|
2929
|
+
}
|
|
2930
|
+
return;
|
|
2931
|
+
}
|
|
2932
|
+
isLock = true;
|
|
2933
|
+
_setTimeout(() => {
|
|
2934
|
+
isLock = false;
|
|
2935
|
+
}, lockTime * 1000);
|
|
2936
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2937
|
+
args[_key2] = arguments[_key2];
|
|
2938
|
+
}
|
|
2939
|
+
oldFun.apply(this, args);
|
|
2940
|
+
};
|
|
2941
|
+
return descriptor;
|
|
2942
|
+
};
|
|
2943
|
+
};
|
|
2944
|
+
|
|
2945
|
+
const cat = _globalThis._cat ??= Manager.instance;
|
|
2946
|
+
/**
|
|
2947
|
+
* 项目数据初始化之后的处理APP初始化事务
|
|
2948
|
+
* 执行顺序 onAppInitDelegate -> onPlugInInitDelegate
|
|
2949
|
+
*/
|
|
2950
|
+
game.onPostProjectInitDelegate.add(async () => {
|
|
2951
|
+
console.time('[Init App]');
|
|
2952
|
+
try {
|
|
2953
|
+
await cat.boot();
|
|
2954
|
+
await cat.onAppInitDelegate.dispatch();
|
|
2955
|
+
await cat.onPlugInInitDelegate.dispatch();
|
|
2956
|
+
} catch (err) {
|
|
2957
|
+
error(`[Init App] 初始化失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
2958
|
+
throw err;
|
|
2959
|
+
} finally {
|
|
2960
|
+
console.timeEnd('[Init App]');
|
|
2961
|
+
}
|
|
2962
|
+
});
|
|
2963
|
+
|
|
2964
|
+
export { AudioEffect, AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, BaseStore, ButtonLock, CoreBlackMask, CoreNotice, CoreReconnection, CoreShowLoading, CoreStore, CoreToast, CoreUIContainer, CoreUIModal, CoreUtil, GlobalEventConstant, Gui, GuiManager, LayerType, Manager, ReconnectPrompt, RootUILayer, SceneLayer, TimerManager, ToastType, UILayer, WrapperSocialGameClient, cat };
|