diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 59c2ba2..098953e 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -3,12 +3,11 @@ name: Main Pipeline on: push: branches: [ main ] - pull_request: - branches: [ main ] jobs: - test-and-build: + deploy: runs-on: ubuntu-latest + steps: - uses: actions/checkout@v5 @@ -22,34 +21,18 @@ jobs: run: npm install - name: Generate Prisma Client - env: - DATABASE_URL: sqlite://./dummy.db run: npx prisma generate --schema=server/prisma/schema.prisma - name: Lint run: npm run lint - - name: Build - env: - DATABASE_URL: sqlite://./dummy.db + - name: Build Application run: npm run build - deploy: - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - needs: test-and-build - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v5 - - - name: Setup Node.js - uses: actions/setup-node@v5 + - name: Connect to Tailscale + uses: tailscale/github-action@v3 with: - node-version: '24' - cache: 'npm' - - - name: Install dependencies - run: npm install + authkey: ${{ secrets.TAILSCALE_AUTH_KEY }} - name: Validate Secrets run: | @@ -57,13 +40,6 @@ jobs: if [ -z "${{ secrets.REMOTE_USER }}" ]; then echo "Error: REMOTE_USER secret is missing"; exit 1; fi if [ -z "${{ secrets.SSH_PRIVATE_KEY }}" ]; then echo "Error: SSH_PRIVATE_KEY secret is missing"; exit 1; fi - - name: Build Application - env: - DATABASE_URL: sqlite://./dummy.db - run: | - npx prisma generate --schema=server/prisma/schema.prisma - npm run build - - name: Deploy via rsync env: SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }} @@ -86,17 +62,18 @@ jobs: --exclude 'logs/' \ --exclude '*.log' \ ./ $REMOTE_USER@$REMOTE_HOST:~/SigiLife/ - rm deploy_key.pem - + - name: Restart Application - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.REMOTE_HOST }} - username: ${{ secrets.REMOTE_USER }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - script: | + env: + SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + REMOTE_HOST: ${{ secrets.REMOTE_HOST }} + REMOTE_USER: ${{ secrets.REMOTE_USER }} + run: | + ssh -i deploy_key.pem -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST << 'EOF' cd ~/SigiLife npm install npx prisma migrate deploy --schema=server/prisma/schema.prisma npx prisma generate --schema=server/prisma/schema.prisma pm2 restart sigilife || pm2 start ecosystem.config.cjs --env production + EOF + rm deploy_key.pem \ No newline at end of file diff --git a/server/prisma/migrations/20260413050231_add_tutorial_field/migration.sql b/server/prisma/migrations/20260413050231_add_tutorial_field/migration.sql new file mode 100644 index 0000000..248f3f2 --- /dev/null +++ b/server/prisma/migrations/20260413050231_add_tutorial_field/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE `users` ADD COLUMN `hasCompletedTutorial` BOOLEAN NOT NULL DEFAULT false; diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index b43443f..7005546 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -1,6 +1,6 @@ generator client { -provider = "prisma-client-ts" -output = "./generated" + provider = "prisma-client-ts" + output = "./generated" } datasource db { @@ -8,43 +8,45 @@ datasource db { } model User { -id Int @id @default(autoincrement()) -username String? @unique @db.VarChar(100) -email String @unique @db.VarChar(255) -name String? @db.VarChar(255) -picture String? @db.VarChar(500) -googleId String? @unique @db.VarChar(255) -avatar Int @default(0) -theme Int @default(1) -color_theme String @default("cyber") @db.VarChar(50) -isAdmin Boolean @default(false) -createdAt DateTime @default(now()) -updatedAt DateTime @updatedAt -homeLocation String? @db.VarChar(500) -hasCompletedTutorial Boolean @default(false) -sigils Sigil[] -following Follow[] @relation("follower") -followers Follow[] @relation("following") + id Int @id @default(autoincrement()) + username String? @unique @db.VarChar(100) + email String @unique @db.VarChar(255) + name String? @db.VarChar(255) + picture String? @db.VarChar(500) + googleId String? @unique @db.VarChar(255) + avatar Int @default(0) + theme Int @default(1) + color_theme String @default("cyber") @db.VarChar(50) + isAdmin Boolean @default(false) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + homeLocation String? @db.VarChar(500) + hasCompletedTutorial Boolean @default(false) + sigils Sigil[] + following Follow[] @relation("follower") + followers Follow[] @relation("following") + arPlacement ArPlacement? - @@map("users") + @@map("users") } model Sigil { -id Int @id @default(autoincrement()) -name String @db.VarChar(100) -userId Int -intention String? @db.Text -canvasData String? @db.LongText -imageData String? @db.LongText -isCharged Boolean @default(false) -locationName String? @db.VarChar(200) -latitude Decimal? @db.Decimal(10, 8) -longitude Decimal? @db.Decimal(11, 8) -createdAt DateTime @default(now()) -sigilGroups SigilGroup[] -user User @relation(fields: [userId], references: [id], onDelete: Cascade) + id Int @id @default(autoincrement()) + name String @db.VarChar(100) + userId Int + intention String? @db.Text + canvasData String? @db.LongText + imageData String? @db.LongText + isCharged Boolean @default(false) + locationName String? @db.VarChar(200) + latitude Decimal? @db.Decimal(10, 8) + longitude Decimal? @db.Decimal(11, 8) + createdAt DateTime @default(now()) + sigilGroups SigilGroup[] + arPlacement ArPlacement? + user User @relation(fields: [userId], references: [id], onDelete: Cascade) - @@map("sigils") + @@map("sigils") } model Follow { @@ -53,38 +55,57 @@ model Follow { followingId Int createdAt DateTime @default(now()) - follower User @relation("follower", fields: [followerId], references: [id], onDelete: Cascade) // ← add - following User @relation("following", fields: [followingId], references: [id], onDelete: Cascade) // ← add + follower User @relation("follower", fields: [followerId], references: [id], onDelete: Cascade) + following User @relation("following", fields: [followingId], references: [id], onDelete: Cascade) @@unique([followerId, followingId]) + @@map("follows") } - - model SigilGroup { -id Int @id @default(autoincrement()) -sigilId Int -groupMember String @db.VarChar(100) -sigil Sigil @relation(fields: [sigilId], references: [id], onDelete: Cascade) + id Int @id @default(autoincrement()) + sigilId Int + groupMember String @db.VarChar(100) + sigil Sigil @relation(fields: [sigilId], references: [id], onDelete: Cascade) -@@index([sigilId], map: "sigil_groups_sigilId_fkey") -@@map("sigil_groups") + @@index([sigilId]) + @@map("sigil_groups") } model SvgVector { -id Int @id @default(autoincrement()) -sigilId Int? @map("sigil_id") -filename String @db.Text -vectorData String @map("vector_data") @db.Text -width Int -height Int -fileSize Int @map("file_size") -createdAt DateTime @default(now()) - @@map("svg_vectors") + id Int @id @default(autoincrement()) + sigilId Int? @map("sigil_id") + filename String @db.Text + vectorData String @map("vector_data") @db.Text + width Int + height Int + fileSize Int @map("file_size") + createdAt DateTime @default(now()) + @@map("svg_vectors") } model sessions { -session_id String @id @db.VarChar(128) -expires Int @db.UnsignedInt -data String? @db.MediumText + session_id String @id @db.VarChar(128) + expires Int @db.UnsignedInt + data String? @db.MediumText + @@map("sessions") +} + +model ArPlacement { + id Int @id @default(autoincrement()) + userId Int @unique + sigilId Int @unique + posX Decimal @db.Decimal(10, 5) + posY Decimal @db.Decimal(10, 5) + posZ Decimal @db.Decimal(10, 5) + rotationX Decimal @db.Decimal(10, 5) + rotationY Decimal @db.Decimal(10, 5) + rotationZ Decimal @db.Decimal(10, 5) + rotationW Decimal @db.Decimal(10, 5) + createdAt DateTime @default(now()) + + sigil Sigil @relation(fields: [sigilId], references: [id], onDelete: Cascade) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) + + @@map("ar_placements") } diff --git a/src/App.tsx b/src/App.tsx index 7cc4a6e..0444bb6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,7 @@ import { useUser } from '@/context/UserContext'; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Landing Page & Log in import ProtectedRoute from './components/LogInAuth/ProtectedRoute' import LandingPage from './components/LogInAuth/LandingPage' +import CreateProfile from './components/LogInAuth/CreateProfile' //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ User @@ -67,6 +68,7 @@ console.log('App render - isLoading:', isLoading, 'path:', window.location.pathn {/* Auth flow */} } /> } /> + } /> {/* User */} } /> diff --git a/src/components/LogInAuth/CreateProfile.tsx b/src/components/LogInAuth/CreateProfile.tsx new file mode 100644 index 0000000..a2a891a --- /dev/null +++ b/src/components/LogInAuth/CreateProfile.tsx @@ -0,0 +1,92 @@ +import { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import * as SwitchPrimitive from "@radix-ui/react-switch"; +import { useUser } from '@/context/UserContext'; +import MapSearchBox from '@/components/SigilRoomHome/Grimoire/LeftPage/Map/MapSearchBox'; + +export default function CreateProfile() { + const { user, setUser } = useUser(); + const navigate = useNavigate(); + const [username, setUsername] = useState(''); + const [avatar, setAvatar] = useState('0'); + const [homeLocation, setHomeLocation] = useState(''); + const [isDark, setIsDark] = useState(false); + + const handleCreate = async () => { + if (!user) return; + try { + const res = await fetch(`/api/users/${user.id}`, { + method: "PATCH", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + username, + avatar: parseInt(avatar), + theme: isDark ? 1 : 0, + homeLocation + }) + }); + const updated = await res.json(); + setUser(updated); + navigate('/make-sigil/write'); + } catch (err) { + console.error(err); + } + }; + + const handleThemeChange = (checked: boolean) => { + setIsDark(checked); + document.documentElement.classList.toggle("dark", checked); + }; + + return ( +
+
+
+

