From b0bcda407aa8a7b6ce89d9c5bac9de6349fecc01 Mon Sep 17 00:00:00 2001 From: Orion Reed Date: Mon, 25 Mar 2024 02:34:47 -0700 Subject: [PATCH] fixed physics build bug --- index.html | 4 ++-- package.json | 6 +++--- src/App.tsx | 10 +++++----- src/{ts => }/components/Canvas.tsx | 4 ++-- src/{ts => }/components/Contact.tsx | 0 src/{ts => }/components/Default.tsx | 0 src/{ts => }/components/Toggle.tsx | 2 +- src/css/style.css | 3 ++- src/{ts => }/hooks/usePhysics.ts | 0 src/{ts => }/physics/PhysicsControls.tsx | 0 src/{ts => }/physics/config.ts | 0 src/{ts => }/physics/math.ts | 0 src/{ts => }/physics/simulation.ts | 7 ++----- src/{assets => public}/favicon.ico | Bin .../gravity.svg => public/gravity-button.svg} | 0 src/{ts => }/shapes/HTMLShapeUtil.tsx | 0 vite.config.ts | 4 ++++ 17 files changed, 21 insertions(+), 19 deletions(-) rename src/{ts => }/components/Canvas.tsx (86%) rename src/{ts => }/components/Contact.tsx (100%) rename src/{ts => }/components/Default.tsx (100%) rename src/{ts => }/components/Toggle.tsx (74%) rename src/{ts => }/hooks/usePhysics.ts (100%) rename src/{ts => }/physics/PhysicsControls.tsx (100%) rename src/{ts => }/physics/config.ts (100%) rename src/{ts => }/physics/math.ts (100%) rename src/{ts => }/physics/simulation.ts (98%) rename src/{assets => public}/favicon.ico (100%) rename src/{assets/gravity.svg => public/gravity-button.svg} (100%) rename src/{ts => }/shapes/HTMLShapeUtil.tsx (100%) diff --git a/index.html b/index.html index 1d4d89f..0a02ffe 100644 --- a/index.html +++ b/index.html @@ -4,8 +4,8 @@ Orion Reed - - + + ); diff --git a/src/ts/components/Canvas.tsx b/src/components/Canvas.tsx similarity index 86% rename from src/ts/components/Canvas.tsx rename to src/components/Canvas.tsx index 94fb5f6..ff9362e 100644 --- a/src/ts/components/Canvas.tsx +++ b/src/components/Canvas.tsx @@ -1,6 +1,6 @@ import { Tldraw, TLShape, TLUiComponents } from "@tldraw/tldraw"; -import { SimController } from "@/ts/physics/PhysicsControls"; -import { HTMLShapeUtil } from "@/ts/shapes/HTMLShapeUtil"; +import { SimController } from "@/physics/PhysicsControls"; +import { HTMLShapeUtil } from "@/shapes/HTMLShapeUtil"; const components: TLUiComponents = { HelpMenu: null, diff --git a/src/ts/components/Contact.tsx b/src/components/Contact.tsx similarity index 100% rename from src/ts/components/Contact.tsx rename to src/components/Contact.tsx diff --git a/src/ts/components/Default.tsx b/src/components/Default.tsx similarity index 100% rename from src/ts/components/Default.tsx rename to src/components/Default.tsx diff --git a/src/ts/components/Toggle.tsx b/src/components/Toggle.tsx similarity index 74% rename from src/ts/components/Toggle.tsx rename to src/components/Toggle.tsx index 74f3a0b..af2a9c6 100644 --- a/src/ts/components/Toggle.tsx +++ b/src/components/Toggle.tsx @@ -2,7 +2,7 @@ export function Toggle() { return ( <> ); diff --git a/src/css/style.css b/src/css/style.css index c2f7b2a..9e4c5d0 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -142,7 +142,8 @@ ul { .fade-out { opacity: 0 !important; - transition: opacity 0.2s ease-in-out; + transition: opacity 0.5s ease-in-out; + transition-delay: 0.25s; /* visibility: hidden; */ /* display: none; */ } diff --git a/src/ts/hooks/usePhysics.ts b/src/hooks/usePhysics.ts similarity index 100% rename from src/ts/hooks/usePhysics.ts rename to src/hooks/usePhysics.ts diff --git a/src/ts/physics/PhysicsControls.tsx b/src/physics/PhysicsControls.tsx similarity index 100% rename from src/ts/physics/PhysicsControls.tsx rename to src/physics/PhysicsControls.tsx diff --git a/src/ts/physics/config.ts b/src/physics/config.ts similarity index 100% rename from src/ts/physics/config.ts rename to src/physics/config.ts diff --git a/src/ts/physics/math.ts b/src/physics/math.ts similarity index 100% rename from src/ts/physics/math.ts rename to src/physics/math.ts diff --git a/src/ts/physics/simulation.ts b/src/physics/simulation.ts similarity index 98% rename from src/ts/physics/simulation.ts rename to src/physics/simulation.ts index f73900f..2014f23 100644 --- a/src/ts/physics/simulation.ts +++ b/src/physics/simulation.ts @@ -9,7 +9,7 @@ type BodyWithShapeData = RAPIER.RigidBody & { }; type RigidbodyLookup = { [key: TLShapeId]: RAPIER.RigidBody }; -const START_DELAY = 1500; +const START_DELAY = 500; export class PhysicsWorld { private editor: Editor; @@ -30,7 +30,6 @@ export class PhysicsWorld { public start() { this.world = new RAPIER.World(GRAVITY); - // setTimeout(() => { this.addShapes(this.editor.getCurrentPageShapes()); const simLoop = () => { @@ -41,7 +40,6 @@ export class PhysicsWorld { }; simLoop(); return () => cancelAnimationFrame(this.animFrame); - // }, START_DELAY); }; public stop() { @@ -77,7 +75,6 @@ export class PhysicsWorld { } createShape(shape: TLGeoShape | TLDrawShape) { - console.log('creating shape'); if (!shape.meta.fixed) { const rb = this.createRigidbody(shape, 1); this.createCollider(shape, rb); @@ -383,7 +380,7 @@ export function usePhysicsSimulation(editor: Editor, enabled: boolean) { useEffect(() => { if (enabled) { - sim.current.start(); + setTimeout(() => sim.current.start(), START_DELAY); return () => sim.current.stop(); } }, [enabled, sim]); diff --git a/src/assets/favicon.ico b/src/public/favicon.ico similarity index 100% rename from src/assets/favicon.ico rename to src/public/favicon.ico diff --git a/src/assets/gravity.svg b/src/public/gravity-button.svg similarity index 100% rename from src/assets/gravity.svg rename to src/public/gravity-button.svg diff --git a/src/ts/shapes/HTMLShapeUtil.tsx b/src/shapes/HTMLShapeUtil.tsx similarity index 100% rename from src/ts/shapes/HTMLShapeUtil.tsx rename to src/shapes/HTMLShapeUtil.tsx diff --git a/vite.config.ts b/vite.config.ts index 7450621..9b55a11 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,6 +9,10 @@ export default defineConfig({ wasm(), topLevelAwait() ], + build: { + sourcemap: true, // Enable source maps for production + }, + publicDir: 'src/public', resolve: { alias: { '@': '/src',