@flare-engine/devtools 0.4.10 → 0.4.12
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/dist/index.d.mts +11 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -92,7 +92,10 @@ interface DevtoolsConfig {
|
|
|
92
92
|
ringSize?: number;
|
|
93
93
|
/** Capture every Nth `onUpdate`. Default 1 (every frame). */
|
|
94
94
|
captureInterval?: number;
|
|
95
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Enable devtools on native. Default true. When false on a native platform,
|
|
97
|
+
* `DevtoolsHUD` renders nothing and the provider captures no snapshots. Ignored on web.
|
|
98
|
+
*/
|
|
96
99
|
enabledOnNative?: boolean;
|
|
97
100
|
}
|
|
98
101
|
/** Value exposed via `DevtoolsContext`. */
|
|
@@ -103,6 +106,11 @@ interface DevtoolsContextValue {
|
|
|
103
106
|
scrubber: TimeScrubber<unknown>;
|
|
104
107
|
selectedEntity: number | null;
|
|
105
108
|
select(entity: number | null): void;
|
|
109
|
+
/**
|
|
110
|
+
* False only when the platform is native and the config sets
|
|
111
|
+
* `enabledOnNative: false`. Set by `DevtoolsProvider`; absent means enabled.
|
|
112
|
+
*/
|
|
113
|
+
enabled?: boolean;
|
|
106
114
|
}
|
|
107
115
|
export declare const DevtoolsContext: import("react").Context<DevtoolsContextValue | null>;
|
|
108
116
|
export declare function isDevMode(): boolean;
|
|
@@ -129,7 +137,8 @@ interface TimeScrubView {
|
|
|
129
137
|
export declare function useTimeScrub(): TimeScrubView;
|
|
130
138
|
/**
|
|
131
139
|
* DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume
|
|
132
|
-
* buttons. No-op on web (renders `null`)
|
|
140
|
+
* buttons. No-op on web (renders `null`), and when the provider's config sets
|
|
141
|
+
* `enabledOnNative: false`.
|
|
133
142
|
*/
|
|
134
143
|
export declare function DevtoolsHUD(): ReactNode;
|
|
135
144
|
/**
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;wBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;qBAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;EAEI,YAAA,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;UChGe;;EAEf;;EAEA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;wBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;qBAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;EAEI,YAAA,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;UChGe;;EAEf;;EAEA;;;;;EAKA;;;UAIe;EACf,OAAO;EACP,MAAM;EACN,QAAQ;EACR,UAAU;EACV;EACA,OAAO;;;;;EAKP;;qBAGW,iCAAe,QAAA;wBChCZ;;wBCEA,eAAe;UAQd;EACf;EACA,OAAO;;EAEP;;;wBAIc,sBAAsB;UAOrB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;;;wBAIO,gBAAgB;;;;;;wBC7BhB,eAAe;;;;;wBCDf,iBAAiB;UCAhB,sBAAsB;EACrC,OAAO;EACP,MAAM;;EAEN,UAAU,eAAe;;EAEzB,UAAU,gBAAgB;EAC1B,SAAS;EACT,WAAW;;;;;;;wBAcG,iBAAiB,KAC/B,OACA,MACA,UACA,SACA,QACA,YACC,sBAAsB,KAAK"}
|
package/dist/index.d.ts
CHANGED
|
@@ -92,7 +92,10 @@ interface DevtoolsConfig {
|
|
|
92
92
|
ringSize?: number;
|
|
93
93
|
/** Capture every Nth `onUpdate`. Default 1 (every frame). */
|
|
94
94
|
captureInterval?: number;
|
|
95
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Enable devtools on native. Default true. When false on a native platform,
|
|
97
|
+
* `DevtoolsHUD` renders nothing and the provider captures no snapshots. Ignored on web.
|
|
98
|
+
*/
|
|
96
99
|
enabledOnNative?: boolean;
|
|
97
100
|
}
|
|
98
101
|
/** Value exposed via `DevtoolsContext`. */
|
|
@@ -103,6 +106,11 @@ interface DevtoolsContextValue {
|
|
|
103
106
|
scrubber: TimeScrubber<unknown>;
|
|
104
107
|
selectedEntity: number | null;
|
|
105
108
|
select(entity: number | null): void;
|
|
109
|
+
/**
|
|
110
|
+
* False only when the platform is native and the config sets
|
|
111
|
+
* `enabledOnNative: false`. Set by `DevtoolsProvider`; absent means enabled.
|
|
112
|
+
*/
|
|
113
|
+
enabled?: boolean;
|
|
106
114
|
}
|
|
107
115
|
export declare const DevtoolsContext: import("react").Context<DevtoolsContextValue | null>;
|
|
108
116
|
export declare function isDevMode(): boolean;
|
|
@@ -129,7 +137,8 @@ interface TimeScrubView {
|
|
|
129
137
|
export declare function useTimeScrub(): TimeScrubView;
|
|
130
138
|
/**
|
|
131
139
|
* DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume
|
|
132
|
-
* buttons. No-op on web (renders `null`)
|
|
140
|
+
* buttons. No-op on web (renders `null`), and when the provider's config sets
|
|
141
|
+
* `enabledOnNative: false`.
|
|
133
142
|
*/
|
|
134
143
|
export declare function DevtoolsHUD(): ReactNode;
|
|
135
144
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;wBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;qBAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;EAEI,YAAA,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;UChGe;;EAEf;;EAEA
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;wBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;qBAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;EAEI,YAAA,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;UChGe;;EAEf;;EAEA;;;;;EAKA;;;UAIe;EACf,OAAO;EACP,MAAM;EACN,QAAQ;EACR,UAAU;EACV;EACA,OAAO;;;;;EAKP;;qBAGW,iCAAe,QAAA;wBChCZ;;wBCEA,eAAe;UAQd;EACf;EACA,OAAO;;EAEP;;;wBAIc,sBAAsB;UAOrB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;;;wBAIO,gBAAgB;;;;;;wBC7BhB,eAAe;;;;;wBCDf,iBAAiB;UCAhB,sBAAsB;EACrC,OAAO;EACP,MAAM;;EAEN,UAAU,eAAe;;EAEzB,UAAU,gBAAgB;EAC1B,SAAS;EACT,WAAW;;;;;;;wBAcG,iBAAiB,KAC/B,OACA,MACA,UACA,SACA,QACA,YACC,sBAAsB,KAAK"}
|
package/dist/index.js
CHANGED
|
@@ -44,15 +44,17 @@ function useTimeScrub() {
|
|
|
44
44
|
// src/hud.tsx
|
|
45
45
|
/**
|
|
46
46
|
* DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume
|
|
47
|
-
* buttons. No-op on web (renders `null`)
|
|
47
|
+
* buttons. No-op on web (renders `null`), and when the provider's config sets
|
|
48
|
+
* `enabledOnNative: false`.
|
|
48
49
|
*/
|
|
49
50
|
function DevtoolsHUD() {
|
|
50
51
|
if (react_native.Platform.OS === "web") return null;
|
|
51
52
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HUDBody, {});
|
|
52
53
|
}
|
|
53
54
|
function HUDBody() {
|
|
54
|
-
const { buffer } = useDevtools();
|
|
55
|
+
const { buffer, enabled } = useDevtools();
|
|
55
56
|
const scrub = useTimeScrub();
|
|
57
|
+
if (enabled === false) return null;
|
|
56
58
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
|
|
57
59
|
style: {
|
|
58
60
|
position: "absolute",
|
|
@@ -338,6 +340,7 @@ const DEFAULT_CONFIG = {
|
|
|
338
340
|
function DevtoolsProvider({ world, loop, snapshot, restore, config, children }) {
|
|
339
341
|
const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;
|
|
340
342
|
const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;
|
|
343
|
+
const enabled = react_native.Platform.OS === "web" || (config?.enabledOnNative ?? DEFAULT_CONFIG.enabledOnNative);
|
|
341
344
|
const [selectedEntity, select] = (0, react.useState)(null);
|
|
342
345
|
const snapshotRef = (0, react.useRef)(snapshot);
|
|
343
346
|
snapshotRef.current = snapshot;
|
|
@@ -355,6 +358,7 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
|
|
|
355
358
|
};
|
|
356
359
|
}, [loop, ringSize]);
|
|
357
360
|
(0, react.useEffect)(() => {
|
|
361
|
+
if (!enabled) return;
|
|
358
362
|
let ticks = 0;
|
|
359
363
|
const unsub = loop.onUpdate.add(() => {
|
|
360
364
|
ticks++;
|
|
@@ -366,7 +370,8 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
|
|
|
366
370
|
}, [
|
|
367
371
|
loop,
|
|
368
372
|
buffer,
|
|
369
|
-
captureInterval
|
|
373
|
+
captureInterval,
|
|
374
|
+
enabled
|
|
370
375
|
]);
|
|
371
376
|
const value = {
|
|
372
377
|
world,
|
|
@@ -374,7 +379,8 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
|
|
|
374
379
|
buffer,
|
|
375
380
|
scrubber,
|
|
376
381
|
selectedEntity,
|
|
377
|
-
select
|
|
382
|
+
select,
|
|
383
|
+
enabled
|
|
378
384
|
};
|
|
379
385
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DevtoolsContext.Provider, {
|
|
380
386
|
value,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createContext","useContext","Platform","View","Text","Pressable","Platform","View","Text","Pressable","useState","useRef","useMemo"],"sources":["../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /** Enable the native HUD surface. Default true. */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`).\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer } = useDevtools();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue['scrubber'];\n"],"mappings":";;;;;AA0BA,MAAa,mBAAA,GAAkBA,MAAAA,cAAAA,CAA2C,IAAI;;ACxB9E,SAAgB,YAAqB;CACnC,OAAO,OAAO,YAAY,eAAe,QAAQ,OAAO;AAC1D;;;ACAA,SAAgB,cAAoC;CAClD,MAAM,OAAA,GAAMC,MAAAA,WAAAA,CAAW,eAAe;CACtC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;AAUA,SAAgB,qBAA0C;CACxD,MAAM,EAAE,OAAO,gBAAgB,WAAW,YAAY;CACtD,MAAM,WAAqB,CAAC;CAC5B,MAAM,eAAe,OAAO,SAAS,KAAK,EAAE,CAAC;CAC7C,OAAO;EAAE,UAAU;EAAgB;EAAQ;CAAS;AACtD;;AAaA,SAAgB,eAA8B;CAC5C,MAAM,EAAE,aAAa,YAAY;CACjC,OAAO;EACL,QAAQ,SAAS;EACjB,WAAW,SAAS;EACpB,WAAW,SAAS;EACpB,aAAa,SAAS,MAAM;EAC5B,cAAc,SAAS,OAAO;EAC9B,YAAY,SAAS,KAAK;EAC1B,SAAS,cAAsB;GAC7B,SAAS,OAAO,SAAS;EAC3B;CACF;AACF;;;;;;AC3CA,SAAgB,cAAyB;CACvC,IAAIC,aAAAA,SAAS,OAAO,OAAO,OAAO;CAClC,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD,CAAU,CAAA;AACnB;AAEA,SAAS,UAAqB;CAC5B,MAAM,EAAE,WAAW,YAAY;CAC/B,MAAM,QAAQ,aAAa;CAE3B,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACC,aAAAA,MAAD;EACE,OAAO;GACL,UAAU;GACV,QAAQ;GACR,OAAO;GACP,eAAe;GACf,YAAY;GACZ,SAAS;GACT,iBAAiB;GACjB,cA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,OACA,MACA,UACA,SACA,QACA,YACsC;CACtC,MAAM,WAAW,QAAQ,YAAY,eAAe;CACpD,MAAM,kBAAkB,QAAQ,mBAAmB,eAAe;CAClE,MAAM,CAAC,gBAAgB,WAAA,GAAUE,MAAAA,SAAAA,CAAwB,IAAI;CAI7D,MAAM,eAAA,GAAcC,MAAAA,OAAAA,CAAO,QAAQ;CACnC,YAAY,UAAU;CACtB,MAAM,cAAA,GAAaA,MAAAA,OAAAA,CAAO,OAAO;CACjC,WAAW,UAAU;CAErB,MAAM,EAAE,QAAQ,cAAA,GAAaC,MAAAA,QAAAA,OAAc;EACzC,MAAM,MAAM,yBAA4B,gBAAgB,YAAY,QAAQ,CAAC;EAM7E,OAAO;GAAE,QAAQ;GAAK,UAAU,IALd,aAAgB;IAChC;IACA,QAAQ;IACR,UAAU,MAAS,WAAW,UAAU,CAAC;GAC3C,CACoC;EAAE;CACxC,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,QAAQ;EACZ,MAAM,QAAQ,KAAK,SAAS,UAAU;GACpC;GACA,IAAI,QAAQ,oBAAoB,GAAG,OAAO,QAAQ;EACpD,CAAC;EACD,aAAa;GACX,MAAM;EACR;CACF,GAAG;EAAC;EAAM;EAAQ;CAAe,CAAC;CAElC,MAAM,QAA8B;EAClC;EACA;EACQ;EACE;EACV;EACA;CACF;CAEA,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAgB,UAAjB;EAAiC;EAAQ;CAAmC,CAAA;AACrF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createContext","useContext","Platform","View","Text","Pressable","Platform","View","Text","Pressable","Platform","useState","useRef","useMemo"],"sources":["../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /**\n * Enable devtools on native. Default true. When false on a native platform,\n * `DevtoolsHUD` renders nothing and the provider captures no snapshots. Ignored on web.\n */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n /**\n * False only when the platform is native and the config sets\n * `enabledOnNative: false`. Set by `DevtoolsProvider`; absent means enabled.\n */\n enabled?: boolean;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`), and when the provider's config sets\n * `enabledOnNative: false`.\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer, enabled } = useDevtools();\n const scrub = useTimeScrub();\n if (enabled === false) return null;\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { Platform } from 'react-native';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const enabled =\n Platform.OS === 'web' || (config?.enabledOnNative ?? DEFAULT_CONFIG.enabledOnNative);\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n if (!enabled) return;\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval, enabled]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n enabled,\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue['scrubber'];\n"],"mappings":";;;;;AAkCA,MAAa,mBAAA,GAAkBA,MAAAA,cAAAA,CAA2C,IAAI;;AChC9E,SAAgB,YAAqB;CACnC,OAAO,OAAO,YAAY,eAAe,QAAQ,OAAO;AAC1D;;;ACAA,SAAgB,cAAoC;CAClD,MAAM,OAAA,GAAMC,MAAAA,WAAAA,CAAW,eAAe;CACtC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;A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O;CACjC,WAAW,UAAU;CAErB,MAAM,EAAE,QAAQ,cAAA,GAAaC,MAAAA,QAAAA,OAAc;EACzC,MAAM,MAAM,yBAA4B,gBAAgB,YAAY,QAAQ,CAAC;EAM7E,OAAO;GAAE,QAAQ;GAAK,UAAU,IALd,aAAgB;IAChC;IACA,QAAQ;IACR,UAAU,MAAS,WAAW,UAAU,CAAC;GAC3C,CACoC;EAAE;CACxC,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,CAAC,SAAS;EACd,IAAI,QAAQ;EACZ,MAAM,QAAQ,KAAK,SAAS,UAAU;GACpC;GACA,IAAI,QAAQ,oBAAoB,GAAG,OAAO,QAAQ;EACpD,CAAC;EACD,aAAa;GACX,MAAM;EACR;CACF,GAAG;EAAC;EAAM;EAAQ;EAAiB;CAAO,CAAC;CAE3C,MAAM,QAA8B;EAClC;EACA;EACQ;EACE;EACV;EACA;EACA;CACF;CAEA,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAgB,UAAjB;EAAiC;EAAQ;CAAmC,CAAA;AACrF"}
|
package/dist/index.mjs
CHANGED
|
@@ -43,15 +43,17 @@ function useTimeScrub() {
|
|
|
43
43
|
// src/hud.tsx
|
|
44
44
|
/**
|
|
45
45
|
* DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume
|
|
46
|
-
* buttons. No-op on web (renders `null`)
|
|
46
|
+
* buttons. No-op on web (renders `null`), and when the provider's config sets
|
|
47
|
+
* `enabledOnNative: false`.
|
|
47
48
|
*/
|
|
48
49
|
function DevtoolsHUD() {
|
|
49
50
|
if (Platform.OS === "web") return null;
|
|
50
51
|
return /* @__PURE__ */ jsx(HUDBody, {});
|
|
51
52
|
}
|
|
52
53
|
function HUDBody() {
|
|
53
|
-
const { buffer } = useDevtools();
|
|
54
|
+
const { buffer, enabled } = useDevtools();
|
|
54
55
|
const scrub = useTimeScrub();
|
|
56
|
+
if (enabled === false) return null;
|
|
55
57
|
return /* @__PURE__ */ jsxs(View, {
|
|
56
58
|
style: {
|
|
57
59
|
position: "absolute",
|
|
@@ -337,6 +339,7 @@ const DEFAULT_CONFIG = {
|
|
|
337
339
|
function DevtoolsProvider({ world, loop, snapshot, restore, config, children }) {
|
|
338
340
|
const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;
|
|
339
341
|
const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;
|
|
342
|
+
const enabled = Platform.OS === "web" || (config?.enabledOnNative ?? DEFAULT_CONFIG.enabledOnNative);
|
|
340
343
|
const [selectedEntity, select] = useState(null);
|
|
341
344
|
const snapshotRef = useRef(snapshot);
|
|
342
345
|
snapshotRef.current = snapshot;
|
|
@@ -354,6 +357,7 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
|
|
|
354
357
|
};
|
|
355
358
|
}, [loop, ringSize]);
|
|
356
359
|
useEffect(() => {
|
|
360
|
+
if (!enabled) return;
|
|
357
361
|
let ticks = 0;
|
|
358
362
|
const unsub = loop.onUpdate.add(() => {
|
|
359
363
|
ticks++;
|
|
@@ -365,7 +369,8 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
|
|
|
365
369
|
}, [
|
|
366
370
|
loop,
|
|
367
371
|
buffer,
|
|
368
|
-
captureInterval
|
|
372
|
+
captureInterval,
|
|
373
|
+
enabled
|
|
369
374
|
]);
|
|
370
375
|
const value = {
|
|
371
376
|
world,
|
|
@@ -373,7 +378,8 @@ function DevtoolsProvider({ world, loop, snapshot, restore, config, children })
|
|
|
373
378
|
buffer,
|
|
374
379
|
scrubber,
|
|
375
380
|
selectedEntity,
|
|
376
|
-
select
|
|
381
|
+
select,
|
|
382
|
+
enabled
|
|
377
383
|
};
|
|
378
384
|
return /* @__PURE__ */ jsx(DevtoolsContext.Provider, {
|
|
379
385
|
value,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /** Enable the native HUD surface. Default true. */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`).\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer } = useDevtools();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue['scrubber'];\n"],"mappings":";;;;AA0BA,MAAa,kBAAkB,cAA2C,IAAI;;ACxB9E,SAAgB,YAAqB;CACnC,OAAO,OAAO,YAAY,eAAe,QAAQ,OAAO;AAC1D;;;ACAA,SAAgB,cAAoC;CAClD,MAAM,MAAM,WAAW,eAAe;CACtC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;AAUA,SAAgB,qBAA0C;CACxD,MAAM,EAAE,OAAO,gBAAgB,WAAW,YAAY;CACtD,MAAM,WAAqB,CAAC;CAC5B,MAAM,eAAe,OAAO,SAAS,KAAK,EAAE,CAAC;CAC7C,OAAO;EAAE,UAAU;EA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AAQ,YAAY,eAAe;CACpD,MAAM,kBAAkB,QAAQ,mBAAmB,eAAe;CAClE,MAAM,CAAC,gBAAgB,UAAU,SAAwB,IAAI;CAI7D,MAAM,cAAc,OAAO,QAAQ;CACnC,YAAY,UAAU;CACtB,MAAM,aAAa,OAAO,OAAO;CACjC,WAAW,UAAU;CAErB,MAAM,EAAE,QAAQ,aAAa,cAAc;EACzC,MAAM,MAAM,yBAA4B,gBAAgB,YAAY,QAAQ,CAAC;EAM7E,OAAO;GAAE,QAAQ;GAAK,UAAU,IALd,aAAgB;IAChC;IACA,QAAQ;IACR,UAAU,MAAS,WAAW,UAAU,CAAC;GAC3C,CACoC;EAAE;CACxC,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,gBAAgB;EACd,IAAI,QAAQ;EACZ,MAAM,QAAQ,KAAK,SAAS,UAAU;GACpC;GACA,IAAI,QAAQ,oBAAoB,GAAG,OAAO,QAAQ;EACpD,CAAC;EACD,aAAa;GACX,MAAM;EACR;CACF,GAAG;EAAC;EAAM;EAAQ;CAAe,CAAC;CAElC,MAAM,QAA8B;EAClC;EACA;EACQ;EACE;EACV;EACA;CACF;CAEA,OAAO,oBAAC,gBAAgB,UAAjB;EAAiC;EAAQ;CAAmC,CAAA;AACrF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/ring-buffer.ts","../src/time-scrubber.ts","../src/provider.tsx"],"sourcesContent":["import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { createContext } from 'react';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\nimport type { TimeScrubber } from './time-scrubber.js';\n\n/** Devtools configuration. */\nexport interface DevtoolsConfig {\n /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */\n ringSize?: number;\n /** Capture every Nth `onUpdate`. Default 1 (every frame). */\n captureInterval?: number;\n /**\n * Enable devtools on native. Default true. When false on a native platform,\n * `DevtoolsHUD` renders nothing and the provider captures no snapshots. Ignored on web.\n */\n enabledOnNative?: boolean;\n}\n\n/** Value exposed via `DevtoolsContext`. */\nexport interface DevtoolsContextValue {\n world: World;\n loop: GameLoop;\n buffer: SnapshotRingBuffer<unknown>;\n scrubber: TimeScrubber<unknown>;\n selectedEntity: number | null;\n select(entity: number | null): void;\n /**\n * False only when the platform is native and the config sets\n * `enabledOnNative: false`. Set by `DevtoolsProvider`; absent means enabled.\n */\n enabled?: boolean;\n}\n\nexport const DevtoolsContext = createContext<DevtoolsContextValue | null>(null);\n","declare const __DEV__: boolean | undefined;\n\nexport function isDevMode(): boolean {\n return typeof __DEV__ !== 'undefined' && Boolean(__DEV__);\n}\n","import { useContext } from 'react';\nimport { DevtoolsContext, type DevtoolsContextValue } from './context.js';\n\n/** Returns the active devtools context, or throws if no provider is mounted. */\nexport function useDevtools(): DevtoolsContextValue {\n const ctx = useContext(DevtoolsContext);\n if (!ctx) {\n throw new Error('useDevtools must be used inside a <DevtoolsProvider>');\n }\n return ctx;\n}\n\nexport interface EntityInspectorView {\n selected: number | null;\n select(entity: number | null): void;\n /** Entity IDs present in the world at the moment the hook was read. */\n entities: readonly number[];\n}\n\n/** Entity-inspector hook. Never mutates the world — read-only snapshot. */\nexport function useEntityInspector(): EntityInspectorView {\n const { world, selectedEntity, select } = useDevtools();\n const entities: number[] = [];\n world.forEachEntity((id) => entities.push(id));\n return { selected: selectedEntity, select, entities };\n}\n\nexport interface TimeScrubView {\n paused: boolean;\n scrubbing: boolean;\n available: number;\n pause(): void;\n resume(): void;\n step(): void;\n rewind(framesAgo: number): void;\n}\n\n/** Time-scrub hook — exposes the scrubber's imperative controls. */\nexport function useTimeScrub(): TimeScrubView {\n const { scrubber } = useDevtools();\n return {\n paused: scrubber.paused,\n scrubbing: scrubber.scrubbing,\n available: scrubber.available,\n pause: () => scrubber.pause(),\n resume: () => scrubber.resume(),\n step: () => scrubber.step(),\n rewind: (framesAgo: number) => {\n scrubber.rewind(framesAgo);\n },\n };\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume\n * buttons. No-op on web (renders `null`), and when the provider's config sets\n * `enabledOnNative: false`.\n */\nexport function DevtoolsHUD(): ReactNode {\n if (Platform.OS === 'web') return null;\n return <HUDBody />;\n}\n\nfunction HUDBody(): ReactNode {\n const { buffer, enabled } = useDevtools();\n const scrub = useTimeScrub();\n if (enabled === false) return null;\n\n return (\n <View\n style={{\n position: 'absolute',\n bottom: 16,\n right: 16,\n flexDirection: 'row',\n alignItems: 'center',\n padding: 6,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n }}\n >\n <Text style={{ color: '#fff', marginRight: 8 }}>\n {buffer.length}/{buffer.size}\n </Text>\n <HudButton label=\"||\" onPress={scrub.pause} />\n <HudButton label=\">|\" onPress={scrub.step} />\n <HudButton label=\">\" onPress={scrub.resume} />\n </View>\n );\n}\n\nfunction HudButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginLeft: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","import type { ReactNode } from 'react';\nimport { Platform, Pressable, Text, View } from 'react-native';\nimport { useDevtools, useEntityInspector, useTimeScrub } from './hooks.js';\n\n/**\n * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub\n * controls, and buffer depth. No-op on native (renders `null`).\n */\nexport function DevtoolsPanel(): ReactNode {\n if (Platform.OS !== 'web') return null;\n return <PanelBody />;\n}\n\nfunction PanelBody(): ReactNode {\n const { buffer } = useDevtools();\n const { entities, selected, select } = useEntityInspector();\n const scrub = useTimeScrub();\n\n return (\n <View\n style={{\n position: 'absolute',\n top: 8,\n right: 8,\n padding: 8,\n backgroundColor: 'rgba(0,0,0,0.75)',\n borderRadius: 4,\n minWidth: 200,\n }}\n >\n <Text style={{ color: '#fff', fontWeight: 'bold' }}>Devtools</Text>\n <Text style={{ color: '#ccc' }}>\n buffer {buffer.length}/{buffer.size}\n </Text>\n <Text style={{ color: '#ccc' }}>\n {scrub.paused ? 'paused' : 'running'}\n {scrub.scrubbing ? ' (scrub)' : ''}\n </Text>\n <View style={{ flexDirection: 'row', marginTop: 4 }}>\n <DevButton label=\"Pause\" onPress={scrub.pause} />\n <DevButton label=\"Step\" onPress={scrub.step} />\n <DevButton label=\"Resume\" onPress={scrub.resume} />\n </View>\n <View style={{ marginTop: 8 }}>\n <Text style={{ color: '#fff' }}>entities ({entities.length})</Text>\n {entities.slice(0, 20).map((id) => (\n <Pressable key={id} onPress={() => select(id)}>\n <Text style={{ color: id === selected ? '#ff0' : '#fff' }}>#{id}</Text>\n </Pressable>\n ))}\n </View>\n </View>\n );\n}\n\nfunction DevButton({ label, onPress }: { label: string; onPress: () => void }): ReactNode {\n return (\n <Pressable\n onPress={onPress}\n style={{\n paddingHorizontal: 6,\n paddingVertical: 2,\n marginRight: 4,\n backgroundColor: '#444',\n borderRadius: 2,\n }}\n >\n <Text style={{ color: '#fff' }}>{label}</Text>\n </Pressable>\n );\n}\n","/**\n * Source callback used by `createSnapshotRingBuffer` to produce a snapshot\n * each capture tick. The ring buffer never introspects the snapshot — it is\n * an opaque `T` to this package. A future `World.serialize()` can be passed\n * in directly by consumers.\n */\nexport type SnapshotSource<T> = () => T;\n\n/**\n * Pre-allocated snapshot ring buffer. Slots are allocated once at\n * construction and the `write` cursor walks in place — zero per-frame\n * allocation. `rewind(framesAgo)` returns the snapshot that was `framesAgo`\n * captures back (0 = latest), or `null` if the requested offset exceeds the\n * number of snapshots currently held.\n */\nexport interface SnapshotRingBuffer<T> {\n /** Maximum number of snapshots retained. */\n readonly size: number;\n /** Number of snapshots currently held (0…size). */\n readonly length: number;\n /** Most recent snapshot, or `null` if `length === 0`. */\n readonly latest: T | null;\n /** Capture a new snapshot. Overwrites the oldest slot once full. */\n capture(): void;\n /** Return the snapshot from `framesAgo` captures back, or `null`. */\n rewind(framesAgo: number): T | null;\n /** Drop all retained snapshots. */\n reset(): void;\n}\n\nexport function createSnapshotRingBuffer<T>(\n size: number,\n source: SnapshotSource<T>,\n): SnapshotRingBuffer<T> {\n if (size <= 0 || !Number.isFinite(size)) {\n throw new Error(`SnapshotRingBuffer size must be a positive finite number, got ${size}`);\n }\n const capacity = Math.floor(size);\n const slots: (T | null)[] = new Array(capacity).fill(null);\n let head = 0; // next write index\n let count = 0;\n\n return {\n size: capacity,\n get length(): number {\n return count;\n },\n get latest(): T | null {\n if (count === 0) return null;\n const idx = (head - 1 + capacity) % capacity;\n return slots[idx] ?? null;\n },\n capture(): void {\n slots[head] = source();\n head = (head + 1) % capacity;\n if (count < capacity) count++;\n },\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const offset = Math.floor(framesAgo);\n if (offset >= count) return null;\n const idx = (head - 1 - offset + capacity * 2) % capacity;\n return slots[idx] ?? null;\n },\n reset(): void {\n for (let i = 0; i < capacity; i++) slots[i] = null;\n head = 0;\n count = 0;\n },\n };\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { SnapshotRingBuffer } from './ring-buffer.js';\n\n/**\n * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical\n * snapshot back to world state. Consumers implement deserialize semantics\n * here — the scrubber itself never touches ECS state.\n */\nexport type RestoreCallback<T> = (snapshot: T) => void;\n\nexport interface TimeScrubberOptions<T> {\n loop: GameLoop;\n buffer: SnapshotRingBuffer<T>;\n /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */\n restore?: RestoreCallback<T>;\n}\n\n/**\n * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot\n * ring buffer. Exposes pause / step / resume plus `rewind(framesAgo)` which\n * pauses the loop and hands the historical snapshot to the restore callback.\n */\nexport class TimeScrubber<T> {\n private readonly loop: GameLoop;\n private readonly buffer: SnapshotRingBuffer<T>;\n private readonly restore: RestoreCallback<T> | undefined;\n private _stepRequested = false;\n private _scrubFrames = 0;\n /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */\n private _savedTimescale = 1;\n\n constructor(options: TimeScrubberOptions<T>) {\n this.loop = options.loop;\n this.buffer = options.buffer;\n this.restore = options.restore;\n }\n\n /** Whether the loop is currently paused. */\n get paused(): boolean {\n return this.loop.clock.timescale === 0;\n }\n\n /** Whether the scrubber is currently displaying a historical snapshot. */\n get scrubbing(): boolean {\n return this._scrubFrames > 0;\n }\n\n /** Current scrub offset (0 = latest, N = N frames back). */\n get scrubOffset(): number {\n return this._scrubFrames;\n }\n\n /** Pause the loop (timescale → 0), remembering the running speed.\n * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`\n * while already paused) keeps the first saved value instead of storing 0. */\n pause(): void {\n if (this.loop.clock.timescale !== 0) {\n this._savedTimescale = this.loop.clock.timescale;\n }\n this.loop.clock.timescale = 0;\n }\n\n /** Resume the loop at its pre-pause speed and clear any scrub state.\n * Restores the timescale captured at `pause()` (defaults to 1 if never\n * paused), so resuming an active slow-mo returns to that rate, not 1×. */\n resume(): void {\n this.loop.clock.timescale = this._savedTimescale;\n this._scrubFrames = 0;\n this._stepRequested = false;\n }\n\n /** Request a single-frame step. Caller polls `consumeStep()` each frame. */\n step(): void {\n this._stepRequested = true;\n }\n\n /** Ring-buffer depth available for rewind. */\n get available(): number {\n return this.buffer.length;\n }\n\n /**\n * Pause the loop and restore the snapshot from `framesAgo` captures back.\n * Clamps to available history. Returns the snapshot applied, or `null`\n * when the buffer is empty.\n */\n rewind(framesAgo: number): T | null {\n if (framesAgo < 0 || !Number.isFinite(framesAgo)) return null;\n const max = this.buffer.length - 1;\n if (max < 0) return null;\n const offset = Math.min(Math.floor(framesAgo), max);\n const snap = this.buffer.rewind(offset);\n if (snap === null) return null;\n this.pause();\n this._scrubFrames = offset;\n if (this.restore) this.restore(snap);\n return snap;\n }\n\n /**\n * Returns true once per `step()` call, then resets. Frame-driver code is\n * expected to advance the simulation by one fixed tick when this is true.\n */\n consumeStep(): boolean {\n if (!this._stepRequested) return false;\n this._stepRequested = false;\n return true;\n }\n}\n","import type { GameLoop } from '@flare-engine/core';\nimport type { World } from '@flare-engine/ecs';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';\nimport { Platform } from 'react-native';\nimport { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue } from './context.js';\nimport { createSnapshotRingBuffer, type SnapshotSource } from './ring-buffer.js';\nimport { type RestoreCallback, TimeScrubber } from './time-scrubber.js';\n\nexport interface DevtoolsProviderProps<T = unknown> {\n world: World;\n loop: GameLoop;\n /** Snapshot producer. Called on every capture tick. Must be cheap. */\n snapshot: SnapshotSource<T>;\n /** Optional restore callback for `TimeScrubber.rewind()`. */\n restore?: RestoreCallback<T>;\n config?: DevtoolsConfig;\n children?: ReactNode;\n}\n\nconst DEFAULT_CONFIG: Required<DevtoolsConfig> = {\n ringSize: 120,\n captureInterval: 1,\n enabledOnNative: true,\n};\n\n/**\n * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.\n * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated\n * ring buffer; exposes scrubber controls via `DevtoolsContext`.\n */\nexport function DevtoolsProvider<T>({\n world,\n loop,\n snapshot,\n restore,\n config,\n children,\n}: DevtoolsProviderProps<T>): ReactNode {\n const ringSize = config?.ringSize ?? DEFAULT_CONFIG.ringSize;\n const captureInterval = config?.captureInterval ?? DEFAULT_CONFIG.captureInterval;\n const enabled =\n Platform.OS === 'web' || (config?.enabledOnNative ?? DEFAULT_CONFIG.enabledOnNative);\n const [selectedEntity, select] = useState<number | null>(null);\n\n // Capture snapshot + restore in refs so the buffer/scrubber identity is\n // stable across renders — the live callbacks are read each tick.\n const snapshotRef = useRef(snapshot);\n snapshotRef.current = snapshot;\n const restoreRef = useRef(restore);\n restoreRef.current = restore;\n\n const { buffer, scrubber } = useMemo(() => {\n const buf = createSnapshotRingBuffer<T>(ringSize, () => snapshotRef.current());\n const scrub = new TimeScrubber<T>({\n loop,\n buffer: buf,\n restore: (s: T) => restoreRef.current?.(s),\n });\n return { buffer: buf, scrubber: scrub };\n }, [loop, ringSize]);\n\n useEffect(() => {\n if (!enabled) return;\n let ticks = 0;\n const unsub = loop.onUpdate.add(() => {\n ticks++;\n if (ticks % captureInterval === 0) buffer.capture();\n });\n return () => {\n unsub();\n };\n }, [loop, buffer, captureInterval, enabled]);\n\n const value: DevtoolsContextValue = {\n world,\n loop,\n buffer: buffer as SnapshotRingBufferUnknown,\n scrubber: scrubber as TimeScrubberUnknown,\n selectedEntity,\n select,\n enabled,\n };\n\n return <DevtoolsContext.Provider value={value}>{children}</DevtoolsContext.Provider>;\n}\n\n// Narrow aliases so the context value type stays concrete without exposing the\n// provider's generic parameter in every downstream import.\ntype SnapshotRingBufferUnknown = DevtoolsContextValue['buffer'];\ntype TimeScrubberUnknown = DevtoolsContextValue['scrubber'];\n"],"mappings":";;;;AAkCA,MAAa,kBAAkB,cAA2C,IAAI;;AChC9E,SAAgB,YAAqB;CACnC,OAAO,OAAO,YAAY,eAAe,QAAQ,OAAO;AAC1D;;;ACAA,SAAgB,cAAoC;CAClD,MAAM,MAAM,WAAW,eAAe;CACtC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,sDAAsD;CAExE,OAAO;AACT;;AAUA,SAAgB,qBAA0C;CACxD,MAAM,EAAE,OAAO,gBAAgB,WAAW,YAAY;CACtD,MAAM,WAAqB,CAAC;CAC5B,MAAM,eAAe,OAAO,SAAS,KAAK,EAAE,CAAC;CAC7C,OAAO;EAAE,UAAU;EAAgB;EAAQ;CAAS;AACtD;;AAaA,SAAgB,eAA8B;CAC5C,MAAM,EAAE,aAAa,YAAY;CACjC,OAAO;EACL,QAAQ,SAAS;EACjB,WAA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SAAS,OAAO,UAAU,QAAQ,mBAAmB,eAAe;CACtE,MAAM,CAAC,gBAAgB,UAAU,SAAwB,IAAI;CAI7D,MAAM,cAAc,OAAO,QAAQ;CACnC,YAAY,UAAU;CACtB,MAAM,aAAa,OAAO,OAAO;CACjC,WAAW,UAAU;CAErB,MAAM,EAAE,QAAQ,aAAa,cAAc;EACzC,MAAM,MAAM,yBAA4B,gBAAgB,YAAY,QAAQ,CAAC;EAM7E,OAAO;GAAE,QAAQ;GAAK,UAAU,IALd,aAAgB;IAChC;IACA,QAAQ;IACR,UAAU,MAAS,WAAW,UAAU,CAAC;GAC3C,CACoC;EAAE;CACxC,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,gBAAgB;EACd,IAAI,CAAC,SAAS;EACd,IAAI,QAAQ;EACZ,MAAM,QAAQ,KAAK,SAAS,UAAU;GACpC;GACA,IAAI,QAAQ,oBAAoB,GAAG,OAAO,QAAQ;EACpD,CAAC;EACD,aAAa;GACX,MAAM;EACR;CACF,GAAG;EAAC;EAAM;EAAQ;EAAiB;CAAO,CAAC;CAE3C,MAAM,QAA8B;EAClC;EACA;EACQ;EACE;EACV;EACA;EACA;CACF;CAEA,OAAO,oBAAC,gBAAgB,UAAjB;EAAiC;EAAQ;CAAmC,CAAA;AACrF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/devtools",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
4
4
|
"description": "Devtools partial — entity inspector, time scrub, pause/step",
|
|
5
5
|
"keywords": ["flare-engine", "devtools", "inspector", "debug", "react-native", "typescript"],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@types/react": "^19.3.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@flare-engine/core": "^0.4.
|
|
44
|
-
"@flare-engine/ecs": "^0.4.
|
|
43
|
+
"@flare-engine/core": "^0.4.12",
|
|
44
|
+
"@flare-engine/ecs": "^0.4.12"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=19.0.0",
|