@uzuhq/code-sdk 0.8.1 → 0.8.3

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.
@@ -1,4 +1,4 @@
1
- import { i as UzuDevHooks } from "./dev-hooks-BYl_jrcy.js";
1
+ import { i as UzuDevHooks } from "./dev-hooks-DOtJHP55.js";
2
2
  //#region src/dev-globals.d.ts
3
3
  declare global {
4
4
  interface Window {
@@ -125,6 +125,16 @@ declare const plus: (t: GameTime, d: Duration) => GameTime;
125
125
  declare const sub: (t: GameTime, d: Duration) => GameTime;
126
126
  /** 2 つの `GameTime` の差 (ms)。 */
127
127
  declare const minus: (a: GameTime, b: GameTime) => Duration;
128
+ /**
129
+ * ゲーム内時計の原点。ゲーム開始の瞬間で、`setup()` の `ctx.time` と同じ値。
130
+ *
131
+ * `minus(t, GAME_START)` がゲーム開始からの経過 ms になる。表示やログのために
132
+ * 素の数値が要る場面は、これを使えば cast を書かずに済む。
133
+ *
134
+ * `toMs` を公開しないのは `toMs(a) - toMs(b)` と書けて保護が丸ごと消えるためだが、
135
+ * `GAME_START` にその使い方は無い。差を取るには結局 `minus` を通る。
136
+ */
137
+ declare const GAME_START: GameTime;
128
138
  //#endregion
129
139
  //#region ../engine-core/src/types.d.ts
130
140
  /**
@@ -728,4 +738,4 @@ interface DevHooksCtx<S = unknown> {
728
738
  declare function createDevHooks<S>(ctx: DevHooksCtx<S>): UzuDevHooks<S>;
729
739
  declare function attachDevHooks<S>(ctx: DevHooksCtx<S>): void;
730
740
  //#endregion
731
- export { minus as $, DEFAULT_ICON_URLS as A, ServerActionContext as B, SetFn as C, ActionContext as D, ActionArgs as E, GameLogic as F, ServerOnlyActionContext as G, ServerActionMap as H, SERVER_TIME as I, SetupContext as J, ServerOnlyActionHandlerFn as K, Seat as L, DeadlineArgs as M, DeadlineContext as N, ActionHandler as O, Emit as P, GameTime as Q, SeededRandom as R, SendAction as S, Operation as T, ServerEvent as U, ServerActionHandler as V, ServerOnlyAction as W, UpdateContext as X, UpdateArgs as Y, Duration as Z, PayloadMap as _, attachDevHooks as a, applyJsonPatch as at, PlayersChangedMessage as b, getPredictionWarnings as c, ConnectionCallbacks as d, plus as et, ConnectionState as f, PatchFn as g, GameConfig as h, UzuDevHooks as i, applyJsonMergePatch as it, Deadline as j, ActionMap as k, BridgeChannel as l, EventSubscription as m, RunHandle as n, JsonMergePatch as nt, createDevHooks as o, EventHandler as p, SetupArgs as q, SyncHandle as r, JsonPatchOp as rt, PredictionWarning as s, DevHooksCtx as t, sub as tt, BridgeMessage as u, PlayScreenMessage as v, SyncConfig as w, SeatKind as x, PlayerVoiceState as y, ServerActionArgs as z };
741
+ export { GameTime as $, DEFAULT_ICON_URLS as A, ServerActionContext as B, SetFn as C, ActionContext as D, ActionArgs as E, GameLogic as F, ServerOnlyActionContext as G, ServerActionMap as H, SERVER_TIME as I, SetupContext as J, ServerOnlyActionHandlerFn as K, Seat as L, DeadlineArgs as M, DeadlineContext as N, ActionHandler as O, Emit as P, GAME_START as Q, SeededRandom as R, SendAction as S, Operation as T, ServerEvent as U, ServerActionHandler as V, ServerOnlyAction as W, UpdateContext as X, UpdateArgs as Y, Duration as Z, PayloadMap as _, attachDevHooks as a, applyJsonMergePatch as at, PlayersChangedMessage as b, getPredictionWarnings as c, ConnectionCallbacks as d, minus as et, ConnectionState as f, PatchFn as g, GameConfig as h, UzuDevHooks as i, JsonPatchOp as it, Deadline as j, ActionMap as k, BridgeChannel as l, EventSubscription as m, RunHandle as n, sub as nt, createDevHooks as o, applyJsonPatch as ot, EventHandler as p, SetupArgs as q, SyncHandle as r, JsonMergePatch as rt, PredictionWarning as s, DevHooksCtx as t, plus as tt, BridgeMessage as u, PlayScreenMessage as v, SyncConfig as w, SeatKind as x, PlayerVoiceState as y, ServerActionArgs as z };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as minus, A as DEFAULT_ICON_URLS, B as ServerActionContext, C as SetFn, D as ActionContext, E as ActionArgs, F as GameLogic, G as ServerOnlyActionContext, H as ServerActionMap, I as SERVER_TIME, J as SetupContext, K as ServerOnlyActionHandlerFn, L as Seat, M as DeadlineArgs, N as DeadlineContext, O as ActionHandler, P as Emit, Q as GameTime, R as SeededRandom, S as SendAction, T as Operation, U as ServerEvent, V as ServerActionHandler, W as ServerOnlyAction, X as UpdateContext, Y as UpdateArgs, Z as Duration, _ as PayloadMap, a as attachDevHooks, at as applyJsonPatch, b as PlayersChangedMessage, c as getPredictionWarnings, d as ConnectionCallbacks, et as plus, f as ConnectionState, g as PatchFn, h as GameConfig, i as UzuDevHooks, it as applyJsonMergePatch, j as Deadline, k as ActionMap, l as BridgeChannel, m as EventSubscription, n as RunHandle, nt as JsonMergePatch, o as createDevHooks, p as EventHandler, q as SetupArgs, r as SyncHandle, rt as JsonPatchOp, s as PredictionWarning, t as DevHooksCtx, tt as sub, u as BridgeMessage, v as PlayScreenMessage, w as SyncConfig, x as SeatKind, y as PlayerVoiceState, z as ServerActionArgs } from "./dev-hooks-BYl_jrcy.js";
1
+ import { $ as GameTime, A as DEFAULT_ICON_URLS, B as ServerActionContext, C as SetFn, D as ActionContext, E as ActionArgs, F as GameLogic, G as ServerOnlyActionContext, H as ServerActionMap, I as SERVER_TIME, J as SetupContext, K as ServerOnlyActionHandlerFn, L as Seat, M as DeadlineArgs, N as DeadlineContext, O as ActionHandler, P as Emit, Q as GAME_START, R as SeededRandom, S as SendAction, T as Operation, U as ServerEvent, V as ServerActionHandler, W as ServerOnlyAction, X as UpdateContext, Y as UpdateArgs, Z as Duration, _ as PayloadMap, a as attachDevHooks, at as applyJsonMergePatch, b as PlayersChangedMessage, c as getPredictionWarnings, d as ConnectionCallbacks, et as minus, f as ConnectionState, g as PatchFn, h as GameConfig, i as UzuDevHooks, it as JsonPatchOp, j as Deadline, k as ActionMap, l as BridgeChannel, m as EventSubscription, n as RunHandle, nt as sub, o as createDevHooks, ot as applyJsonPatch, p as EventHandler, q as SetupArgs, r as SyncHandle, rt as JsonMergePatch, s as PredictionWarning, t as DevHooksCtx, tt as plus, u as BridgeMessage, v as PlayScreenMessage, w as SyncConfig, x as SeatKind, y as PlayerVoiceState, z as ServerActionArgs } from "./dev-hooks-DOtJHP55.js";
2
2
  //#region ../engine-core/src/random.d.ts
3
3
  declare class SeededRandomImpl implements SeededRandom {
4
4
  private _state;
@@ -205,4 +205,4 @@ declare function onPlayersChanged(handler: PlayersChangedHandler): void;
205
205
  declare function run<S, A extends ActionMap<S> = ActionMap<S>, SA extends ServerActionMap<S> = Record<never, never>>(config: GameConfig<S, A, SA>): void;
206
206
  declare function sync<S>(config: SyncConfig<S>): void;
207
207
  //#endregion
208
- 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, type GameConfig, type GameLogic, type GameTime, type JsonMergePatch, type JsonPatchOp, type Operation, type PatchFn, type PayloadMap, type PlayScreenMessage, type PlayerVoiceState, type PlayersChangedMessage, type PredictionWarning, type ReconnectableWSOptions, ReconnectableWebSocket, Room, type RoomLike, type RunHandle, SERVER_TIME, 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 SetFn, type SetupArgs, type SetupContext, type SyncConfig, type SyncHandle, type UpdateArgs, type UpdateContext, type UzuDevHooks, applyJsonMergePatch, applyJsonPatch, attachDevHooks, changeRoom, createDevHooks, firstFrameReady, gameReady, gameTime, getPredictionWarnings, getRoom, init, isHosted, isPaused, isServerOnlyAction, minus, on, onPauseChange, onPlayersChanged, onRoom, playBgm, playSound, plus, run, send, serverOnly, setMicEnabled, stopBgm, sub, sync };
208
+ 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 JsonMergePatch, type JsonPatchOp, type Operation, type PatchFn, type PayloadMap, type PlayScreenMessage, type PlayerVoiceState, type PlayersChangedMessage, type PredictionWarning, type ReconnectableWSOptions, ReconnectableWebSocket, Room, type RoomLike, type RunHandle, SERVER_TIME, 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 SetFn, type SetupArgs, type SetupContext, type SyncConfig, type SyncHandle, type UpdateArgs, type UpdateContext, type UzuDevHooks, applyJsonMergePatch, applyJsonPatch, attachDevHooks, changeRoom, createDevHooks, firstFrameReady, gameReady, gameTime, getPredictionWarnings, getRoom, init, isHosted, isPaused, isServerOnlyAction, minus, on, onPauseChange, onPlayersChanged, onRoom, playBgm, playSound, plus, run, send, serverOnly, setMicEnabled, stopBgm, sub, sync };
package/dist/index.js CHANGED
@@ -33,6 +33,16 @@ const minus = (a, b) => toMs(a) - toMs(b);
33
33
  * 時計の実装 (play-server の facet / dev-server / ソロ / SDK の補間) だけがここを通る。
34
34
  */
35
35
  const asGameTime = (ms) => ms;
36
+ /**
37
+ * ゲーム内時計の原点。ゲーム開始の瞬間で、`setup()` の `ctx.time` と同じ値。
38
+ *
39
+ * `minus(t, GAME_START)` がゲーム開始からの経過 ms になる。表示やログのために
40
+ * 素の数値が要る場面は、これを使えば cast を書かずに済む。
41
+ *
42
+ * `toMs` を公開しないのは `toMs(a) - toMs(b)` と書けて保護が丸ごと消えるためだが、
43
+ * `GAME_START` にその使い方は無い。差を取るには結局 `minus` を通る。
44
+ */
45
+ const GAME_START = asGameTime(0);
36
46
  //#endregion
37
47
  //#region ../engine-core/src/game-clock.ts
38
48
  /**
@@ -838,7 +848,8 @@ function replaceRoot(doc, value) {
838
848
  //#region src/dev-prediction-traps.ts
839
849
  /** 描画経路の警告に使う擬似 action 名。 */
840
850
  const RENDER_CONTEXT = "(render)";
841
- const CLOCK_TRAPS = [{ install: (report) => {
851
+ /** 実時刻。先読みでも描画でもサーバーとズレる。 */
852
+ const WALL_CLOCK_TRAPS = [{ install: (report) => {
842
853
  const RealDate = Date;
843
854
  const realNow = Date.now;
844
855
  globalThis.Date = new Proxy(RealDate, { construct: (target, args) => {
@@ -853,7 +864,22 @@ const CLOCK_TRAPS = [{ install: (report) => {
853
864
  Date.now = realNow;
854
865
  globalThis.Date = RealDate;
855
866
  };
856
- } }, { install: (report) => {
867
+ } }];
868
+ /**
869
+ * 単調時計。**描画では張らない。**
870
+ *
871
+ * `gameTime()` の実装がこれを使っている。描画から毎フレーム呼ぶ前提の公開 API なので、
872
+ * 描画でも張ると「時刻は gameTime() から取れ」という指示どおりに書いたコードが
873
+ * そのまま警告される。誤検知が常時出ると本物の `Date.now()` 混入まで無視される。
874
+ *
875
+ * 代償として、生の `performance.now()` を描画で締切に混ぜる誤りは拾えない。実時刻ほど
876
+ * 桁が飛ばず (どちらも小さい数なので静かに少しズレる)、かつ作家が書くのは圧倒的に
877
+ * `Date.now()` の方なので、この取りこぼしを受け入れる。
878
+ *
879
+ * 先読みでは張る。`gameTime()` の値を state に書けばサーバーの結果とズレるので、
880
+ * これは正しい検出になる。
881
+ */
882
+ const MONOTONIC_TRAPS = [{ install: (report) => {
857
883
  const real = globalThis.performance?.now;
858
884
  if (!real) return () => {};
859
885
  const bound = real.bind(globalThis.performance);
@@ -887,7 +913,12 @@ const RANDOM_TRAPS = [{ install: (report) => {
887
913
  globalThis.crypto.randomUUID = real;
888
914
  };
889
915
  } }];
890
- const TRAPS = [...CLOCK_TRAPS, ...RANDOM_TRAPS];
916
+ const PREDICTION_TRAPS = [
917
+ ...WALL_CLOCK_TRAPS,
918
+ ...MONOTONIC_TRAPS,
919
+ ...RANDOM_TRAPS
920
+ ];
921
+ const RENDER_TRAPS = WALL_CLOCK_TRAPS;
891
922
  const warnings = [];
892
923
  const reported = /* @__PURE__ */ new Set();
893
924
  const printWarning = (action, api) => {
@@ -947,7 +978,8 @@ const runPredicted = (action, run) => {
947
978
  /**
948
979
  * `onState` から同期で走る描画を計装する。
949
980
  *
950
- * 乱数は描画で使ってよいので、時刻の罠だけ張る。ここで拾えるのは同期の描画だけで、
981
+ * 張るのは実時刻だけ。乱数は演出に使ってよく、単調時計は `gameTime()` の実装が
982
+ * 使っているので張れない (`MONOTONIC_TRAPS` を見よ)。ここで拾えるのは同期の描画だけで、
951
983
  * `requestAnimationFrame` の中は原理的に拾えない。
952
984
  */
953
985
  const runRendered = (run) => {
@@ -969,7 +1001,7 @@ const runInstrumented = (action, run) => {
969
1001
  printWarning(action, api);
970
1002
  notifyParent(action, api);
971
1003
  };
972
- const restores = (action === RENDER_CONTEXT ? CLOCK_TRAPS : TRAPS).map((trap) => trap.install(report));
1004
+ const restores = (action === RENDER_CONTEXT ? RENDER_TRAPS : PREDICTION_TRAPS).map((trap) => trap.install(report));
973
1005
  try {
974
1006
  run();
975
1007
  } finally {
@@ -2237,4 +2269,4 @@ function calcHudInsets(params) {
2237
2269
  };
2238
2270
  }
2239
2271
  //#endregion
2240
- export { DEFAULT_ICON_URLS, ReconnectableWebSocket, Room, SERVER_TIME, SeededRandomImpl, applyJsonMergePatch, applyJsonPatch, attachDevHooks, changeRoom, createDevHooks, firstFrameReady, gameReady, gameTime, getPredictionWarnings, getRoom, init, isHosted, isPaused, isServerOnlyAction, minus, on, onPauseChange, onPlayersChanged, onRoom, playBgm, playSound, plus, run, send, serverOnly, setMicEnabled, stopBgm, sub, sync };
2272
+ export { DEFAULT_ICON_URLS, GAME_START, ReconnectableWebSocket, Room, SERVER_TIME, SeededRandomImpl, applyJsonMergePatch, applyJsonPatch, attachDevHooks, changeRoom, createDevHooks, firstFrameReady, gameReady, gameTime, getPredictionWarnings, getRoom, init, isHosted, isPaused, isServerOnlyAction, minus, on, onPauseChange, onPlayersChanged, onRoom, playBgm, playSound, plus, run, send, serverOnly, setMicEnabled, stopBgm, sub, sync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uzuhq/code-sdk",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "UZU PlayScreen SDK - Flutter ↔ JS ゲーム通信ライブラリ",
5
5
  "type": "module",
6
6
  "exports": {