@shimotsuki/core 1.0.43 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +47 -120
  2. package/dist/index.js +2842 -1
  3. package/package.json +3 -2
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Component, Node, Prefab, Vec3, Quat, math, Layers, AudioSource, Label, Button, Scene, Asset, Constructor, AssetManager, SpriteFrame, Sprite, AsyncDelegate } from 'cc';
2
2
  import { IReactionPublic, IReactionOptions } from '@shimotsuki/mobx';
3
+ import EventEmitter, { EventEmitter as EventEmitter$1 } from 'eventemitter3';
3
4
  import * as crypto_es_lib_cipher_core from 'crypto-es/lib/cipher-core';
4
5
  import { DescMessage, MessageShape } from '@bufbuild/protobuf';
5
6
  import { ClientOption } from 'pitayaclient';
6
- import { SocialGameClient, SocialGameClientOption, AllEventResponsePairs, AudienceOptions } from 'sgc';
7
+ import { SocialGameClientOption, AllEventResponsePairs, SocialGameClient, AudienceOptionsJson } from 'sgc';
7
8
  import { ReflectMessage } from '@bufbuild/protobuf/reflect';
8
9
 
9
10
  /**
@@ -168,63 +169,6 @@ declare class StorageManager extends BaseManager {
168
169
  clear(): void;
169
170
  }
170
171
 
171
- /**
172
- * @describe 事件消息管理
173
- * @author 游金宇(KM)
174
- * @date 2023-08-03 18:15:38
175
- */
176
-
177
- type ListenerFunc = (data: any, event: string | number) => void;
178
- type EventKeyType = string | number;
179
- interface EventBase {
180
- /**注册事件 */
181
- on(event: string, listener: ListenerFunc, obj: object): void;
182
- /**取消所有事件 */
183
- offAll(): void;
184
- /**注册单次触发事件 */
185
- once(event: string, listener: ListenerFunc, obj: object): void;
186
- /**取消单个事件 */
187
- off(event: string, listener: Function, obj: object): void;
188
- /**调用事件 */
189
- dispatchEvent<T>(event: string, args: Record<string, T>): void;
190
- }
191
- declare class MessageManager implements EventBase {
192
- private events;
193
- /**
194
- * 注册全局事件
195
- * @param event 事件名
196
- * @param listener 处理事件的侦听器函数
197
- * @param obj 侦听函数绑定的作用域对象
198
- */
199
- on<T extends EventKeyType>(event: T, listener: ListenerFunc | null, obj: object): this;
200
- /**
201
- * 监听一次事件,事件响应后,该监听自动移除
202
- * @param event 事件名
203
- * @param listener 事件触发回调方法
204
- * @param obj 侦听函数绑定的作用域对象
205
- */
206
- once<T extends EventKeyType>(event: T, listener: ListenerFunc, obj: object | Symbol): void;
207
- /**
208
- * 移除单个事件
209
- * @param event 事件名
210
- * @param listener 处理事件的侦听器函数
211
- * @param obj 侦听函数绑定的作用域对象
212
- */
213
- off<T extends EventKeyType>(event: T, listener: Function | null, obj: object): this;
214
- /**
215
- * 触发全局事件
216
- * @param event(string) 事件名
217
- * @param args(any) 事件参数
218
- */
219
- dispatchEvent<T extends EventKeyType>(event: T, args?: any): this;
220
- /**移除所有事件 */
221
- offAll(): void;
222
- /**是否存在事件 */
223
- has(event: EventKeyType): boolean;
224
- /**删除事件通过组件 */
225
- deleteEventByComponent(component: Component): void;
226
- }
227
-
228
172
  /**
229
173
  * @describe 组件基类
230
174
  * @author 游金宇(KM)
@@ -253,7 +197,7 @@ declare class BaseComponent<T extends object = {}, K extends object = {}> extend
253
197
  private autorunDisposers;
254
198
  /**reaction销毁 */
255
199
  private reactionDisposers;
256
- private messageManagers;
200
+ private eventEmitter;
257
201
  hook: HOOK;
258
202
  /**初始化UI(可在本函数中进行节点赋值或注册节点事件等...) */
259
203
  protected initUI(): void;
