Skip to content

Commit

Permalink
🏜️🍇 ↝ [SSG-96 SSG-123 SSG-124 SSC-83]: Showing user automatons along …
Browse files Browse the repository at this point in the history
…with the pickplanet
  • Loading branch information
Gizmotronn committed Feb 9, 2025
1 parent 9d2f935 commit ffd3033
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 20 deletions.
Binary file modified .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions app/api/gameplay/inventory/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ const inventoryItems: InventoryItem[] = [
itemLevel: 1,
gif: "/assets/Items/Roover.gif", }, // https://cdn.dribbble.com/users/107759/screenshots/4248752/rover.gif

{
id: 24,
name: 'Satellite 1',
description: '',
cost: 1,
icon_url: '/assets/Automatons/Sat.png',
ItemCategory: 'Automaton',
itemLevel: 1,
},


// Structures
{
Expand Down
3 changes: 3 additions & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Onboarding from "./scenes/onboarding/page";
import VerticalToolbar from "@/components/Layout/Toolbar";
import SimpleeMissionGuide from "./tests/singleMissionGuide";
import Navbar from "@/components/Layout/Navbar";
import AllSatellitesOnActivePlanet from "@/components/Structures/Auto/AllSatellites";

export default function Home() {
const session = useSession();
Expand Down Expand Up @@ -54,6 +55,7 @@ export default function Home() {
<div className="w-full">
<div className="py-2">
<center>
<AllSatellitesOnActivePlanet />
<AtmosphereStructuresOnPlanet />
</center>
</div>
Expand Down Expand Up @@ -100,6 +102,7 @@ export default function Home() {
<div className="w-full">
<div className="py-2">
<center>
<AllSatellitesOnActivePlanet />
<AtmosphereStructuresOnPlanet />
</center>
</div>
Expand Down
6 changes: 1 addition & 5 deletions app/tests/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"use client";

import { BasicPopupModal } from "@/components/Layout/Modal";
import PlanetTempCalculator from "@/components/Structures/Missions/Astronomers/PlanetHunters/TemperatureCalc";

export default function TestPage() {

return (
// <StarnetLayout>
<>
<BasicPopupModal />
<PlanetTempCalculator />

</>
// {/* </StarnetLayout> */}
);
Expand Down
73 changes: 68 additions & 5 deletions components/Account/ProfileSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState, type ChangeEvent } from "react";
import Image from "next/image";
import { useRouter } from "next/navigation";
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
import { useActivePlanet } from "@/context/ActivePlanet";

interface ProfileSetupFormProps {
onProfileUpdate: () => void | null;
Expand All @@ -10,7 +11,9 @@ interface ProfileSetupFormProps {
export default function ProfileSetupForm({ onProfileUpdate }: ProfileSetupFormProps) {
const supabase = useSupabaseClient();
const session = useSession();
const router = useRouter();

const { activePlanet } = useActivePlanet();
const router = useRouter();

const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
Expand All @@ -20,6 +23,8 @@ export default function ProfileSetupForm({ onProfileUpdate }: ProfileSetupFormPr
const [avatar, setAvatar] = useState<File | null>(null);
const [avatarPreview, setAvatarPreview] = useState<string | null>(null);

const [inventoryItems, setInventoryItems] = useState<{ item: number }[] | null>(null);

useEffect(() => {
let ignore = false;
async function getProfile() {
Expand All @@ -45,13 +50,32 @@ export default function ProfileSetupForm({ onProfileUpdate }: ProfileSetupFormPr

if (session?.user?.id) {
getProfile();
};
}

return () => {
ignore = true;
};
}, [session, supabase]);

useEffect(() => {
async function fetchInventory() {
if (!session?.user?.id) return;
const { data, error } = await supabase
.from("inventory")
.select("item")
.eq("owner", session?.user?.id)
.in("item", [23, 24]);

if (error) {
console.warn(error);
} else {
setInventoryItems(data);
}
}

fetchInventory();
}, [session, supabase]);

const handleAvatarChange = (e: ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
Expand All @@ -69,11 +93,50 @@ export default function ProfileSetupForm({ onProfileUpdate }: ProfileSetupFormPr
if (!username || !session?.user?.email) {
setError("Username and email are required.");
return;
};
}

setLoading(true);
setError(null);

// Check and add missing items to inventory
if (inventoryItems) {
const userHasItem23 = inventoryItems.some(item => item.item === 23);
const userHasItem24 = inventoryItems.some(item => item.item === 24);

const itemsToAdd = [];

if (!userHasItem23) {
itemsToAdd.push({
item: 23,
owner: session?.user?.id,
anomay: activePlanet?.id,
quantity: 1,
time_of_deploy: new Date(),
});
}

if (!userHasItem24) {
itemsToAdd.push({
item: 24,
owner: session?.user?.id,
anomay: activePlanet?.id,
quantity: 1,
time_of_deploy: new Date(),
});
}

// Insert missing items into the inventory
if (itemsToAdd.length > 0) {
const { error: insertError } = await supabase.from("inventory").insert(itemsToAdd);

if (insertError) {
setError(insertError.message);
setLoading(false);
return;
}
}
}

let avatar_url = avatarPreview;

if (avatar) {
Expand Down Expand Up @@ -106,12 +169,12 @@ export default function ProfileSetupForm({ onProfileUpdate }: ProfileSetupFormPr
if (error) {
alert(error.message);
} else {
router.push("/");
router.push("/");
onProfileUpdate();
}

setLoading(false);
};
}

return (
<div className="min-h-screen flex items-center justify-center bg-[#1D2833] p-4 bg-[url('/game-background.jpg')] bg-cover bg-center">
Expand Down
12 changes: 7 additions & 5 deletions components/Projects/(classifications)/Annotating/Annotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { SciFiPanel } from '@/components/ui/styles/sci-fi/panel';
interface ImageAnnotatorProps {
initialImageUrl: string;
otherAssets?: string[];
anomalyType: string;
anomalyId: string;
missionNumber: number;
assetMentioned: string | string[];
anomalyType?: string;
anomalyId?: string;
missionNumber?: number;
assetMentioned?: string | string[];
structureItemId?: number;
parentPlanetLocation?: string;
annotationType: 'AI4M' | 'P4' | 'PH' | 'CoM' | 'Custom';
Expand Down Expand Up @@ -216,7 +216,8 @@ export default function ImageAnnotator({
)}
{isFormVisible && (
<SciFiPanel className="p-4">
<ClassificationForm
{anomalyId && anomalyType && missionNumber && (
<ClassificationForm
anomalyId={anomalyId}
anomalyType={anomalyType}
missionNumber={missionNumber}
Expand All @@ -229,6 +230,7 @@ export default function ImageAnnotator({
structureItemId={structureItemId}
annotationOptions={annotationOptions}
/>
)}
</SciFiPanel>
)}
</div>
Expand Down
4 changes: 3 additions & 1 deletion components/Projects/(classifications)/FreeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Upload, ChevronRight, Camera, ChevronDown } from 'lucide-react';
import ImageAnnotator from './Annotating/Annotator';

const STRUCTURE_OPTIONS: Record<string, string[]> = {
Telescope: ["Sunspot", "Asteroid", "Planet", "Star", "Nebula", "Crater"],
Expand Down Expand Up @@ -175,7 +176,8 @@ const FreeformUploadData = () => {
<form onSubmit={handleSubmitClassification} className="space-y-4 h-full flex flex-col">
<div className="bg-[#5FCBC3] rounded-lg p-4 h-40 mb-4">
{captureImage && (
<img src={captureImage} alt="Captured" className="w-full h-full object-cover rounded" />
// <img src={captureImage} alt="Captured" className="w-full h-full object-cover rounded" />
<ImageAnnotator initialImageUrl={captureImage} annotationType='Custom' />
)}
</div>
<Input
Expand Down
3 changes: 2 additions & 1 deletion components/Projects/Zoodex/Upload/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Upload, ChevronRight } from "lucide-react";
import ImageAnnotator from '../../(classifications)/Annotating/Annotator';

const CameraComponent = () => {
const supabase = useSupabaseClient();
Expand Down Expand Up @@ -190,7 +191,7 @@ const CameraComponent = () => {
</>
) : (
<form onSubmit={handleSubmitClassification} className="space-y-4">
<img src={captureImage || undefined} alt="Captured" className="w-full h-full object-cover rounded" />
{captureImage && ( <ImageAnnotator initialImageUrl={captureImage} annotationType='Custom' /> )}
<Input
type="text"
placeholder="Add a comment (optional)"
Expand Down
8 changes: 5 additions & 3 deletions components/Structures/Auto/AllAutomatons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ interface InventoryItem {
export default function AllAutomatonsOnActivePlanet() {
const supabase = useSupabaseClient();
const session = useSession();

const { activePlanet } = useActivePlanet();

const [automatons, setAutomatons] = useState<{ id: number; iconUrl: string }[]>([]);
const [inventoryItems, setInventoryItems] = useState<InventoryItem[]>([]);
const [loading, setLoading] = useState(true);

const [isModalVisible, setIsModalVisible] = useState(false);

const handleAutomatonClick = () => {
Expand Down Expand Up @@ -75,7 +77,7 @@ export default function AllAutomatonsOnActivePlanet() {

setAutomatons(automatonsWithIcons);
} catch (error) {
console.error("Error fetching automatons:", error);
console.error("Error fetching automatons: ", error);
} finally {
setLoading(false);
}
Expand Down Expand Up @@ -103,7 +105,7 @@ export default function AllAutomatonsOnActivePlanet() {
))}
</div>

{isModalVisible && (
{/* {isModalVisible && (
<div
className="fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center z-50"
onClick={handleOverlayClick}
Expand All @@ -119,7 +121,7 @@ export default function AllAutomatonsOnActivePlanet() {
<MiningComponentComponent />
</div>
</div>
)}
)} */}
</div>
);
};
Loading

0 comments on commit ffd3033

Please sign in to comment.