Create Your Profile:

+ + + + + + + + + +
+
+
+ ); +} diff --git a/src/components/LogInAuth/GoogleAuth.tsx b/src/components/LogInAuth/GoogleAuth.tsx index 926f12d..952520b 100644 --- a/src/components/LogInAuth/GoogleAuth.tsx +++ b/src/components/LogInAuth/GoogleAuth.tsx @@ -9,19 +9,11 @@ declare global { } } -export default function GoogleAuth({ formData, isNewUser = false }: { formData: any, isNewUser?: boolean }) { +export default function GoogleAuth() { const { setUser } = useUser(); const navigate = useNavigate(); const initialized = useRef(false); - const formDataRef = useRef(formData); - const buttonId = isNewUser ? 'google-signin-button-new' : 'google-signin-button'; - - - - - useEffect(() => { - formDataRef.current = formData; - }, [formData]); + const buttonId = 'google-signin-button'; useEffect(() => { console.log('[GoogleAuth] Mounted. Checking for window.google'); @@ -31,7 +23,6 @@ export default function GoogleAuth({ formData, isNewUser = false }: { formData: try { const payload = { credential: response.credential, - ...formDataRef.current }; console.log('[GoogleAuth] Sending login data to backend:', { ...payload, credential: 'HIDDEN' }); @@ -50,15 +41,12 @@ export default function GoogleAuth({ formData, isNewUser = false }: { formData: const data = await res.json(); console.log('[GoogleAuth] Backend response successful:', data.success); - setUser(data.user); setTimeout(() => { if (data.needsProfile) { - navigate('/login'); - } else if (isNewUser) { - navigate('/make-sigil/write'); + navigate('/create-profile'); } else { - navigate('/home'); + navigate('/home'); } }, 300); } catch (error) { diff --git a/src/components/LogInAuth/LandingPage.tsx b/src/components/LogInAuth/LandingPage.tsx index 511061a..9d7c7cd 100644 --- a/src/components/LogInAuth/LandingPage.tsx +++ b/src/components/LogInAuth/LandingPage.tsx @@ -2,9 +2,7 @@ import { useState, useEffect, useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import SigiLifeLogo from '../../assets/SigilifeLogo.svg'; import GoogleAuth from './GoogleAuth'; -import MapSearchBox from '@/components/SigilRoomHome/Grimoire/LeftPage/Map/MapSearchBox'; import { useUser } from '@/context/UserContext'; -import * as SwitchPrimitive from "@radix-ui/react-switch" import { Carousel, CarouselContent, @@ -14,41 +12,26 @@ import { type CarouselApi, } from "@/components/ui/carousel" - export default function LandingPage() { - const { user, isLoading, setUser } = useUser(); + const { user, isLoading } = useUser(); const navigate = useNavigate(); - const [username, setUsername] = useState(''); - const [avatar, setAvatar] = useState('0'); - const [homeLocation, setHomeLocation] = useState(''); - const [isNewUser, setIsNewUser] = useState(false); - const [isDark, setIsDark] = useState(false) const [carouselApi, setCarouselApi] = useState(); - const handleSlideClick = useCallback(() => { carouselApi?.scrollNext(); }, [carouselApi]); - - const handleThemeChange = (checked: boolean) => { - setIsDark(checked) - document.documentElement.classList.toggle("dark", checked) - if (!user) return - fetch(`/api/users/${user!.id}`, { - method: "PATCH", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ theme: checked ? 1 : 0 }) - }) - .then(res => res.json()) - .then(updated => setUser(updated)) - } - useEffect(() => { if (!isLoading && user) { - navigate('/home'); + const needsProfile = !user.username || user.avatar === null || user.theme === null || !user.homeLocation; + if (needsProfile) { + navigate('/create-profile'); + } else { + navigate('/home'); + } } - }, [user, isLoading]); + }, [user, isLoading, navigate]); + useEffect(() => { if (!carouselApi) return; @@ -59,7 +42,6 @@ export default function LandingPage() { return () => clearInterval(interval) }, [carouselApi]); - const slides = [ <>Mark your intent.
Leave a trace.

Nothing disappears without a ritual., <>SigiLife is a map of hidden intentions:

yours and everyone else's., @@ -81,9 +63,7 @@ export default function LandingPage() { return ( <>
-
- {!isNewUser && ( <> Sigil-Life-Logo
@@ -105,66 +85,12 @@ export default function LandingPage() {
- )} - {isNewUser && ( -
-

Create Your Profile:

- - - - - - - +
+
- )} - - -
- - {!isNewUser && ( - - )}
-
-
- -); + + ); } \ No newline at end of file diff --git a/src/components/SigilRoomHome/Grimoire/LeftPage/Map/PlaceSigilInWorld.tsx b/src/components/SigilRoomHome/Grimoire/LeftPage/Map/PlaceSigilInWorld.tsx index ef73926..986a196 100644 --- a/src/components/SigilRoomHome/Grimoire/LeftPage/Map/PlaceSigilInWorld.tsx +++ b/src/components/SigilRoomHome/Grimoire/LeftPage/Map/PlaceSigilInWorld.tsx @@ -107,9 +107,18 @@ export default function PlaceSigilInWorld() { textureLoader.load(sigilData.imageData, (texture: any) => { sigilMaterial.map = texture; sigilMaterial.needsUpdate = true; + + // Apply charge visual effect if sigil is charged + if (sigilData.isCharged) { + sigilMaterial.color.setHex(0x00ffcc); // Cyan color for charged sigils + } }); } else { sigilMaterial.color.setHex(0xc70eff); + // Apply charge visual effect if sigil is charged (fallback) + if (sigilData?.isCharged) { + sigilMaterial.color.setHex(0x00ffcc); // Cyan color for charged sigils + } } // Setup Pointcloud visualizer @@ -141,12 +150,21 @@ export default function PlaceSigilInWorld() { // debugDiv.style.padding = '10px'; // document.body.appendChild(debugDiv); + let targetPosition = new THREE.Vector3(); + let targetQuaternion = new THREE.Quaternion(); + let lastRefineFrame = 0; + const REFINE_INTERVAL_FRAMES = 60; // Refine anchor every 1s (at 60fps) + const getOrCreateMesh = () => { if (!placedSigilMesh) { const geometry = new THREE.PlaneGeometry(1, 1); placedSigilMesh = new THREE.Mesh(geometry, sigilMaterial); scene.add(placedSigilMesh); setIsPlaced(true); + + // Initialize targets to current position/rotation on first placement + targetPosition.copy(placedSigilMesh.position); + targetQuaternion.copy(placedSigilMesh.quaternion); } return placedSigilMesh; }; @@ -175,15 +193,18 @@ export default function PlaceSigilInWorld() { const mesh = getOrCreateMesh(); if (intersection) { - mesh.position.copy(intersection); + targetPosition.copy(intersection); } else { - mesh.position.copy(planeCenter); // Absolute fallback + targetPosition.copy(planeCenter); // Absolute fallback } // Rotate to face the camera (billboard toward viewer) - mesh.lookAt(camPos); + const lookAtMatrix = new THREE.Matrix4(); + lookAtMatrix.lookAt(targetPosition, camPos, new THREE.Vector3(0, 1, 0)); + targetQuaternion.setFromRotationMatrix(lookAtMatrix); + setStatus("Sigil Placed!"); - console.log(`[AR] Placed via raycast fallback at (${mesh.position.x.toFixed(2)}, ${mesh.position.y.toFixed(2)})`); + console.log(`[AR] Placed via raycast fallback at (${targetPosition.x.toFixed(2)}, ${targetPosition.y.toFixed(2)})`); }; const handleTap = (e: TouchEvent | MouseEvent) => { @@ -211,25 +232,27 @@ export default function PlaceSigilInWorld() { let slamSucceeded = false; try { if (XR8.XrController && XR8.XrController.hitTest) { + // Prioritize DETECTED_SURFACE and ESTIMATED_SURFACE for better stability const hitTestResults = XR8.XrController.hitTest( - tapX, tapY, ['FEATURE_POINT', 'ESTIMATED_SURFACE', 'DETECTED_SURFACE'] + tapX, tapY, ['DETECTED_SURFACE', 'ESTIMATED_SURFACE', 'FEATURE_POINT'] ); - console.log("[AR] hitTest results:", hitTestResults); + if (hitTestResults && hitTestResults.length > 0) { const hit = hitTestResults[0]; - const mesh = getOrCreateMesh(); - mesh.position.set(hit.position.x, hit.position.y, hit.position.z); + getOrCreateMesh(); + + targetPosition.set(hit.position.x, hit.position.y, hit.position.z); if (hit.rotation) { - mesh.quaternion.set( + targetQuaternion.set( hit.rotation.x, hit.rotation.y, hit.rotation.z, hit.rotation.w ); } else { - mesh.rotation.x = -Math.PI / 2; // default: flat on floor + // Default to flat on floor (X-axis rotation) + targetQuaternion.setFromAxisAngle(new THREE.Vector3(1, 0, 0), -Math.PI / 2); } + setStatus("Sigil Anchored!"); slamSucceeded = true; - } else { - console.log("[AR] hitTest returned no results, using fallback."); } } } catch (err: any) { @@ -257,24 +280,46 @@ export default function PlaceSigilInWorld() { } } + const { camera } = XR8.Threejs.xrScene(); + + // Apply Smoothing (Lerp/Slerp) if sigil is placed + if (placedSigilMesh && isPlaced) { + const SMOOTHING_FACTOR = 0.15; // Adjust this: lower = smoother/slower, higher = snappier/jitterier + placedSigilMesh.position.lerp(targetPosition, SMOOTHING_FACTOR); + placedSigilMesh.quaternion.slerp(targetQuaternion, SMOOTHING_FACTOR); + + // Periodic Anchor Refinement: + // This re-runs a hit test at the sigil's screen position to "cling" to the moving points. + if (frameCount % REFINE_INTERVAL_FRAMES === 0 && XR8.XrController && XR8.XrController.hitTest) { + try { + // Project the current 3D position back to screen space (0 to 1) + const vector = targetPosition.clone(); + vector.project(camera); + const screenX = (vector.x + 1) / 2; + const screenY = -(vector.y - 1) / 2; + + // Re-run hit test at that screen coordinate + const results = XR8.XrController.hitTest(screenX, screenY, ['DETECTED_SURFACE', 'ESTIMATED_SURFACE']); + if (results && results.length > 0) { + const hit = results[0]; + // Slowly nudge the target towards the refined surface position + const refineLerp = 0.5; // Weight of the new refinement + targetPosition.x = targetPosition.x * (1 - refineLerp) + hit.position.x * refineLerp; + targetPosition.y = targetPosition.y * (1 - refineLerp) + hit.position.y * refineLerp; + targetPosition.z = targetPosition.z * (1 - refineLerp) + hit.position.z * refineLerp; + } + } catch (err) { + // Silently ignore hit test failures during refinement + } + } + } + // Update the point cloud visualization if data is available if (pointCloudMesh && pointCloudGeom && e.processCpuResult && e.processCpuResult.reality) { const reality = e.processCpuResult.reality; // Support multiple legacy naming conventions const pc = reality.pointCloud || reality.worldPoints; - // const debugDiv = document.getElementById('slam-debug-info'); - // if (debugDiv) { - // const keys = Object.keys(reality).join(', '); - // const type = pc ? (typeof pc[0] === 'number' ? 'Float32Array' : 'ObjectArray') : 'N/A'; - // const length = pc ? pc.length : 0; - // debugDiv.innerHTML = ` - // Reality Keys:
${keys}
- // PC Type: ${type}
- // PC Length: ${length} - // `; - // } - if (pc && pc.length > 0) { const positions = pointCloudGeom.attributes.position.array as Float32Array; diff --git a/src/components/SigilRoomHome/HomeRoom.tsx b/src/components/SigilRoomHome/HomeRoom.tsx index 10c32ac..921ab77 100644 --- a/src/components/SigilRoomHome/HomeRoom.tsx +++ b/src/components/SigilRoomHome/HomeRoom.tsx @@ -40,6 +40,7 @@ export default function HomeRoom() {