mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 15:36:18 +00:00
🆙 Enable back the live previes of the floorplan
This commit is contained in:
@@ -121,9 +121,8 @@ export const useFloorplanLiveSync = (opts: UseFloorplanLiveSyncOptions): UseFloo
|
|||||||
|
|
||||||
const baselineRef = useRef<LivePreviewPayload | null>(null);
|
const baselineRef = useRef<LivePreviewPayload | null>(null);
|
||||||
const lastAppliedRef = useRef<LivePreviewPayload | null>(null);
|
const lastAppliedRef = useRef<LivePreviewPayload | null>(null);
|
||||||
|
const wasEnabledRef = useRef(false);
|
||||||
|
|
||||||
// Destructure first so the memo deps stay precise without
|
|
||||||
// triggering exhaustive-deps on `state` as a whole.
|
|
||||||
const { tiles, door, thickness, wallHeight } = state;
|
const { tiles, door, thickness, wallHeight } = state;
|
||||||
const currentPayload = useMemo<LivePreviewPayload>(() => ({
|
const currentPayload = useMemo<LivePreviewPayload>(() => ({
|
||||||
tilemap: serializeTilemap(tiles),
|
tilemap: serializeTilemap(tiles),
|
||||||
@@ -150,18 +149,22 @@ export const useFloorplanLiveSync = (opts: UseFloorplanLiveSyncOptions): UseFloo
|
|||||||
if(applyToRenderer(baseline, roomId)) lastAppliedRef.current = baseline;
|
if(applyToRenderer(baseline, roomId)) lastAppliedRef.current = baseline;
|
||||||
}, [ roomId ]);
|
}, [ roomId ]);
|
||||||
|
|
||||||
// Apply the current payload to the renderer whenever it
|
|
||||||
// diverges from what's already in the room. Synchronous + no
|
|
||||||
// debounce — the renderer pipeline is fast enough that every
|
|
||||||
// brush stroke can land a paint.
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
if(!enabled) return;
|
if(!enabled)
|
||||||
|
{
|
||||||
|
wasEnabledRef.current = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!baselineRef.current) return;
|
||||||
|
|
||||||
|
const isFirstEnable = !wasEnabledRef.current;
|
||||||
|
wasEnabledRef.current = true;
|
||||||
|
|
||||||
const previous = lastAppliedRef.current;
|
const previous = lastAppliedRef.current;
|
||||||
|
|
||||||
if(previous && livePreviewPayloadsEqual(currentPayload, previous)) return;
|
if(!isFirstEnable && previous && livePreviewPayloadsEqual(currentPayload, previous)) return;
|
||||||
if(!previous && !baselineRef.current) return;
|
|
||||||
|
|
||||||
if(applyToRenderer(currentPayload, roomId)) lastAppliedRef.current = currentPayload;
|
if(applyToRenderer(currentPayload, roomId)) lastAppliedRef.current = currentPayload;
|
||||||
}, [ enabled, currentPayload, roomId ]);
|
}, [ enabled, currentPayload, roomId ]);
|
||||||
|
|||||||
Reference in New Issue
Block a user