@uzuhq/code-sdk 0.8.8 → 0.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/dev-globals.d.ts +1 -1
- package/dist/{dev-hooks-B9mpXwaP.d.ts → dev-hooks-7UDN8Xac.d.ts} +168 -162
- package/dist/index.d.ts +54 -33
- package/dist/index.js +547 -517
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as plus, A as Deadline, B as ServerActionMap, C as SeatKind, D as ActionHandler, E as ActionContext, F as Seat, G as SetupArgs, H as ServerOnlyAction, I as SeededRandom, J as UpdateContext, K as SetupContext, L as ServerActionArgs, M as DeadlineContext, N as Emit, O as ActionMap, P as GameLogic, Q as minus, R as ServerActionContext, S as PlayersChangedMessage, T as ActionArgs, U as ServerOnlyActionContext, V as ServerEvent, W as ServerOnlyActionHandlerFn, X as GAME_START, Y as Duration, Z as GameTime, _ as EventSubscription, a as createDevHooks, b as PlayScreenMessage, c as applyJsonMergePatch, d as getPredictionWarnings, et as sub, f as BridgeChannel, g as EventHandler, h as ConnectionState, i as attachDevHooks, j as DeadlineArgs, k as DEFAULT_ICON_URLS, l as applyJsonPatch, m as ConnectionCallbacks, n as RunHandle, o as JsonMergePatch, p as BridgeMessage, q as UpdateArgs, r as UzuDevHooks, s as JsonPatchOp, t as DevHooksCtx, u as PredictionWarning, v as GameConfig, w as SendAction, x as PlayerVoiceState, y as PayloadMap, z as ServerActionHandler } from "./dev-hooks-7UDN8Xac.js";
|
|
2
2
|
//#region ../engine-core/src/json-patch.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* @docs
|
|
@@ -7,11 +7,11 @@ import { $ as applyJsonMergePatch, A as GameLogic, B as ServerOnlyActionHandlerF
|
|
|
7
7
|
* state 差分同期用の JSON Patch。RFC 6902 の全 op は実装せず、
|
|
8
8
|
* `compare` が生成する replace / add / remove だけを扱う。
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
type Operation = {
|
|
11
11
|
op: 'replace' | 'add' | 'remove';
|
|
12
12
|
path: string;
|
|
13
13
|
value?: unknown;
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region ../engine-core/src/random.d.ts
|
|
17
17
|
declare class SeededRandomImpl implements SeededRandom {
|
|
@@ -36,13 +36,13 @@ declare class SeededRandomImpl implements SeededRandom {
|
|
|
36
36
|
* serverActions: { notifyExternal: async (state) => { ... } }
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
declare
|
|
39
|
+
declare const serverOnly: <S>(handler: ServerActionHandler<S>) => ServerOnlyAction<S>;
|
|
40
40
|
/**
|
|
41
41
|
* handler が `serverOnly()` で wrap されているか判定する。
|
|
42
42
|
*
|
|
43
43
|
* 移行期の互換用。`serverActions` へ移行済みの logic では常に false になる。
|
|
44
44
|
*/
|
|
45
|
-
declare
|
|
45
|
+
declare const isServerOnlyAction: <S>(handler: ActionHandler<S> | ServerActionHandler<S> | ServerOnlyAction<S> | undefined) => handler is ServerOnlyAction<S>;
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region src/server-clock.d.ts
|
|
48
48
|
/**
|
|
@@ -51,13 +51,13 @@ declare function isServerOnlyAction<S>(handler: ActionHandler<S> | ServerActionH
|
|
|
51
51
|
* カウントダウン描画のように毎秒/毎フレーム呼ぶ用途を想定しているので、
|
|
52
52
|
* state の到着とは無関係にいつでも呼べる。
|
|
53
53
|
*/
|
|
54
|
-
declare
|
|
54
|
+
declare const gameTime: () => GameTime;
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region src/pause-state.d.ts
|
|
57
57
|
/** 緊急停止中か。 */
|
|
58
|
-
declare
|
|
58
|
+
declare const isPaused: () => boolean;
|
|
59
59
|
/** 停止状態の変化を購読する。 */
|
|
60
|
-
declare
|
|
60
|
+
declare const onPauseChange: (cb: (paused: boolean) => void) => void;
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/reconnectable-ws.d.ts
|
|
63
63
|
/**
|
|
@@ -68,7 +68,7 @@ declare function onPauseChange(cb: (paused: boolean) => void): void;
|
|
|
68
68
|
* - 再接続中のメッセージバッファリング
|
|
69
69
|
*/
|
|
70
70
|
type ConnectionState$1 = 'connecting' | 'connected' | 'reconnecting' | 'disconnected';
|
|
71
|
-
|
|
71
|
+
type ReconnectableWSOptions = {
|
|
72
72
|
/** 最大再接続試行回数 (default: 15) */
|
|
73
73
|
maxReconnectAttempts?: number;
|
|
74
74
|
/** Backoff の基準遅延 ms (default: 1000) */
|
|
@@ -87,7 +87,7 @@ interface ReconnectableWSOptions {
|
|
|
87
87
|
shouldBuffer?: (data: string) => boolean;
|
|
88
88
|
/** 接続状態変更コールバック */
|
|
89
89
|
onConnectionStateChange?: (state: ConnectionState$1) => void;
|
|
90
|
-
}
|
|
90
|
+
};
|
|
91
91
|
declare class ReconnectableWebSocket {
|
|
92
92
|
private ws;
|
|
93
93
|
private readonly url;
|
|
@@ -105,8 +105,8 @@ declare class ReconnectableWebSocket {
|
|
|
105
105
|
/** WebSocket.readyState 互換 (既存コードとの互換用) */
|
|
106
106
|
get readyState(): number;
|
|
107
107
|
send(data: string): void;
|
|
108
|
-
addEventListener(
|
|
109
|
-
removeEventListener(
|
|
108
|
+
addEventListener(_type: 'message', handler: (ev: MessageEvent) => void): void;
|
|
109
|
+
removeEventListener(_type: 'message', handler: (ev: MessageEvent) => void): void;
|
|
110
110
|
/** バッファをクリア(権威的 state 受信時に呼ぶ) */
|
|
111
111
|
clearBuffer(): void;
|
|
112
112
|
/** 全リソース解放 */
|
|
@@ -138,14 +138,14 @@ declare class ReconnectableWebSocket {
|
|
|
138
138
|
* [csswg-drafts#4670]: https://github.com/w3c/csswg-drafts/issues/4670
|
|
139
139
|
*/
|
|
140
140
|
/** 4 辺の inset (CSS px)。 */
|
|
141
|
-
|
|
141
|
+
type Insets = {
|
|
142
142
|
top: number;
|
|
143
143
|
right: number;
|
|
144
144
|
bottom: number;
|
|
145
145
|
left: number;
|
|
146
|
-
}
|
|
146
|
+
};
|
|
147
147
|
/** ホストが配る inset の全層。 */
|
|
148
|
-
|
|
148
|
+
type UzuInsets = {
|
|
149
149
|
/** デバイスの safe area (ノッチ / 角丸 / ホームインジケータ)。 */
|
|
150
150
|
safeArea: Insets;
|
|
151
151
|
/**
|
|
@@ -158,14 +158,14 @@ interface UzuInsets {
|
|
|
158
158
|
x: number;
|
|
159
159
|
y: number;
|
|
160
160
|
};
|
|
161
|
-
}
|
|
161
|
+
};
|
|
162
162
|
/**
|
|
163
163
|
* 現在の inset を返す。
|
|
164
164
|
*
|
|
165
165
|
* canvas / WebGL は CSS 変数で避けられないので、そこから読む口。値は初回ペイント前に
|
|
166
166
|
* 確定しているので、setup の中で読んでよい。
|
|
167
167
|
*/
|
|
168
|
-
declare
|
|
168
|
+
declare const getInsets: () => UzuInsets;
|
|
169
169
|
/**
|
|
170
170
|
* inset の変化を購読する。戻り値を呼ぶと解除できる。
|
|
171
171
|
*
|
|
@@ -174,30 +174,30 @@ declare function getInsets(): UzuInsets;
|
|
|
174
174
|
*
|
|
175
175
|
* 登録時に即時呼び出しはしない。初期値は [getInsets] で読むこと。
|
|
176
176
|
*/
|
|
177
|
-
declare
|
|
177
|
+
declare const onInsetsChange: (cb: (insets: UzuInsets) => void) => (() => void);
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region src/index.d.ts
|
|
180
180
|
type GameMessageHandler = (payload: Record<string, unknown>) => void;
|
|
181
181
|
type PlayersChangedHandler = (players: Record<string, PlayerVoiceState>) => void;
|
|
182
182
|
declare const isHosted: boolean;
|
|
183
|
-
declare
|
|
183
|
+
declare const init: (_opts?: {
|
|
184
184
|
playerCount?: number;
|
|
185
|
-
orientation?:
|
|
185
|
+
orientation?: "portrait" | "landscape";
|
|
186
186
|
/**
|
|
187
187
|
* Dev harness の iframe inner viewport 短辺 (CSS px) の下限。default 360。
|
|
188
188
|
* harness 側で参照される値で、 SDK runtime 本体は使わない。
|
|
189
189
|
*/
|
|
190
190
|
devMinIframeShortEdge?: number;
|
|
191
|
-
})
|
|
191
|
+
}) => void;
|
|
192
192
|
/** game channel でカスタムメッセージを送信する。 native コマンドには使用不可。 */
|
|
193
|
-
declare
|
|
193
|
+
declare const send: (type: string, payload?: Record<string, unknown>) => void;
|
|
194
194
|
/** game channel のカスタムメッセージを受信する。 */
|
|
195
|
-
declare
|
|
196
|
-
declare
|
|
197
|
-
declare
|
|
198
|
-
declare
|
|
199
|
-
declare
|
|
200
|
-
declare
|
|
195
|
+
declare const on: (type: string, handler: GameMessageHandler) => void;
|
|
196
|
+
declare const playSound: (sound: string) => void;
|
|
197
|
+
declare const playBgm: (sound: string) => void;
|
|
198
|
+
declare const stopBgm: () => void;
|
|
199
|
+
declare const setMicEnabled: (enabled: boolean) => void;
|
|
200
|
+
declare const changeRoom: (roomId: string | null) => void;
|
|
201
201
|
/**
|
|
202
202
|
* splash 描画完了を Flutter ホストに通知する。
|
|
203
203
|
*
|
|
@@ -214,7 +214,7 @@ declare function changeRoom(roomId: string | null): void;
|
|
|
214
214
|
* requestAnimationFrame(() => firstFrameReady());
|
|
215
215
|
* ```
|
|
216
216
|
*/
|
|
217
|
-
declare
|
|
217
|
+
declare const firstFrameReady: () => void;
|
|
218
218
|
/**
|
|
219
219
|
* ユーザー操作受付可能を Flutter ホストに通知する。
|
|
220
220
|
*
|
|
@@ -231,9 +231,30 @@ declare function firstFrameReady(): void;
|
|
|
231
231
|
* gameReady();
|
|
232
232
|
* ```
|
|
233
233
|
*/
|
|
234
|
-
declare
|
|
234
|
+
declare const gameReady: () => void;
|
|
235
|
+
/**
|
|
236
|
+
* ゲームを終えてプレイ画面を閉じるよう Flutter ホストに通知する。
|
|
237
|
+
*
|
|
238
|
+
* 閉じるのは**呼んだ端末だけ**。全員を閉じたいときは、終了を表す state を全員へ配り、
|
|
239
|
+
* 各端末の `onState` から呼ぶ。ホストはイベントを終了扱いにし (finishedAt を立てるのは
|
|
240
|
+
* 最初の 1 人だけ)、呼んだプレイヤーを退出させてから画面を閉じる。
|
|
241
|
+
*
|
|
242
|
+
* 呼び出しタイミング: 結果や感想戦を見終えて閉じるときなど、シナリオとしてゲームが完全に
|
|
243
|
+
* 終わった瞬間。勝敗が決まった瞬間 (`gameover` など) に呼ぶと、結果を見る前に画面が閉じる。
|
|
244
|
+
*
|
|
245
|
+
* 対応していない古いアプリや `uzu dev` harness では何も起きない。呼んだあとも画面を
|
|
246
|
+
* 操作不能にしないこと。
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* onState(state) {
|
|
251
|
+
* if (state.debriefClosed) finishGame();
|
|
252
|
+
* }
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare const finishGame: () => void;
|
|
235
256
|
/** Flutter からの playersChanged メッセージを受信するハンドラを登録する。 */
|
|
236
|
-
declare
|
|
257
|
+
declare const onPlayersChanged: (handler: PlayersChangedHandler) => void;
|
|
237
258
|
/**
|
|
238
259
|
* `A` に既定値が要る。 TypeScript は型引数の部分推論ができないので、 既定が無いと
|
|
239
260
|
* 既存の `run<State>({…})` が「2 つ必要」で落ちる。 既定を置けば型引数を書かない
|
|
@@ -243,6 +264,6 @@ declare function onPlayersChanged(handler: PlayersChangedHandler): void;
|
|
|
243
264
|
* `keyof (A & SA)` が `string` へ潰れ、action 名の検査が丸ごと消える。
|
|
244
265
|
* `serverActions` を持たない logic でもキーが残るよう空 map を既定にする。
|
|
245
266
|
*/
|
|
246
|
-
declare
|
|
267
|
+
declare const run: <S, A extends ActionMap<S> = ActionMap<S>, SA extends ServerActionMap<S> = Record<never, never>>(config: GameConfig<S, A, SA>) => void;
|
|
247
268
|
//#endregion
|
|
248
|
-
export { type ActionArgs, type ActionContext, type ActionHandler, type ActionMap, type BridgeChannel, type BridgeMessage, type ConnectionCallbacks, type ConnectionState, DEFAULT_ICON_URLS, type Deadline, type DeadlineArgs, type DeadlineContext, type DevHooksCtx, type Duration, type Emit, type EventHandler, type EventSubscription, GAME_START, type GameConfig, type GameLogic, type GameTime, type Insets, type JsonMergePatch, type JsonPatchOp, type Operation, type PayloadMap, type PlayScreenMessage, type PlayerVoiceState, type PlayersChangedMessage, type PredictionWarning, type ReconnectableWSOptions, ReconnectableWebSocket, type RunHandle, type Seat, type SeatKind, type SeededRandom, SeededRandomImpl, type SendAction, type ServerActionArgs, type ServerActionContext, type ServerActionHandler, type ServerActionMap, type ServerEvent, type ServerOnlyAction, type ServerOnlyActionContext, type ServerOnlyActionHandlerFn, type SetupArgs, type SetupContext, type UpdateArgs, type UpdateContext, type UzuDevHooks, type UzuInsets, applyJsonMergePatch, applyJsonPatch, attachDevHooks, changeRoom, createDevHooks, firstFrameReady, gameReady, gameTime, getInsets, getPredictionWarnings, init, isHosted, isPaused, isServerOnlyAction, minus, on, onInsetsChange, onPauseChange, onPlayersChanged, playBgm, playSound, plus, run, send, serverOnly, setMicEnabled, stopBgm, sub };
|
|
269
|
+
export { type ActionArgs, type ActionContext, type ActionHandler, type ActionMap, type BridgeChannel, type BridgeMessage, type ConnectionCallbacks, type ConnectionState, DEFAULT_ICON_URLS, type Deadline, type DeadlineArgs, type DeadlineContext, type DevHooksCtx, type Duration, type Emit, type EventHandler, type EventSubscription, GAME_START, type GameConfig, type GameLogic, type GameTime, type Insets, type JsonMergePatch, type JsonPatchOp, type Operation, type PayloadMap, type PlayScreenMessage, type PlayerVoiceState, type PlayersChangedMessage, type PredictionWarning, type ReconnectableWSOptions, ReconnectableWebSocket, type RunHandle, type Seat, type SeatKind, type SeededRandom, SeededRandomImpl, type SendAction, type ServerActionArgs, type ServerActionContext, type ServerActionHandler, type ServerActionMap, type ServerEvent, type ServerOnlyAction, type ServerOnlyActionContext, type ServerOnlyActionHandlerFn, type SetupArgs, type SetupContext, type UpdateArgs, type UpdateContext, type UzuDevHooks, type UzuInsets, applyJsonMergePatch, applyJsonPatch, attachDevHooks, changeRoom, createDevHooks, finishGame, firstFrameReady, gameReady, gameTime, getInsets, getPredictionWarnings, init, isHosted, isPaused, isServerOnlyAction, minus, on, onInsetsChange, onPauseChange, onPlayersChanged, playBgm, playSound, plus, run, send, serverOnly, setMicEnabled, stopBgm, sub };
|