@@ -265,9 +209,10 @@ declare class BaseComponent<T extends object = {}, K extends object = {}> extend
265
209
  protected addAutorun(cb: (() => void) | (() => void)[]): this;
266
210
  /**添加自动收集 */
267
211
  protected addReaction<T, FireImmediately extends boolean = false>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: FireImmediately extends true ? T | undefined : T, r: IReactionPublic) => void, opts?: IReactionOptions<T, FireImmediately>): this;
268
- protected addAudoListener(messageManager: MessageManager): MessageManager;
212
+ protected addAudoListener(eventEmitter: EventEmitter): EventEmitter<string | symbol, any>;
269
213
  _onPreDestroy(): void;
270
214
  protected onDisable(): void;
215
+ private deleteAllEventByEmitter;
271
216
  protected onEnable(): void;
272
217
  /**子类继承该方法(全局事件(cat.event)注册在components上的事件可以不添加取消监听(自动取消监听了)) */
273
218
  protected onEventListener(): void;
@@ -820,6 +765,44 @@ declare class CoreUtil extends BaseManager {
820
765
  encryptUtil: typeof EncryptUtil;
821
766
  }
822
767
 
768
+ /**
769
+ * @describe 基于社交游戏封装的游戏基础ws类
770
+ * @author 游金宇(KM)
771
+ * @date 2024-09-12 11:47:51
772
+ */
773
+ declare class WrapperSocialGameClient extends SocialGameClient {
774
+ /**名称 */
775
+ name: string;
776
+ /**日志黑名单 */
777
+ protected logBlackList: string[];
778
+ ignore: (route: string) => boolean;
779
+ constructor(name: string, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>, clientOption?: ClientOption);
780
+ destroy(): void;
781
+ GameRequest<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resp: U, audOptions?: AudienceOptionsJson): Promise<MessageShape<U>>;
782
+ subscribe<T extends DescMessage>(route: string, respType: T, fn?: (data: MessageShape<T>) => void): this;
783
+ }
784
+ declare class SocialGameClientManager extends BaseManager {
785
+ private managedClients;
786
+ private isGlobalOnline;
787
+ private isInBackground;
788
+ constructor(cat: Manager);
789
+ /**
790
+ * 创建并注册WebSocket客户端
791
+ * @param name 客户端唯一标识(如"game", "room")
792
+ * @param clientOption 客户端配置选项
793
+ * @param opts 社交游戏选项
794
+ * @param eventResponsePairs 事件响应配置
795
+ */
796
+ createWebSocket(name: string, clientOption: ClientOption, opts: Partial<SocialGameClientOption>, eventResponsePairs: Partial<AllEventResponsePairs>): WrapperSocialGameClient;
797
+ register(client: WrapperSocialGameClient): void;
798
+ unregister(client: WrapperSocialGameClient): void;
799
+ private initGlobalListeners;
800
+ private handleGlobalStateChange;
801
+ private triggerReconnectAll;
802
+ private disconnectAll;
803
+ private handleSingleReconnect;
804
+ }
805
+
823
806
  declare enum AudioEventConstant {
824
807
  /**音乐开 */
825
808
  MUSIC_ON = "AudioEventConstant/MUSIC_ON",
@@ -859,64 +842,6 @@ declare enum GlobalEventConstant {
859
842
  ROOT_MASK_CHANGE = "GlobalEventConstant/ROOT_MASK_CHANGE"
860
843
  }
861
844
 
862
- type GameNotifyType = (route: string, reqReflect: ReflectMessage, options?: {
863
- audOptions?: {
864
- forwardReq: false;
865
- forwardResp: false;
866
- };
867
- show_log?: boolean;
868
- }) => Promise<void>;
869
- /**
870
- * @describe 基于社交游戏封装的游戏基础ws类
871
- * @author 游金宇(KM)
872
- * @date 2024-09-12 11:47:51
873
- */
874
- declare class WrapperSocialGameClient extends SocialGameClient {
875
- /**需要重连(标记接下来需要重连) */
876
- private isNeedReconnect;
877
- /**网络在线 */
878
- private isOnline;
879
- /**在后台 */
880
- private isInBackground;
881
- /**状态机运行 */
882
- private running;
883
- private index;
884
- /**日志黑名单 */
885
- protected logBlackList: string[];
886
- constructor(opts: SocialGameClientOption, eventResponsePairs: AllEventResponsePairs, clientOption?: ClientOption);
887
- /**初始化 */
888
- addEvent(): void;
889
- removeEvent(): void;
890
- private onShowHandler;
891
- private onHideHandler;
892
- /**网络在线处理 */
893
- private onOnlineHandler;
894
- /**网络断开处理 */
895
- private onOfflineHandler;
896
- private handleEvent;
897
- destroy(): void;
898
- /**
899
- * 断开
900
- * @param activeDisconnect 主动断开
901
- */
902
- disconnect(activeDisconnect?: boolean): void;
903
- private destroyStateMachine;
904
- request<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resSchema: U): Promise<MessageShape<U>>;
905
- Request<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resSchema: U, { audOptions, show_log }?: {
906
- audOptions?: {
907
- forwardReq: boolean;
908
- forwardResp: boolean;
909
- } | undefined;
910
- show_log?: boolean | undefined;
911
- }): Promise<MessageShape<U>>;
912
- protected GameRequest<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resp: U, audOptions?: AudienceOptions): Promise<MessageShape<U>>;
913
- protected gameRequest<U extends DescMessage>(route: string, reqReflect: ReflectMessage, resSchema: U): Promise<MessageShape<U>>;
914
- protected GameNotify: (route: string, reqReflect: ReflectMessage, audOptions?: AudienceOptions) => Promise<void>;
915
- Notify: GameNotifyType;
916
- subscribe<T extends DescMessage>(route: string, respType: T, fn?: (data: MessageShape<T>) => void): this;
917
- onData(body: Uint8Array): void;
918
- }
919
-
920
845
  type CoreUIModalProps = {
921
846
  content: string | SpriteFrame | null;
922
847
  confirmCB: () => void;
@@ -1070,7 +995,7 @@ declare class Manager {
1070
995
  /**音频 */
1071
996
  audio: AudioManager;
1072
997
  /**事件 */
1073
- event: MessageManager;
998
+ event: EventEmitter$1;
1074
999
  /**gui */
1075
1000
  gui: Gui;
1076
1001
  /**本地存储 */
@@ -1079,6 +1004,8 @@ declare class Manager {
1079
1004
  res: ResLoader;
1080
1005
  /**工具类 */
1081
1006
  util: CoreUtil;
1007
+ /**类 */
1008
+ socialGameClient: SocialGameClientManager;
1082
1009
  /**GUI */
1083
1010
  gui_bundle_name: string;
1084
1011
  /**音效本地存储key */
@@ -1093,4 +1020,4 @@ declare class Manager {
1093
1020
  }
1094
1021
  declare const cat: Manager;
1095
1022
 
1096
- export { AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, CoreBlackMask, CoreNotice, type CoreNoticeProps, CoreReconnection, CoreShowLoading, type CoreShowLoadingProps, CoreToast, CoreUIContainer, CoreUIModal, type CoreUIModalProps, CoreUtil, type EventKeyType, GlobalEventConstant, Gui, GuiManager, type HOOK, type ICloseOptions, type IDirection, type IOpenOptions, type IUIOption, LayerType, type ListenerFunc, Manager, MessageManager, ReconnectPrompt, RootUILayer, type SceneComponentType, type SceneDataType, SceneLayer, type ScenePropsType, TimerManager, type ToastProps, ToastType, type UIComponentType, UILayer, WrapperSocialGameClient, cat };
1023
+ export { AudioEventConstant, AudioManager, AudioSourceBaseComponent, AudioSourceUILayer, AudioTypeEnum, BaseComponent, BaseManager, BasePrefab, CoreBlackMask, CoreNotice, type CoreNoticeProps, CoreReconnection, CoreShowLoading, type CoreShowLoadingProps, CoreToast, CoreUIContainer, CoreUIModal, type CoreUIModalProps, CoreUtil, GlobalEventConstant, Gui, GuiManager, type HOOK, type ICloseOptions, type IDirection, type IOpenOptions, type IUIOption, LayerType, Manager, ReconnectPrompt, RootUILayer, type SceneComponentType, type SceneDataType, SceneLayer, type ScenePropsType, TimerManager, type ToastProps, ToastType, type UIComponentType, UILayer, WrapperSocialGameClient, cat };