@uzuhq/code-sdk 0.8.9 → 0.8.11
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 +15 -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 +48 -34
- package/dist/index.js +544 -519
- 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,44 @@ 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
|
+
/**
|
|
202
|
+
* 振動の強さ。
|
|
203
|
+
*
|
|
204
|
+
* ミリ秒ではなく段階で渡すのは、iOS の触覚が長さを指定できず種類で選ぶ仕組みだから。
|
|
205
|
+
* 段階なら iOS / Android で同じ意味になる。
|
|
206
|
+
*/
|
|
207
|
+
type HapticKind = 'light' | 'medium' | 'heavy';
|
|
208
|
+
/**
|
|
209
|
+
* 端末を短く振動させる。
|
|
210
|
+
*
|
|
211
|
+
* アプリの WebView では `navigator.vibrate` が効かない (iOS には Web から振動させる手段が
|
|
212
|
+
* 無い) ので、ホストへ依頼する。端末の設定で触覚を切っている人には OS 側で効かない。
|
|
213
|
+
*/
|
|
214
|
+
declare const haptic: (kind: HapticKind) => void;
|
|
201
215
|
/**
|
|
202
216
|
* splash 描画完了を Flutter ホストに通知する。
|
|
203
217
|
*
|
|
@@ -214,7 +228,7 @@ declare function changeRoom(roomId: string | null): void;
|
|
|
214
228
|
* requestAnimationFrame(() => firstFrameReady());
|
|
215
229
|
* ```
|
|
216
230
|
*/
|
|
217
|
-
declare
|
|
231
|
+
declare const firstFrameReady: () => void;
|
|
218
232
|
/**
|
|
219
233
|
* ユーザー操作受付可能を Flutter ホストに通知する。
|
|
220
234
|
*
|
|
@@ -231,7 +245,7 @@ declare function firstFrameReady(): void;
|
|
|
231
245
|
* gameReady();
|
|
232
246
|
* ```
|
|
233
247
|
*/
|
|
234
|
-
declare
|
|
248
|
+
declare const gameReady: () => void;
|
|
235
249
|
/**
|
|
236
250
|
* ゲームを終えてプレイ画面を閉じるよう Flutter ホストに通知する。
|
|
237
251
|
*
|
|
@@ -252,9 +266,9 @@ declare function gameReady(): void;
|
|
|
252
266
|
* }
|
|
253
267
|
* ```
|
|
254
268
|
*/
|
|
255
|
-
declare
|
|
269
|
+
declare const finishGame: () => void;
|
|
256
270
|
/** Flutter からの playersChanged メッセージを受信するハンドラを登録する。 */
|
|
257
|
-
declare
|
|
271
|
+
declare const onPlayersChanged: (handler: PlayersChangedHandler) => void;
|
|
258
272
|
/**
|
|
259
273
|
* `A` に既定値が要る。 TypeScript は型引数の部分推論ができないので、 既定が無いと
|
|
260
274
|
* 既存の `run<State>({…})` が「2 つ必要」で落ちる。 既定を置けば型引数を書かない
|
|
@@ -264,6 +278,6 @@ declare function onPlayersChanged(handler: PlayersChangedHandler): void;
|
|
|
264
278
|
* `keyof (A & SA)` が `string` へ潰れ、action 名の検査が丸ごと消える。
|
|
265
279
|
* `serverActions` を持たない logic でもキーが残るよう空 map を既定にする。
|
|
266
280
|
*/
|
|
267
|
-
declare
|
|
281
|
+
declare const run: <S, A extends ActionMap<S> = ActionMap<S>, SA extends ServerActionMap<S> = Record<never, never>>(config: GameConfig<S, A, SA>) => void;
|
|
268
282
|
//#endregion
|
|
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 };
|
|
283
|
+
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, HapticKind, 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, haptic, init, isHosted, isPaused, isServerOnlyAction, minus, on, onInsetsChange, onPauseChange, onPlayersChanged, playBgm, playSound, plus, run, send, serverOnly, setMicEnabled, stopBgm, sub };
|