diff --git a/dist/moye.d.ts b/dist/moye.d.ts index 50933fc..3fc1180 100644 --- a/dist/moye.d.ts +++ b/dist/moye.d.ts @@ -563,12 +563,6 @@ export declare class SceneFactory { static createClientScene(): Scene; static createCurrentScene(id: bigint, name: string): Scene; } -/** - * manage client scene - */ -export declare class SceneRefCom extends Entity { - scene: Scene; -} /** * key对应value数组的map */ @@ -583,6 +577,11 @@ export declare class MultiMap { getOne(t: T): K | undefined; contains(t: T, k: K): boolean; } +export declare class SceneMgr extends Singleton { + process: Scene; + client: Scene; + current: Scene; +} export interface Entity { currentScene(): Scene; clientScene(): Scene; diff --git a/dist/moye.min.mjs b/dist/moye.min.mjs index 1aa25e6..e363c55 100644 --- a/dist/moye.min.mjs +++ b/dist/moye.min.mjs @@ -1 +1 @@ -import{debug as debug$1,log as log$1,warn as warn$1,error as error$1,_decorator,Component,director,SpriteFrame,Texture2D,instantiate,native,assetManager,UITransform,CCBoolean,Node,Enum,Layout,Vec3,Label,Widget,CCObject,CCFloat,Size,NodeEventType,v3,dynamicAtlasManager,Sprite,SpriteAtlas,CCInteger,UIRenderer,cclegacy,InstanceMaterialType,RenderTexture,Material,Vec2,BitMask,Color,Tween,tween,CCString,EventTarget,UIOpacity,Input,misc,RigidBody2D}from"cc";import{DEBUG,NATIVE,EDITOR,BUILD}from"cc/env";class Singleton{constructor(){this._isDisposed=!1}static get(){const e=this;if(null==e._inst)throw new Error(`Singleton is not initialized or destroyed, name is ${e.name}`);return e._inst}get isDisposed(){return this._isDisposed}dispose(){this._onPreDestroy()}_onPreDestroy(){this._isDisposed||(this.destroy&&this.destroy(),Singleton._inst=null,this._isDisposed=!0)}}class TimeInfo extends Singleton{constructor(){super(...arguments),this.deltaTime=0}awake(){this.serverMinusClientTime=0}clientNow(){return Date.now()}serverNow(){return this.clientNow()+this.serverMinusClientTime}update(e){this.deltaTime=e}}class JsHelper{static getMethodName(){const e=(new Error).stack.split("at ")[2],t=e.indexOf(" ");return e.substring(0,t)}static getRootDirName(e){return e.split("/")[0]}static sleep(e){return new Promise((t=>setTimeout(t,e)))}static isNullOrEmpty(e){return null==e||(0==e.length||void 0)}static getStringHashCode(e){let t=5381,o=e.length;for(;o;)t=33*t^e.charCodeAt(--o);return t>>>0}static modeString(e,t){return this.getStringHashCode(e)%t}static powBigInt(e,t){let o=BigInt(1);for(let s=0;sthis._lastTime?(this._lastTime=e,this._idCount=0):(++this._idCount,this._idCount>powValueBit$1&&(++this._lastTime,this._idCount=0,moyeErrorF("IdGenerator","{0}: idCount per sec overflow: {1} {2}",(new this).constructor.name,e,this._lastTime)));const t=IdStruct.inst;return t.init(this._lastTime,1,this._idCount),t.result}static convertToId(e,t,o){return IdStruct.inst.init(e,t,o).result}static parseId(e){return IdStruct.inst.initById(e)}static timeSinceEpoch(){const e=(TimeInfo.get().clientNow()-epoch$1)/1e3;return Math.floor(e)}initById(e){return this.result=e,this.time=e&powTimeBit$1,e>>=timeBit$1,this.process=e&powProcessBit,e>>=processBit,this.value=e&powValueBit$1,this}init(e,t,o){return this.time=BigInt(e),this.process=BigInt(t),this.value=BigInt(o),this.updateResult(),this}updateResult(){this.result=this.value,this.result<<=processBit,this.result|=this.process,this.result<<=timeBit$1,this.result|=this.time}}IdStruct._lastTime=0,IdStruct._idCount=0;const timeBit=32n,valueBit=32n,powTimeBit=JsHelper.powBigInt(2n,timeBit)-1n,powValueBit=JsHelper.powBigInt(2n,valueBit)-1n,epoch=new Date(2023,4,1).getTime();class InstanceIdStruct{static get inst(){return null==InstanceIdStruct._inst&&(InstanceIdStruct._inst=new InstanceIdStruct),InstanceIdStruct._inst}static generate(){0==this._lastTime&&(this._lastTime=this.timeSinceEpoch(),this._lastTime<=0&&(moyeWarnF("IdGenerator","{0}: lastTime less than 0: {1}",(new this).constructor.name,this._lastTime),this._lastTime=1));const e=this.timeSinceEpoch();e>this._lastTime?(this._lastTime=e,this._idCount=0):(++this._idCount,this._idCount>powValueBit&&(++this._lastTime,this._idCount=0,moyeErrorF("IdGenerator","{0}: idCount per sec overflow: {1} {2}",(new this).constructor.name,e,this._lastTime)));const t=InstanceIdStruct.inst;return t.init(this._lastTime,this._idCount),t.result}static convertToId(e,t){return InstanceIdStruct.inst.init(e,t).result}static parseId(e){return InstanceIdStruct.inst.initById(e)}static timeSinceEpoch(){const e=(TimeInfo.get().clientNow()-epoch)/1e3;return Math.floor(e)}initById(e){return this.result=e,this.time=e&powTimeBit,e>>=timeBit,this.value=e&powValueBit,this}init(e,t){return this.time=BigInt(e),this.value=BigInt(t),this.updateResult(),this}updateResult(){this.result=this.value,this.result<<=timeBit,this.result|=this.time}}InstanceIdStruct._lastTime=0,InstanceIdStruct._idCount=0;class IdGenerator extends Singleton{generateInstanceId(){return InstanceIdStruct.generate()}generateId(){return IdStruct.generate()}}class ObjectPool extends Singleton{constructor(){super(...arguments),this._pool=new Map}fetch(e){const t=this._pool.get(e);return t?0===t.length?new e:t.shift():new e}recycle(e){const t=e.constructor;let o=this._pool.get(t);o||(o=[],this._pool.set(t,o)),o.length>1e3?console.warn(`pool ${t.name} is too large`):o.push(e)}}class EntityCenter extends Singleton{constructor(){super(...arguments),this._allEntities=new Map}add(e){this._allEntities.set(e.instanceId,e)}remove(e){this._allEntities.delete(e)}get(e){return this._allEntities.get(e)}}var InstanceQueueIndex,EntityStatus,SceneType;!function(e){e[e.NONE=-1]="NONE",e[e.UPDATE=0]="UPDATE",e[e.LATE_UPDATE=1]="LATE_UPDATE",e[e.MAX=2]="MAX"}(InstanceQueueIndex||(InstanceQueueIndex={}));class EntityLifiCycleMgr extends Singleton{constructor(){super(...arguments),this._queues=new Array(InstanceQueueIndex.MAX)}awake(){for(let e=0;e=0;o--){const s=e[o],r=t.get(s);r?r.isDisposed?e.splice(o,1):r.update():e.splice(o,1)}}lateUpdate(){const e=this._queues[InstanceQueueIndex.LATE_UPDATE],t=EntityCenter.get();for(let o=e.length-1;o>=0;o--){const s=e[o],r=t.get(s);r?r.isDisposed?e.splice(o,1):r.lateUpdate():e.splice(o,1)}}}!function(e){e[e.NONE=0]="NONE",e[e.IS_FROM_POOL=1]="IS_FROM_POOL",e[e.IS_REGISTER=2]="IS_REGISTER",e[e.IS_COMPONENT=4]="IS_COMPONENT",e[e.IS_CREATED=8]="IS_CREATED",e[e.IS_NEW=16]="IS_NEW"}(EntityStatus||(EntityStatus={}));class Entity{constructor(){this._status=EntityStatus.NONE}get parent(){return this._parent}set parent(e){if(null==e)throw new Error(`cant set parent null: ${this.constructor.name}`);if(e==this)throw new Error(`cant set parent self: ${this.constructor.name}`);if(null==e.domain)throw new Error(`cant set parent because parent domain is null: ${this.constructor.name} ${e.constructor.name}`);if(null!=this._parent){if(this._parent==e)throw new Error(`重复设置了Parent: ${this.constructor.name} parent: ${this._parent.constructor.name}`);this._parent.removeFromChildren(this)}this._parent=e,this.isComponent=!1,this._parent.addToChildren(this),this.domain=this.parent.domain}get domain(){return this._domain}set domain(e){if(null==e)throw new Error(`domain cant set null: ${this.constructor.name}`);if(this._domain==e)return;const t=this._domain;if(this._domain=e,null==t&&(this.instanceId=IdGenerator.get().generateInstanceId(),this.isRegister=!0),null!=this._children)for(const[e,t]of this._children.entries())t.domain=this._domain;if(null!=this._components)for(const[e,t]of this._components.entries())t.domain=this._domain;this.isCreated||(this.isCreated=!0)}get isDisposed(){return 0n==this.instanceId}get children(){return this._children??(this._children=ObjectPool.get().fetch(Map))}get components(){return this._components??(this._components=ObjectPool.get().fetch(Map))}get isFromPool(){return(this._status&EntityStatus.IS_FROM_POOL)==EntityStatus.IS_FROM_POOL}set isFromPool(e){e?this._status|=EntityStatus.IS_FROM_POOL:this._status&=~EntityStatus.IS_FROM_POOL}get isComponent(){return(this._status&EntityStatus.IS_COMPONENT)==EntityStatus.IS_COMPONENT}set isComponent(e){e?this._status|=EntityStatus.IS_COMPONENT:this._status&=~EntityStatus.IS_COMPONENT}get isCreated(){return(this._status&EntityStatus.IS_CREATED)==EntityStatus.IS_CREATED}set isCreated(e){e?this._status|=EntityStatus.IS_CREATED:this._status&=~EntityStatus.IS_CREATED}get isNew(){return(this._status&EntityStatus.IS_NEW)==EntityStatus.IS_NEW}set isNew(e){e?this._status|=EntityStatus.IS_NEW:this._status&=~EntityStatus.IS_NEW}get isRegister(){return(this._status&EntityStatus.IS_REGISTER)==EntityStatus.IS_REGISTER}set isRegister(e){if(this.isRegister!=e)if(e?this._status|=EntityStatus.IS_REGISTER:this._status&=~EntityStatus.IS_REGISTER,e){const e=this;EntityCenter.get().add(e),EntityLifiCycleMgr.get().registerSystem(e)}else EntityCenter.get().remove(this.instanceId)}set componentParent(e){if(null==e)throw new Error(`cant set parent null: ${this.constructor.name}`);if(e==this)throw new Error(`cant set parent self: ${this.constructor.name}`);if(null==e.domain)throw new Error(`cant set parent because parent domain is null: ${this.constructor.name} ${e.constructor.name}`);if(null!=this.parent){if(this.parent==e)throw new Error(`重复设置了Parent: ${this.constructor.name} parent: ${this.parent.constructor.name}`);this.parent.removeFromComponents(this)}this._parent=e,this.isComponent=!0,this._parent.addToComponents(this),this.domain=this.parent.domain}addCom(e,t){return e instanceof Entity?this.addComByEntity(e):this.addComByType(e,t)}tryAddCom(e){let t=this.getCom(e);return null==t&&(t=this.addCom(e)),t}addComByEntity(e){const t=e.constructor;if(null!=this._components&&this._components.has(t))throw new Error(`entity already has component: ${t.name}`);return e.componentParent=this,e}addComByType(e,t=!1){if(null!=this._components&&this._components.has(e))throw new Error(`entity already has component: ${e.name}`);const o=this.createInst(e,t);return o.id=this.id,o.componentParent=this,o.awake&&EntityLifiCycleMgr.get().awakeComEvent(o),o}addChild(e,t){return e instanceof Entity?this.addChildByEntity(e):this.addChildByType(e,t)}addChildWithId(e,t,o=!1){const s=this.createInst(e,o);return s.id=t,s.parent=this,s.awake&&EntityLifiCycleMgr.get().awakeComEvent(s),s}addChildByEntity(e){return e.parent=this,e}addChildByType(e,t=!1){const o=this.createInst(e,t);return o.id=IdGenerator.get().generateId(),o.parent=this,o.awake&&EntityLifiCycleMgr.get().awakeComEvent(o),o}createInst(e,t){let o;return o=t?ObjectPool.get().fetch(e):new e,o.isFromPool=t,o.isCreated=!0,o.isNew=!0,o.id=0n,o}removeFromChildren(e){null!=this._children&&(this._children.delete(e.id),0==this._children.size&&(ObjectPool.get().recycle(this._children),this._children=null))}removeFromComponents(e){null!=this._components&&(this._components.delete(e.constructor),0==this._components.size&&(ObjectPool.get().recycle(this._components),this._components=null))}addToComponents(e){this.components.set(e.constructor,e)}addToChildren(e){if(this.children.has(e.id))throw new Error(`entity already has child: ${e.id}`);this.children.set(e.id,e)}getCom(e){if(null==this._components)return null;const t=this._components.get(e);return t||null}removeCom(e){if(this.isDisposed)return;if(null==this._components)return;const t=this.getCom(e);null!=t&&(this.removeFromComponents(t),t.dispose())}getParent(e){return this.parent}getChild(e,t){if(null==this._children)return null;return this._children.get(t)}removeChild(e){if(null==this._children)return;const t=this._children.get(e);t&&(this._children.delete(e),t.dispose())}dispose(){if(!this.isDisposed){if(this.isRegister=!1,this.instanceId=0n,null!=this._children){for(const[e,t]of this._children.entries())t.dispose();this._children.clear(),ObjectPool.get().recycle(this._children),this._children=null}if(null!=this._components){for(const[e,t]of this._components.entries())t.dispose();this._components.clear(),ObjectPool.get().recycle(this._components),this._components=null}this.destroy&&EntityLifiCycleMgr.get().destroyComEvent(this),this._domain=null,null==this._parent||this._parent.isDisposed||(this.isComponent?this._parent.removeCom(this.getType()):this._parent.removeFromChildren(this)),this._parent=null,this.isFromPool&&ObjectPool.get().recycle(this),this._status=EntityStatus.NONE}}domainScene(){return this.domain}getType(){return this.constructor}}class Scene extends Entity{set domain(e){this._domain=e}get domain(){return this._domain}set parent(e){null!=e&&(this._parent=e,this._parent.children.set(this.id,this))}get parent(){return this._parent}init(e){this.id=e.id,this.instanceId=e.instanceId,this.sceneType=e.sceneType,this.name=e.name,this.parent=e.parent,this.isCreated=!0,this.isNew=!0,this.domain=this,this.isRegister=!0,moyeLogF("scene","scene create sceneType = {0}, name = {1}, id = {2}",this.sceneType,this.name,this.id)}}!function(e){e.NONE="NONE",e.PROCESS="PROCESS",e.CLIENT="CLIENT",e.CURRENT="CURRENT"}(SceneType||(SceneType={}));class Root extends Singleton{get scene(){return this._scene}awake(){const e=new Scene;e.init({id:0n,sceneType:SceneType.PROCESS,name:"Process",instanceId:IdGenerator.get().generateInstanceId()}),this._scene=e}}class RecycleObj{static create(e){const t=ObjectPool.get().fetch(this);return e&&Object.assign(t,e),t._isRecycle=!0,t}dispose(){this._isRecycle&&ObjectPool.get().recycle(this)}}class AEvent extends RecycleObj{}class BeforeSingletonAdd extends AEvent{}class AfterSingletonAdd extends AEvent{}class BeforeProgramInit extends AEvent{}class AfterProgramInit extends AEvent{}class BeforeProgramStart extends AEvent{}class AfterProgramStart extends AEvent{}class AfterCreateClientScene extends AEvent{}class AfterCreateCurrentScene extends AEvent{}class DecoratorCollector{constructor(){this._decorators=new Map}static get inst(){return null==DecoratorCollector._inst&&(DecoratorCollector._inst=new DecoratorCollector),DecoratorCollector._inst}add(e,...t){let o=this._decorators.get(e);o||(o=[],this._decorators.set(e,o)),o.push(t)}get(e){return this._decorators.get(e)||[]}}const EventDecoratorType="EventDecoratorType";function EventDecorator(e,t){return function(o){null==t&&console.error("EventDecorator必须要传 sceneType"),DecoratorCollector.inst.add(EventDecoratorType,e,o,t)}}class EventInfo{constructor(e,t){this.eventHandler=e,this.sceneType=t}}class MoyeEventCenter{constructor(){this.allEvents=new Map}static get inst(){return null==this._inst&&(this._inst=new MoyeEventCenter,this._inst.reloadEvent()),this._inst}reloadEvent(){const e=DecoratorCollector.inst.get(EventDecoratorType);this.allEvents.clear();for(const t of e){const e=t[0],o=t[1],s=t[2];let r=this.allEvents.get(e);r||(r=[],this.allEvents.set(e,r)),r.push(new EventInfo(new o,s))}}publish(e){const t=this.allEvents.get(e.constructor);if(t){for(let o=0;o{t=e}));return o._resolve=t,o}setResult(e){if(!this._resolve)throw new Error("setResult but task has been disposed");this._resolve(e),this.dispose()}constructor(e){super(e)}dispose(){this._resolve=null}}class Game{static addSingleton(e,t=!0){if(Game._singletonMap.has(e))throw new Error(`already exist singleton: ${e.name}`);t&&MoyeEventCenter.inst.publish(BeforeSingletonAdd.create({singletonType:e}));const o=new e;e._inst=o,Game._singletonMap.set(e,o),Game._singletons.push(o);const s=o;return s.awake&&s.awake(),Game._destroys.push(s),s.update&&Game._updates.push(s),s.lateUpdate&&Game._lateUpdates.push(s),t&&MoyeEventCenter.inst.publish(AfterSingletonAdd.create({singletonType:e})),o}static async waitFrameFinish(){const e=Task.create();Game._frameFinishTaskQueue.push(e),await e}static update(e){for(let t=0;t=0;e--){const t=Game._singletons[e];t.isDisposed||t._onPreDestroy()}}}Game._singletonMap=new Map,Game._singletons=[],Game._destroys=[],Game._updates=[],Game._lateUpdates=[],Game._frameFinishTaskQueue=[];class EventSystem extends Singleton{async publishAsync(e,t){const o=MoyeEventCenter.inst.allEvents.get(t.constructor);if(!o)return;const s=[];for(let r=0;r=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$m,property:property$m}=_decorator;let MoyeRuntime=class extends Component{start(){director.addPersistRootNode(this.node)}update(e){Game.update(1e3*e)}lateUpdate(e){Game.lateUpdate(1e3*e),Game.frameFinishUpdate()}onDestroy(){Game.dispose()}};MoyeRuntime=__decorate$u([ccclass$m("MoyeRuntime")],MoyeRuntime);class TimeHelper{static clientNow(){return TimeInfo.get().clientNow()}static clientNowSeconds(){return Math.floor(TimeHelper.clientNow()/1e3)}static serverNow(){return TimeInfo.get().serverNow()}}var TimerType;TimeHelper.oneDay=864e5,TimeHelper.oneHour=36e5,TimeHelper.oneMinute=6e4,function(e){e[e.ONCE=0]="ONCE",e[e.REPEAT=1]="REPEAT"}(TimerType||(TimerType={}));class Timer{static create(){const e=ObjectPool.get().fetch(Timer);return e.reset(),e.id=Timer.getId(),e}static getId(){return++this._idGenerator}reset(){this.cb=null,this.tcs=null,this.id=0,this.expireTime=0,this.interval=0}dispose(){this.reset(),ObjectPool.get().recycle(this)}}Timer._idGenerator=1e3;class TimerMgr extends Singleton{constructor(){super(...arguments),this._timerMap=new Map,this._timers=[]}newRepeatedTimer(e,t,o=!1){const s=Timer.create();return s.type=TimerType.REPEAT,s.cb=t,s.interval=e,s.expireTime=e+TimeHelper.clientNow(),this._timerMap.set(s.id,s),this._timers.push(s),o&&t(),s.id}newOnceTimer(e,t){const o=Timer.create();return o.type=TimerType.ONCE,o.cb=t,o.expireTime=e+TimeHelper.clientNow(),this._timerMap.set(o.id,o),this._timers.push(o),o.id}newFrameTimer(e){const t=Timer.create();return t.type=TimerType.REPEAT,t.cb=e,t.interval=1,t.expireTime=t.interval+TimeHelper.clientNow(),this._timerMap.set(t.id,t),this._timers.push(t),t.id}remove(e){const t=this._timerMap.get(e);return!!t&&(t.id=0,this._timerMap.delete(e),!0)}update(){const e=TimeHelper.clientNow();for(let t=this._timers.length-1;t>=0;t--){const o=this._timers[t];0!=o.id?o.expireTime>e||(null!=o.cb&&o.cb(),null!=o.tcs&&o.tcs.setResult(),o.type==TimerType.REPEAT?o.expireTime+=o.interval:this.remove(o.id)):(this._timers.splice(t,1),o.dispose())}}async waitAsync(e,t){if(e<=0)return;const o=Task.create(),s=Timer.create();let r;s.type=TimerType.ONCE,s.tcs=o,s.expireTime=e+TimeHelper.clientNow(),this._timerMap.set(s.id,s),this._timers.push(s),t&&(r=()=>{this.remove(s.id)&&o.setResult()},t.add(r));try{await o}finally{t?.remove(r),r=null}}}const CoroutineLockTag="CoroutineLock";class CoroutineLockItem{init(e){this.key=e,this.task=Task.create(),this.setTimeout(6e4,"CoroutineLock timeout")}setTimeout(e,t){this.deleteTimeout(),this._timerId=TimerMgr.get().newOnceTimer(e,this.timeout.bind(this)),this._timeoutInfo=t}deleteTimeout(){null!=this._timerId&&(TimerMgr.get().remove(this._timerId),this._timerId=null)}async timeout(){moyeWarnF("CoroutineLock","CoroutineLock timeout key: {0}, info: {1}",this.key,this._timeoutInfo)}dispose(){null!=this.key?(this.deleteTimeout(),CoroutineLock.get().runNextLock(this),this.key=null,this.task=null):moyeWarnF("CoroutineLock","repeat dispose CoroutineLockItem")}}class CoroutineLock extends Singleton{constructor(){super(...arguments),this._lockMap=new Map}async wait(e,t){const o=`${e}_${t}`;let s=this._lockMap.get(o);s||(s=new Set,this._lockMap.set(o,s));const r=ObjectPool.get().fetch(CoroutineLockItem);return r.init(o),s.add(r),s.size>1?await r.task:r.task.setResult(),r}runNextLock(e){const t=this._lockMap.get(e.key);t.delete(e),ObjectPool.get().recycle(e);for(const e of Array.from(t.values())){e.task.setResult();break}}}class SceneRefCom extends Entity{}class SceneFactory{static createClientScene(){const e=Root.get().scene.getCom(SceneRefCom);e.scene?.dispose();const t=new Scene;return t.init({id:1n,sceneType:SceneType.CLIENT,name:"Game",instanceId:IdGenerator.get().generateInstanceId(),parent:e}),t.addCom(SceneRefCom),e.scene=t,EventSystem.get().publish(t,AfterCreateClientScene.create()),t}static createCurrentScene(e,t){const o=Root.get().scene.getCom(SceneRefCom).scene.getCom(SceneRefCom);o.scene?.dispose();const s=new Scene;return s.init({id:e,sceneType:SceneType.CURRENT,name:t,instanceId:IdGenerator.get().generateInstanceId(),parent:o}),o.scene=s,EventSystem.get().publish(s,AfterCreateCurrentScene.create()),s}}class Program{static init(e){MoyeEventCenter.inst.publish(new BeforeProgramInit),Game.addSingleton(ObjectPool,!1),Game.addSingleton(Logger),Game.addSingleton(EventSystem),Game.addSingleton(TimeInfo),Game.addSingleton(TimerMgr),Game.addSingleton(CoroutineLock),Game.addSingleton(IdGenerator),Game.addSingleton(EntityCenter),Game.addSingleton(EntityLifiCycleMgr),Game.addSingleton(Root),e.addComponent(MoyeRuntime),MoyeEventCenter.inst.publish(new AfterProgramInit)}static start(){MoyeEventCenter.inst.reloadEvent(),MoyeEventCenter.inst.publish(new BeforeProgramStart),MoyeEventCenter.inst.publish(new AfterProgramStart),Root.get().scene.addCom(SceneRefCom),SceneFactory.createClientScene()}}async function safeCall(e){try{return await e}catch(e){moyeErrorF("safeCall",e)}}const EventHandlerTag="EventHandler";class AEventHandler{async handleAsync(e,t){try{await this.run(e,t)}catch(e){moyeErrorF("EventHandler","error:{0}",e.stack)}}handle(e,t){try{const o=this.run(e,t);o instanceof Promise&&(moyeWarnF("EventHandler","{0}的run方法是异步的, 请尽量不要用publish来通知",this.constructor.name),safeCall(o))}catch(e){moyeErrorF("EventHandler","error:{0}",e.stack)}}}const CancellationTokenTag="CancellationToken";class CancellationToken{constructor(){this._actions=new Set}add(e){null!=e?this._actions.add(e):moyeErrorF("CancellationToken","CancellationToken add error, callback is null")}remove(e){this._actions?.delete(e)}cancel(){null!=this._actions?this.invoke():moyeErrorF("CancellationToken","CancellationToken cancel error, repeat cancel")}isCancel(){return null==this._actions}invoke(){const e=this._actions;this._actions=null;try{for(const t of e)t();e.clear()}catch(e){moyeErrorF("CancellationToken",e)}}}class MultiMap{constructor(){this._empty=[],this._map=new Map}add(e,t){let o=this._map.get(e);void 0===o&&(o=[],this._map.set(e,o)),o.push(t)}remove(e,t){const o=this._map.get(e);if(void 0===o)return!1;const s=o.indexOf(t);return-1!==s&&(o.splice(s,1),0===o.length&&this._map.delete(e),!0)}getAll(e){const t=this._map.get(e);return void 0===t?[]:t}get(e){return this._map.get(e)??this._empty}getOne(e){const t=this._map.get(e);if(void 0!==t&&t.length>0)return t[0]}contains(e,t){const o=this._map.get(e);return void 0!==o&&o.includes(t)}}Entity.prototype.clientScene=function(){const e=this.domainScene();return e.sceneType==SceneType.CLIENT?e:e.sceneType==SceneType.CURRENT?e.parent.parent:e.sceneType==SceneType.PROCESS?e.getCom(SceneRefCom).scene:void 0},Entity.prototype.currentScene=function(){return this.clientScene().getCom(SceneRefCom).scene};class EventAutoReleaseCom extends Entity{constructor(){super(...arguments),this.events=[]}addItem(e){this.events.push(e)}destroy(){const e=this.eventCom.eventMap;for(const t of this.events){e.get(t.eventType).delete(t),t.entity=null,t.handler=null,t.eventType=null,t.dispose()}this.events=null,this.eventCom=null}}class EventItem extends RecycleObj{}class EventCom extends Entity{constructor(){super(...arguments),this._eventMap=new Map}destroy(){const e=this._eventMap;for(const t of e.values()){for(const e of t)e.entity=null,e.handler=null,e.eventType=null,e.dispose();t.clear()}e.clear()}subscribe(e,t,o){const s=EventItem.create({entity:o,handler:t,eventType:e});let r=this._eventMap.get(e);r||(r=new Set,this._eventMap.set(e,r)),r.add(s);let i=o.getCom(EventAutoReleaseCom);i||(i=o.addCom(EventAutoReleaseCom),i.eventCom=this),i.addItem(s)}publish(e,...t){const o=this._eventMap.get(e);if(o)for(const e of o)e.handler.apply(e.entity,t)}}class LocalStorageHelper{static getNumber(e,t){const o=localStorage.getItem(e);if(!o)return t;try{return Number(o)}catch(e){return t}}static setNumber(e,t){localStorage.setItem(e,t.toString())}static getString(e,t){const o=localStorage.getItem(e);return o||t}static setString(e,t){localStorage.setItem(e,t)}static setBoolean(e,t){localStorage.setItem(e,t?"1":"0")}static getBoolean(e,t){const o=localStorage.getItem(e);return o?"1"==o:t}static setObject(e){localStorage.setItem(e.constructor.name,JSON.stringify(e))}static getObject(e){const t=localStorage.getItem(e.name);if(!t)return null;try{return JSON.parse(t)}catch(e){return null}}}class LoginCom extends Entity{constructor(){super(...arguments),this._isLogin=!1,this._isReconnecting=!1,this._reLoginTryMaxCount=3}registerExecutor(e){this._loginExecutor=e}async login(e){const t=await this._loginExecutor.login(this.domainScene(),e);return 0==t&&(this._isLogin=!0,this._loginArgs=e),t}}class AfterAddLoginCom extends AEvent{}var __decorate$t=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterCreateClientSceneHandler$1=class extends AEventHandler{run(e,t){e.addCom(LoginCom),EventSystem.get().publish(e,new AfterAddLoginCom)}};AfterCreateClientSceneHandler$1=__decorate$t([EventDecorator(AfterCreateClientScene,SceneType.CLIENT)],AfterCreateClientSceneHandler$1);class MsgMgr extends Singleton{constructor(){super(...arguments),this._responseTypeMap=new Set,this._typeOpcodeMap=new Map,this._opcodeTypeMap=new Map}awake(){}register(e,t,o=!1){this._typeOpcodeMap.set(e,t),this._opcodeTypeMap.set(t,e),o&&this._responseTypeMap.add(t)}isResponse(e){return this._responseTypeMap.has(e)}getOpcode(e){return this._typeOpcodeMap.get(e)}getType(e){return this._opcodeTypeMap.get(e)}}class MsgSerializeMgr extends Singleton{register(e){this._serialize=e}serialize(e,t){return this._serialize.encode(e,t)}deserialize(e){return this._serialize.decode(e)}}var __decorate$s=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterSingletonAddHandler=class extends AEventHandler{run(e,t){if(t.singletonType===MsgMgr)Game.addSingleton(MsgSerializeMgr)}};AfterSingletonAddHandler=__decorate$s([EventDecorator(AfterSingletonAdd,SceneType.PROCESS)],AfterSingletonAddHandler);const MsgHandlerDecoratorType="MsgHandlerDecorator";function MsgHandlerDecorator(e){return function(t){DecoratorCollector.inst.add("MsgHandlerDecorator",t,e)}}class MessageDispatcherMgr extends Singleton{constructor(){super(...arguments),this._handlers=new Map}awake(){const e=DecoratorCollector.inst.get("MsgHandlerDecorator");for(const t of e){const e=t[0],o=t[1],s=new e;this._handlers.has(o)||this._handlers.set(o,[]),this._handlers.get(o).push(s)}}destroy(){this._handlers.clear()}handle(e,t){const o=t.constructor,s=this._handlers.get(o);if(s)for(const o of s)o.handle(e,t);else console.error("[MessageDispatcherMgr] msg not found handler",t)}}var __decorate$r=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let BeforeProgramStartHandler=class extends AEventHandler{run(e,t){Game.addSingleton(MsgMgr),Game.addSingleton(MessageDispatcherMgr)}};BeforeProgramStartHandler=__decorate$r([EventDecorator(BeforeProgramStart,SceneType.PROCESS)],BeforeProgramStartHandler);class NetClientComponentOnRead extends AEvent{}var __decorate$q=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let NetClientComponentOnReadEvent=class extends AEventHandler{run(e,t){t.session;t.data;Uint8Array}};NetClientComponentOnReadEvent=__decorate$q([EventDecorator(NetClientComponentOnRead,SceneType.CLIENT)],NetClientComponentOnReadEvent);const NetworkTag="Network";class NetServices extends Singleton{constructor(){super(...arguments),this._acceptIdGenerator=Number.MAX_SAFE_INTEGER-1,this._services=new Map,this._serviceIdGenerator=0,this._acceptCallback=new Map,this._readCallback=new Map,this._errorCallback=new Map}sendMessage(e,t,o){const s=this.get(e);null!=s&&s.send(t,o)}addService(e){return e.id=++this._serviceIdGenerator,this.add(e),e.id}removeService(e){this.remove(e)}createChannel(e,t,o){const s=this.get(e);null!=s&&s.create(t,o)}removeChannel(e,t,o){const s=this.get(e);null!=s&&s.remove(t,o)}registerAcceptCallback(e,t){this._acceptCallback.set(e,t)}registerReadCallback(e,t){this._readCallback.set(e,t)}registerErrorCallback(e,t){this._errorCallback.has(e)&&moyeErrorF("Network","重复注册servece的errorCallback, serviceId={0}",e),this._errorCallback.set(e,t)}onAccept(e,t,o){const s=this._acceptCallback.get(e);s&&s(t,o)}onRead(e,t,o){const s=this._readCallback.get(e);s&&s(t,o)}onError(e,t,o){const s=this._errorCallback.get(e);s&&s(t,o)}get(e){return this._services.get(e)}createAcceptChannelId(){return--this._acceptIdGenerator}add(e){this._services.set(e.id,e)}remove(e){const t=this._services.get(e);t&&t.dispose()}}var __decorate$p=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterProgramInitHandler$1=class extends AEventHandler{run(e,t){Game.addSingleton(NetServices)}};AfterProgramInitHandler$1=__decorate$p([EventDecorator(AfterProgramInit,SceneType.PROCESS)],AfterProgramInitHandler$1);class NetworkErrorCode{}NetworkErrorCode.ERR_SendMessageNotFoundChannel=1,NetworkErrorCode.ERR_ChannelReadError=2,NetworkErrorCode.ERR_WebSocketError=3;class IPEndPoint{constructor(e,t=0){if(0==t){const t=e.split(":");this.host=t[0],this.port=parseInt(t[1])}else this.host=e,this.port=t}toString(){return`${this.host}:${this.port}`}}var ServiceType;!function(e){e[e.Outer=0]="Outer",e[e.Inner=1]="Inner"}(ServiceType||(ServiceType={}));class AChannel{constructor(){this.id=0n}get isDisposed(){return 0n==this.id}}const NetworkWebsocketTag="WService";class WChannel extends AChannel{constructor(){super(...arguments),this._isConnected=!1,this._msgQueue=[]}initByAddress(e,t,o){this.wSocket=new WebSocket(`ws://${e}`),this.wSocket.binaryType="arraybuffer",this.id=t,this._service=o,this.remoteAddress=e,this.wSocket.onopen=this.onConnectComplete.bind(this),this.wSocket.onclose=this.onSocketClose.bind(this),this.wSocket.onerror=this.onWsSocketError.bind(this),this.wSocket.onmessage=this.onMessage.bind(this)}onConnectComplete(){this._isConnected=!0;for(const e of this._msgQueue)this.innerSend(e);this._msgQueue=[]}onMessage(e){try{const t=this.id;NetServices.get().onRead(this._service.id,t,e.data)}catch(e){moyeErrorF("WService","Channel onMessage, remoteAddress={1} error={0}",e.stack,this.remoteAddress.toString()),this.onError(NetworkErrorCode.ERR_ChannelReadError)}}dispose(){this.isDisposed||(this.id=0n,this.wSocket=null,this._msgQueue=null,this._service=null,this._isConnected=!1,this.remoteAddress=null)}onWsSocketError(e){this.onSocketClose(NetworkErrorCode.ERR_WebSocketError)}onSocketClose(e){this._service&&this._service.channelClose(this,e)}closeSocket(e){e<4e3?null!=this.wSocket&&this.wSocket.close():null!=this.wSocket&&this.wSocket.close(e)}onError(e){this._service.remove(this.id,e)}innerSend(e){this.wSocket.send(e)}send(e){this.isDisposed||(this._isConnected?this.innerSend(e):this._msgQueue.push(e))}}class AService{}class WService extends AService{constructor(){super(...arguments),this._idChannels=new Map}initSender(e){this.serviceType=e}send(e,t){const o=this._idChannels.get(e);null!=o?o.send(t):NetServices.get().onError(this.id,e,NetworkErrorCode.ERR_SendMessageNotFoundChannel)}create(e,t){this._idChannels.has(e)||this.innerCreate(e,t)}remove(e,t){const o=this._idChannels.get(e);o&&(o.closeSocket(t),this._idChannels.delete(e),o.dispose())}dispose(){}innerCreate(e,t){const o=new WChannel;o.initByAddress(t,e,this),this._idChannels.set(o.id,o)}channelClose(e,t){this._idChannels.delete(e.id),NetServices.get().onError(this.id,e.id,t),e.dispose()}}class NetComReadEvent extends AEvent{}const MessageTag="Message";class MessageErrorCode extends NetworkErrorCode{}MessageErrorCode.ERR_SessionDisposed=101;class RpcResponse{constructor(e){Object.assign(this,e)}}class Session extends Entity{constructor(){super(...arguments),this.requestCallbacks=new Map,this.error=0}init(e){this.serviceId=e;const t=TimeHelper.clientNow();this.lastRecvTime=t,this.lastSendTime=t}onResponse(e){const t=this.requestCallbacks.get(e.rpcId);t&&(this.requestCallbacks.delete(e.rpcId),t.setResult(e))}send(e){if(this.isDisposed)moyeLogF("Message","session已经销毁,不能发送消息, message={0}, sessionId={1}",e.constructor.name,this.id);else try{const t=MsgMgr.get().getOpcode(e.constructor),o=MsgSerializeMgr.get().serialize(t,e);this.lastSendTime=TimeHelper.clientNow(),NetServices.get().sendMessage(this.serviceId,this.id,o)}catch(e){moyeErrorF("Message","session send error={0}",e.stack)}}async call(e){if(this.isDisposed){moyeLogF("Message","session已经销毁,不能发送消息, message={0}, sessionId={1}",e.constructor.name,this.id);return new RpcResponse({error:MessageErrorCode.ERR_SessionDisposed})}const t=++Session._rpcId,o=Task.create();this.requestCallbacks.set(t,o),e.rpcId=t,this.send(e);return await o}destroy(){if(this.error>0&&NetServices.get().onError(this.serviceId,this.id,this.error),NetServices.get().removeChannel(this.serviceId,this.id,this.error),this.requestCallbacks.size>0){const e=new RpcResponse({error:MessageErrorCode.ERR_SessionDisposed});for(const[t,o]of this.requestCallbacks)o.setResult(e);this.requestCallbacks.clear()}}}Session._rpcId=0;class NetCom extends Entity{awake(){const e=new WService;e.initSender(ServiceType.Outer);const t=NetServices.get();this.serviceId=t.addService(e),t.registerReadCallback(this.serviceId,this.onRead.bind(this)),t.registerErrorCallback(this.serviceId,this.onError.bind(this))}destroy(){NetServices.get().removeService(this.serviceId)}onRead(e,t){const o=this.getChild(Session,e);if(null==o)return;o.lastRecvTime=TimeHelper.clientNow();const s=NetComReadEvent.create({data:t,session:o});EventSystem.get().publish(this.domainScene(),s)}onError(e,t){const o=this.getChild(Session,e);null!=o&&(o.error=t,o.dispose())}create(e){const t=this.addChild(Session);return t.init(this.serviceId),t.remoteAddress=e,NetServices.get().createChannel(this.serviceId,t.id,e),t}}class SessionCom extends Entity{destroy(){this.session?.dispose(),this.session=null}}var __decorate$o=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterCreateClientSceneHandler=class extends AEventHandler{run(e,t){e.addCom(NetCom),e.addCom(SessionCom)}};AfterCreateClientSceneHandler=__decorate$o([EventDecorator(AfterCreateClientScene,SceneType.CLIENT)],AfterCreateClientSceneHandler);var __decorate$n=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let NetComReadEventHandler=class extends AEventHandler{run(e,t){const o=t.session,s=t.data,[r,i]=MsgSerializeMgr.get().deserialize(s);MsgMgr.get().isResponse(r)?o.onResponse(i):MessageDispatcherMgr.get().handle(o,i)}};NetComReadEventHandler=__decorate$n([EventDecorator(NetComReadEvent,SceneType.CLIENT)],NetComReadEventHandler);class AMHandler{handle(e,t){if(!e.isDisposed){const o=this.run(e,t);o instanceof Promise&&(moyeWarnF("AMHandler","{0}.run 请不要使用异步, 因为异步没办法保证消息接收后的处理顺序",this.constructor.name),safeCall(o))}}}class AssetInfo{init(e,t){const o=(t=this.parseLocation(e,t)).split("/");let s="";for(let e=1;e=AssetSystem._frameMaxAddQueueProvider)return;if(this._loadingSet.size>=AssetSystem._maxLoadingProvider)return;if(0==this._waitLoads.length)return;const e=this._waitLoads.shift();this._loadingSet.add(e),e.internalLoad()}removeProvider(e){this._loadingSet.delete(e),this.updateLoadingSet()}}AssetSystem._maxLoadingProvider=1,AssetSystem._frameMaxAddQueueProvider=1;const MoyeAssetTag="MoyeAsset";class AssetOperationHandle{constructor(){this.isDisposed=!1}getAsset(e){return this.provider.asset}dispose(){this.isDisposed?moyeErrorF("MoyeAsset","重复销毁AssetOperationHandle"):(this.isDisposed=!0,this.provider.releaseHandle(this))}instantiateSync(){return instantiate(this.provider.asset)}async instantiateAsync(){return instantiate(this.provider.asset)}}class BundleAssetProvider{constructor(){this.refCount=0,this._handleSet=new Set}async internalLoad(){const e=this.assetInfo.assetPath,t=this.assetInfo.assetType;this.bundleAsset.bundle.load(e,t,((e,t)=>{e?moyeErrorF("MoyeAsset","加载资源错误:{0},{1}",this.assetInfo.uuid,e):this.asset=t,this._task.setResult(),this.assetSystem.removeProvider(this)}))}async load(){this._task=Task.create(),this.assetSystem.addProvider(this),await this._task}createHandle(){this.refCount++;const e=new AssetOperationHandle;return e.provider=this,this._handleSet.add(e),e}releaseHandle(e){this.refCount<=0&&moyeWarnF("MoyeAsset","Asset provider reference count is already zero. There may be resource leaks !"),0==this._handleSet.delete(e)&&moyeErrorF("MoyeAsset","Should never get here !"),this.refCount--}}var AssetLockType;!function(e){e.BUNDLE_ASSET_LOAD="bundle_asset_load",e.BUNDLE_LOAD="bundle_load"}(AssetLockType||(AssetLockType={}));class BundleAsset{constructor(){this.refCount=0,this.isAutoRelease=!0,this._providerMap=new Map}async loadAssetAsync(e){let t=this._providerMap.get(e.uuid);t||(t=await this.createProvider(e));return t.createHandle()}async createProvider(e){const t=await CoroutineLock.get().wait(AssetLockType.BUNDLE_ASSET_LOAD,e.uuid);try{let t=this._providerMap.get(e.uuid);return t||(t=new BundleAssetProvider,t.assetInfo=e,t.assetSystem=this.assetSystem,t.bundleAsset=this,this.refCount++,await t.load(),this._providerMap.set(e.uuid,t),t)}finally{t.dispose()}}unloadUnusedAssets(){for(const[e,t]of this._providerMap)0==t.refCount&&(this.bundle.release(t.assetInfo.assetPath,t.assetInfo.assetType),this._providerMap.delete(e),this.refCount--)}}class MoyeAssets extends Singleton{awake(){MoyeAssets.assetSystem=new AssetSystem}update(){MoyeAssets.assetSystem.update()}static async loadAssetAsync(e,t){try{const o=new AssetInfo;o.init(e,t);const s=o.bundleName;let r=MoyeAssets._bundleMap.get(s);r||(r=await this.loadBundleAsync(s));return await r.loadAssetAsync(o)}catch(e){moyeErrorF("MoyeAsset",e)}}static async loadBundleAsync(e){const t=await CoroutineLock.get().wait(AssetLockType.BUNDLE_LOAD,e);try{let t=MoyeAssets._bundleMap.get(e);if(t)return t;const o=Task.create();if(!this._bundlePathMap.has(e)&&(this._bundlePathMap.set(e,e),NATIVE)){const t=`${native.fileUtils.getWritablePath()}hot/${e}`;native.fileUtils.isDirectoryExist(t)&&this._bundlePathMap.set(e,t)}const s=this._bundlePathMap.get(e);moyeLogF("MoyeAsset","加载bundle: {0}",s),assetManager.loadBundle(s,((t,s)=>{t?moyeLogF("MoyeAsset","加载Bundle错误, bundle={0}, error={1}",e,t):moyeLogF("MoyeAsset","加载Bundle完成, bundle={0}",e),o.setResult(s)}));const r=await o;return t=new BundleAsset,t.bundle=r,t.bundleName=e,t.assetSystem=MoyeAssets.assetSystem,MoyeAssets._bundleMap.set(e,t),t}finally{t.dispose()}}static releaseBundle(e){0==e.refCount?(this._bundleMap.delete(e.bundleName),assetManager.removeBundle(e.bundle),moyeLogF("MoyeAsset","卸载bundle:{0}",e.bundleName)):moyeErrorF("MoyeAsset","释放的bundle:{0}, 引用计数不为0",e.bundleName)}static unloadUnusedAssets(){for(const[e,t]of this._bundleMap)0==t.refCount&&t.isAutoRelease&&(t.unloadUnusedAssets(),MoyeAssets.releaseBundle(t))}}MoyeAssets._bundleMap=new Map,MoyeAssets._bundlePathMap=new Map;var __decorate$m=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterProgramInitHandler=class extends AEventHandler{run(e,t){Game.addSingleton(MoyeAssets)}};var WaitError;AfterProgramInitHandler=__decorate$m([EventDecorator(AfterProgramInit,SceneType.NONE)],AfterProgramInitHandler),function(e){e[e.SUCCESS=0]="SUCCESS",e[e.DESTROY=1]="DESTROY",e[e.CANCEL=2]="CANCEL",e[e.TIMEOUT=3]="TIMEOUT"}(WaitError||(WaitError={}));class AWait extends RecycleObj{constructor(){super(...arguments),this.error=WaitError.SUCCESS}}class ObjectWait extends Entity{constructor(){super(...arguments),this._tasks=new Map}destroy(){for(const[e,t]of this._tasks){const t=this.createWaitInstance(e,WaitError.DESTROY);this.notify(t)}}async wait(e,t){this.cancelLastWait(e);const o=Task.create(e);let s,r;this._tasks.set(e,o),t&&(s=()=>{const t=this.createWaitInstance(e,WaitError.CANCEL);this.notify(t)},t.add(s));try{r=await o}finally{t?.remove(s),s=null}return r}async waitWithTimeout(e,t,o){this.cancelLastWait(e);const s=Task.create(e);let r,i;this._tasks.set(e,s),this.timeoutRun(e,t,o),o&&(r=()=>{const t=this.createWaitInstance(e,WaitError.CANCEL);this.notify(t)},o.add(r));try{i=await s}finally{o?.remove(r),r=null}return i}cancelLastWait(e){if(!this._tasks.has(e))return;moyeWarnF("上一个wait已经取消, {0}",e.name);const t=this.createWaitInstance(e,WaitError.CANCEL);this.notify(t)}async timeoutRun(e,t,o){if(await TimerMgr.get().waitAsync(t,o),o?.isCancel())return;if(!this._tasks.has(e))return;const s=this.createWaitInstance(e,WaitError.TIMEOUT);this.notify(s)}createWaitInstance(e,t){const o=e.create();return o.error=t,o}notify(e){const t=this._tasks.get(e.constructor);t&&(this._tasks.delete(e.constructor),t.setResult(e),e.dispose())}}class AsyncButtonListener{constructor(e){this._callback=e}async invoke(...e){this._isClick||(this._isClick=!0,await this._callback(...e),this._isClick=!1)}static create(e){const t=new AsyncButtonListener(e);return t.invoke.bind(t)}}var __decorate$l=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$l,property:property$l,menu:menu$b}=_decorator;let BgAdapter=class extends Component{constructor(){super(...arguments),this.coverNode=null,this.isShowMax=!0,this._selfTransform=null}start(){this._selfTransform=this.node.getComponent(UITransform),this.updateSize(),this.coverNode.node.on(Node.EventType.SIZE_CHANGED,this.updateSize,this)}onDestroy(){this.coverNode.node.off(Node.EventType.SIZE_CHANGED,this.updateSize,this),this.coverNode=null,this._selfTransform=null}updateSize(){let e=0;e=this.isShowMax?Math.max(this.coverNode.width/this._selfTransform.width,this.coverNode.height/this._selfTransform.height):Math.min(this.coverNode.width/this._selfTransform.width,this.coverNode.height/this._selfTransform.height);const t=this._selfTransform.width*e,o=this._selfTransform.height*e;this._selfTransform.width=t,this._selfTransform.height=o}};__decorate$l([property$l(UITransform)],BgAdapter.prototype,"coverNode",void 0),__decorate$l([property$l(CCBoolean)],BgAdapter.prototype,"isShowMax",void 0),BgAdapter=__decorate$l([ccclass$l("BgAdapter"),menu$b("moye/BgAdapter")],BgAdapter);var __decorate$k=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$k,inspector:inspector$1,property:property$k,disallowMultiple:disallowMultiple$1,menu:menu$a}=_decorator;var CenterHorizontalDirection;!function(e){e[e.LEFT_TO_RIGHT=0]="LEFT_TO_RIGHT",e[e.RIGHT_TO_LEFT=1]="RIGHT_TO_LEFT",e[e.CENTER_TO_SIDE=2]="CENTER_TO_SIDE"}(CenterHorizontalDirection||(CenterHorizontalDirection={}));let CenterLayout=class extends Layout{constructor(){super(...arguments),this.centerHorizontalDirection=CenterHorizontalDirection.CENTER_TO_SIDE}_doLayoutHorizontally(e,t,o,s){const r=this.node._uiProps.uiTransformComp.anchorPoint,i=this._getFixedBreakingNum();let n=1,a=this._paddingLeft;this._horizontalDirection===Layout.HorizontalDirection.RIGHT_TO_LEFT&&(n=-1,a=this._paddingRight);const c=(this._horizontalDirection-r.x)*e+n*a;let l=c-n*this._spacingX,d=0,h=0,p=0,_=0,u=!1;const y=this._usefulLayoutObj.length;let g=this._cellSize.width;const m=this._getPaddingH();this._layoutType!==Layout.Type.GRID&&this._resizeMode===Layout.ResizeMode.CHILDREN&&(g=(e-m-(y-1)*this._spacingX)/y);const T=this._usefulLayoutObj;for(let a=0;ap&&(_=Math.max(p,_),h=p||w,p=w),l+=n*(v*I+this._spacingX);const R=n*(1-v)*I;if(t){if(i>0)u=a/i>0&&a%i==0,u&&(h=p>w?p:h);else if(I>e-m)l>c+n*(v*I)&&(u=!0);else{const t=(1-this._horizontalDirection-r.x)*e,o=l+R+n*(n>0?this._paddingRight:this._paddingLeft);u=Math.abs(o)>Math.abs(t)}u&&(l=c+n*(v*I),w!==p&&(h=p),d+=h+this._spacingY,h=p=w)}const O=o(f,y,d);s&&f.setPosition(l,O),l+=R}h=Math.max(h,p);const f=Math.max(_,d+h)+this._getPaddingV();if(T.length>0&&this.centerHorizontalDirection==CenterHorizontalDirection.CENTER_TO_SIDE){const t=(.5-r.x)*e;let o=0,s=-1,i=Number.MIN_SAFE_INTEGER;n=-1;for(let c=T.length-1;c>=0;c--){const l=T[c],d=this._getUsedScaleValue(l.node.scale.x),h=l.getComponent(UITransform).anchorX,p=l.getComponent(UITransform).width*d;if(Math.abs(l.node.position.y-i)>1){i=l.node.position.y,o=l.node.position.x+(1-h)*p+this.paddingRight,o=e*r.x+o;s=t+.5*o+n*a-n*this.spacingX}if(!l.node.activeInHierarchy)continue;s=s+n*h*p+n*this.spacingX,l.node.setPosition(new Vec3(s,l.node.position.y,0));s+=n*(1-h)*p}}return f}_getUsedScaleValue(e){return this.affectedByScale?Math.abs(e):1}};__decorate$k([property$k({type:Enum(CenterHorizontalDirection)})],CenterLayout.prototype,"centerHorizontalDirection",void 0),CenterLayout=__decorate$k([ccclass$k("CenterLayout"),disallowMultiple$1(),menu$a("moye/CenterLayout")],CenterLayout);var __decorate$j=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$j,inspector:inspector,property:property$j,disallowMultiple:disallowMultiple,menu:menu$9}=_decorator;let MoyeLabel=class extends Label{constructor(){super(...arguments),this._tempString="",this._clearOnRun=!1}set clearOnRun(e){e!=this._clearOnRun&&(this._clearOnRun=e,this.string=e?this._string:this._tempString)}get clearOnRun(){return this._clearOnRun}set string(e){if(this.clearOnRun&&EDITOR)this._tempString=e,this._string=" ",this.markForUpdateRenderData();else{if(e=null==e?"":e.toString(),this._string===e)return;this._string=e,this.markForUpdateRenderData()}}get string(){return this.clearOnRun&&EDITOR?this._tempString:this._string}};__decorate$j([property$j({editorOnly:!0})],MoyeLabel.prototype,"_tempString",void 0),__decorate$j([property$j],MoyeLabel.prototype,"_clearOnRun",void 0),__decorate$j([property$j({type:CCBoolean,displayName:"运行时清空",tooltip:"运行时清空"})],MoyeLabel.prototype,"clearOnRun",null),MoyeLabel=__decorate$j([ccclass$j("MoyeLabel"),disallowMultiple(),menu$9("moye/MoyeLabel")],MoyeLabel);var __decorate$i=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$i,property:property$i,menu:menu$8}=_decorator;let RichTextListener=class extends Component{constructor(){super(...arguments),this._cbs=[]}onDestroy(){this._cbs=[]}onClicked(e,t){for(const e of this._cbs)e(t)}addListener(e){this._cbs.push(e)}};RichTextListener=__decorate$i([ccclass$i("RichTextListener"),menu$8("moye/RichTextListener")],RichTextListener);const ViewDecoratorType="ViewDecorator";function ViewDecorator(e,t,o){return function(s){DecoratorCollector.inst.add("ViewDecorator",s,e,t,o)}}var ViewLayer;!function(e){e[e.SCENE=1]="SCENE",e[e.BACKGROUND=2]="BACKGROUND",e[e.NORMAL=3]="NORMAL",e[e.INFO=4]="INFO",e[e.TIPS=5]="TIPS",e[e.TOP=6]="TOP"}(ViewLayer||(ViewLayer={}));class ViewCleanCom extends Entity{constructor(){super(...arguments),this._views=new Set}init(e){return this._viewMgr=e,this}add(e){this._views.add(e)}remove(e){this._views.delete(e)}destroy(){for(const e of this._views)this._viewMgr.hide(e)}}const MoyeViewTag="MoyeView",viewLoadLock="MoyeViewLoadLock";class MoyeViewMgr extends Entity{constructor(){super(...arguments),this._views=new Map,this._type2Names=new Map,this._showingViews=new Set,this._hideViews=new Set,this._viewCfgs=new Map,this._layers=new Map,this._checkInterval=5e3}awake(){MoyeViewMgr.inst=this}destroy(){null!=this._checkTimerId&&(TimerMgr.get().remove(this._checkTimerId),this._checkTimerId=null),MoyeViewMgr.inst=null}init(e,t){return null!=this._uiRoot?moyeErrorF("MoyeView","MoyeViewMgr is already inited"):(this._uiRoot=e,this._globalViewCfgType=t,this.reload(),this._checkTimerId=TimerMgr.get().newRepeatedTimer(this._checkInterval,this.check.bind(this)),this)}async show(e,t){let o;if(o="string"==typeof e?e:this._type2Names.get(e),JsHelper.isNullOrEmpty(o))return void moyeErrorF("MoyeView","MoyeView name is null or empty, name={0}",o);const s=await CoroutineLock.get().wait(viewLoadLock,o);moyeLogF("MoyeView","show view, name={0}",o);try{if(null==this._uiRoot)throw new Error("MoyeViewMgr is not inited");if(this._showingViews.has(o)){return this._views.get(o)}if(this._views.has(o)){const e=this._views.get(o);return await this.enterViewShow(e,t),e}const e=this._viewCfgs.get(o),s=await e.load(o),r=this.getLayerNode(e.layer);s.parent=r;const i=this.addCom(e.viewType);return i.node=s,i.layer=e.layer,i.viewName=o,i.onLoad?.(),i._viewMgr=this,this._views.set(o,i),await this.enterViewShow(i,t),i}catch(e){moyeErrorF("MoyeView","show view errr, {0}",e.stack)}finally{s.dispose()}}async hide(e){const t=await CoroutineLock.get().wait(viewLoadLock,e);moyeLogF("MoyeView","hide view, name={0}",e);try{if(!this._showingViews.has(e))return;const t=this._views.get(e);await this.enterViewHide(t)}catch(e){moyeErrorF("MoyeView","hide view errr, {0}",e.stack)}finally{t.dispose()}}getView(e){let t;if(t="string"==typeof e?e:this._type2Names.get(e),this._showingViews.has(t)){return this._views.get(t)}}reload(){const e=DecoratorCollector.inst.get("ViewDecorator");for(const t of e){const e=t[0],o=t[1],s=t[2],r=t[3];if(this._viewCfgs.has(o))continue;let i;i=null!=r?new r:new this._globalViewCfgType,i.layer=s,i.name=o,i.viewType=e,i.cleanEntitys=new Set,this._type2Names.set(e,o),this._viewCfgs.set(o,i)}}check(){const e=TimeInfo.get().clientNow();for(const t of this._hideViews){e>=this._viewCfgs.get(t).expireTime&&this.enterViewDestroy(this._views.get(t))}}getLayerNode(e){let t=this._layers.get(e);if(null==t){t=new Node,t.name=ViewLayer[e],t.parent=this._uiRoot,this._layers.set(e,t);for(let e=ViewLayer.SCENE;e<=ViewLayer.TOP;e++){if(!this._layers.has(e))continue;this._layers.get(e).setSiblingIndex(-1)}const o=this._uiRoot.getComponent(UITransform).contentSize;t.addComponent(UITransform).setContentSize(o);const s=t.addComponent(Widget);s.top=0,s.bottom=0,s.left=0,s.right=0,s.alignMode=Widget.AlignMode.ON_WINDOW_RESIZE,s.isAlignBottom=!0,s.isAlignLeft=!0,s.isAlignRight=!0,s.isAlignTop=!0}return t}addToCleanCom(e,t){if(null==e)return;let o=e.getCom(ViewCleanCom);const s=this._viewCfgs.get(t);null==o&&(o=e.addCom(ViewCleanCom).init(this)),s.cleanEntitys.add(o),o.add(t)}async enterViewShow(e,t){e.node.active=!0,e.bringToFront();const o=this._viewCfgs.get(e.viewName);if(null!=o.doShowAnimation){const t=Task.create();o.doShowAnimation(e,t),await t}this._showingViews.add(e.viewName),this._hideViews.delete(e.viewName),this.addToCleanCom(t,e.viewName),e.onShow?.()}async enterViewHide(e){const t=this._viewCfgs.get(e.viewName);if(null!=t.doHideAnimation){const o=Task.create();t.doHideAnimation(e,o),await o}e.onHide?.(),e.node.active=!1,this._hideViews.add(e.viewName),this._showingViews.delete(e.viewName);for(const o of t.cleanEntitys)o.remove(e.viewName);t.cleanEntitys.clear(),t.expireTime=TimeInfo.get().clientNow()+t.expire}enterViewDestroy(e){e._realDispose(),e.node.destroy(),this._views.delete(e.viewName),this._hideViews.delete(e.viewName);this._viewCfgs.get(e.viewName).destroy()}}class AMoyeView extends Entity{_realDispose(){super.dispose()}dispose(){this._viewMgr.hide(this.viewName)}bringToFront(){this.node.setSiblingIndex(-1)}}var __decorate$h=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$h,property:property$h,executeInEditMode:executeInEditMode$4,menu:menu$7}=_decorator;let NodeNotBuild=class extends Component{constructor(){super(...arguments),this.note="节点不参与构建",this._destroyOnRun=!0}set destroyOnRun(e){this._destroyOnRun=e}get destroyOnRun(){return this._destroyOnRun}onLoad(){}onEnable(){EDITOR?this.node.hideFlags=this.node.hideFlags|CCObject.Flags.EditorOnly:this._destroyOnRun&&this.node.destroy()}onDisable(){this.node.hideFlags=this.node.hideFlags&~CCObject.Flags.EditorOnly}onDestroy(){this.node.hideFlags=this.node.hideFlags&~CCObject.Flags.EditorOnly}};__decorate$h([property$h({displayName:"注释",tooltip:"注释",editorOnly:!0,multiline:!0})],NodeNotBuild.prototype,"note",void 0),__decorate$h([property$h],NodeNotBuild.prototype,"_destroyOnRun",void 0),__decorate$h([property$h({type:CCBoolean,tooltip:"运行时销毁节点",displayName:"运行时销毁节点"})],NodeNotBuild.prototype,"destroyOnRun",null),NodeNotBuild=__decorate$h([ccclass$h("NodeNotBuild"),menu$7("moye/NodeNotBuild"),executeInEditMode$4],NodeNotBuild);var __decorate$g=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$g,property:property$g,menu:menu$6,executeInEditMode:executeInEditMode$3,requireComponent:requireComponent}=_decorator;let SizeFollow=class extends Component{constructor(){super(...arguments),this._heightFollow=!0,this._widthFollow=!0,this.minH=0,this.maxH=-1,this.minW=0,this.maxW=-1,this._heightOffset=0,this._widthOffset=0,this._changeSize=new Size}get target(){return this._target}set target(e){null!=this._target&&this._target.node.off(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this),this._target=e,null!=this._target&&(EDITOR&&this._target.getComponent(Label)&&console.info("检查到目标节点上有Label组件, 请注意设置string后调用updateRenderData(true)"),this._target.node.on(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this),this.updateSizeOffset())}set heightFollow(e){this._heightFollow=e}get heightFollow(){return this._heightFollow}set widthFollow(e){this._widthFollow=e}get widthFollow(){return this._widthFollow}onLoad(){EDITOR&&this.node.on(NodeEventType.SIZE_CHANGED,this.onSelfSizeChange,this),null!=this._target&&this._target.node.on(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this)}onDestroy(){EDITOR&&this.node.off(NodeEventType.SIZE_CHANGED,this.onSelfSizeChange,this),null!=this._target&&(this._target.isValid?(this._target.node.off(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this),this._target=null):this._target=null)}onTargetSizeChange(){this.updateSelfSize()}onSelfSizeChange(){null!=this._target&&this.updateSizeOffset()}updateSelfSize(){const e=this.node.getComponent(UITransform),t=this._target;if(this._changeSize.set(e.contentSize),this._widthFollow){let e=Math.max(this.minW,t.width+this._widthOffset);this.maxW>=0&&(e=Math.min(this.maxW,e)),this._changeSize.width=e}if(this._heightFollow){let e=Math.max(this.minH,t.height+this._heightOffset);this.maxH>=0&&(e=Math.min(this.maxH,e)),this._changeSize.height=e}e.setContentSize(this._changeSize)}updateSizeOffset(){if(!EDITOR)return;const e=this.node.getComponent(UITransform),t=this._target,o=t.width,s=e.width,r=e.height,i=t.height;let n=!0,a=!0;s<=this.minW&&(console.log("当前节点宽度达到最小宽度, 不记录本次的偏移数据"),n=!1),this.maxW>=0&&s>=this.maxW&&(console.log("当前节点宽度达到最大宽度, 不记录本次的偏移数据"),n=!1),n&&(this._widthOffset=s-o),r<=this.minH&&(console.log("当前节点高度达到最小高度, 不记录本次的偏移数据"),a=!1),this.maxH>=0&&r>=this.maxH&&(console.log("当前节点高度达到最大高度, 不记录本次的偏移数据"),a=!1),a&&(this._heightOffset=r-i)}};__decorate$g([property$g({type:UITransform})],SizeFollow.prototype,"target",null),__decorate$g([property$g({type:UITransform})],SizeFollow.prototype,"_target",void 0),__decorate$g([property$g({displayName:"高度跟随"})],SizeFollow.prototype,"heightFollow",null),__decorate$g([property$g],SizeFollow.prototype,"_heightFollow",void 0),__decorate$g([property$g({displayName:"宽度跟随"})],SizeFollow.prototype,"widthFollow",null),__decorate$g([property$g],SizeFollow.prototype,"_widthFollow",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最小高度",min:0,visible(){return 1==this.heightFollow}})],SizeFollow.prototype,"minH",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最大高度",tooltip:"最大高度, 小于0表示不限制",visible(){return 1==this.heightFollow}})],SizeFollow.prototype,"maxH",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最小宽度",min:0,visible(){return 1==this.widthFollow}})],SizeFollow.prototype,"minW",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最大宽度",tooltip:"最大宽度, 小于0表示不限制",visible(){return 1==this.widthFollow}})],SizeFollow.prototype,"maxW",void 0),__decorate$g([property$g({type:CCFloat})],SizeFollow.prototype,"_heightOffset",void 0),__decorate$g([property$g({type:CCFloat})],SizeFollow.prototype,"_widthOffset",void 0),SizeFollow=__decorate$g([ccclass$g("SizeFollow"),menu$6("moye/SizeFollow"),requireComponent(UITransform),executeInEditMode$3],SizeFollow);var __decorate$f=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$f,property:property$f,executeInEditMode:executeInEditMode$2,menu:menu$5}=_decorator;var WidgetBase,WidgetDirection;!function(e){e[e.LEFT=1]="LEFT",e[e.RIGHT=2]="RIGHT",e[e.TOP=3]="TOP",e[e.BOTTOM=4]="BOTTOM"}(WidgetBase||(WidgetBase={})),function(e){e[e.LEFT=1]="LEFT",e[e.RIGHT=2]="RIGHT",e[e.TOP=3]="TOP",e[e.BOTTOM=4]="BOTTOM",e[e.LEFT_EXTEND=5]="LEFT_EXTEND",e[e.RIGHT_EXTEND=6]="RIGHT_EXTEND",e[e.TOP_EXTEND=7]="TOP_EXTEND",e[e.BOTTOM_EXTEND=8]="BOTTOM_EXTEND"}(WidgetDirection||(WidgetDirection={}));let CTWidget=class extends Component{constructor(){super(...arguments),this._targetDir=WidgetDirection.TOP,this._dir=WidgetDirection.TOP,this.visibleOffset=0,this._isVertical=!0,this._distance=0,this._changePos=new Vec3(0,0,0),this._targetOldPos=new Vec3(0,0,0),this._targetOldSize=0,this._selfOldPos=new Vec3(0,0,0),this._selfOldSize=0}get target(){return this._target}set target(e){this._target=e,this.unregisterEvt(),this.registerEvt(),this.updateData()}set targetDir(e){if(EDITOR){if(e==WidgetDirection.LEFT||e==WidgetDirection.RIGHT){switch(this._dir){case WidgetDirection.TOP:case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM:case WidgetDirection.BOTTOM_EXTEND:this._dir=WidgetDirection.LEFT}this._isVertical=!1}else{switch(this._dir){case WidgetDirection.LEFT:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT:case WidgetDirection.RIGHT_EXTEND:this._dir=WidgetDirection.TOP}this._isVertical=!0}this._targetDir=e,this.updateData()}}get targetDir(){return this._targetDir}set dir(e){if(EDITOR){switch(e){case WidgetDirection.LEFT:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT:case WidgetDirection.RIGHT_EXTEND:switch(this._targetDir){case WidgetDirection.TOP:case WidgetDirection.BOTTOM:this._targetDir=WidgetDirection.LEFT}this._isVertical=!1;break;case WidgetDirection.TOP:case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM:case WidgetDirection.BOTTOM_EXTEND:switch(this._targetDir){case WidgetDirection.LEFT:case WidgetDirection.RIGHT:this._targetDir=WidgetDirection.TOP}this._isVertical=!0}this._dir=e,this.updateData()}}get dir(){return this._dir}onEnable(){EDITOR&&(this.registerEvt(),this.updateData())}onDisable(){EDITOR&&this.unregisterEvt()}onLoad(){this._trans=this.node.getComponent(UITransform),EDITOR||this.registerEvt()}onDestroy(){EDITOR||(this.unregisterEvt(),this._trans=null,this._target=null,this._changePos=null)}registerEvt(){this._target&&(EDITOR&&(this._target.node.on(NodeEventType.ANCHOR_CHANGED,this.updateData,this),this.node.on(NodeEventType.TRANSFORM_CHANGED,this.updateData,this),this.node.on(NodeEventType.SIZE_CHANGED,this.updateData,this)),this._target.node.on(NodeEventType.SIZE_CHANGED,this.onTargetChange,this),this._target.node.on(NodeEventType.TRANSFORM_CHANGED,this.onTargetChange,this),this._target.node.on(NodeEventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onTargetChange,this))}unregisterEvt(){this._target&&this._target.isValid&&(EDITOR&&(this._target.node.off(NodeEventType.ANCHOR_CHANGED,this.updateData,this),this.node.off(NodeEventType.TRANSFORM_CHANGED,this.updateData,this),this.node.off(NodeEventType.SIZE_CHANGED,this.updateData,this)),this._target.node.off(NodeEventType.SIZE_CHANGED,this.onTargetChange,this),this._target.node.off(NodeEventType.TRANSFORM_CHANGED,this.onTargetChange,this),this._target.node.off(NodeEventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onTargetChange,this))}updateData(){if(null!=this._target)switch(this._dir){case WidgetDirection.TOP:case WidgetDirection.BOTTOM:case WidgetDirection.LEFT:case WidgetDirection.RIGHT:this.updateDistance();break;case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM_EXTEND:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT_EXTEND:this.updateTargetPos()}}onTargetChange(){if(null!=this._target)switch(this._dir){case WidgetDirection.TOP:case WidgetDirection.BOTTOM:case WidgetDirection.LEFT:case WidgetDirection.RIGHT:this.updatePos();break;case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM_EXTEND:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT_EXTEND:this.updateSize()}}updateSize(){if(this._isVertical){const e=this._targetOldPos.y-this._target.node.position.y;let t=this._target.height-this._targetOldSize;const o=this._trans.anchorY;this._changePos.set(this._selfOldPos),this._target.getComponent(Label)&&!this._target.node.active&&(t=this._targetOldSize);const s=e+t;this._trans.height=this._selfOldSize+s,this._dir==WidgetDirection.TOP_EXTEND?this.node.setPosition(this._changePos):this._dir==WidgetDirection.BOTTOM_EXTEND&&(this._changePos.y-=s*(1-o),this.node.setPosition(v3(this._changePos)))}}updatePos(){const e=this._trans,t=this._target;let o=this.getPos(t,this._targetDir)-this._distance;if(this._changePos.set(this.node.worldPosition),this._isVertical){switch(this._dir){case WidgetDirection.TOP:o-=e.height*(1-e.anchorY);break;case WidgetDirection.BOTTOM:o+=e.height*e.anchorY;break}this._changePos.y=o}else this._changePos.x=o;this.node.worldPosition=this._changePos}updateTargetPos(){EDITOR&&null==this._changePos&&(console.error("编辑器数据错乱, 请重新添加本组件"),this._changePos=v3()),this.target.node.getPosition(this._targetOldPos),this.node.getPosition(this._selfOldPos),this._isVertical?(this._selfOldSize=this._trans.height,this._targetOldSize=this._target.height):(this._selfOldSize=this._trans.width,this._targetOldSize=this._target.height)}updateDistance(){if(!EDITOR)return;if(null==this._target)return;const e=this.node.getComponent(UITransform),t=this._target,o=this.getPos(e,this._dir),s=this.getPos(t,this._targetDir);this._distance=s-o}getPos(e,t){if(this._isVertical){let o=e.node.worldPosition.y;const s=e.height,r=e.anchorY;switch(t){case WidgetDirection.TOP:case WidgetDirection.TOP_EXTEND:return e.node.active||(o=o-s-this.visibleOffset),o+s*(1-r);case WidgetDirection.BOTTOM:case WidgetDirection.BOTTOM_EXTEND:return e.node.active||(o=o+s+this.visibleOffset),o-s*r}}else{const o=e.node.worldPosition.x,s=e.width,r=e.anchorX;switch(t){case WidgetDirection.LEFT:return o-s*r;case WidgetDirection.RIGHT:return o+s*(1-r)}}}};__decorate$f([property$f({type:UITransform})],CTWidget.prototype,"target",null),__decorate$f([property$f({type:UITransform})],CTWidget.prototype,"_target",void 0),__decorate$f([property$f({type:Enum(WidgetBase)})],CTWidget.prototype,"targetDir",null),__decorate$f([property$f],CTWidget.prototype,"_targetDir",void 0),__decorate$f([property$f({type:Enum(WidgetDirection)})],CTWidget.prototype,"dir",null),__decorate$f([property$f],CTWidget.prototype,"_dir",void 0),__decorate$f([property$f({type:CCFloat})],CTWidget.prototype,"visibleOffset",void 0),__decorate$f([property$f],CTWidget.prototype,"_isVertical",void 0),__decorate$f([property$f],CTWidget.prototype,"_distance",void 0),__decorate$f([property$f],CTWidget.prototype,"_changePos",void 0),__decorate$f([property$f],CTWidget.prototype,"_targetOldPos",void 0),__decorate$f([property$f],CTWidget.prototype,"_targetOldSize",void 0),__decorate$f([property$f],CTWidget.prototype,"_selfOldPos",void 0),__decorate$f([property$f],CTWidget.prototype,"_selfOldSize",void 0),CTWidget=__decorate$f([ccclass$f("CTWidget"),menu$5("moye/CTWidget"),executeInEditMode$2],CTWidget);const RoundBoxAssembler={GetIndexBuffer(e){const t=[0,1,2,2,3,0,4,5,6,6,7,4,8,9,10,10,11,8];let o=12;const s=function(s,r,i){let n=r;for(let r=0;r=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$e,property:property$e,type:type,menu:menu$4}=_decorator;var EventType;!function(e){e.SPRITE_FRAME_CHANGED="spriteframe-changed"}(EventType||(EventType={}));let RoundBoxSprite=class extends UIRenderer{constructor(){super(...arguments),this._sizeMode=Sprite.SizeMode.TRIMMED,this._useGrayscale=!1,this._atlas=null,this._segments=10,this._radius=20,this._spriteFrame=null,this._leftTop=!0,this._rightTop=!0,this._leftBottom=!0,this._rightBottom=!0}get sizeMode(){return this._sizeMode}set sizeMode(e){this._sizeMode!==e&&(this._sizeMode=e,e!==Sprite.SizeMode.CUSTOM&&this._applySpriteSize())}get grayscale(){return this._useGrayscale}set grayscale(e){this._useGrayscale!==e&&(this._useGrayscale=e,this.changeMaterialForDefine(),this.updateMaterial())}get spriteAtlas(){return this._atlas}set spriteAtlas(e){this._atlas!==e&&(this._atlas=e)}get segments(){return this._segments}set segments(e){this._segments=e,this._renderData=null,this._flushAssembler()}get radius(){return this._radius}set radius(e){this._radius=e,this._updateUVs(),this.markForUpdateRenderData(!0)}get spriteFrame(){return this._spriteFrame}set spriteFrame(e){if(this._spriteFrame===e)return;const t=this._spriteFrame;this._spriteFrame=e,this.markForUpdateRenderData(),this._applySpriteFrame(t),EDITOR&&this.node.emit(EventType.SPRITE_FRAME_CHANGED,this)}get leftTop(){return this._leftTop}set leftTop(e){this._leftTop=e,this.resetAssembler()}get rightTop(){return this._rightTop}set rightTop(e){this._rightTop=e,this.resetAssembler()}get leftBottom(){return this._leftBottom}set leftBottom(e){this._leftBottom=e,this.resetAssembler()}get rightBottom(){return this._rightBottom}set rightBottom(e){this._rightBottom=e,this.resetAssembler()}onLoad(){this._flushAssembler()}__preload(){this.changeMaterialForDefine(),super.__preload(),EDITOR&&(this._resized(),this.node.on(NodeEventType.SIZE_CHANGED,this._resized,this))}onEnable(){super.onEnable(),this._activateMaterial();this._spriteFrame&&this._updateUVs()}onDestroy(){EDITOR&&this.node.off(NodeEventType.SIZE_CHANGED,this._resized,this),super.onDestroy()}changeSpriteFrameFromAtlas(e){if(!this._atlas)return void console.warn("SpriteAtlas is null.");const t=this._atlas.getSpriteFrame(e);this.spriteFrame=t}changeMaterialForDefine(){let e;const t=this._instanceMaterialType;this._spriteFrame&&(e=this._spriteFrame.texture);let o=!1;if(e instanceof cclegacy.TextureBase){const t=e.getPixelFormat();o=t===cclegacy.TextureBase.PixelFormat.RGBA_ETC1||t===cclegacy.TextureBase.PixelFormat.RGB_A_PVRTC_4BPPV1||t===cclegacy.TextureBase.PixelFormat.RGB_A_PVRTC_2BPPV1}o&&this.grayscale?this._instanceMaterialType=InstanceMaterialType.USE_ALPHA_SEPARATED_AND_GRAY:o?this._instanceMaterialType=InstanceMaterialType.USE_ALPHA_SEPARATED:this.grayscale?this._instanceMaterialType=InstanceMaterialType.GRAYSCALE:this._instanceMaterialType=InstanceMaterialType.ADD_COLOR_AND_TEXTURE,t!==this._instanceMaterialType&&this.updateMaterial()}_updateBuiltinMaterial(){let e=super._updateBuiltinMaterial();if(this.spriteFrame&&this.spriteFrame.texture instanceof RenderTexture){const t={SAMPLE_FROM_RT:!0,...e.passes[0].defines},o=new Material;o.initialize({effectAsset:e.effectAsset,defines:t}),e=o}return e}_render(e){e.commitComp(this,this.renderData,this._spriteFrame,this._assembler,null)}_canRender(){if(!super._canRender())return!1;const e=this._spriteFrame;return!(!e||!e.texture)}resetAssembler(){this._assembler=null,this._flushAssembler()}_flushAssembler(){const e=RoundBoxAssembler;this._assembler!==e&&(this.destroyRenderData(),this._assembler=e),this._renderData||this._assembler&&this._assembler.createData&&(this._renderData=this._assembler.createData(this),this._renderData.material=this.getRenderMaterial(0),this.markForUpdateRenderData(),this.spriteFrame&&this._assembler.updateRenderData(this),this._updateColor())}_applySpriteSize(){if(this._spriteFrame){if(BUILD||!this._spriteFrame.isDefault)if(Sprite.SizeMode.RAW===this._sizeMode){const e=this._spriteFrame.originalSize;this.node._uiProps.uiTransformComp.setContentSize(e)}else if(Sprite.SizeMode.TRIMMED===this._sizeMode){const e=this._spriteFrame.rect;this.node._uiProps.uiTransformComp.setContentSize(e.width,e.height)}this.markForUpdateRenderData(!0),this._assembler.updateRenderData(this)}}_resized(){if(EDITOR&&this._spriteFrame){const e=this.node._uiProps.uiTransformComp.contentSize;let t=e.width,o=e.height;if(this._sizeMode===Sprite.SizeMode.RAW){const e=this._spriteFrame.originalSize;t=e.width,o=e.height}else if(this._sizeMode===Sprite.SizeMode.TRIMMED){const e=this._spriteFrame.rect;t=e.width,o=e.height}t===e.width&&o===e.height||(this._sizeMode=Sprite.SizeMode.CUSTOM)}}_activateMaterial(){const e=this._spriteFrame,t=this.getRenderMaterial(0);e&&t&&this.markForUpdateRenderData(),this.renderData&&(this.renderData.material=t)}_updateUVs(){this._assembler&&this._assembler.updateUVs(this)}_applySpriteFrame(e){const t=this._spriteFrame;let o=!1;t&&(e&&e.texture===t.texture||(o=!0),o&&(this.renderData&&(this.renderData.textureDirty=!0),this.changeMaterialForDefine()),this._applySpriteSize())}};__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_sizeMode",void 0),__decorate$e([type(Sprite.SizeMode)],RoundBoxSprite.prototype,"sizeMode",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_useGrayscale",void 0),__decorate$e([property$e({type:CCBoolean})],RoundBoxSprite.prototype,"grayscale",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_atlas",void 0),__decorate$e([type(SpriteAtlas)],RoundBoxSprite.prototype,"spriteAtlas",null),__decorate$e([property$e({type:CCInteger,serializable:!0})],RoundBoxSprite.prototype,"_segments",void 0),__decorate$e([property$e({type:CCInteger,serializable:!0,min:1})],RoundBoxSprite.prototype,"segments",null),__decorate$e([property$e({type:CCFloat,serializable:!0})],RoundBoxSprite.prototype,"_radius",void 0),__decorate$e([property$e({type:CCFloat,serializable:!0,min:0})],RoundBoxSprite.prototype,"radius",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_spriteFrame",void 0),__decorate$e([type(SpriteFrame)],RoundBoxSprite.prototype,"spriteFrame",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_leftTop",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"leftTop",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_rightTop",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"rightTop",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_leftBottom",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"leftBottom",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_rightBottom",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"rightBottom",null),RoundBoxSprite=__decorate$e([ccclass$e("RoundBoxSprite"),menu$4("moye/RoundBoxSprite")],RoundBoxSprite);var __decorate$d=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$d,property:property$d,executeInEditMode:executeInEditMode$1,menu:menu$3}=_decorator;var UIControllerIndex;!function(e){e[e.Index_0=1]="Index_0",e[e.Index_1=2]="Index_1",e[e.Index_2=4]="Index_2",e[e.Index_3=8]="Index_3",e[e.Index_4=16]="Index_4",e[e.Index_5=32]="Index_5",e[e.Index_6=64]="Index_6",e[e.Index_7=128]="Index_7",e[e.Index_8=256]="Index_8",e[e.Index_9=512]="Index_9",e[e.Index_10=1024]="Index_10",e[e.Index_11=2048]="Index_11",e[e.Index_12=4096]="Index_12"}(UIControllerIndex||(UIControllerIndex={}));let UIController=class extends Component{constructor(){super(...arguments),this._index=UIControllerIndex.Index_0,this._listeners=[],this._callbacks=[]}set index(e){this._index!=e&&(this._index=e,this.notifyListeners())}get index(){return this._index}onDestroy(){this._listeners=[],this._callbacks=[]}setIndex(e){if(this._index!=e){this._index=e;for(let e=0;e=0;e--)null!=this._listeners[e]&&null!=this._listeners[e]||this._listeners.splice(e,1)}_removeListener(e){const t=this._listeners.indexOf(e);if(-1!=t&&this._listeners.splice(t,1),EDITOR)for(let e=this._listeners.length-1;e>=0;e--)null!=this._listeners[e]&&null!=this._listeners[e]||this._listeners.splice(e,1)}notifyListeners(){for(let e=0;e=0;e--)null!=this._listeners[e]&&null!=this._listeners[e]||this._listeners.splice(e,1);const e=this.node.getComponent("UIControllerListener");e&&e.registerUIController()}}};var UIControlType;__decorate$d([property$d],UIController.prototype,"_index",void 0),__decorate$d([property$d({type:Enum(UIControllerIndex),displayOrder:1})],UIController.prototype,"index",null),__decorate$d([property$d],UIController.prototype,"_listeners",void 0),UIController=__decorate$d([ccclass$d("UIController"),menu$3("moye/UIController"),executeInEditMode$1],UIController),function(e){e[e.None=0]="None",e[e.Visible=1]="Visible",e[e.Position=2]="Position",e[e.Size=3]="Size",e[e.Scale=4]="Scale",e[e.Angle=5]="Angle",e[e.Anchor=6]="Anchor",e[e.UIController=7]="UIController",e[e.SpriteColor=8]="SpriteColor"}(UIControlType||(UIControlType={}));var __decorate$c=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$c,property:property$c}=_decorator;let UIController_Transition=class{constructor(){this.duration=0,this.delay=0}};__decorate$c([property$c({type:CCFloat,displayName:"持续时间"})],UIController_Transition.prototype,"duration",void 0),__decorate$c([property$c({type:CCFloat,displayName:"延迟时间"})],UIController_Transition.prototype,"delay",void 0),UIController_Transition=__decorate$c([ccclass$c("UIController_Transition")],UIController_Transition);var __decorate$b=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$b,property:property$b}=_decorator;let UIControlType_Position=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$a,property:property$a}=_decorator;let UIControlType_Size=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$9,property:property$9}=_decorator;let UIControlType_Scale=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$8,property:property$8}=_decorator;let UIControlType_Controller=class{constructor(){this._records=[]}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$7,property:property$7}=_decorator;let UIControlType_Angle=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$6,property:property$6}=_decorator;let UIControlType_Anchor=class{constructor(){this._records=[]}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$5,property:property$5}=_decorator;let UIControlType_Visible=class{constructor(){this.indexMask=UIControllerIndexMask.Index_0}isVisible(e){return 0!=(this.indexMask&e)}};__decorate$5([property$5({type:BitMask(UIControllerIndexMask)})],UIControlType_Visible.prototype,"indexMask",void 0),UIControlType_Visible=__decorate$5([ccclass$5("UIControlType_Visible")],UIControlType_Visible);var __decorate$4=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$4,property:property$4}=_decorator;let UIControlType_SpriteColor=class{constructor(){this._records=[]}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$3,property:property$3}=_decorator;let UIControllerAttr=class{constructor(){this._controlType=UIControlType.None}set controlType(e){this._controlType=e,this.resetData()}get controlType(){return this._controlType}isVisible(e){return this.visible.isVisible(e)}setPosition(e,t){this.position.setRecord(e,t)}getPosition(e){return this.position.getRecord(e)}setSize(e,t){this.size.setRecord(e,t)}getSize(e){return this.size.getRecord(e)}setScale(e,t){this.scale.setRecord(e,t)}getScale(e){return this.scale.getRecord(e)}setAngle(e,t){this.angle.setRecord(e,t)}getAngle(e){return this.angle.getRecord(e)}setAnchor(e,t){this.anchor.setRecord(e,t)}getAnchor(e){return this.anchor.getRecord(e)}setUIController(e,t){this.controller.setRecord(e,t)}getUIController(e){return this.controller.getRecord(e)}setSpriteColor(e,t){this.spriteColor.setRecord(e,t)}getSpriteColor(e){return this.spriteColor.getRecord(e)}getTransition(){switch(this.controlType){case UIControlType.Position:return this.position.transitionAttr;case UIControlType.Size:return this.size.transitionAttr;case UIControlType.Scale:return this.scale.transitionAttr;case UIControlType.Angle:return this.angle.transitionAttr}}resetData(){DEBUG&&(this.controlType!=UIControlType.Position?this.position=null:this.position||(this.position=new UIControlType_Position),this.controlType!=UIControlType.Size?this.size=null:null==this.size&&(this.size=new UIControlType_Size),this.controlType!=UIControlType.Scale?this.scale=null:null==this.scale&&(this.scale=new UIControlType_Scale),this.controlType!=UIControlType.Angle?this.angle=null:null==this.angle&&(this.angle=new UIControlType_Angle),this.controlType!=UIControlType.Anchor?this.anchor=null:null==this.anchor&&(this.anchor=new UIControlType_Anchor),this.controlType!=UIControlType.UIController?this.controller=null:null==this.controller&&(this.controller=new UIControlType_Controller),this.controlType!=UIControlType.Visible?this.visible=null:this.visible||(this.visible=new UIControlType_Visible),this.controlType!=UIControlType.SpriteColor?this.spriteColor=null:null==this.spriteColor&&(this.spriteColor=new UIControlType_SpriteColor))}};__decorate$3([property$3({type:Enum(UIControlType)})],UIControllerAttr.prototype,"controlType",null),__decorate$3([property$3],UIControllerAttr.prototype,"_controlType",void 0),__decorate$3([property$3({displayName:"位置",type:UIControlType_Position,visible(){return this.controlType==UIControlType.Position}})],UIControllerAttr.prototype,"position",void 0),__decorate$3([property$3({displayName:"锚点",type:UIControlType_Anchor,visible(){return this.controlType==UIControlType.Anchor}})],UIControllerAttr.prototype,"anchor",void 0),__decorate$3([property$3({displayName:"角度",type:UIControlType_Angle,visible(){return this.controlType==UIControlType.Angle}})],UIControllerAttr.prototype,"angle",void 0),__decorate$3([property$3({displayName:"控制器",type:UIControlType_Controller,visible(){return this.controlType==UIControlType.UIController}})],UIControllerAttr.prototype,"controller",void 0),__decorate$3([property$3({displayName:"缩放",type:UIControlType_Scale,visible(){return this.controlType==UIControlType.Scale}})],UIControllerAttr.prototype,"scale",void 0),__decorate$3([property$3({displayName:"尺寸",type:UIControlType_Size,visible(){return this.controlType==UIControlType.Size}})],UIControllerAttr.prototype,"size",void 0),__decorate$3([property$3({displayName:"可见",type:UIControlType_Visible,visible(){return this.controlType==UIControlType.Visible}})],UIControllerAttr.prototype,"visible",void 0),__decorate$3([property$3({displayName:"精灵颜色",type:UIControlType_SpriteColor,visible(){return this.controlType==UIControlType.SpriteColor}})],UIControllerAttr.prototype,"spriteColor",void 0),UIControllerAttr=__decorate$3([ccclass$3("UIControllerAttr")],UIControllerAttr);const TransitionTag_Size=465,TransitionTag_Position=466,TransitionTag_Scale=467,TransitionTag_Angle=468;class TransitionHelper{static position(e,t,o){Tween.stopAllByTag(466,e),tween(e).tag(466).delay(o.delay).to(o.duration,{position:t}).start()}static size(e,t,o){Tween.stopAllByTag(465,e),tween(e).tag(465).delay(o.delay).to(o.duration,{contentSize:t}).start()}static scale(e,t,o){Tween.stopAllByTag(467,e),tween(e).tag(467).delay(o.delay).to(o.duration,{scale:t}).start()}static angle(e,t,o){Tween.stopAllByTag(468,e),tween(e).tag(468).delay(o.delay).to(o.duration,{angle:t}).start()}}var __decorate$2=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$2,property:property$2,executeInEditMode:executeInEditMode,menu:menu$2}=_decorator;let UIControllerListener=class extends Component{constructor(){super(...arguments),this._controller=null,this._attrs=[]}set controller(e){this._controller!=e&&(this._controller&&this._controller._removeListener(this),this._controller=e,this.listenController())}get controller(){return this._controller}get curIndex(){if(!this._controller)return"";return`${UIControllerIndex[this._controller.index]}`}set attrs(e){this._attrs=e,this.updateAttr()}get attrs(){return this._attrs}onLoad(){this.listenController()}onDestroy(){if(EDITOR)this.unRegisterEditorEvent();else{if(!this._controller)return;if(!this._controller.isValid)return;this._controller._removeListener(this)}}onDisable(){}onFocusInEditor(){this.registerEditorEvent()}onLostFocusInEditor(){this.unRegisterEditorEvent()}registerEditorEvent(){this.unRegisterEditorEvent(),this.node.on(Node.EventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onChangeActive,this),this.node.on(Node.EventType.TRANSFORM_CHANGED,this.onTransformChange,this),this.node.on(Node.EventType.SIZE_CHANGED,this.onSizeChange,this),this.node.on(Node.EventType.ANCHOR_CHANGED,this.onAnchorChange,this),this.node.on(Node.EventType.COLOR_CHANGED,this.onColorChange,this)}unRegisterEditorEvent(){this.node.off(Node.EventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onChangeActive,this),this.node.off(Node.EventType.TRANSFORM_CHANGED,this.onTransformChange,this),this.node.off(Node.EventType.SIZE_CHANGED,this.onSizeChange,this),this.node.off(Node.EventType.ANCHOR_CHANGED,this.onAnchorChange,this),this.node.off(Node.EventType.COLOR_CHANGED,this.onColorChange,this)}listenController(){this._controller&&this._controller._addListener(this)}onChangeActive(){}onTransformChange(){this.registerTransform()}onSizeChange(){this.registerSize()}onAnchorChange(){this.registerAnchor()}onColorChange(){this.registerColor()}registerTransform(){if(!this._controller)return;const e=this._controller.index;for(let t=0;t=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$1,property:property$1,menu:menu$1}=_decorator,instance=new EventTarget,SET_JOYSTICK_TYPE="SET_JOYSTICK_TYPE";var DirectionType,SpeedType,JoystickType;!function(e){e[e.FOUR=0]="FOUR",e[e.EIGHT=1]="EIGHT",e[e.ALL=2]="ALL"}(DirectionType||(DirectionType={})),function(e){e[e.STOP=0]="STOP",e[e.NORMAL=1]="NORMAL",e[e.FAST=2]="FAST"}(SpeedType||(SpeedType={})),function(e){e[e.FIXED=0]="FIXED",e[e.FOLLOW=1]="FOLLOW"}(JoystickType||(JoystickType={}));let YYJJoystick=class extends Component{constructor(){super(...arguments),this.dot=null,this.ring=null,this.joystickType=JoystickType.FIXED,this.directionType=DirectionType.ALL,this._stickPos=new Vec3,this._touchLocation=new Vec2,this.radius=50}onLoad(){if(!this.dot)return void console.warn("Joystick Dot is null!");if(!this.ring)return void console.warn("Joystick Ring is null!");const e=this.ring.getComponent(UITransform),t=2*this.radius,o=new Size(t,t);e?.setContentSize(o),this.ring.getChildByName("bg").getComponent(UITransform)?.setContentSize(o),this._initTouchEvent();const s=this.node.getComponent(UIOpacity);this.joystickType===JoystickType.FOLLOW&&s&&(s.opacity=0)}onEnable(){instance.on(SET_JOYSTICK_TYPE,this._onSetJoystickType,this)}onDisable(){instance.off(SET_JOYSTICK_TYPE,this._onSetJoystickType,this)}_onSetJoystickType(e){this.joystickType=e;const t=this.node.getComponent(UIOpacity);t&&(t.opacity=e===JoystickType.FIXED?255:0)}_initTouchEvent(){this.node.on(Input.EventType.TOUCH_START,this._touchStartEvent,this),this.node.on(Input.EventType.TOUCH_MOVE,this._touchMoveEvent,this),this.node.on(Input.EventType.TOUCH_END,this._touchEndEvent,this),this.node.on(Input.EventType.TOUCH_CANCEL,this._touchEndEvent,this)}_touchStartEvent(e){if(!this.ring||!this.dot)return;instance.emit(Input.EventType.TOUCH_START,e);const t=e.getUILocation(),o=new Vec3(t.x,t.y);if(this.joystickType===JoystickType.FIXED){this._stickPos=this.ring.getPosition();const e=o.subtract(this.ring.getPosition()),t=e.length();this.radius>t&&this.dot.setPosition(e)}else this.joystickType===JoystickType.FOLLOW&&(this._stickPos=o,this.node.getComponent(UIOpacity).opacity=255,this._touchLocation=e.getUILocation(),this.ring.setPosition(o),this.dot.setPosition(new Vec3))}_touchMoveEvent(e){if(!this.dot||!this.ring)return;if(this.joystickType===JoystickType.FOLLOW&&this._touchLocation===e.getUILocation())return!1;const t=e.getUILocation(),o=new Vec3(t.x,t.y).subtract(this.ring.getPosition()),s=o.length();let r=SpeedType.NORMAL;this.radius>s?(this.dot.setPosition(o),r=SpeedType.NORMAL):(this.dot.setPosition(o.normalize().multiplyScalar(this.radius)),r=SpeedType.FAST),instance.emit(Input.EventType.TOUCH_MOVE,e,{speedType:r,moveVec:o.normalize()})}_touchEndEvent(e){this.dot&&this.ring&&(this.dot.setPosition(new Vec3),this.joystickType===JoystickType.FOLLOW&&(this.node.getComponent(UIOpacity).opacity=0),instance.emit(Input.EventType.TOUCH_END,e,{speedType:SpeedType.STOP}))}};__decorate$1([property$1({type:Node,displayName:"Dot",tooltip:"摇杆操纵点"})],YYJJoystick.prototype,"dot",void 0),__decorate$1([property$1({type:Node,displayName:"Ring",tooltip:"摇杆背景节点"})],YYJJoystick.prototype,"ring",void 0),__decorate$1([property$1({type:Enum(JoystickType),displayName:"Touch Type",tooltip:"触摸类型"})],YYJJoystick.prototype,"joystickType",void 0),__decorate$1([property$1({type:Enum(DirectionType),displayName:"Direction Type",tooltip:"方向类型"})],YYJJoystick.prototype,"directionType",void 0),__decorate$1([property$1({type:Vec3,tooltip:"摇杆所在位置"})],YYJJoystick.prototype,"_stickPos",void 0),__decorate$1([property$1({type:Vec2,tooltip:"触摸位置"})],YYJJoystick.prototype,"_touchLocation",void 0),__decorate$1([property$1({type:CCInteger,displayName:"Ring Radius",tooltip:"半径"})],YYJJoystick.prototype,"radius",void 0),YYJJoystick=__decorate$1([ccclass$1("YYJJoystick"),menu$1("moye/YYJJoystick")],YYJJoystick);class YYJJoystickCom extends Entity{constructor(){super(...arguments),this.moveDir=new Vec3(0,1,0),this._speedType=SpeedType.STOP,this._moveSpeed=0,this.stopSpeed=0,this.normalSpeed=100,this.fastSpeed=200,this.isRotation=!0}init(e){return this._entity=e,instance.on(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.on(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.on(Input.EventType.TOUCH_END,this.onTouchEnd,this),this}destroy(){instance.off(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.off(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.off(Input.EventType.TOUCH_END,this.onTouchEnd,this)}onTouchStart(){}onTouchMove(e,t){const o=this._speedType;this._speedType=t.speedType,this.moveDir=t.moveVec,this.onSetMoveSpeed(this._speedType),o!==this._speedType&&this._entity.speedChange(this._speedType,this._moveSpeed)}onTouchEnd(e,t){const o=this._speedType;this._speedType=t.speedType,this.onSetMoveSpeed(this._speedType),o!==this._speedType&&this._entity.speedChange(this._speedType,this._moveSpeed)}onSetMoveSpeed(e){switch(e){case SpeedType.STOP:this._moveSpeed=this.stopSpeed;break;case SpeedType.NORMAL:this._moveSpeed=this.normalSpeed;break;case SpeedType.FAST:this._moveSpeed=this.fastSpeed}}move(){this.isRotation&&this._entity.setAngle(misc.radiansToDegrees(Math.atan2(this.moveDir.y,this.moveDir.x))-90);const e=this._entity.getPos().add(this.moveDir.clone().multiplyScalar(this._moveSpeed/60));this._entity.setPos(e)}update(){this._speedType!==SpeedType.STOP&&this.move()}}var __decorate=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass,property:property,menu:menu}=_decorator;let YYJJoystickPlayer=class extends Component{constructor(){super(...arguments),this.rigidbody=!1,this.moveDir=new Vec3(0,1,0),this._speedType=SpeedType.STOP,this._moveSpeed=0,this.stopSpeed=0,this.normalSpeed=100,this.fastSpeed=200,this.isRotation=!0,this._body=null}onLoad(){this.rigidbody&&(this._body=this.node.getComponent(RigidBody2D)),instance.on(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.on(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.on(Input.EventType.TOUCH_END,this.onTouchEnd,this)}onTouchStart(){}onTouchMove(e,t){this._speedType=t.speedType,this.moveDir=t.moveVec,this.onSetMoveSpeed(this._speedType)}onTouchEnd(e,t){this._speedType=t.speedType,this.onSetMoveSpeed(this._speedType)}onSetMoveSpeed(e){switch(e){case SpeedType.STOP:this._moveSpeed=this.stopSpeed;break;case SpeedType.NORMAL:this._moveSpeed=this.normalSpeed;break;case SpeedType.FAST:this._moveSpeed=this.fastSpeed}}move(){if(this.isRotation&&(this.node.angle=misc.radiansToDegrees(Math.atan2(this.moveDir.y,this.moveDir.x))-90),this.rigidbody&&this._body){const e=this.moveDir.clone().multiplyScalar(this._moveSpeed/20),t=new Vec2(e.x,e.y);this._body.applyForceToCenter(t,!0)}else{const e=this.node.getPosition().add(this.moveDir.clone().multiplyScalar(this._moveSpeed/60));this.node.setPosition(e)}}update(e){this._speedType!==SpeedType.STOP&&this.move()}};__decorate([property({displayName:"刚体模式",tooltip:"不会立即停止"})],YYJJoystickPlayer.prototype,"rigidbody",void 0),__decorate([property({displayName:"Move Dir",tooltip:"移动方向"})],YYJJoystickPlayer.prototype,"moveDir",void 0),__decorate([property({tooltip:"速度级别"})],YYJJoystickPlayer.prototype,"_speedType",void 0),__decorate([property({type:CCInteger,tooltip:"移动速度"})],YYJJoystickPlayer.prototype,"_moveSpeed",void 0),__decorate([property({type:CCInteger,tooltip:"停止时速度"})],YYJJoystickPlayer.prototype,"stopSpeed",void 0),__decorate([property({type:CCInteger,tooltip:"正常速度"})],YYJJoystickPlayer.prototype,"normalSpeed",void 0),__decorate([property({type:CCInteger,tooltip:"最快速度"})],YYJJoystickPlayer.prototype,"fastSpeed",void 0),__decorate([property({tooltip:"最快速度"})],YYJJoystickPlayer.prototype,"isRotation",void 0),YYJJoystickPlayer=__decorate([ccclass("YYJJoystickPlayer"),menu("moye/YYJJoystickPlayer")],YYJJoystickPlayer);class YYJJoystickSpeedChangeEvent extends AEvent{}class YYJJoystickMoveEvent extends AEvent{}class YYJJoystickListener extends Entity{constructor(){super(...arguments),this._speedType=SpeedType.STOP}awake(){instance.on(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.on(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.on(Input.EventType.TOUCH_END,this.onTouchEnd,this)}destroy(){instance.off(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.off(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.off(Input.EventType.TOUCH_END,this.onTouchEnd,this)}onTouchStart(){}onTouchMove(e,t){const o=this._speedType;this._speedType=t.speedType,o!==this._speedType&&EventSystem.get().publish(this.domainScene(),YYJJoystickSpeedChangeEvent.create({speedType:this._speedType})),EventSystem.get().publish(this.domainScene(),YYJJoystickMoveEvent.create({dir:t.moveVec}))}onTouchEnd(e,t){this.onTouchMove(e,t)}}export{AEvent,AEventHandler,AMHandler,AMoyeView,AWait,AfterAddLoginCom,AfterCreateClientScene,AfterCreateCurrentScene,AfterProgramInit,AfterProgramStart,AfterSingletonAdd,AssetOperationHandle,AsyncButtonListener,BeforeProgramInit,BeforeProgramStart,BeforeSingletonAdd,BgAdapter,BundleAsset,CTWidget,CancellationToken,CancellationTokenTag,CenterLayout,CoroutineLock,CoroutineLockItem,CoroutineLockTag,DecoratorCollector,Entity,EntityCenter,EventCom,EventDecorator,EventDecoratorType,EventHandlerTag,EventSystem,Game,IPEndPoint,IdGenerator,IdStruct,InstanceIdStruct,JsHelper,LocalStorageHelper,Logger,LoginCom,MoyeAssets,MoyeLabel,MoyeViewMgr,MsgHandlerDecorator,MsgHandlerDecoratorType,MsgMgr,MsgSerializeMgr,MultiMap,NetCom,NetServices,NetworkErrorCode,NodeNotBuild,ObjectPool,ObjectWait,Program,RecycleObj,RichTextListener,Root,RoundBoxSprite,Scene,SceneFactory,SceneRefCom,SceneType,Session,SessionCom,Singleton,SizeFollow,SpeedType,Task,TimeHelper,TimeInfo,TimerMgr,UIController,UIControllerAttr,UIControllerIndex,UIControllerListener,ViewDecorator,ViewDecoratorType,ViewLayer,WChannel,WService,WaitError,YYJJoystick,YYJJoystickCom,YYJJoystickListener,YYJJoystickMoveEvent,YYJJoystickSpeedChangeEvent,debug,debugF,error,errorF,log,logF,safeCall,warn,warnF}; \ No newline at end of file +import{debug as debug$1,log as log$1,warn as warn$1,error as error$1,_decorator,Component,director,SpriteFrame,Texture2D,instantiate,native,assetManager,UITransform,CCBoolean,Node,Enum,Layout,Vec3,Label,Widget,CCObject,CCFloat,Size,NodeEventType,v3,dynamicAtlasManager,Sprite,SpriteAtlas,CCInteger,UIRenderer,cclegacy,InstanceMaterialType,RenderTexture,Material,Vec2,BitMask,Color,Tween,tween,CCString,EventTarget,UIOpacity,Input,misc,RigidBody2D}from"cc";import{DEBUG,NATIVE,EDITOR,BUILD}from"cc/env";class Singleton{constructor(){this._isDisposed=!1}static get(){const e=this;if(null==e._inst)throw new Error(`Singleton is not initialized or destroyed, name is ${e.name}`);return e._inst}get isDisposed(){return this._isDisposed}dispose(){this._onPreDestroy()}_onPreDestroy(){this._isDisposed||(this.destroy&&this.destroy(),Singleton._inst=null,this._isDisposed=!0)}}class TimeInfo extends Singleton{constructor(){super(...arguments),this.deltaTime=0}awake(){this.serverMinusClientTime=0}clientNow(){return Date.now()}serverNow(){return this.clientNow()+this.serverMinusClientTime}update(e){this.deltaTime=e}}class JsHelper{static getMethodName(){const e=(new Error).stack.split("at ")[2],t=e.indexOf(" ");return e.substring(0,t)}static getRootDirName(e){return e.split("/")[0]}static sleep(e){return new Promise((t=>setTimeout(t,e)))}static isNullOrEmpty(e){return null==e||(0==e.length||void 0)}static getStringHashCode(e){let t=5381,o=e.length;for(;o;)t=33*t^e.charCodeAt(--o);return t>>>0}static modeString(e,t){return this.getStringHashCode(e)%t}static powBigInt(e,t){let o=BigInt(1);for(let s=0;sthis._lastTime?(this._lastTime=e,this._idCount=0):(++this._idCount,this._idCount>powValueBit$1&&(++this._lastTime,this._idCount=0,moyeErrorF("IdGenerator","{0}: idCount per sec overflow: {1} {2}",(new this).constructor.name,e,this._lastTime)));const t=IdStruct.inst;return t.init(this._lastTime,1,this._idCount),t.result}static convertToId(e,t,o){return IdStruct.inst.init(e,t,o).result}static parseId(e){return IdStruct.inst.initById(e)}static timeSinceEpoch(){const e=(TimeInfo.get().clientNow()-epoch$1)/1e3;return Math.floor(e)}initById(e){return this.result=e,this.time=e&powTimeBit$1,e>>=timeBit$1,this.process=e&powProcessBit,e>>=processBit,this.value=e&powValueBit$1,this}init(e,t,o){return this.time=BigInt(e),this.process=BigInt(t),this.value=BigInt(o),this.updateResult(),this}updateResult(){this.result=this.value,this.result<<=processBit,this.result|=this.process,this.result<<=timeBit$1,this.result|=this.time}}IdStruct._lastTime=0,IdStruct._idCount=0;const timeBit=32n,valueBit=32n,powTimeBit=JsHelper.powBigInt(2n,timeBit)-1n,powValueBit=JsHelper.powBigInt(2n,valueBit)-1n,epoch=new Date(2023,4,1).getTime();class InstanceIdStruct{static get inst(){return null==InstanceIdStruct._inst&&(InstanceIdStruct._inst=new InstanceIdStruct),InstanceIdStruct._inst}static generate(){0==this._lastTime&&(this._lastTime=this.timeSinceEpoch(),this._lastTime<=0&&(moyeWarnF("IdGenerator","{0}: lastTime less than 0: {1}",(new this).constructor.name,this._lastTime),this._lastTime=1));const e=this.timeSinceEpoch();e>this._lastTime?(this._lastTime=e,this._idCount=0):(++this._idCount,this._idCount>powValueBit&&(++this._lastTime,this._idCount=0,moyeErrorF("IdGenerator","{0}: idCount per sec overflow: {1} {2}",(new this).constructor.name,e,this._lastTime)));const t=InstanceIdStruct.inst;return t.init(this._lastTime,this._idCount),t.result}static convertToId(e,t){return InstanceIdStruct.inst.init(e,t).result}static parseId(e){return InstanceIdStruct.inst.initById(e)}static timeSinceEpoch(){const e=(TimeInfo.get().clientNow()-epoch)/1e3;return Math.floor(e)}initById(e){return this.result=e,this.time=e&powTimeBit,e>>=timeBit,this.value=e&powValueBit,this}init(e,t){return this.time=BigInt(e),this.value=BigInt(t),this.updateResult(),this}updateResult(){this.result=this.value,this.result<<=timeBit,this.result|=this.time}}InstanceIdStruct._lastTime=0,InstanceIdStruct._idCount=0;class IdGenerator extends Singleton{generateInstanceId(){return InstanceIdStruct.generate()}generateId(){return IdStruct.generate()}}class ObjectPool extends Singleton{constructor(){super(...arguments),this._pool=new Map}fetch(e){const t=this._pool.get(e);return t?0===t.length?new e:t.shift():new e}recycle(e){const t=e.constructor;let o=this._pool.get(t);o||(o=[],this._pool.set(t,o)),o.length>1e3?console.warn(`pool ${t.name} is too large`):o.push(e)}}class EntityCenter extends Singleton{constructor(){super(...arguments),this._allEntities=new Map}add(e){this._allEntities.set(e.instanceId,e)}remove(e){this._allEntities.delete(e)}get(e){return this._allEntities.get(e)}}var InstanceQueueIndex,EntityStatus,SceneType;!function(e){e[e.NONE=-1]="NONE",e[e.UPDATE=0]="UPDATE",e[e.LATE_UPDATE=1]="LATE_UPDATE",e[e.MAX=2]="MAX"}(InstanceQueueIndex||(InstanceQueueIndex={}));class EntityLifiCycleMgr extends Singleton{constructor(){super(...arguments),this._queues=new Array(InstanceQueueIndex.MAX)}awake(){for(let e=0;e=0;o--){const s=e[o],r=t.get(s);r?r.isDisposed?e.splice(o,1):r.update():e.splice(o,1)}}lateUpdate(){const e=this._queues[InstanceQueueIndex.LATE_UPDATE],t=EntityCenter.get();for(let o=e.length-1;o>=0;o--){const s=e[o],r=t.get(s);r?r.isDisposed?e.splice(o,1):r.lateUpdate():e.splice(o,1)}}}!function(e){e[e.NONE=0]="NONE",e[e.IS_FROM_POOL=1]="IS_FROM_POOL",e[e.IS_REGISTER=2]="IS_REGISTER",e[e.IS_COMPONENT=4]="IS_COMPONENT",e[e.IS_CREATED=8]="IS_CREATED",e[e.IS_NEW=16]="IS_NEW"}(EntityStatus||(EntityStatus={}));class Entity{constructor(){this._status=EntityStatus.NONE}get parent(){return this._parent}set parent(e){if(null==e)throw new Error(`cant set parent null: ${this.constructor.name}`);if(e==this)throw new Error(`cant set parent self: ${this.constructor.name}`);if(null==e.domain)throw new Error(`cant set parent because parent domain is null: ${this.constructor.name} ${e.constructor.name}`);if(null!=this._parent){if(this._parent==e)throw new Error(`重复设置了Parent: ${this.constructor.name} parent: ${this._parent.constructor.name}`);this._parent.removeFromChildren(this)}this._parent=e,this.isComponent=!1,this._parent.addToChildren(this),this.domain=this.parent.domain}get domain(){return this._domain}set domain(e){if(null==e)throw new Error(`domain cant set null: ${this.constructor.name}`);if(this._domain==e)return;const t=this._domain;if(this._domain=e,null==t&&(this.instanceId=IdGenerator.get().generateInstanceId(),this.isRegister=!0),null!=this._children)for(const[e,t]of this._children.entries())t.domain=this._domain;if(null!=this._components)for(const[e,t]of this._components.entries())t.domain=this._domain;this.isCreated||(this.isCreated=!0)}get isDisposed(){return 0n==this.instanceId}get children(){return this._children??(this._children=ObjectPool.get().fetch(Map))}get components(){return this._components??(this._components=ObjectPool.get().fetch(Map))}get isFromPool(){return(this._status&EntityStatus.IS_FROM_POOL)==EntityStatus.IS_FROM_POOL}set isFromPool(e){e?this._status|=EntityStatus.IS_FROM_POOL:this._status&=~EntityStatus.IS_FROM_POOL}get isComponent(){return(this._status&EntityStatus.IS_COMPONENT)==EntityStatus.IS_COMPONENT}set isComponent(e){e?this._status|=EntityStatus.IS_COMPONENT:this._status&=~EntityStatus.IS_COMPONENT}get isCreated(){return(this._status&EntityStatus.IS_CREATED)==EntityStatus.IS_CREATED}set isCreated(e){e?this._status|=EntityStatus.IS_CREATED:this._status&=~EntityStatus.IS_CREATED}get isNew(){return(this._status&EntityStatus.IS_NEW)==EntityStatus.IS_NEW}set isNew(e){e?this._status|=EntityStatus.IS_NEW:this._status&=~EntityStatus.IS_NEW}get isRegister(){return(this._status&EntityStatus.IS_REGISTER)==EntityStatus.IS_REGISTER}set isRegister(e){if(this.isRegister!=e)if(e?this._status|=EntityStatus.IS_REGISTER:this._status&=~EntityStatus.IS_REGISTER,e){const e=this;EntityCenter.get().add(e),EntityLifiCycleMgr.get().registerSystem(e)}else EntityCenter.get().remove(this.instanceId)}set componentParent(e){if(null==e)throw new Error(`cant set parent null: ${this.constructor.name}`);if(e==this)throw new Error(`cant set parent self: ${this.constructor.name}`);if(null==e.domain)throw new Error(`cant set parent because parent domain is null: ${this.constructor.name} ${e.constructor.name}`);if(null!=this.parent){if(this.parent==e)throw new Error(`重复设置了Parent: ${this.constructor.name} parent: ${this.parent.constructor.name}`);this.parent.removeFromComponents(this)}this._parent=e,this.isComponent=!0,this._parent.addToComponents(this),this.domain=this.parent.domain}addCom(e,t){return e instanceof Entity?this.addComByEntity(e):this.addComByType(e,t)}tryAddCom(e){let t=this.getCom(e);return null==t&&(t=this.addCom(e)),t}addComByEntity(e){const t=e.constructor;if(null!=this._components&&this._components.has(t))throw new Error(`entity already has component: ${t.name}`);return e.componentParent=this,e}addComByType(e,t=!1){if(null!=this._components&&this._components.has(e))throw new Error(`entity already has component: ${e.name}`);const o=this.createInst(e,t);return o.id=this.id,o.componentParent=this,o.awake&&EntityLifiCycleMgr.get().awakeComEvent(o),o}addChild(e,t){return e instanceof Entity?this.addChildByEntity(e):this.addChildByType(e,t)}addChildWithId(e,t,o=!1){const s=this.createInst(e,o);return s.id=t,s.parent=this,s.awake&&EntityLifiCycleMgr.get().awakeComEvent(s),s}addChildByEntity(e){return e.parent=this,e}addChildByType(e,t=!1){const o=this.createInst(e,t);return o.id=IdGenerator.get().generateId(),o.parent=this,o.awake&&EntityLifiCycleMgr.get().awakeComEvent(o),o}createInst(e,t){let o;return o=t?ObjectPool.get().fetch(e):new e,o.isFromPool=t,o.isCreated=!0,o.isNew=!0,o.id=0n,o}removeFromChildren(e){null!=this._children&&(this._children.delete(e.id),0==this._children.size&&(ObjectPool.get().recycle(this._children),this._children=null))}removeFromComponents(e){null!=this._components&&(this._components.delete(e.constructor),0==this._components.size&&(ObjectPool.get().recycle(this._components),this._components=null))}addToComponents(e){this.components.set(e.constructor,e)}addToChildren(e){if(this.children.has(e.id))throw new Error(`entity already has child: ${e.id}`);this.children.set(e.id,e)}getCom(e){if(null==this._components)return null;const t=this._components.get(e);return t||null}removeCom(e){if(this.isDisposed)return;if(null==this._components)return;const t=this.getCom(e);null!=t&&(this.removeFromComponents(t),t.dispose())}getParent(e){return this.parent}getChild(e,t){if(null==this._children)return null;return this._children.get(t)}removeChild(e){if(null==this._children)return;const t=this._children.get(e);t&&(this._children.delete(e),t.dispose())}dispose(){if(!this.isDisposed){if(this.isRegister=!1,this.instanceId=0n,null!=this._children){for(const[e,t]of this._children.entries())t.dispose();this._children.clear(),ObjectPool.get().recycle(this._children),this._children=null}if(null!=this._components){for(const[e,t]of this._components.entries())t.dispose();this._components.clear(),ObjectPool.get().recycle(this._components),this._components=null}this.destroy&&EntityLifiCycleMgr.get().destroyComEvent(this),this._domain=null,null==this._parent||this._parent.isDisposed||(this.isComponent?this._parent.removeCom(this.getType()):this._parent.removeFromChildren(this)),this._parent=null,this.isFromPool&&ObjectPool.get().recycle(this),this._status=EntityStatus.NONE}}domainScene(){return this.domain}getType(){return this.constructor}}class Scene extends Entity{set domain(e){this._domain=e}get domain(){return this._domain}set parent(e){null!=e&&(this._parent=e,this._parent.children.set(this.id,this))}get parent(){return this._parent}init(e){this.id=e.id,this.instanceId=e.instanceId,this.sceneType=e.sceneType,this.name=e.name,this.parent=e.parent,this.isCreated=!0,this.isNew=!0,this.domain=this,this.isRegister=!0,moyeLogF("scene","scene create sceneType = {0}, name = {1}, id = {2}",this.sceneType,this.name,this.id)}}!function(e){e.NONE="NONE",e.PROCESS="PROCESS",e.CLIENT="CLIENT",e.CURRENT="CURRENT"}(SceneType||(SceneType={}));class Root extends Singleton{get scene(){return this._scene}awake(){const e=new Scene;e.init({id:0n,sceneType:SceneType.PROCESS,name:"Process",instanceId:IdGenerator.get().generateInstanceId()}),this._scene=e}}class RecycleObj{static create(e){const t=ObjectPool.get().fetch(this);return e&&Object.assign(t,e),t._isRecycle=!0,t}dispose(){this._isRecycle&&ObjectPool.get().recycle(this)}}class AEvent extends RecycleObj{}class BeforeSingletonAdd extends AEvent{}class AfterSingletonAdd extends AEvent{}class BeforeProgramInit extends AEvent{}class AfterProgramInit extends AEvent{}class BeforeProgramStart extends AEvent{}class AfterProgramStart extends AEvent{}class AfterCreateClientScene extends AEvent{}class AfterCreateCurrentScene extends AEvent{}class DecoratorCollector{constructor(){this._decorators=new Map}static get inst(){return null==DecoratorCollector._inst&&(DecoratorCollector._inst=new DecoratorCollector),DecoratorCollector._inst}add(e,...t){let o=this._decorators.get(e);o||(o=[],this._decorators.set(e,o)),o.push(t)}get(e){return this._decorators.get(e)||[]}}const EventDecoratorType="EventDecoratorType";function EventDecorator(e,t){return function(o){null==t&&console.error("EventDecorator必须要传 sceneType"),DecoratorCollector.inst.add(EventDecoratorType,e,o,t)}}class EventInfo{constructor(e,t){this.eventHandler=e,this.sceneType=t}}class MoyeEventCenter{constructor(){this.allEvents=new Map}static get inst(){return null==this._inst&&(this._inst=new MoyeEventCenter,this._inst.reloadEvent()),this._inst}reloadEvent(){const e=DecoratorCollector.inst.get(EventDecoratorType);this.allEvents.clear();for(const t of e){const e=t[0],o=t[1],s=t[2];let r=this.allEvents.get(e);r||(r=[],this.allEvents.set(e,r)),r.push(new EventInfo(new o,s))}}publish(e){const t=this.allEvents.get(e.constructor);if(t){for(let o=0;o{t=e}));return o._resolve=t,o}setResult(e){if(!this._resolve)throw new Error("setResult but task has been disposed");this._resolve(e),this.dispose()}constructor(e){super(e)}dispose(){this._resolve=null}}class Game{static addSingleton(e,t=!0){if(Game._singletonMap.has(e))throw new Error(`already exist singleton: ${e.name}`);t&&MoyeEventCenter.inst.publish(BeforeSingletonAdd.create({singletonType:e}));const o=new e;e._inst=o,Game._singletonMap.set(e,o),Game._singletons.push(o);const s=o;return s.awake&&s.awake(),Game._destroys.push(s),s.update&&Game._updates.push(s),s.lateUpdate&&Game._lateUpdates.push(s),t&&MoyeEventCenter.inst.publish(AfterSingletonAdd.create({singletonType:e})),o}static async waitFrameFinish(){const e=Task.create();Game._frameFinishTaskQueue.push(e),await e}static update(e){for(let t=0;t=0;e--){const t=Game._singletons[e];t.isDisposed||t._onPreDestroy()}}}Game._singletonMap=new Map,Game._singletons=[],Game._destroys=[],Game._updates=[],Game._lateUpdates=[],Game._frameFinishTaskQueue=[];class EventSystem extends Singleton{async publishAsync(e,t){const o=MoyeEventCenter.inst.allEvents.get(t.constructor);if(!o)return;const s=[];for(let r=0;r=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$m,property:property$m}=_decorator;let MoyeRuntime=class extends Component{start(){director.addPersistRootNode(this.node)}update(e){Game.update(1e3*e)}lateUpdate(e){Game.lateUpdate(1e3*e),Game.frameFinishUpdate()}onDestroy(){Game.dispose()}};MoyeRuntime=__decorate$u([ccclass$m("MoyeRuntime")],MoyeRuntime);class TimeHelper{static clientNow(){return TimeInfo.get().clientNow()}static clientNowSeconds(){return Math.floor(TimeHelper.clientNow()/1e3)}static serverNow(){return TimeInfo.get().serverNow()}}var TimerType;TimeHelper.oneDay=864e5,TimeHelper.oneHour=36e5,TimeHelper.oneMinute=6e4,function(e){e[e.ONCE=0]="ONCE",e[e.REPEAT=1]="REPEAT"}(TimerType||(TimerType={}));class Timer{static create(){const e=ObjectPool.get().fetch(Timer);return e.reset(),e.id=Timer.getId(),e}static getId(){return++this._idGenerator}reset(){this.cb=null,this.tcs=null,this.id=0,this.expireTime=0,this.interval=0}dispose(){this.reset(),ObjectPool.get().recycle(this)}}Timer._idGenerator=1e3;class TimerMgr extends Singleton{constructor(){super(...arguments),this._timerMap=new Map,this._timers=[]}newRepeatedTimer(e,t,o=!1){const s=Timer.create();return s.type=TimerType.REPEAT,s.cb=t,s.interval=e,s.expireTime=e+TimeHelper.clientNow(),this._timerMap.set(s.id,s),this._timers.push(s),o&&t(),s.id}newOnceTimer(e,t){const o=Timer.create();return o.type=TimerType.ONCE,o.cb=t,o.expireTime=e+TimeHelper.clientNow(),this._timerMap.set(o.id,o),this._timers.push(o),o.id}newFrameTimer(e){const t=Timer.create();return t.type=TimerType.REPEAT,t.cb=e,t.interval=1,t.expireTime=t.interval+TimeHelper.clientNow(),this._timerMap.set(t.id,t),this._timers.push(t),t.id}remove(e){const t=this._timerMap.get(e);return!!t&&(t.id=0,this._timerMap.delete(e),!0)}update(){const e=TimeHelper.clientNow();for(let t=this._timers.length-1;t>=0;t--){const o=this._timers[t];0!=o.id?o.expireTime>e||(null!=o.cb&&o.cb(),null!=o.tcs&&o.tcs.setResult(),o.type==TimerType.REPEAT?o.expireTime+=o.interval:this.remove(o.id)):(this._timers.splice(t,1),o.dispose())}}async waitAsync(e,t){if(e<=0)return;const o=Task.create(),s=Timer.create();let r;s.type=TimerType.ONCE,s.tcs=o,s.expireTime=e+TimeHelper.clientNow(),this._timerMap.set(s.id,s),this._timers.push(s),t&&(r=()=>{this.remove(s.id)&&o.setResult()},t.add(r));try{await o}finally{t?.remove(r),r=null}}}const CoroutineLockTag="CoroutineLock";class CoroutineLockItem{init(e){this.key=e,this.task=Task.create(),this.setTimeout(6e4,"CoroutineLock timeout")}setTimeout(e,t){this.deleteTimeout(),this._timerId=TimerMgr.get().newOnceTimer(e,this.timeout.bind(this)),this._timeoutInfo=t}deleteTimeout(){null!=this._timerId&&(TimerMgr.get().remove(this._timerId),this._timerId=null)}async timeout(){moyeWarnF("CoroutineLock","CoroutineLock timeout key: {0}, info: {1}",this.key,this._timeoutInfo)}dispose(){null!=this.key?(this.deleteTimeout(),CoroutineLock.get().runNextLock(this),this.key=null,this.task=null):moyeWarnF("CoroutineLock","repeat dispose CoroutineLockItem")}}class CoroutineLock extends Singleton{constructor(){super(...arguments),this._lockMap=new Map}async wait(e,t){const o=`${e}_${t}`;let s=this._lockMap.get(o);s||(s=new Set,this._lockMap.set(o,s));const r=ObjectPool.get().fetch(CoroutineLockItem);return r.init(o),s.add(r),s.size>1?await r.task:r.task.setResult(),r}runNextLock(e){const t=this._lockMap.get(e.key);t.delete(e),ObjectPool.get().recycle(e);for(const e of Array.from(t.values())){e.task.setResult();break}}}class SceneMgr extends Singleton{}class SceneFactory{static createClientScene(){const e=new Scene;return e.init({id:1n,sceneType:SceneType.CLIENT,name:"Game",instanceId:IdGenerator.get().generateInstanceId(),parent:SceneMgr.get().process}),SceneMgr.get().client=e,EventSystem.get().publish(e,AfterCreateClientScene.create()),e}static createCurrentScene(e,t){SceneMgr.get().current?.dispose();const o=new Scene;return o.init({id:e,sceneType:SceneType.CURRENT,name:t,instanceId:IdGenerator.get().generateInstanceId(),parent:SceneMgr.get().client}),SceneMgr.get().current=o,EventSystem.get().publish(o,AfterCreateCurrentScene.create()),o}}class Program{static init(e){MoyeEventCenter.inst.publish(new BeforeProgramInit),Game.addSingleton(ObjectPool,!1),Game.addSingleton(Logger),Game.addSingleton(EventSystem),Game.addSingleton(TimeInfo),Game.addSingleton(TimerMgr),Game.addSingleton(CoroutineLock),Game.addSingleton(IdGenerator),Game.addSingleton(EntityCenter),Game.addSingleton(EntityLifiCycleMgr),Game.addSingleton(Root),Game.addSingleton(SceneMgr).process=Root.get().scene,e.addComponent(MoyeRuntime),MoyeEventCenter.inst.publish(new AfterProgramInit)}static start(){MoyeEventCenter.inst.reloadEvent(),MoyeEventCenter.inst.publish(new BeforeProgramStart),MoyeEventCenter.inst.publish(new AfterProgramStart),SceneFactory.createClientScene()}}async function safeCall(e){try{return await e}catch(e){moyeErrorF("safeCall",e)}}const EventHandlerTag="EventHandler";class AEventHandler{async handleAsync(e,t){try{await this.run(e,t)}catch(e){moyeErrorF("EventHandler","error:{0}",e.stack)}}handle(e,t){try{const o=this.run(e,t);o instanceof Promise&&(moyeWarnF("EventHandler","{0}的run方法是异步的, 请尽量不要用publish来通知",this.constructor.name),safeCall(o))}catch(e){moyeErrorF("EventHandler","error:{0}",e.stack)}}}const CancellationTokenTag="CancellationToken";class CancellationToken{constructor(){this._actions=new Set}add(e){null!=e?this._actions.add(e):moyeErrorF("CancellationToken","CancellationToken add error, callback is null")}remove(e){this._actions?.delete(e)}cancel(){null!=this._actions?this.invoke():moyeErrorF("CancellationToken","CancellationToken cancel error, repeat cancel")}isCancel(){return null==this._actions}invoke(){const e=this._actions;this._actions=null;try{for(const t of e)t();e.clear()}catch(e){moyeErrorF("CancellationToken",e)}}}class MultiMap{constructor(){this._empty=[],this._map=new Map}add(e,t){let o=this._map.get(e);void 0===o&&(o=[],this._map.set(e,o)),o.push(t)}remove(e,t){const o=this._map.get(e);if(void 0===o)return!1;const s=o.indexOf(t);return-1!==s&&(o.splice(s,1),0===o.length&&this._map.delete(e),!0)}getAll(e){const t=this._map.get(e);return void 0===t?[]:t}get(e){return this._map.get(e)??this._empty}getOne(e){const t=this._map.get(e);if(void 0!==t&&t.length>0)return t[0]}contains(e,t){const o=this._map.get(e);return void 0!==o&&o.includes(t)}}Entity.prototype.clientScene=function(){return SceneMgr.get().client},Entity.prototype.currentScene=function(){return SceneMgr.get().current};class EventAutoReleaseCom extends Entity{constructor(){super(...arguments),this.events=[]}addItem(e){this.events.push(e)}destroy(){const e=this.eventCom.eventMap;for(const t of this.events){e.get(t.eventType).delete(t),t.entity=null,t.handler=null,t.eventType=null,t.dispose()}this.events=null,this.eventCom=null}}class EventItem extends RecycleObj{}class EventCom extends Entity{constructor(){super(...arguments),this._eventMap=new Map}destroy(){const e=this._eventMap;for(const t of e.values()){for(const e of t)e.entity=null,e.handler=null,e.eventType=null,e.dispose();t.clear()}e.clear()}subscribe(e,t,o){const s=EventItem.create({entity:o,handler:t,eventType:e});let r=this._eventMap.get(e);r||(r=new Set,this._eventMap.set(e,r)),r.add(s);let i=o.getCom(EventAutoReleaseCom);i||(i=o.addCom(EventAutoReleaseCom),i.eventCom=this),i.addItem(s)}publish(e,...t){const o=this._eventMap.get(e);if(o)for(const e of o)e.handler.apply(e.entity,t)}}class LocalStorageHelper{static getNumber(e,t){const o=localStorage.getItem(e);if(!o)return t;try{return Number(o)}catch(e){return t}}static setNumber(e,t){localStorage.setItem(e,t.toString())}static getString(e,t){const o=localStorage.getItem(e);return o||t}static setString(e,t){localStorage.setItem(e,t)}static setBoolean(e,t){localStorage.setItem(e,t?"1":"0")}static getBoolean(e,t){const o=localStorage.getItem(e);return o?"1"==o:t}static setObject(e){localStorage.setItem(e.constructor.name,JSON.stringify(e))}static getObject(e){const t=localStorage.getItem(e.name);if(!t)return null;try{return JSON.parse(t)}catch(e){return null}}}class LoginCom extends Entity{constructor(){super(...arguments),this._isLogin=!1,this._isReconnecting=!1,this._reLoginTryMaxCount=3}registerExecutor(e){this._loginExecutor=e}async login(e){const t=await this._loginExecutor.login(this.domainScene(),e);return 0==t&&(this._isLogin=!0,this._loginArgs=e),t}}class AfterAddLoginCom extends AEvent{}var __decorate$t=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterCreateClientSceneHandler$1=class extends AEventHandler{run(e,t){e.addCom(LoginCom),EventSystem.get().publish(e,new AfterAddLoginCom)}};AfterCreateClientSceneHandler$1=__decorate$t([EventDecorator(AfterCreateClientScene,SceneType.CLIENT)],AfterCreateClientSceneHandler$1);class MsgMgr extends Singleton{constructor(){super(...arguments),this._responseTypeMap=new Set,this._typeOpcodeMap=new Map,this._opcodeTypeMap=new Map}awake(){}register(e,t,o=!1){this._typeOpcodeMap.set(e,t),this._opcodeTypeMap.set(t,e),o&&this._responseTypeMap.add(t)}isResponse(e){return this._responseTypeMap.has(e)}getOpcode(e){return this._typeOpcodeMap.get(e)}getType(e){return this._opcodeTypeMap.get(e)}}class MsgSerializeMgr extends Singleton{register(e){this._serialize=e}serialize(e,t){return this._serialize.encode(e,t)}deserialize(e){return this._serialize.decode(e)}}var __decorate$s=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterSingletonAddHandler=class extends AEventHandler{run(e,t){if(t.singletonType===MsgMgr)Game.addSingleton(MsgSerializeMgr)}};AfterSingletonAddHandler=__decorate$s([EventDecorator(AfterSingletonAdd,SceneType.PROCESS)],AfterSingletonAddHandler);const MsgHandlerDecoratorType="MsgHandlerDecorator";function MsgHandlerDecorator(e){return function(t){DecoratorCollector.inst.add("MsgHandlerDecorator",t,e)}}class MessageDispatcherMgr extends Singleton{constructor(){super(...arguments),this._handlers=new Map}awake(){const e=DecoratorCollector.inst.get("MsgHandlerDecorator");for(const t of e){const e=t[0],o=t[1],s=new e;this._handlers.has(o)||this._handlers.set(o,[]),this._handlers.get(o).push(s)}}destroy(){this._handlers.clear()}handle(e,t){const o=t.constructor,s=this._handlers.get(o);if(s)for(const o of s)o.handle(e,t);else console.error("[MessageDispatcherMgr] msg not found handler",t)}}var __decorate$r=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let BeforeProgramStartHandler=class extends AEventHandler{run(e,t){Game.addSingleton(MsgMgr),Game.addSingleton(MessageDispatcherMgr)}};BeforeProgramStartHandler=__decorate$r([EventDecorator(BeforeProgramStart,SceneType.PROCESS)],BeforeProgramStartHandler);class NetClientComponentOnRead extends AEvent{}var __decorate$q=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let NetClientComponentOnReadEvent=class extends AEventHandler{run(e,t){t.session;t.data;Uint8Array}};NetClientComponentOnReadEvent=__decorate$q([EventDecorator(NetClientComponentOnRead,SceneType.CLIENT)],NetClientComponentOnReadEvent);const NetworkTag="Network";class NetServices extends Singleton{constructor(){super(...arguments),this._acceptIdGenerator=Number.MAX_SAFE_INTEGER-1,this._services=new Map,this._serviceIdGenerator=0,this._acceptCallback=new Map,this._readCallback=new Map,this._errorCallback=new Map}sendMessage(e,t,o){const s=this.get(e);null!=s&&s.send(t,o)}addService(e){return e.id=++this._serviceIdGenerator,this.add(e),e.id}removeService(e){this.remove(e)}createChannel(e,t,o){const s=this.get(e);null!=s&&s.create(t,o)}removeChannel(e,t,o){const s=this.get(e);null!=s&&s.remove(t,o)}registerAcceptCallback(e,t){this._acceptCallback.set(e,t)}registerReadCallback(e,t){this._readCallback.set(e,t)}registerErrorCallback(e,t){this._errorCallback.has(e)&&moyeErrorF("Network","重复注册servece的errorCallback, serviceId={0}",e),this._errorCallback.set(e,t)}onAccept(e,t,o){const s=this._acceptCallback.get(e);s&&s(t,o)}onRead(e,t,o){const s=this._readCallback.get(e);s&&s(t,o)}onError(e,t,o){const s=this._errorCallback.get(e);s&&s(t,o)}get(e){return this._services.get(e)}createAcceptChannelId(){return--this._acceptIdGenerator}add(e){this._services.set(e.id,e)}remove(e){const t=this._services.get(e);t&&t.dispose()}}var __decorate$p=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterProgramInitHandler$1=class extends AEventHandler{run(e,t){Game.addSingleton(NetServices)}};AfterProgramInitHandler$1=__decorate$p([EventDecorator(AfterProgramInit,SceneType.PROCESS)],AfterProgramInitHandler$1);class NetworkErrorCode{}NetworkErrorCode.ERR_SendMessageNotFoundChannel=1,NetworkErrorCode.ERR_ChannelReadError=2,NetworkErrorCode.ERR_WebSocketError=3;class IPEndPoint{constructor(e,t=0){if(0==t){const t=e.split(":");this.host=t[0],this.port=parseInt(t[1])}else this.host=e,this.port=t}toString(){return`${this.host}:${this.port}`}}var ServiceType;!function(e){e[e.Outer=0]="Outer",e[e.Inner=1]="Inner"}(ServiceType||(ServiceType={}));class AChannel{constructor(){this.id=0n}get isDisposed(){return 0n==this.id}}const NetworkWebsocketTag="WService";class WChannel extends AChannel{constructor(){super(...arguments),this._isConnected=!1,this._msgQueue=[]}initByAddress(e,t,o){this.wSocket=new WebSocket(`ws://${e}`),this.wSocket.binaryType="arraybuffer",this.id=t,this._service=o,this.remoteAddress=e,this.wSocket.onopen=this.onConnectComplete.bind(this),this.wSocket.onclose=this.onSocketClose.bind(this),this.wSocket.onerror=this.onWsSocketError.bind(this),this.wSocket.onmessage=this.onMessage.bind(this)}onConnectComplete(){this._isConnected=!0;for(const e of this._msgQueue)this.innerSend(e);this._msgQueue=[]}onMessage(e){try{const t=this.id;NetServices.get().onRead(this._service.id,t,e.data)}catch(e){moyeErrorF("WService","Channel onMessage, remoteAddress={1} error={0}",e.stack,this.remoteAddress.toString()),this.onError(NetworkErrorCode.ERR_ChannelReadError)}}dispose(){this.isDisposed||(this.id=0n,this.wSocket=null,this._msgQueue=null,this._service=null,this._isConnected=!1,this.remoteAddress=null)}onWsSocketError(e){this.onSocketClose(NetworkErrorCode.ERR_WebSocketError)}onSocketClose(e){this._service&&this._service.channelClose(this,e)}closeSocket(e){e<4e3?null!=this.wSocket&&this.wSocket.close():null!=this.wSocket&&this.wSocket.close(e)}onError(e){this._service.remove(this.id,e)}innerSend(e){this.wSocket.send(e)}send(e){this.isDisposed||(this._isConnected?this.innerSend(e):this._msgQueue.push(e))}}class AService{}class WService extends AService{constructor(){super(...arguments),this._idChannels=new Map}initSender(e){this.serviceType=e}send(e,t){const o=this._idChannels.get(e);null!=o?o.send(t):NetServices.get().onError(this.id,e,NetworkErrorCode.ERR_SendMessageNotFoundChannel)}create(e,t){this._idChannels.has(e)||this.innerCreate(e,t)}remove(e,t){const o=this._idChannels.get(e);o&&(o.closeSocket(t),this._idChannels.delete(e),o.dispose())}dispose(){}innerCreate(e,t){const o=new WChannel;o.initByAddress(t,e,this),this._idChannels.set(o.id,o)}channelClose(e,t){this._idChannels.delete(e.id),NetServices.get().onError(this.id,e.id,t),e.dispose()}}class NetComReadEvent extends AEvent{}const MessageTag="Message";class MessageErrorCode extends NetworkErrorCode{}MessageErrorCode.ERR_SessionDisposed=101;class RpcResponse{constructor(e){Object.assign(this,e)}}class Session extends Entity{constructor(){super(...arguments),this.requestCallbacks=new Map,this.error=0}init(e){this.serviceId=e;const t=TimeHelper.clientNow();this.lastRecvTime=t,this.lastSendTime=t}onResponse(e){const t=this.requestCallbacks.get(e.rpcId);t&&(this.requestCallbacks.delete(e.rpcId),t.setResult(e))}send(e){if(this.isDisposed)moyeLogF("Message","session已经销毁,不能发送消息, message={0}, sessionId={1}",e.constructor.name,this.id);else try{const t=MsgMgr.get().getOpcode(e.constructor),o=MsgSerializeMgr.get().serialize(t,e);this.lastSendTime=TimeHelper.clientNow(),NetServices.get().sendMessage(this.serviceId,this.id,o)}catch(e){moyeErrorF("Message","session send error={0}",e.stack)}}async call(e){if(this.isDisposed){moyeLogF("Message","session已经销毁,不能发送消息, message={0}, sessionId={1}",e.constructor.name,this.id);return new RpcResponse({error:MessageErrorCode.ERR_SessionDisposed})}const t=++Session._rpcId,o=Task.create();this.requestCallbacks.set(t,o),e.rpcId=t,this.send(e);return await o}destroy(){if(this.error>0&&NetServices.get().onError(this.serviceId,this.id,this.error),NetServices.get().removeChannel(this.serviceId,this.id,this.error),this.requestCallbacks.size>0){const e=new RpcResponse({error:MessageErrorCode.ERR_SessionDisposed});for(const[t,o]of this.requestCallbacks)o.setResult(e);this.requestCallbacks.clear()}}}Session._rpcId=0;class NetCom extends Entity{awake(){const e=new WService;e.initSender(ServiceType.Outer);const t=NetServices.get();this.serviceId=t.addService(e),t.registerReadCallback(this.serviceId,this.onRead.bind(this)),t.registerErrorCallback(this.serviceId,this.onError.bind(this))}destroy(){NetServices.get().removeService(this.serviceId)}onRead(e,t){const o=this.getChild(Session,e);if(null==o)return;o.lastRecvTime=TimeHelper.clientNow();const s=NetComReadEvent.create({data:t,session:o});EventSystem.get().publish(this.domainScene(),s)}onError(e,t){const o=this.getChild(Session,e);null!=o&&(o.error=t,o.dispose())}create(e){const t=this.addChild(Session);return t.init(this.serviceId),t.remoteAddress=e,NetServices.get().createChannel(this.serviceId,t.id,e),t}}class SessionCom extends Entity{destroy(){this.session?.dispose(),this.session=null}}var __decorate$o=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterCreateClientSceneHandler=class extends AEventHandler{run(e,t){e.addCom(NetCom),e.addCom(SessionCom)}};AfterCreateClientSceneHandler=__decorate$o([EventDecorator(AfterCreateClientScene,SceneType.CLIENT)],AfterCreateClientSceneHandler);var __decorate$n=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let NetComReadEventHandler=class extends AEventHandler{run(e,t){const o=t.session,s=t.data,[r,i]=MsgSerializeMgr.get().deserialize(s);MsgMgr.get().isResponse(r)?o.onResponse(i):MessageDispatcherMgr.get().handle(o,i)}};NetComReadEventHandler=__decorate$n([EventDecorator(NetComReadEvent,SceneType.CLIENT)],NetComReadEventHandler);class AMHandler{handle(e,t){if(!e.isDisposed){const o=this.run(e,t);o instanceof Promise&&(moyeWarnF("AMHandler","{0}.run 请不要使用异步, 因为异步没办法保证消息接收后的处理顺序",this.constructor.name),safeCall(o))}}}class AssetInfo{init(e,t){const o=(t=this.parseLocation(e,t)).split("/");let s="";for(let e=1;e=AssetSystem._frameMaxAddQueueProvider)return;if(this._loadingSet.size>=AssetSystem._maxLoadingProvider)return;if(0==this._waitLoads.length)return;const e=this._waitLoads.shift();this._loadingSet.add(e),e.internalLoad()}removeProvider(e){this._loadingSet.delete(e),this.updateLoadingSet()}}AssetSystem._maxLoadingProvider=1,AssetSystem._frameMaxAddQueueProvider=1;const MoyeAssetTag="MoyeAsset";class AssetOperationHandle{constructor(){this.isDisposed=!1}getAsset(e){return this.provider.asset}dispose(){this.isDisposed?moyeErrorF("MoyeAsset","重复销毁AssetOperationHandle"):(this.isDisposed=!0,this.provider.releaseHandle(this))}instantiateSync(){return instantiate(this.provider.asset)}async instantiateAsync(){return instantiate(this.provider.asset)}}class BundleAssetProvider{constructor(){this.refCount=0,this._handleSet=new Set}async internalLoad(){const e=this.assetInfo.assetPath,t=this.assetInfo.assetType;this.bundleAsset.bundle.load(e,t,((e,t)=>{e?moyeErrorF("MoyeAsset","加载资源错误:{0},{1}",this.assetInfo.uuid,e):this.asset=t,this._task.setResult(),this.assetSystem.removeProvider(this)}))}async load(){this._task=Task.create(),this.assetSystem.addProvider(this),await this._task}createHandle(){this.refCount++;const e=new AssetOperationHandle;return e.provider=this,this._handleSet.add(e),e}releaseHandle(e){this.refCount<=0&&moyeWarnF("MoyeAsset","Asset provider reference count is already zero. There may be resource leaks !"),0==this._handleSet.delete(e)&&moyeErrorF("MoyeAsset","Should never get here !"),this.refCount--}}var AssetLockType;!function(e){e.BUNDLE_ASSET_LOAD="bundle_asset_load",e.BUNDLE_LOAD="bundle_load"}(AssetLockType||(AssetLockType={}));class BundleAsset{constructor(){this.refCount=0,this.isAutoRelease=!0,this._providerMap=new Map}async loadAssetAsync(e){let t=this._providerMap.get(e.uuid);t||(t=await this.createProvider(e));return t.createHandle()}async createProvider(e){const t=await CoroutineLock.get().wait(AssetLockType.BUNDLE_ASSET_LOAD,e.uuid);try{let t=this._providerMap.get(e.uuid);return t||(t=new BundleAssetProvider,t.assetInfo=e,t.assetSystem=this.assetSystem,t.bundleAsset=this,this.refCount++,await t.load(),this._providerMap.set(e.uuid,t),t)}finally{t.dispose()}}unloadUnusedAssets(){for(const[e,t]of this._providerMap)0==t.refCount&&(this.bundle.release(t.assetInfo.assetPath,t.assetInfo.assetType),this._providerMap.delete(e),this.refCount--)}}class MoyeAssets extends Singleton{awake(){MoyeAssets.assetSystem=new AssetSystem}update(){MoyeAssets.assetSystem.update()}static async loadAssetAsync(e,t){try{const o=new AssetInfo;o.init(e,t);const s=o.bundleName;let r=MoyeAssets._bundleMap.get(s);r||(r=await this.loadBundleAsync(s));return await r.loadAssetAsync(o)}catch(e){moyeErrorF("MoyeAsset",e)}}static async loadBundleAsync(e){const t=await CoroutineLock.get().wait(AssetLockType.BUNDLE_LOAD,e);try{let t=MoyeAssets._bundleMap.get(e);if(t)return t;const o=Task.create();if(!this._bundlePathMap.has(e)&&(this._bundlePathMap.set(e,e),NATIVE)){const t=`${native.fileUtils.getWritablePath()}hot/${e}`;native.fileUtils.isDirectoryExist(t)&&this._bundlePathMap.set(e,t)}const s=this._bundlePathMap.get(e);moyeLogF("MoyeAsset","加载bundle: {0}",s),assetManager.loadBundle(s,((t,s)=>{t?moyeLogF("MoyeAsset","加载Bundle错误, bundle={0}, error={1}",e,t):moyeLogF("MoyeAsset","加载Bundle完成, bundle={0}",e),o.setResult(s)}));const r=await o;return t=new BundleAsset,t.bundle=r,t.bundleName=e,t.assetSystem=MoyeAssets.assetSystem,MoyeAssets._bundleMap.set(e,t),t}finally{t.dispose()}}static releaseBundle(e){0==e.refCount?(this._bundleMap.delete(e.bundleName),assetManager.removeBundle(e.bundle),moyeLogF("MoyeAsset","卸载bundle:{0}",e.bundleName)):moyeErrorF("MoyeAsset","释放的bundle:{0}, 引用计数不为0",e.bundleName)}static unloadUnusedAssets(){for(const[e,t]of this._bundleMap)0==t.refCount&&t.isAutoRelease&&(t.unloadUnusedAssets(),MoyeAssets.releaseBundle(t))}}MoyeAssets._bundleMap=new Map,MoyeAssets._bundlePathMap=new Map;var __decorate$m=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};let AfterProgramInitHandler=class extends AEventHandler{run(e,t){Game.addSingleton(MoyeAssets)}};var WaitError;AfterProgramInitHandler=__decorate$m([EventDecorator(AfterProgramInit,SceneType.NONE)],AfterProgramInitHandler),function(e){e[e.SUCCESS=0]="SUCCESS",e[e.DESTROY=1]="DESTROY",e[e.CANCEL=2]="CANCEL",e[e.TIMEOUT=3]="TIMEOUT"}(WaitError||(WaitError={}));class AWait extends RecycleObj{constructor(){super(...arguments),this.error=WaitError.SUCCESS}}class ObjectWait extends Entity{constructor(){super(...arguments),this._tasks=new Map}destroy(){for(const[e,t]of this._tasks){const t=this.createWaitInstance(e,WaitError.DESTROY);this.notify(t)}}async wait(e,t){this.cancelLastWait(e);const o=Task.create(e);let s,r;this._tasks.set(e,o),t&&(s=()=>{const t=this.createWaitInstance(e,WaitError.CANCEL);this.notify(t)},t.add(s));try{r=await o}finally{t?.remove(s),s=null}return r}async waitWithTimeout(e,t,o){this.cancelLastWait(e);const s=Task.create(e);let r,i;this._tasks.set(e,s),this.timeoutRun(e,t,o),o&&(r=()=>{const t=this.createWaitInstance(e,WaitError.CANCEL);this.notify(t)},o.add(r));try{i=await s}finally{o?.remove(r),r=null}return i}cancelLastWait(e){if(!this._tasks.has(e))return;moyeWarnF("上一个wait已经取消, {0}",e.name);const t=this.createWaitInstance(e,WaitError.CANCEL);this.notify(t)}async timeoutRun(e,t,o){if(await TimerMgr.get().waitAsync(t,o),o?.isCancel())return;if(!this._tasks.has(e))return;const s=this.createWaitInstance(e,WaitError.TIMEOUT);this.notify(s)}createWaitInstance(e,t){const o=e.create();return o.error=t,o}notify(e){const t=this._tasks.get(e.constructor);t&&(this._tasks.delete(e.constructor),t.setResult(e),e.dispose())}}class AsyncButtonListener{constructor(e){this._callback=e}async invoke(...e){this._isClick||(this._isClick=!0,await this._callback(...e),this._isClick=!1)}static create(e){const t=new AsyncButtonListener(e);return t.invoke.bind(t)}}var __decorate$l=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$l,property:property$l,menu:menu$b}=_decorator;let BgAdapter=class extends Component{constructor(){super(...arguments),this.coverNode=null,this.isShowMax=!0,this._selfTransform=null}start(){this._selfTransform=this.node.getComponent(UITransform),this.updateSize(),this.coverNode.node.on(Node.EventType.SIZE_CHANGED,this.updateSize,this)}onDestroy(){this.coverNode.node.off(Node.EventType.SIZE_CHANGED,this.updateSize,this),this.coverNode=null,this._selfTransform=null}updateSize(){let e=0;e=this.isShowMax?Math.max(this.coverNode.width/this._selfTransform.width,this.coverNode.height/this._selfTransform.height):Math.min(this.coverNode.width/this._selfTransform.width,this.coverNode.height/this._selfTransform.height);const t=this._selfTransform.width*e,o=this._selfTransform.height*e;this._selfTransform.width=t,this._selfTransform.height=o}};__decorate$l([property$l(UITransform)],BgAdapter.prototype,"coverNode",void 0),__decorate$l([property$l(CCBoolean)],BgAdapter.prototype,"isShowMax",void 0),BgAdapter=__decorate$l([ccclass$l("BgAdapter"),menu$b("moye/BgAdapter")],BgAdapter);var __decorate$k=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$k,inspector:inspector$1,property:property$k,disallowMultiple:disallowMultiple$1,menu:menu$a}=_decorator;var CenterHorizontalDirection;!function(e){e[e.LEFT_TO_RIGHT=0]="LEFT_TO_RIGHT",e[e.RIGHT_TO_LEFT=1]="RIGHT_TO_LEFT",e[e.CENTER_TO_SIDE=2]="CENTER_TO_SIDE"}(CenterHorizontalDirection||(CenterHorizontalDirection={}));let CenterLayout=class extends Layout{constructor(){super(...arguments),this.centerHorizontalDirection=CenterHorizontalDirection.CENTER_TO_SIDE}_doLayoutHorizontally(e,t,o,s){const r=this.node._uiProps.uiTransformComp.anchorPoint,i=this._getFixedBreakingNum();let n=1,a=this._paddingLeft;this._horizontalDirection===Layout.HorizontalDirection.RIGHT_TO_LEFT&&(n=-1,a=this._paddingRight);const l=(this._horizontalDirection-r.x)*e+n*a;let c=l-n*this._spacingX,d=0,h=0,p=0,_=0,u=!1;const y=this._usefulLayoutObj.length;let g=this._cellSize.width;const T=this._getPaddingH();this._layoutType!==Layout.Type.GRID&&this._resizeMode===Layout.ResizeMode.CHILDREN&&(g=(e-T-(y-1)*this._spacingX)/y);const m=this._usefulLayoutObj;for(let a=0;ap&&(_=Math.max(p,_),h=p||w,p=w),c+=n*(v*I+this._spacingX);const R=n*(1-v)*I;if(t){if(i>0)u=a/i>0&&a%i==0,u&&(h=p>w?p:h);else if(I>e-T)c>l+n*(v*I)&&(u=!0);else{const t=(1-this._horizontalDirection-r.x)*e,o=c+R+n*(n>0?this._paddingRight:this._paddingLeft);u=Math.abs(o)>Math.abs(t)}u&&(c=l+n*(v*I),w!==p&&(h=p),d+=h+this._spacingY,h=p=w)}const O=o(f,y,d);s&&f.setPosition(c,O),c+=R}h=Math.max(h,p);const f=Math.max(_,d+h)+this._getPaddingV();if(m.length>0&&this.centerHorizontalDirection==CenterHorizontalDirection.CENTER_TO_SIDE){const t=(.5-r.x)*e;let o=0,s=-1,i=Number.MIN_SAFE_INTEGER;n=-1;for(let l=m.length-1;l>=0;l--){const c=m[l],d=this._getUsedScaleValue(c.node.scale.x),h=c.getComponent(UITransform).anchorX,p=c.getComponent(UITransform).width*d;if(Math.abs(c.node.position.y-i)>1){i=c.node.position.y,o=c.node.position.x+(1-h)*p+this.paddingRight,o=e*r.x+o;s=t+.5*o+n*a-n*this.spacingX}if(!c.node.activeInHierarchy)continue;s=s+n*h*p+n*this.spacingX,c.node.setPosition(new Vec3(s,c.node.position.y,0));s+=n*(1-h)*p}}return f}_getUsedScaleValue(e){return this.affectedByScale?Math.abs(e):1}};__decorate$k([property$k({type:Enum(CenterHorizontalDirection)})],CenterLayout.prototype,"centerHorizontalDirection",void 0),CenterLayout=__decorate$k([ccclass$k("CenterLayout"),disallowMultiple$1(),menu$a("moye/CenterLayout")],CenterLayout);var __decorate$j=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$j,inspector:inspector,property:property$j,disallowMultiple:disallowMultiple,menu:menu$9}=_decorator;let MoyeLabel=class extends Label{constructor(){super(...arguments),this._tempString="",this._clearOnRun=!1}set clearOnRun(e){e!=this._clearOnRun&&(this._clearOnRun=e,this.string=e?this._string:this._tempString)}get clearOnRun(){return this._clearOnRun}set string(e){if(this.clearOnRun&&EDITOR)this._tempString=e,this._string=" ",this.markForUpdateRenderData();else{if(e=null==e?"":e.toString(),this._string===e)return;this._string=e,this.markForUpdateRenderData()}}get string(){return this.clearOnRun&&EDITOR?this._tempString:this._string}};__decorate$j([property$j({editorOnly:!0})],MoyeLabel.prototype,"_tempString",void 0),__decorate$j([property$j],MoyeLabel.prototype,"_clearOnRun",void 0),__decorate$j([property$j({type:CCBoolean,displayName:"运行时清空",tooltip:"运行时清空"})],MoyeLabel.prototype,"clearOnRun",null),MoyeLabel=__decorate$j([ccclass$j("MoyeLabel"),disallowMultiple(),menu$9("moye/MoyeLabel")],MoyeLabel);var __decorate$i=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$i,property:property$i,menu:menu$8}=_decorator;let RichTextListener=class extends Component{constructor(){super(...arguments),this._cbs=[]}onDestroy(){this._cbs=[]}onClicked(e,t){for(const e of this._cbs)e(t)}addListener(e){this._cbs.push(e)}};RichTextListener=__decorate$i([ccclass$i("RichTextListener"),menu$8("moye/RichTextListener")],RichTextListener);const ViewDecoratorType="ViewDecorator";function ViewDecorator(e,t,o){return function(s){DecoratorCollector.inst.add("ViewDecorator",s,e,t,o)}}var ViewLayer;!function(e){e[e.SCENE=1]="SCENE",e[e.BACKGROUND=2]="BACKGROUND",e[e.NORMAL=3]="NORMAL",e[e.INFO=4]="INFO",e[e.TIPS=5]="TIPS",e[e.TOP=6]="TOP"}(ViewLayer||(ViewLayer={}));class ViewCleanCom extends Entity{constructor(){super(...arguments),this._views=new Set}init(e){return this._viewMgr=e,this}add(e){this._views.add(e)}remove(e){this._views.delete(e)}destroy(){for(const e of this._views)this._viewMgr.hide(e)}}const MoyeViewTag="MoyeView",viewLoadLock="MoyeViewLoadLock";class MoyeViewMgr extends Entity{constructor(){super(...arguments),this._views=new Map,this._type2Names=new Map,this._showingViews=new Set,this._hideViews=new Set,this._viewCfgs=new Map,this._layers=new Map,this._checkInterval=5e3}awake(){MoyeViewMgr.inst=this}destroy(){null!=this._checkTimerId&&(TimerMgr.get().remove(this._checkTimerId),this._checkTimerId=null),MoyeViewMgr.inst=null}init(e,t){return null!=this._uiRoot?moyeErrorF("MoyeView","MoyeViewMgr is already inited"):(this._uiRoot=e,this._globalViewCfgType=t,this.reload(),this._checkTimerId=TimerMgr.get().newRepeatedTimer(this._checkInterval,this.check.bind(this)),this)}async show(e,t){let o;if(o="string"==typeof e?e:this._type2Names.get(e),JsHelper.isNullOrEmpty(o))return void moyeErrorF("MoyeView","MoyeView name is null or empty, name={0}",o);const s=await CoroutineLock.get().wait(viewLoadLock,o);moyeLogF("MoyeView","show view, name={0}",o);try{if(null==this._uiRoot)throw new Error("MoyeViewMgr is not inited");if(this._showingViews.has(o)){return this._views.get(o)}if(this._views.has(o)){const e=this._views.get(o);return await this.enterViewShow(e,t),e}const e=this._viewCfgs.get(o),s=await e.load(o),r=this.getLayerNode(e.layer);s.parent=r;const i=this.addCom(e.viewType);return i.node=s,i.layer=e.layer,i.viewName=o,i.onLoad?.(),i._viewMgr=this,this._views.set(o,i),await this.enterViewShow(i,t),i}catch(e){moyeErrorF("MoyeView","show view errr, {0}",e.stack)}finally{s.dispose()}}async hide(e){const t=await CoroutineLock.get().wait(viewLoadLock,e);moyeLogF("MoyeView","hide view, name={0}",e);try{if(!this._showingViews.has(e))return;const t=this._views.get(e);await this.enterViewHide(t)}catch(e){moyeErrorF("MoyeView","hide view errr, {0}",e.stack)}finally{t.dispose()}}getView(e){let t;if(t="string"==typeof e?e:this._type2Names.get(e),this._showingViews.has(t)){return this._views.get(t)}}reload(){const e=DecoratorCollector.inst.get("ViewDecorator");for(const t of e){const e=t[0],o=t[1],s=t[2],r=t[3];if(this._viewCfgs.has(o))continue;let i;i=null!=r?new r:new this._globalViewCfgType,i.layer=s,i.name=o,i.viewType=e,i.cleanEntitys=new Set,this._type2Names.set(e,o),this._viewCfgs.set(o,i)}}check(){const e=TimeInfo.get().clientNow();for(const t of this._hideViews){e>=this._viewCfgs.get(t).expireTime&&this.enterViewDestroy(this._views.get(t))}}getLayerNode(e){let t=this._layers.get(e);if(null==t){t=new Node,t.name=ViewLayer[e],t.parent=this._uiRoot,this._layers.set(e,t);for(let e=ViewLayer.SCENE;e<=ViewLayer.TOP;e++){if(!this._layers.has(e))continue;this._layers.get(e).setSiblingIndex(-1)}const o=this._uiRoot.getComponent(UITransform).contentSize;t.addComponent(UITransform).setContentSize(o);const s=t.addComponent(Widget);s.top=0,s.bottom=0,s.left=0,s.right=0,s.alignMode=Widget.AlignMode.ON_WINDOW_RESIZE,s.isAlignBottom=!0,s.isAlignLeft=!0,s.isAlignRight=!0,s.isAlignTop=!0}return t}addToCleanCom(e,t){if(null==e)return;let o=e.getCom(ViewCleanCom);const s=this._viewCfgs.get(t);null==o&&(o=e.addCom(ViewCleanCom).init(this)),s.cleanEntitys.add(o),o.add(t)}async enterViewShow(e,t){e.node.active=!0,e.bringToFront();const o=this._viewCfgs.get(e.viewName);if(null!=o.doShowAnimation){const t=Task.create();o.doShowAnimation(e,t),await t}this._showingViews.add(e.viewName),this._hideViews.delete(e.viewName),this.addToCleanCom(t,e.viewName),e.onShow?.()}async enterViewHide(e){const t=this._viewCfgs.get(e.viewName);if(null!=t.doHideAnimation){const o=Task.create();t.doHideAnimation(e,o),await o}e.onHide?.(),e.node.active=!1,this._hideViews.add(e.viewName),this._showingViews.delete(e.viewName);for(const o of t.cleanEntitys)o.remove(e.viewName);t.cleanEntitys.clear(),t.expireTime=TimeInfo.get().clientNow()+t.expire}enterViewDestroy(e){e._realDispose(),e.node.destroy(),this._views.delete(e.viewName),this._hideViews.delete(e.viewName);this._viewCfgs.get(e.viewName).destroy()}}class AMoyeView extends Entity{_realDispose(){super.dispose()}dispose(){this._viewMgr.hide(this.viewName)}bringToFront(){this.node.setSiblingIndex(-1)}}var __decorate$h=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$h,property:property$h,executeInEditMode:executeInEditMode$4,menu:menu$7}=_decorator;let NodeNotBuild=class extends Component{constructor(){super(...arguments),this.note="节点不参与构建",this._destroyOnRun=!0}set destroyOnRun(e){this._destroyOnRun=e}get destroyOnRun(){return this._destroyOnRun}onLoad(){}onEnable(){EDITOR?this.node.hideFlags=this.node.hideFlags|CCObject.Flags.EditorOnly:this._destroyOnRun&&this.node.destroy()}onDisable(){this.node.hideFlags=this.node.hideFlags&~CCObject.Flags.EditorOnly}onDestroy(){this.node.hideFlags=this.node.hideFlags&~CCObject.Flags.EditorOnly}};__decorate$h([property$h({displayName:"注释",tooltip:"注释",editorOnly:!0,multiline:!0})],NodeNotBuild.prototype,"note",void 0),__decorate$h([property$h],NodeNotBuild.prototype,"_destroyOnRun",void 0),__decorate$h([property$h({type:CCBoolean,tooltip:"运行时销毁节点",displayName:"运行时销毁节点"})],NodeNotBuild.prototype,"destroyOnRun",null),NodeNotBuild=__decorate$h([ccclass$h("NodeNotBuild"),menu$7("moye/NodeNotBuild"),executeInEditMode$4],NodeNotBuild);var __decorate$g=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$g,property:property$g,menu:menu$6,executeInEditMode:executeInEditMode$3,requireComponent:requireComponent}=_decorator;let SizeFollow=class extends Component{constructor(){super(...arguments),this._heightFollow=!0,this._widthFollow=!0,this.minH=0,this.maxH=-1,this.minW=0,this.maxW=-1,this._heightOffset=0,this._widthOffset=0,this._changeSize=new Size}get target(){return this._target}set target(e){null!=this._target&&this._target.node.off(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this),this._target=e,null!=this._target&&(EDITOR&&this._target.getComponent(Label)&&console.info("检查到目标节点上有Label组件, 请注意设置string后调用updateRenderData(true)"),this._target.node.on(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this),this.updateSizeOffset())}set heightFollow(e){this._heightFollow=e}get heightFollow(){return this._heightFollow}set widthFollow(e){this._widthFollow=e}get widthFollow(){return this._widthFollow}onLoad(){EDITOR&&this.node.on(NodeEventType.SIZE_CHANGED,this.onSelfSizeChange,this),null!=this._target&&this._target.node.on(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this)}onDestroy(){EDITOR&&this.node.off(NodeEventType.SIZE_CHANGED,this.onSelfSizeChange,this),null!=this._target&&(this._target.isValid?(this._target.node.off(NodeEventType.SIZE_CHANGED,this.onTargetSizeChange,this),this._target=null):this._target=null)}onTargetSizeChange(){this.updateSelfSize()}onSelfSizeChange(){null!=this._target&&this.updateSizeOffset()}updateSelfSize(){const e=this.node.getComponent(UITransform),t=this._target;if(this._changeSize.set(e.contentSize),this._widthFollow){let e=Math.max(this.minW,t.width+this._widthOffset);this.maxW>=0&&(e=Math.min(this.maxW,e)),this._changeSize.width=e}if(this._heightFollow){let e=Math.max(this.minH,t.height+this._heightOffset);this.maxH>=0&&(e=Math.min(this.maxH,e)),this._changeSize.height=e}e.setContentSize(this._changeSize)}updateSizeOffset(){if(!EDITOR)return;const e=this.node.getComponent(UITransform),t=this._target,o=t.width,s=e.width,r=e.height,i=t.height;let n=!0,a=!0;s<=this.minW&&(console.log("当前节点宽度达到最小宽度, 不记录本次的偏移数据"),n=!1),this.maxW>=0&&s>=this.maxW&&(console.log("当前节点宽度达到最大宽度, 不记录本次的偏移数据"),n=!1),n&&(this._widthOffset=s-o),r<=this.minH&&(console.log("当前节点高度达到最小高度, 不记录本次的偏移数据"),a=!1),this.maxH>=0&&r>=this.maxH&&(console.log("当前节点高度达到最大高度, 不记录本次的偏移数据"),a=!1),a&&(this._heightOffset=r-i)}};__decorate$g([property$g({type:UITransform})],SizeFollow.prototype,"target",null),__decorate$g([property$g({type:UITransform})],SizeFollow.prototype,"_target",void 0),__decorate$g([property$g({displayName:"高度跟随"})],SizeFollow.prototype,"heightFollow",null),__decorate$g([property$g],SizeFollow.prototype,"_heightFollow",void 0),__decorate$g([property$g({displayName:"宽度跟随"})],SizeFollow.prototype,"widthFollow",null),__decorate$g([property$g],SizeFollow.prototype,"_widthFollow",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最小高度",min:0,visible(){return 1==this.heightFollow}})],SizeFollow.prototype,"minH",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最大高度",tooltip:"最大高度, 小于0表示不限制",visible(){return 1==this.heightFollow}})],SizeFollow.prototype,"maxH",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最小宽度",min:0,visible(){return 1==this.widthFollow}})],SizeFollow.prototype,"minW",void 0),__decorate$g([property$g({type:CCFloat,displayName:"最大宽度",tooltip:"最大宽度, 小于0表示不限制",visible(){return 1==this.widthFollow}})],SizeFollow.prototype,"maxW",void 0),__decorate$g([property$g({type:CCFloat})],SizeFollow.prototype,"_heightOffset",void 0),__decorate$g([property$g({type:CCFloat})],SizeFollow.prototype,"_widthOffset",void 0),SizeFollow=__decorate$g([ccclass$g("SizeFollow"),menu$6("moye/SizeFollow"),requireComponent(UITransform),executeInEditMode$3],SizeFollow);var __decorate$f=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$f,property:property$f,executeInEditMode:executeInEditMode$2,menu:menu$5}=_decorator;var WidgetBase,WidgetDirection;!function(e){e[e.LEFT=1]="LEFT",e[e.RIGHT=2]="RIGHT",e[e.TOP=3]="TOP",e[e.BOTTOM=4]="BOTTOM"}(WidgetBase||(WidgetBase={})),function(e){e[e.LEFT=1]="LEFT",e[e.RIGHT=2]="RIGHT",e[e.TOP=3]="TOP",e[e.BOTTOM=4]="BOTTOM",e[e.LEFT_EXTEND=5]="LEFT_EXTEND",e[e.RIGHT_EXTEND=6]="RIGHT_EXTEND",e[e.TOP_EXTEND=7]="TOP_EXTEND",e[e.BOTTOM_EXTEND=8]="BOTTOM_EXTEND"}(WidgetDirection||(WidgetDirection={}));let CTWidget=class extends Component{constructor(){super(...arguments),this._targetDir=WidgetDirection.TOP,this._dir=WidgetDirection.TOP,this.visibleOffset=0,this._isVertical=!0,this._distance=0,this._changePos=new Vec3(0,0,0),this._targetOldPos=new Vec3(0,0,0),this._targetOldSize=0,this._selfOldPos=new Vec3(0,0,0),this._selfOldSize=0}get target(){return this._target}set target(e){this._target=e,this.unregisterEvt(),this.registerEvt(),this.updateData()}set targetDir(e){if(EDITOR){if(e==WidgetDirection.LEFT||e==WidgetDirection.RIGHT){switch(this._dir){case WidgetDirection.TOP:case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM:case WidgetDirection.BOTTOM_EXTEND:this._dir=WidgetDirection.LEFT}this._isVertical=!1}else{switch(this._dir){case WidgetDirection.LEFT:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT:case WidgetDirection.RIGHT_EXTEND:this._dir=WidgetDirection.TOP}this._isVertical=!0}this._targetDir=e,this.updateData()}}get targetDir(){return this._targetDir}set dir(e){if(EDITOR){switch(e){case WidgetDirection.LEFT:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT:case WidgetDirection.RIGHT_EXTEND:switch(this._targetDir){case WidgetDirection.TOP:case WidgetDirection.BOTTOM:this._targetDir=WidgetDirection.LEFT}this._isVertical=!1;break;case WidgetDirection.TOP:case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM:case WidgetDirection.BOTTOM_EXTEND:switch(this._targetDir){case WidgetDirection.LEFT:case WidgetDirection.RIGHT:this._targetDir=WidgetDirection.TOP}this._isVertical=!0}this._dir=e,this.updateData()}}get dir(){return this._dir}onEnable(){EDITOR&&(this.registerEvt(),this.updateData())}onDisable(){EDITOR&&this.unregisterEvt()}onLoad(){this._trans=this.node.getComponent(UITransform),EDITOR||this.registerEvt()}onDestroy(){EDITOR||(this.unregisterEvt(),this._trans=null,this._target=null,this._changePos=null)}registerEvt(){this._target&&(EDITOR&&(this._target.node.on(NodeEventType.ANCHOR_CHANGED,this.updateData,this),this.node.on(NodeEventType.TRANSFORM_CHANGED,this.updateData,this),this.node.on(NodeEventType.SIZE_CHANGED,this.updateData,this)),this._target.node.on(NodeEventType.SIZE_CHANGED,this.onTargetChange,this),this._target.node.on(NodeEventType.TRANSFORM_CHANGED,this.onTargetChange,this),this._target.node.on(NodeEventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onTargetChange,this))}unregisterEvt(){this._target&&this._target.isValid&&(EDITOR&&(this._target.node.off(NodeEventType.ANCHOR_CHANGED,this.updateData,this),this.node.off(NodeEventType.TRANSFORM_CHANGED,this.updateData,this),this.node.off(NodeEventType.SIZE_CHANGED,this.updateData,this)),this._target.node.off(NodeEventType.SIZE_CHANGED,this.onTargetChange,this),this._target.node.off(NodeEventType.TRANSFORM_CHANGED,this.onTargetChange,this),this._target.node.off(NodeEventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onTargetChange,this))}updateData(){if(null!=this._target)switch(this._dir){case WidgetDirection.TOP:case WidgetDirection.BOTTOM:case WidgetDirection.LEFT:case WidgetDirection.RIGHT:this.updateDistance();break;case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM_EXTEND:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT_EXTEND:this.updateTargetPos()}}onTargetChange(){if(null!=this._target)switch(this._dir){case WidgetDirection.TOP:case WidgetDirection.BOTTOM:case WidgetDirection.LEFT:case WidgetDirection.RIGHT:this.updatePos();break;case WidgetDirection.TOP_EXTEND:case WidgetDirection.BOTTOM_EXTEND:case WidgetDirection.LEFT_EXTEND:case WidgetDirection.RIGHT_EXTEND:this.updateSize()}}updateSize(){if(this._isVertical){const e=this._targetOldPos.y-this._target.node.position.y;let t=this._target.height-this._targetOldSize;const o=this._trans.anchorY;this._changePos.set(this._selfOldPos),this._target.getComponent(Label)&&!this._target.node.active&&(t=this._targetOldSize);const s=e+t;this._trans.height=this._selfOldSize+s,this._dir==WidgetDirection.TOP_EXTEND?this.node.setPosition(this._changePos):this._dir==WidgetDirection.BOTTOM_EXTEND&&(this._changePos.y-=s*(1-o),this.node.setPosition(v3(this._changePos)))}}updatePos(){const e=this._trans,t=this._target;let o=this.getPos(t,this._targetDir)-this._distance;if(this._changePos.set(this.node.worldPosition),this._isVertical){switch(this._dir){case WidgetDirection.TOP:o-=e.height*(1-e.anchorY);break;case WidgetDirection.BOTTOM:o+=e.height*e.anchorY;break}this._changePos.y=o}else this._changePos.x=o;this.node.worldPosition=this._changePos}updateTargetPos(){EDITOR&&null==this._changePos&&(console.error("编辑器数据错乱, 请重新添加本组件"),this._changePos=v3()),this.target.node.getPosition(this._targetOldPos),this.node.getPosition(this._selfOldPos),this._isVertical?(this._selfOldSize=this._trans.height,this._targetOldSize=this._target.height):(this._selfOldSize=this._trans.width,this._targetOldSize=this._target.height)}updateDistance(){if(!EDITOR)return;if(null==this._target)return;const e=this.node.getComponent(UITransform),t=this._target,o=this.getPos(e,this._dir),s=this.getPos(t,this._targetDir);this._distance=s-o}getPos(e,t){if(this._isVertical){let o=e.node.worldPosition.y;const s=e.height,r=e.anchorY;switch(t){case WidgetDirection.TOP:case WidgetDirection.TOP_EXTEND:return e.node.active||(o=o-s-this.visibleOffset),o+s*(1-r);case WidgetDirection.BOTTOM:case WidgetDirection.BOTTOM_EXTEND:return e.node.active||(o=o+s+this.visibleOffset),o-s*r}}else{const o=e.node.worldPosition.x,s=e.width,r=e.anchorX;switch(t){case WidgetDirection.LEFT:return o-s*r;case WidgetDirection.RIGHT:return o+s*(1-r)}}}};__decorate$f([property$f({type:UITransform})],CTWidget.prototype,"target",null),__decorate$f([property$f({type:UITransform})],CTWidget.prototype,"_target",void 0),__decorate$f([property$f({type:Enum(WidgetBase)})],CTWidget.prototype,"targetDir",null),__decorate$f([property$f],CTWidget.prototype,"_targetDir",void 0),__decorate$f([property$f({type:Enum(WidgetDirection)})],CTWidget.prototype,"dir",null),__decorate$f([property$f],CTWidget.prototype,"_dir",void 0),__decorate$f([property$f({type:CCFloat})],CTWidget.prototype,"visibleOffset",void 0),__decorate$f([property$f],CTWidget.prototype,"_isVertical",void 0),__decorate$f([property$f],CTWidget.prototype,"_distance",void 0),__decorate$f([property$f],CTWidget.prototype,"_changePos",void 0),__decorate$f([property$f],CTWidget.prototype,"_targetOldPos",void 0),__decorate$f([property$f],CTWidget.prototype,"_targetOldSize",void 0),__decorate$f([property$f],CTWidget.prototype,"_selfOldPos",void 0),__decorate$f([property$f],CTWidget.prototype,"_selfOldSize",void 0),CTWidget=__decorate$f([ccclass$f("CTWidget"),menu$5("moye/CTWidget"),executeInEditMode$2],CTWidget);const RoundBoxAssembler={GetIndexBuffer(e){const t=[0,1,2,2,3,0,4,5,6,6,7,4,8,9,10,10,11,8];let o=12;const s=function(s,r,i){let n=r;for(let r=0;r=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$e,property:property$e,type:type,menu:menu$4}=_decorator;var EventType;!function(e){e.SPRITE_FRAME_CHANGED="spriteframe-changed"}(EventType||(EventType={}));let RoundBoxSprite=class extends UIRenderer{constructor(){super(...arguments),this._sizeMode=Sprite.SizeMode.TRIMMED,this._useGrayscale=!1,this._atlas=null,this._segments=10,this._radius=20,this._spriteFrame=null,this._leftTop=!0,this._rightTop=!0,this._leftBottom=!0,this._rightBottom=!0}get sizeMode(){return this._sizeMode}set sizeMode(e){this._sizeMode!==e&&(this._sizeMode=e,e!==Sprite.SizeMode.CUSTOM&&this._applySpriteSize())}get grayscale(){return this._useGrayscale}set grayscale(e){this._useGrayscale!==e&&(this._useGrayscale=e,this.changeMaterialForDefine(),this.updateMaterial())}get spriteAtlas(){return this._atlas}set spriteAtlas(e){this._atlas!==e&&(this._atlas=e)}get segments(){return this._segments}set segments(e){this._segments=e,this._renderData=null,this._flushAssembler()}get radius(){return this._radius}set radius(e){this._radius=e,this._updateUVs(),this.markForUpdateRenderData(!0)}get spriteFrame(){return this._spriteFrame}set spriteFrame(e){if(this._spriteFrame===e)return;const t=this._spriteFrame;this._spriteFrame=e,this.markForUpdateRenderData(),this._applySpriteFrame(t),EDITOR&&this.node.emit(EventType.SPRITE_FRAME_CHANGED,this)}get leftTop(){return this._leftTop}set leftTop(e){this._leftTop=e,this.resetAssembler()}get rightTop(){return this._rightTop}set rightTop(e){this._rightTop=e,this.resetAssembler()}get leftBottom(){return this._leftBottom}set leftBottom(e){this._leftBottom=e,this.resetAssembler()}get rightBottom(){return this._rightBottom}set rightBottom(e){this._rightBottom=e,this.resetAssembler()}onLoad(){this._flushAssembler()}__preload(){this.changeMaterialForDefine(),super.__preload(),EDITOR&&(this._resized(),this.node.on(NodeEventType.SIZE_CHANGED,this._resized,this))}onEnable(){super.onEnable(),this._activateMaterial();this._spriteFrame&&this._updateUVs()}onDestroy(){EDITOR&&this.node.off(NodeEventType.SIZE_CHANGED,this._resized,this),super.onDestroy()}changeSpriteFrameFromAtlas(e){if(!this._atlas)return void console.warn("SpriteAtlas is null.");const t=this._atlas.getSpriteFrame(e);this.spriteFrame=t}changeMaterialForDefine(){let e;const t=this._instanceMaterialType;this._spriteFrame&&(e=this._spriteFrame.texture);let o=!1;if(e instanceof cclegacy.TextureBase){const t=e.getPixelFormat();o=t===cclegacy.TextureBase.PixelFormat.RGBA_ETC1||t===cclegacy.TextureBase.PixelFormat.RGB_A_PVRTC_4BPPV1||t===cclegacy.TextureBase.PixelFormat.RGB_A_PVRTC_2BPPV1}o&&this.grayscale?this._instanceMaterialType=InstanceMaterialType.USE_ALPHA_SEPARATED_AND_GRAY:o?this._instanceMaterialType=InstanceMaterialType.USE_ALPHA_SEPARATED:this.grayscale?this._instanceMaterialType=InstanceMaterialType.GRAYSCALE:this._instanceMaterialType=InstanceMaterialType.ADD_COLOR_AND_TEXTURE,t!==this._instanceMaterialType&&this.updateMaterial()}_updateBuiltinMaterial(){let e=super._updateBuiltinMaterial();if(this.spriteFrame&&this.spriteFrame.texture instanceof RenderTexture){const t={SAMPLE_FROM_RT:!0,...e.passes[0].defines},o=new Material;o.initialize({effectAsset:e.effectAsset,defines:t}),e=o}return e}_render(e){e.commitComp(this,this.renderData,this._spriteFrame,this._assembler,null)}_canRender(){if(!super._canRender())return!1;const e=this._spriteFrame;return!(!e||!e.texture)}resetAssembler(){this._assembler=null,this._flushAssembler()}_flushAssembler(){const e=RoundBoxAssembler;this._assembler!==e&&(this.destroyRenderData(),this._assembler=e),this._renderData||this._assembler&&this._assembler.createData&&(this._renderData=this._assembler.createData(this),this._renderData.material=this.getRenderMaterial(0),this.markForUpdateRenderData(),this.spriteFrame&&this._assembler.updateRenderData(this),this._updateColor())}_applySpriteSize(){if(this._spriteFrame){if(BUILD||!this._spriteFrame.isDefault)if(Sprite.SizeMode.RAW===this._sizeMode){const e=this._spriteFrame.originalSize;this.node._uiProps.uiTransformComp.setContentSize(e)}else if(Sprite.SizeMode.TRIMMED===this._sizeMode){const e=this._spriteFrame.rect;this.node._uiProps.uiTransformComp.setContentSize(e.width,e.height)}this.markForUpdateRenderData(!0),this._assembler.updateRenderData(this)}}_resized(){if(EDITOR&&this._spriteFrame){const e=this.node._uiProps.uiTransformComp.contentSize;let t=e.width,o=e.height;if(this._sizeMode===Sprite.SizeMode.RAW){const e=this._spriteFrame.originalSize;t=e.width,o=e.height}else if(this._sizeMode===Sprite.SizeMode.TRIMMED){const e=this._spriteFrame.rect;t=e.width,o=e.height}t===e.width&&o===e.height||(this._sizeMode=Sprite.SizeMode.CUSTOM)}}_activateMaterial(){const e=this._spriteFrame,t=this.getRenderMaterial(0);e&&t&&this.markForUpdateRenderData(),this.renderData&&(this.renderData.material=t)}_updateUVs(){this._assembler&&this._assembler.updateUVs(this)}_applySpriteFrame(e){const t=this._spriteFrame;let o=!1;t&&(e&&e.texture===t.texture||(o=!0),o&&(this.renderData&&(this.renderData.textureDirty=!0),this.changeMaterialForDefine()),this._applySpriteSize())}};__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_sizeMode",void 0),__decorate$e([type(Sprite.SizeMode)],RoundBoxSprite.prototype,"sizeMode",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_useGrayscale",void 0),__decorate$e([property$e({type:CCBoolean})],RoundBoxSprite.prototype,"grayscale",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_atlas",void 0),__decorate$e([type(SpriteAtlas)],RoundBoxSprite.prototype,"spriteAtlas",null),__decorate$e([property$e({type:CCInteger,serializable:!0})],RoundBoxSprite.prototype,"_segments",void 0),__decorate$e([property$e({type:CCInteger,serializable:!0,min:1})],RoundBoxSprite.prototype,"segments",null),__decorate$e([property$e({type:CCFloat,serializable:!0})],RoundBoxSprite.prototype,"_radius",void 0),__decorate$e([property$e({type:CCFloat,serializable:!0,min:0})],RoundBoxSprite.prototype,"radius",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_spriteFrame",void 0),__decorate$e([type(SpriteFrame)],RoundBoxSprite.prototype,"spriteFrame",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_leftTop",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"leftTop",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_rightTop",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"rightTop",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_leftBottom",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"leftBottom",null),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"_rightBottom",void 0),__decorate$e([property$e({serializable:!0})],RoundBoxSprite.prototype,"rightBottom",null),RoundBoxSprite=__decorate$e([ccclass$e("RoundBoxSprite"),menu$4("moye/RoundBoxSprite")],RoundBoxSprite);var __decorate$d=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$d,property:property$d,executeInEditMode:executeInEditMode$1,menu:menu$3}=_decorator;var UIControllerIndex;!function(e){e[e.Index_0=1]="Index_0",e[e.Index_1=2]="Index_1",e[e.Index_2=4]="Index_2",e[e.Index_3=8]="Index_3",e[e.Index_4=16]="Index_4",e[e.Index_5=32]="Index_5",e[e.Index_6=64]="Index_6",e[e.Index_7=128]="Index_7",e[e.Index_8=256]="Index_8",e[e.Index_9=512]="Index_9",e[e.Index_10=1024]="Index_10",e[e.Index_11=2048]="Index_11",e[e.Index_12=4096]="Index_12"}(UIControllerIndex||(UIControllerIndex={}));let UIController=class extends Component{constructor(){super(...arguments),this._index=UIControllerIndex.Index_0,this._listeners=[],this._callbacks=[]}set index(e){this._index!=e&&(this._index=e,this.notifyListeners())}get index(){return this._index}onDestroy(){this._listeners=[],this._callbacks=[]}setIndex(e){if(this._index!=e){this._index=e;for(let e=0;e=0;e--)null!=this._listeners[e]&&null!=this._listeners[e]||this._listeners.splice(e,1)}_removeListener(e){const t=this._listeners.indexOf(e);if(-1!=t&&this._listeners.splice(t,1),EDITOR)for(let e=this._listeners.length-1;e>=0;e--)null!=this._listeners[e]&&null!=this._listeners[e]||this._listeners.splice(e,1)}notifyListeners(){for(let e=0;e=0;e--)null!=this._listeners[e]&&null!=this._listeners[e]||this._listeners.splice(e,1);const e=this.node.getComponent("UIControllerListener");e&&e.registerUIController()}}};var UIControlType;__decorate$d([property$d],UIController.prototype,"_index",void 0),__decorate$d([property$d({type:Enum(UIControllerIndex),displayOrder:1})],UIController.prototype,"index",null),__decorate$d([property$d],UIController.prototype,"_listeners",void 0),UIController=__decorate$d([ccclass$d("UIController"),menu$3("moye/UIController"),executeInEditMode$1],UIController),function(e){e[e.None=0]="None",e[e.Visible=1]="Visible",e[e.Position=2]="Position",e[e.Size=3]="Size",e[e.Scale=4]="Scale",e[e.Angle=5]="Angle",e[e.Anchor=6]="Anchor",e[e.UIController=7]="UIController",e[e.SpriteColor=8]="SpriteColor"}(UIControlType||(UIControlType={}));var __decorate$c=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$c,property:property$c}=_decorator;let UIController_Transition=class{constructor(){this.duration=0,this.delay=0}};__decorate$c([property$c({type:CCFloat,displayName:"持续时间"})],UIController_Transition.prototype,"duration",void 0),__decorate$c([property$c({type:CCFloat,displayName:"延迟时间"})],UIController_Transition.prototype,"delay",void 0),UIController_Transition=__decorate$c([ccclass$c("UIController_Transition")],UIController_Transition);var __decorate$b=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$b,property:property$b}=_decorator;let UIControlType_Position=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$a,property:property$a}=_decorator;let UIControlType_Size=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$9,property:property$9}=_decorator;let UIControlType_Scale=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$8,property:property$8}=_decorator;let UIControlType_Controller=class{constructor(){this._records=[]}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$7,property:property$7}=_decorator;let UIControlType_Angle=class{constructor(){this._transition=!1,this._records=[]}set transition(e){this._transition=e,this.transitionAttr=e?new UIController_Transition:null}get transition(){return this._transition}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$6,property:property$6}=_decorator;let UIControlType_Anchor=class{constructor(){this._records=[]}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$5,property:property$5}=_decorator;let UIControlType_Visible=class{constructor(){this.indexMask=UIControllerIndexMask.Index_0}isVisible(e){return 0!=(this.indexMask&e)}};__decorate$5([property$5({type:BitMask(UIControllerIndexMask)})],UIControlType_Visible.prototype,"indexMask",void 0),UIControlType_Visible=__decorate$5([ccclass$5("UIControlType_Visible")],UIControlType_Visible);var __decorate$4=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$4,property:property$4}=_decorator;let UIControlType_SpriteColor=class{constructor(){this._records=[]}getRecord(e){const t=Math.log2(e);return this._records[t]}setRecord(e,t){const o=Math.log2(e),s=this._records.length;if(s<=o){const e=s,r=o+1;this._records.length=r;for(let o=e;o=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$3,property:property$3}=_decorator;let UIControllerAttr=class{constructor(){this._controlType=UIControlType.None}set controlType(e){this._controlType=e,this.resetData()}get controlType(){return this._controlType}isVisible(e){return this.visible.isVisible(e)}setPosition(e,t){this.position.setRecord(e,t)}getPosition(e){return this.position.getRecord(e)}setSize(e,t){this.size.setRecord(e,t)}getSize(e){return this.size.getRecord(e)}setScale(e,t){this.scale.setRecord(e,t)}getScale(e){return this.scale.getRecord(e)}setAngle(e,t){this.angle.setRecord(e,t)}getAngle(e){return this.angle.getRecord(e)}setAnchor(e,t){this.anchor.setRecord(e,t)}getAnchor(e){return this.anchor.getRecord(e)}setUIController(e,t){this.controller.setRecord(e,t)}getUIController(e){return this.controller.getRecord(e)}setSpriteColor(e,t){this.spriteColor.setRecord(e,t)}getSpriteColor(e){return this.spriteColor.getRecord(e)}getTransition(){switch(this.controlType){case UIControlType.Position:return this.position.transitionAttr;case UIControlType.Size:return this.size.transitionAttr;case UIControlType.Scale:return this.scale.transitionAttr;case UIControlType.Angle:return this.angle.transitionAttr}}resetData(){DEBUG&&(this.controlType!=UIControlType.Position?this.position=null:this.position||(this.position=new UIControlType_Position),this.controlType!=UIControlType.Size?this.size=null:null==this.size&&(this.size=new UIControlType_Size),this.controlType!=UIControlType.Scale?this.scale=null:null==this.scale&&(this.scale=new UIControlType_Scale),this.controlType!=UIControlType.Angle?this.angle=null:null==this.angle&&(this.angle=new UIControlType_Angle),this.controlType!=UIControlType.Anchor?this.anchor=null:null==this.anchor&&(this.anchor=new UIControlType_Anchor),this.controlType!=UIControlType.UIController?this.controller=null:null==this.controller&&(this.controller=new UIControlType_Controller),this.controlType!=UIControlType.Visible?this.visible=null:this.visible||(this.visible=new UIControlType_Visible),this.controlType!=UIControlType.SpriteColor?this.spriteColor=null:null==this.spriteColor&&(this.spriteColor=new UIControlType_SpriteColor))}};__decorate$3([property$3({type:Enum(UIControlType)})],UIControllerAttr.prototype,"controlType",null),__decorate$3([property$3],UIControllerAttr.prototype,"_controlType",void 0),__decorate$3([property$3({displayName:"位置",type:UIControlType_Position,visible(){return this.controlType==UIControlType.Position}})],UIControllerAttr.prototype,"position",void 0),__decorate$3([property$3({displayName:"锚点",type:UIControlType_Anchor,visible(){return this.controlType==UIControlType.Anchor}})],UIControllerAttr.prototype,"anchor",void 0),__decorate$3([property$3({displayName:"角度",type:UIControlType_Angle,visible(){return this.controlType==UIControlType.Angle}})],UIControllerAttr.prototype,"angle",void 0),__decorate$3([property$3({displayName:"控制器",type:UIControlType_Controller,visible(){return this.controlType==UIControlType.UIController}})],UIControllerAttr.prototype,"controller",void 0),__decorate$3([property$3({displayName:"缩放",type:UIControlType_Scale,visible(){return this.controlType==UIControlType.Scale}})],UIControllerAttr.prototype,"scale",void 0),__decorate$3([property$3({displayName:"尺寸",type:UIControlType_Size,visible(){return this.controlType==UIControlType.Size}})],UIControllerAttr.prototype,"size",void 0),__decorate$3([property$3({displayName:"可见",type:UIControlType_Visible,visible(){return this.controlType==UIControlType.Visible}})],UIControllerAttr.prototype,"visible",void 0),__decorate$3([property$3({displayName:"精灵颜色",type:UIControlType_SpriteColor,visible(){return this.controlType==UIControlType.SpriteColor}})],UIControllerAttr.prototype,"spriteColor",void 0),UIControllerAttr=__decorate$3([ccclass$3("UIControllerAttr")],UIControllerAttr);const TransitionTag_Size=465,TransitionTag_Position=466,TransitionTag_Scale=467,TransitionTag_Angle=468;class TransitionHelper{static position(e,t,o){Tween.stopAllByTag(466,e),tween(e).tag(466).delay(o.delay).to(o.duration,{position:t}).start()}static size(e,t,o){Tween.stopAllByTag(465,e),tween(e).tag(465).delay(o.delay).to(o.duration,{contentSize:t}).start()}static scale(e,t,o){Tween.stopAllByTag(467,e),tween(e).tag(467).delay(o.delay).to(o.duration,{scale:t}).start()}static angle(e,t,o){Tween.stopAllByTag(468,e),tween(e).tag(468).delay(o.delay).to(o.duration,{angle:t}).start()}}var __decorate$2=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$2,property:property$2,executeInEditMode:executeInEditMode,menu:menu$2}=_decorator;let UIControllerListener=class extends Component{constructor(){super(...arguments),this._controller=null,this._attrs=[]}set controller(e){this._controller!=e&&(this._controller&&this._controller._removeListener(this),this._controller=e,this.listenController())}get controller(){return this._controller}get curIndex(){if(!this._controller)return"";return`${UIControllerIndex[this._controller.index]}`}set attrs(e){this._attrs=e,this.updateAttr()}get attrs(){return this._attrs}onLoad(){this.listenController()}onDestroy(){if(EDITOR)this.unRegisterEditorEvent();else{if(!this._controller)return;if(!this._controller.isValid)return;this._controller._removeListener(this)}}onDisable(){}onFocusInEditor(){this.registerEditorEvent()}onLostFocusInEditor(){this.unRegisterEditorEvent()}registerEditorEvent(){this.unRegisterEditorEvent(),this.node.on(Node.EventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onChangeActive,this),this.node.on(Node.EventType.TRANSFORM_CHANGED,this.onTransformChange,this),this.node.on(Node.EventType.SIZE_CHANGED,this.onSizeChange,this),this.node.on(Node.EventType.ANCHOR_CHANGED,this.onAnchorChange,this),this.node.on(Node.EventType.COLOR_CHANGED,this.onColorChange,this)}unRegisterEditorEvent(){this.node.off(Node.EventType.ACTIVE_IN_HIERARCHY_CHANGED,this.onChangeActive,this),this.node.off(Node.EventType.TRANSFORM_CHANGED,this.onTransformChange,this),this.node.off(Node.EventType.SIZE_CHANGED,this.onSizeChange,this),this.node.off(Node.EventType.ANCHOR_CHANGED,this.onAnchorChange,this),this.node.off(Node.EventType.COLOR_CHANGED,this.onColorChange,this)}listenController(){this._controller&&this._controller._addListener(this)}onChangeActive(){}onTransformChange(){this.registerTransform()}onSizeChange(){this.registerSize()}onAnchorChange(){this.registerAnchor()}onColorChange(){this.registerColor()}registerTransform(){if(!this._controller)return;const e=this._controller.index;for(let t=0;t=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass$1,property:property$1,menu:menu$1}=_decorator,instance=new EventTarget,SET_JOYSTICK_TYPE="SET_JOYSTICK_TYPE";var DirectionType,SpeedType,JoystickType;!function(e){e[e.FOUR=0]="FOUR",e[e.EIGHT=1]="EIGHT",e[e.ALL=2]="ALL"}(DirectionType||(DirectionType={})),function(e){e[e.STOP=0]="STOP",e[e.NORMAL=1]="NORMAL",e[e.FAST=2]="FAST"}(SpeedType||(SpeedType={})),function(e){e[e.FIXED=0]="FIXED",e[e.FOLLOW=1]="FOLLOW"}(JoystickType||(JoystickType={}));let YYJJoystick=class extends Component{constructor(){super(...arguments),this.dot=null,this.ring=null,this.joystickType=JoystickType.FIXED,this.directionType=DirectionType.ALL,this._stickPos=new Vec3,this._touchLocation=new Vec2,this.radius=50}onLoad(){if(!this.dot)return void console.warn("Joystick Dot is null!");if(!this.ring)return void console.warn("Joystick Ring is null!");const e=this.ring.getComponent(UITransform),t=2*this.radius,o=new Size(t,t);e?.setContentSize(o),this.ring.getChildByName("bg").getComponent(UITransform)?.setContentSize(o),this._initTouchEvent();const s=this.node.getComponent(UIOpacity);this.joystickType===JoystickType.FOLLOW&&s&&(s.opacity=0)}onEnable(){instance.on(SET_JOYSTICK_TYPE,this._onSetJoystickType,this)}onDisable(){instance.off(SET_JOYSTICK_TYPE,this._onSetJoystickType,this)}_onSetJoystickType(e){this.joystickType=e;const t=this.node.getComponent(UIOpacity);t&&(t.opacity=e===JoystickType.FIXED?255:0)}_initTouchEvent(){this.node.on(Input.EventType.TOUCH_START,this._touchStartEvent,this),this.node.on(Input.EventType.TOUCH_MOVE,this._touchMoveEvent,this),this.node.on(Input.EventType.TOUCH_END,this._touchEndEvent,this),this.node.on(Input.EventType.TOUCH_CANCEL,this._touchEndEvent,this)}_touchStartEvent(e){if(!this.ring||!this.dot)return;instance.emit(Input.EventType.TOUCH_START,e);const t=e.getUILocation(),o=new Vec3(t.x,t.y);if(this.joystickType===JoystickType.FIXED){this._stickPos=this.ring.getPosition();const e=o.subtract(this.ring.getPosition()),t=e.length();this.radius>t&&this.dot.setPosition(e)}else this.joystickType===JoystickType.FOLLOW&&(this._stickPos=o,this.node.getComponent(UIOpacity).opacity=255,this._touchLocation=e.getUILocation(),this.ring.setPosition(o),this.dot.setPosition(new Vec3))}_touchMoveEvent(e){if(!this.dot||!this.ring)return;if(this.joystickType===JoystickType.FOLLOW&&this._touchLocation===e.getUILocation())return!1;const t=e.getUILocation(),o=new Vec3(t.x,t.y).subtract(this.ring.getPosition()),s=o.length();let r=SpeedType.NORMAL;this.radius>s?(this.dot.setPosition(o),r=SpeedType.NORMAL):(this.dot.setPosition(o.normalize().multiplyScalar(this.radius)),r=SpeedType.FAST),instance.emit(Input.EventType.TOUCH_MOVE,e,{speedType:r,moveVec:o.normalize()})}_touchEndEvent(e){this.dot&&this.ring&&(this.dot.setPosition(new Vec3),this.joystickType===JoystickType.FOLLOW&&(this.node.getComponent(UIOpacity).opacity=0),instance.emit(Input.EventType.TOUCH_END,e,{speedType:SpeedType.STOP}))}};__decorate$1([property$1({type:Node,displayName:"Dot",tooltip:"摇杆操纵点"})],YYJJoystick.prototype,"dot",void 0),__decorate$1([property$1({type:Node,displayName:"Ring",tooltip:"摇杆背景节点"})],YYJJoystick.prototype,"ring",void 0),__decorate$1([property$1({type:Enum(JoystickType),displayName:"Touch Type",tooltip:"触摸类型"})],YYJJoystick.prototype,"joystickType",void 0),__decorate$1([property$1({type:Enum(DirectionType),displayName:"Direction Type",tooltip:"方向类型"})],YYJJoystick.prototype,"directionType",void 0),__decorate$1([property$1({type:Vec3,tooltip:"摇杆所在位置"})],YYJJoystick.prototype,"_stickPos",void 0),__decorate$1([property$1({type:Vec2,tooltip:"触摸位置"})],YYJJoystick.prototype,"_touchLocation",void 0),__decorate$1([property$1({type:CCInteger,displayName:"Ring Radius",tooltip:"半径"})],YYJJoystick.prototype,"radius",void 0),YYJJoystick=__decorate$1([ccclass$1("YYJJoystick"),menu$1("moye/YYJJoystick")],YYJJoystick);class YYJJoystickCom extends Entity{constructor(){super(...arguments),this.moveDir=new Vec3(0,1,0),this._speedType=SpeedType.STOP,this._moveSpeed=0,this.stopSpeed=0,this.normalSpeed=100,this.fastSpeed=200,this.isRotation=!0}init(e){return this._entity=e,instance.on(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.on(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.on(Input.EventType.TOUCH_END,this.onTouchEnd,this),this}destroy(){instance.off(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.off(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.off(Input.EventType.TOUCH_END,this.onTouchEnd,this)}onTouchStart(){}onTouchMove(e,t){const o=this._speedType;this._speedType=t.speedType,this.moveDir=t.moveVec,this.onSetMoveSpeed(this._speedType),o!==this._speedType&&this._entity.speedChange(this._speedType,this._moveSpeed)}onTouchEnd(e,t){const o=this._speedType;this._speedType=t.speedType,this.onSetMoveSpeed(this._speedType),o!==this._speedType&&this._entity.speedChange(this._speedType,this._moveSpeed)}onSetMoveSpeed(e){switch(e){case SpeedType.STOP:this._moveSpeed=this.stopSpeed;break;case SpeedType.NORMAL:this._moveSpeed=this.normalSpeed;break;case SpeedType.FAST:this._moveSpeed=this.fastSpeed}}move(){this.isRotation&&this._entity.setAngle(misc.radiansToDegrees(Math.atan2(this.moveDir.y,this.moveDir.x))-90);const e=this._entity.getPos().add(this.moveDir.clone().multiplyScalar(this._moveSpeed/60));this._entity.setPos(e)}update(){this._speedType!==SpeedType.STOP&&this.move()}}var __decorate=function(e,t,o,s){var r,i=arguments.length,n=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(n=(i<3?r(n):i>3?r(t,o,n):r(t,o))||n);return i>3&&n&&Object.defineProperty(t,o,n),n};const{ccclass:ccclass,property:property,menu:menu}=_decorator;let YYJJoystickPlayer=class extends Component{constructor(){super(...arguments),this.rigidbody=!1,this.moveDir=new Vec3(0,1,0),this._speedType=SpeedType.STOP,this._moveSpeed=0,this.stopSpeed=0,this.normalSpeed=100,this.fastSpeed=200,this.isRotation=!0,this._body=null}onLoad(){this.rigidbody&&(this._body=this.node.getComponent(RigidBody2D)),instance.on(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.on(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.on(Input.EventType.TOUCH_END,this.onTouchEnd,this)}onTouchStart(){}onTouchMove(e,t){this._speedType=t.speedType,this.moveDir=t.moveVec,this.onSetMoveSpeed(this._speedType)}onTouchEnd(e,t){this._speedType=t.speedType,this.onSetMoveSpeed(this._speedType)}onSetMoveSpeed(e){switch(e){case SpeedType.STOP:this._moveSpeed=this.stopSpeed;break;case SpeedType.NORMAL:this._moveSpeed=this.normalSpeed;break;case SpeedType.FAST:this._moveSpeed=this.fastSpeed}}move(){if(this.isRotation&&(this.node.angle=misc.radiansToDegrees(Math.atan2(this.moveDir.y,this.moveDir.x))-90),this.rigidbody&&this._body){const e=this.moveDir.clone().multiplyScalar(this._moveSpeed/20),t=new Vec2(e.x,e.y);this._body.applyForceToCenter(t,!0)}else{const e=this.node.getPosition().add(this.moveDir.clone().multiplyScalar(this._moveSpeed/60));this.node.setPosition(e)}}update(e){this._speedType!==SpeedType.STOP&&this.move()}};__decorate([property({displayName:"刚体模式",tooltip:"不会立即停止"})],YYJJoystickPlayer.prototype,"rigidbody",void 0),__decorate([property({displayName:"Move Dir",tooltip:"移动方向"})],YYJJoystickPlayer.prototype,"moveDir",void 0),__decorate([property({tooltip:"速度级别"})],YYJJoystickPlayer.prototype,"_speedType",void 0),__decorate([property({type:CCInteger,tooltip:"移动速度"})],YYJJoystickPlayer.prototype,"_moveSpeed",void 0),__decorate([property({type:CCInteger,tooltip:"停止时速度"})],YYJJoystickPlayer.prototype,"stopSpeed",void 0),__decorate([property({type:CCInteger,tooltip:"正常速度"})],YYJJoystickPlayer.prototype,"normalSpeed",void 0),__decorate([property({type:CCInteger,tooltip:"最快速度"})],YYJJoystickPlayer.prototype,"fastSpeed",void 0),__decorate([property({tooltip:"最快速度"})],YYJJoystickPlayer.prototype,"isRotation",void 0),YYJJoystickPlayer=__decorate([ccclass("YYJJoystickPlayer"),menu("moye/YYJJoystickPlayer")],YYJJoystickPlayer);class YYJJoystickSpeedChangeEvent extends AEvent{}class YYJJoystickMoveEvent extends AEvent{}class YYJJoystickListener extends Entity{constructor(){super(...arguments),this._speedType=SpeedType.STOP}awake(){instance.on(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.on(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.on(Input.EventType.TOUCH_END,this.onTouchEnd,this)}destroy(){instance.off(Input.EventType.TOUCH_START,this.onTouchStart,this),instance.off(Input.EventType.TOUCH_MOVE,this.onTouchMove,this),instance.off(Input.EventType.TOUCH_END,this.onTouchEnd,this)}onTouchStart(){}onTouchMove(e,t){const o=this._speedType;this._speedType=t.speedType,o!==this._speedType&&EventSystem.get().publish(this.domainScene(),YYJJoystickSpeedChangeEvent.create({speedType:this._speedType})),EventSystem.get().publish(this.domainScene(),YYJJoystickMoveEvent.create({dir:t.moveVec}))}onTouchEnd(e,t){this.onTouchMove(e,t)}}export{AEvent,AEventHandler,AMHandler,AMoyeView,AWait,AfterAddLoginCom,AfterCreateClientScene,AfterCreateCurrentScene,AfterProgramInit,AfterProgramStart,AfterSingletonAdd,AssetOperationHandle,AsyncButtonListener,BeforeProgramInit,BeforeProgramStart,BeforeSingletonAdd,BgAdapter,BundleAsset,CTWidget,CancellationToken,CancellationTokenTag,CenterLayout,CoroutineLock,CoroutineLockItem,CoroutineLockTag,DecoratorCollector,Entity,EntityCenter,EventCom,EventDecorator,EventDecoratorType,EventHandlerTag,EventSystem,Game,IPEndPoint,IdGenerator,IdStruct,InstanceIdStruct,JsHelper,LocalStorageHelper,Logger,LoginCom,MoyeAssets,MoyeLabel,MoyeViewMgr,MsgHandlerDecorator,MsgHandlerDecoratorType,MsgMgr,MsgSerializeMgr,MultiMap,NetCom,NetServices,NetworkErrorCode,NodeNotBuild,ObjectPool,ObjectWait,Program,RecycleObj,RichTextListener,Root,RoundBoxSprite,Scene,SceneFactory,SceneMgr,SceneType,Session,SessionCom,Singleton,SizeFollow,SpeedType,Task,TimeHelper,TimeInfo,TimerMgr,UIController,UIControllerAttr,UIControllerIndex,UIControllerListener,ViewDecorator,ViewDecoratorType,ViewLayer,WChannel,WService,WaitError,YYJJoystick,YYJJoystickCom,YYJJoystickListener,YYJJoystickMoveEvent,YYJJoystickSpeedChangeEvent,debug,debugF,error,errorF,log,logF,safeCall,warn,warnF}; \ No newline at end of file diff --git a/dist/moye.mjs b/dist/moye.mjs index d569249..12f9174 100644 --- a/dist/moye.mjs +++ b/dist/moye.mjs @@ -1676,43 +1676,43 @@ class CoroutineLock extends Singleton { } } -/** - * manage client scene - */ -class SceneRefCom extends Entity { +class SceneMgr extends Singleton { } +// import { SceneRefCom } from "./SceneRefCom"; class SceneFactory { static createClientScene() { - const parent = Root.get().scene.getCom(SceneRefCom); - parent.scene?.dispose(); + // const parent = Root.get().scene.getCom(SceneRefCom); + // parent.scene?.dispose(); const scene = new Scene(); scene.init({ id: 1n, sceneType: SceneType.CLIENT, name: "Game", instanceId: IdGenerator.get().generateInstanceId(), - parent: parent + parent: SceneMgr.get().process }); - scene.addCom(SceneRefCom); - parent.scene = scene; + // scene.addCom(SceneRefCom); + SceneMgr.get().client = scene; + // parent.scene = scene; EventSystem.get().publish(scene, AfterCreateClientScene.create()); return scene; } static createCurrentScene(id, name) { - const clientSceneRef = Root.get().scene.getCom(SceneRefCom); - const clientScene = clientSceneRef.scene; - const parent = clientScene.getCom(SceneRefCom); - parent.scene?.dispose(); + // const clientSceneRef = Root.get().scene.getCom(SceneRefCom); + // const clientScene = clientSceneRef.scene; + // const parent = clientScene.getCom(SceneRefCom); + SceneMgr.get().current?.dispose(); const scene = new Scene(); scene.init({ id: id, sceneType: SceneType.CURRENT, name: name, instanceId: IdGenerator.get().generateInstanceId(), - parent: parent + parent: SceneMgr.get().client }); - parent.scene = scene; + // parent.scene = scene; + SceneMgr.get().current = scene; EventSystem.get().publish(scene, AfterCreateCurrentScene.create()); return scene; } @@ -1731,6 +1731,7 @@ class Program { Game.addSingleton(EntityCenter); Game.addSingleton(EntityLifiCycleMgr); Game.addSingleton(Root); + Game.addSingleton(SceneMgr).process = Root.get().scene; // add client runtime rootNode.addComponent(MoyeRuntime); MoyeEventCenter.inst.publish(new AfterProgramInit()); @@ -1744,7 +1745,7 @@ class Program { MoyeEventCenter.inst.publish(new BeforeProgramStart()); MoyeEventCenter.inst.publish(new AfterProgramStart()); // create client scene - Root.get().scene.addCom(SceneRefCom); + // Root.get().scene.addCom(SceneRefCom); SceneFactory.createClientScene(); } } @@ -1898,23 +1899,19 @@ class MultiMap { Entity.prototype.clientScene = function () { // eslint-disable-next-line @typescript-eslint/no-this-alias - const self = this; - const domainScene = self.domainScene(); - if (domainScene.sceneType == SceneType.CLIENT) { - return domainScene; - } - else if (domainScene.sceneType == SceneType.CURRENT) { - return domainScene.parent.parent; - } - else if (domainScene.sceneType == SceneType.PROCESS) { - return domainScene.getCom(SceneRefCom).scene; - } + // const self: Entity = this; + // const domainScene = self.domainScene(); + // if(domainScene.sceneType == SceneType.CLIENT) { + // return domainScene; + // }else if(domainScene.sceneType == SceneType.CURRENT) { + // return domainScene.parent.parent as Scene; + // }else if(domainScene.sceneType == SceneType.PROCESS) { + // return domainScene.getCom(SceneRefCom).scene; + // } + return SceneMgr.get().client; }; Entity.prototype.currentScene = function () { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const self = this; - const clientScene = self.clientScene(); - return clientScene.getCom(SceneRefCom).scene; + return SceneMgr.get().current; }; /** @@ -6819,4 +6816,4 @@ class YYJJoystickListener extends Entity { } } -export { AEvent, AEventHandler, AMHandler, AMoyeView, AWait, AfterAddLoginCom, AfterCreateClientScene, AfterCreateCurrentScene, AfterProgramInit, AfterProgramStart, AfterSingletonAdd, AssetOperationHandle, AsyncButtonListener, BeforeProgramInit, BeforeProgramStart, BeforeSingletonAdd, BgAdapter, BundleAsset, CTWidget, CancellationToken, CancellationTokenTag, CenterLayout, CoroutineLock, CoroutineLockItem, CoroutineLockTag, DecoratorCollector, Entity, EntityCenter, EventCom, EventDecorator, EventDecoratorType, EventHandlerTag, EventSystem, Game, IPEndPoint, IdGenerator, IdStruct, InstanceIdStruct, JsHelper, LocalStorageHelper, Logger, LoginCom, MoyeAssets, MoyeLabel, MoyeViewMgr, MsgHandlerDecorator, MsgHandlerDecoratorType, MsgMgr, MsgSerializeMgr, MultiMap, NetCom, NetServices, NetworkErrorCode, NodeNotBuild, ObjectPool, ObjectWait, Program, RecycleObj, RichTextListener, Root, RoundBoxSprite, Scene, SceneFactory, SceneRefCom, SceneType, Session, SessionCom, Singleton, SizeFollow, SpeedType, Task, TimeHelper, TimeInfo, TimerMgr, UIController, UIControllerAttr, UIControllerIndex, UIControllerListener, ViewDecorator, ViewDecoratorType, ViewLayer, WChannel, WService, WaitError, YYJJoystick, YYJJoystickCom, YYJJoystickListener, YYJJoystickMoveEvent, YYJJoystickSpeedChangeEvent, debug, debugF, error, errorF, log, logF, safeCall, warn, warnF }; +export { AEvent, AEventHandler, AMHandler, AMoyeView, AWait, AfterAddLoginCom, AfterCreateClientScene, AfterCreateCurrentScene, AfterProgramInit, AfterProgramStart, AfterSingletonAdd, AssetOperationHandle, AsyncButtonListener, BeforeProgramInit, BeforeProgramStart, BeforeSingletonAdd, BgAdapter, BundleAsset, CTWidget, CancellationToken, CancellationTokenTag, CenterLayout, CoroutineLock, CoroutineLockItem, CoroutineLockTag, DecoratorCollector, Entity, EntityCenter, EventCom, EventDecorator, EventDecoratorType, EventHandlerTag, EventSystem, Game, IPEndPoint, IdGenerator, IdStruct, InstanceIdStruct, JsHelper, LocalStorageHelper, Logger, LoginCom, MoyeAssets, MoyeLabel, MoyeViewMgr, MsgHandlerDecorator, MsgHandlerDecoratorType, MsgMgr, MsgSerializeMgr, MultiMap, NetCom, NetServices, NetworkErrorCode, NodeNotBuild, ObjectPool, ObjectWait, Program, RecycleObj, RichTextListener, Root, RoundBoxSprite, Scene, SceneFactory, SceneMgr, SceneType, Session, SessionCom, Singleton, SizeFollow, SpeedType, Task, TimeHelper, TimeInfo, TimerMgr, UIController, UIControllerAttr, UIControllerIndex, UIControllerListener, ViewDecorator, ViewDecoratorType, ViewLayer, WChannel, WService, WaitError, YYJJoystick, YYJJoystickCom, YYJJoystickListener, YYJJoystickMoveEvent, YYJJoystickSpeedChangeEvent, debug, debugF, error, errorF, log, logF, safeCall, warn, warnF }; diff --git a/package.json b/package.json index 54c645e..a6169e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moye-cocos", - "version": "2.0.1", + "version": "2.1.0", "description": "ecs game framework of cocos creator", "main": "dist/moye.mjs", "types": "dist/moye.d.ts", diff --git a/src/Core/Core.ts b/src/Core/Core.ts index a6b2471..07d4e1d 100644 --- a/src/Core/Core.ts +++ b/src/Core/Core.ts @@ -31,4 +31,5 @@ export * from "./Scene/SceneRefCom"; export * from "./Task/Task"; export * from "./Type/Action"; export * from "./Type/Type"; -export * from "./DataStructure/MultiMap"; \ No newline at end of file +export * from "./DataStructure/MultiMap"; +export * from "./Scene/SceneMgr"; \ No newline at end of file diff --git a/src/Core/Program/Program.ts b/src/Core/Program/Program.ts index 22433d6..f3721cf 100644 --- a/src/Core/Program/Program.ts +++ b/src/Core/Program/Program.ts @@ -13,8 +13,9 @@ import { EntityLifiCycleMgr } from "../Entity/EntityLifiCycleMgr"; import { Root } from "../Entity/Root"; import { TimerMgr } from "../Timer/TimerMgr"; import { CoroutineLock } from "../CoroutineLock/CoroutineLock"; -import { SceneRefCom } from "../Scene/SceneRefCom"; +// import { SceneRefCom } from "../Scene/SceneRefCom"; import { SceneFactory } from "../Scene/SceneFactory"; +import { SceneMgr } from "../Scene/SceneMgr"; export class Program { static init(rootNode: Node) { @@ -31,6 +32,8 @@ export class Program { Game.addSingleton(EntityLifiCycleMgr); Game.addSingleton(Root); + Game.addSingleton(SceneMgr).process = Root.get().scene; + // add client runtime rootNode.addComponent(MoyeRuntime); @@ -47,7 +50,7 @@ export class Program { MoyeEventCenter.inst.publish(new AfterProgramStart()); // create client scene - Root.get().scene.addCom(SceneRefCom); + // Root.get().scene.addCom(SceneRefCom); SceneFactory.createClientScene(); } } \ No newline at end of file diff --git a/src/Core/Scene/SceneFactory.ts b/src/Core/Scene/SceneFactory.ts index c093efb..c0d9f6a 100644 --- a/src/Core/Scene/SceneFactory.ts +++ b/src/Core/Scene/SceneFactory.ts @@ -4,13 +4,14 @@ import { SceneType } from "../Entity/SceneType"; import { AfterCreateClientScene, AfterCreateCurrentScene } from "../EventSystem/EventCore"; import { EventSystem } from "../EventSystem/EventSystem"; import { IdGenerator } from "../IdGenerator/IdGenerator"; -import { SceneRefCom } from "./SceneRefCom"; +import { SceneMgr } from "./SceneMgr"; +// import { SceneRefCom } from "./SceneRefCom"; export class SceneFactory { static createClientScene(): Scene { - const parent = Root.get().scene.getCom(SceneRefCom); + // const parent = Root.get().scene.getCom(SceneRefCom); - parent.scene?.dispose(); + // parent.scene?.dispose(); const scene = new Scene(); scene.init({ @@ -18,12 +19,14 @@ export class SceneFactory { sceneType: SceneType.CLIENT, name: "Game", instanceId: IdGenerator.get().generateInstanceId(), - parent: parent + parent: SceneMgr.get().process }); - scene.addCom(SceneRefCom); + // scene.addCom(SceneRefCom); - parent.scene = scene; + SceneMgr.get().client = scene; + + // parent.scene = scene; EventSystem.get().publish(scene, AfterCreateClientScene.create()); @@ -31,11 +34,11 @@ export class SceneFactory { } static createCurrentScene(id: bigint, name: string): Scene { - const clientSceneRef = Root.get().scene.getCom(SceneRefCom); - const clientScene = clientSceneRef.scene; - const parent = clientScene.getCom(SceneRefCom); + // const clientSceneRef = Root.get().scene.getCom(SceneRefCom); + // const clientScene = clientSceneRef.scene; + // const parent = clientScene.getCom(SceneRefCom); - parent.scene?.dispose(); + SceneMgr.get().current?.dispose(); const scene = new Scene(); scene.init({ @@ -43,10 +46,12 @@ export class SceneFactory { sceneType: SceneType.CURRENT, name: name, instanceId: IdGenerator.get().generateInstanceId(), - parent: parent + parent: SceneMgr.get().client }); - parent.scene = scene; + // parent.scene = scene; + + SceneMgr.get().current = scene; EventSystem.get().publish(scene, AfterCreateCurrentScene.create()); diff --git a/src/Core/Scene/SceneMgr.ts b/src/Core/Scene/SceneMgr.ts new file mode 100644 index 0000000..34d48cf --- /dev/null +++ b/src/Core/Scene/SceneMgr.ts @@ -0,0 +1,8 @@ +import { Scene } from "../Entity/Scene"; +import { Singleton } from "../Singleton/Singleton"; + +export class SceneMgr extends Singleton { + process: Scene; + client: Scene; + current: Scene; +} \ No newline at end of file diff --git a/src/Core/Scene/SceneRefCom.ts b/src/Core/Scene/SceneRefCom.ts index 5c08507..b36a216 100644 --- a/src/Core/Scene/SceneRefCom.ts +++ b/src/Core/Scene/SceneRefCom.ts @@ -5,6 +5,6 @@ import { Scene } from "../Entity/Scene"; /** * manage client scene */ -export class SceneRefCom extends Entity { - scene: Scene; -} +// export class SceneRefCom extends Entity { +// scene: Scene; +// } diff --git a/src/EntityExt/EntityExtension.ts b/src/EntityExt/EntityExtension.ts index 2fe69c6..aa76d1e 100644 --- a/src/EntityExt/EntityExtension.ts +++ b/src/EntityExt/EntityExtension.ts @@ -1,4 +1,5 @@ -import { Entity, Scene, SceneRefCom, SceneType } from "../Core/Core"; +import { Entity, Scene, SceneType } from "../Core/Core"; +import { SceneMgr } from "../Core/Scene/SceneMgr"; declare module "../Core/Core" { @@ -11,22 +12,20 @@ declare module "../Core/Core" { Entity.prototype.clientScene = function () { // eslint-disable-next-line @typescript-eslint/no-this-alias - const self: Entity = this; - const domainScene = self.domainScene(); + // const self: Entity = this; + // const domainScene = self.domainScene(); - if(domainScene.sceneType == SceneType.CLIENT) { - return domainScene; - }else if(domainScene.sceneType == SceneType.CURRENT) { - return domainScene.parent.parent as Scene; - }else if(domainScene.sceneType == SceneType.PROCESS) { - return domainScene.getCom(SceneRefCom).scene; - } + // if(domainScene.sceneType == SceneType.CLIENT) { + // return domainScene; + // }else if(domainScene.sceneType == SceneType.CURRENT) { + // return domainScene.parent.parent as Scene; + // }else if(domainScene.sceneType == SceneType.PROCESS) { + // return domainScene.getCom(SceneRefCom).scene; + // } + + return SceneMgr.get().client; }; Entity.prototype.currentScene = function () { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const self: Entity = this; - const clientScene = self.clientScene(); - - return clientScene.getCom(SceneRefCom).scene; + return SceneMgr.get().current; }; \ No newline at end of file