@lzpenguin/server 1.0.0 → 1.0.1

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 (2) hide show
  1. package/index.d.ts +101 -0
  2. package/package.json +5 -3
package/index.d.ts ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Riffle 游戏服务器 WebSocket 客户端 SDK
3
+ */
4
+
5
+ /**
6
+ * RiffleServer 构造函数选项
7
+ */
8
+ export interface RiffleServerOptions {
9
+ /** WebSocket 服务器 URL */
10
+ url: string;
11
+ /** 游戏贴文 ID */
12
+ postId: number;
13
+ /** 认证 token */
14
+ token: string;
15
+ /** 是否自动重连,默认 true */
16
+ autoReconnect?: boolean;
17
+ /** 重连间隔(毫秒),默认 3000 */
18
+ reconnectInterval?: number;
19
+ }
20
+
21
+ /**
22
+ * 玩家数据
23
+ */
24
+ export interface PlayerSelfData {
25
+ /** 公开数据 */
26
+ public?: Record<string, any>;
27
+ /** 私有数据 */
28
+ private?: Record<string, any>;
29
+ }
30
+
31
+ /**
32
+ * 初始化数据
33
+ */
34
+ export interface InitData {
35
+ /** 游戏版本哈希值(必需) */
36
+ hash: string;
37
+ /** 世界初始数据(可选) */
38
+ world?: Record<string, any>;
39
+ /** 玩家初始数据(可选) */
40
+ self?: PlayerSelfData;
41
+ }
42
+
43
+ /**
44
+ * 更新数据
45
+ */
46
+ export interface UpdateData {
47
+ /** 世界数据(可选,部分更新) */
48
+ world?: Record<string, any>;
49
+ /** 玩家数据(可选,部分更新) */
50
+ self?: PlayerSelfData;
51
+ }
52
+
53
+ /**
54
+ * 服务器推送的数据
55
+ */
56
+ export interface ServerData {
57
+ /** 世界数据 */
58
+ world: Record<string, any>;
59
+ /** 当前玩家数据 */
60
+ self: PlayerSelfData;
61
+ /** 其他玩家列表(仅公开数据) */
62
+ players: Array<Record<string, any>>;
63
+ }
64
+
65
+ /**
66
+ * RiffleServer - 游戏服务器 WebSocket 客户端
67
+ */
68
+ export class RiffleServer {
69
+ /**
70
+ * 创建 RiffleServer 实例
71
+ * @param options 配置选项
72
+ */
73
+ constructor(options: RiffleServerOptions);
74
+
75
+ /** 是否已连接 */
76
+ readonly isConnected: boolean;
77
+ /** 是否正在连接 */
78
+ readonly isConnecting: boolean;
79
+ /** 是否已初始化 */
80
+ readonly isInitialized: boolean;
81
+
82
+ /**
83
+ * 初始化服务器(必需,连接后必须先调用)
84
+ * @param initData 初始化数据
85
+ */
86
+ init(initData: InitData): void;
87
+
88
+ /**
89
+ * 更新数据(部分更新,合并到现有数据)
90
+ * @param updateData 更新数据
91
+ */
92
+ update(updateData: UpdateData): void;
93
+
94
+ /**
95
+ * 监听服务器推送的最新数据
96
+ * @param callback 回调函数,接收服务器推送的数据
97
+ * @returns 取消监听的函数
98
+ */
99
+ onData(callback: (data: ServerData) => void): () => void;
100
+ }
101
+
package/package.json CHANGED
@@ -1,18 +1,21 @@
1
1
  {
2
2
  "name": "@lzpenguin/server",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Riffle 游戏服务器 WebSocket 客户端 SDK",
5
5
  "license": "ISC",
6
6
  "author": "lzpenguin",
7
7
  "type": "module",
8
8
  "main": "./index.js",
9
+ "types": "./index.d.ts",
9
10
  "exports": {
10
11
  ".": {
11
- "import": "./index.js"
12
+ "import": "./index.js",
13
+ "types": "./index.d.ts"
12
14
  }
13
15
  },
14
16
  "files": [
15
17
  "index.js",
18
+ "index.d.ts",
16
19
  "README.md"
17
20
  ],
18
21
  "keywords": [
@@ -34,4 +37,3 @@
34
37
  "registry": "https://registry.npmjs.org/"
35
38
  }
36
39
  }
37
-