diff --git a/app/api/gameplay/missions/planets/initialisation/route.ts b/app/api/gameplay/missions/planets/initialisation/route.ts
index 5db88cd9..098ea6df 100644
--- a/app/api/gameplay/missions/planets/initialisation/route.ts
+++ b/app/api/gameplay/missions/planets/initialisation/route.ts
@@ -1,5 +1,4 @@
import { NextRequest, NextResponse } from "next/server";
-// import { Mission } from "@/types/Missions";
export interface Mission {
id: number;
@@ -80,6 +79,16 @@ const planetInitialisationMissions: Mission[] = [
name: "Initialise Saturn",
anomaly: 60,
},
+ {
+ id: 600011,
+ name: "Initialise Enceladus",
+ anomaly: 61,
+ },
+ {
+ id: 600021,
+ name: "Initialise Titan",
+ anomaly: 62,
+ },
{
id: 700001,
name: "Initialise Uranus",
diff --git a/app/api/gameplay/missions/route.ts b/app/api/gameplay/missions/route.ts
index b626c1fb..dcf55e71 100644
--- a/app/api/gameplay/missions/route.ts
+++ b/app/api/gameplay/missions/route.ts
@@ -164,7 +164,7 @@ const missions: Mission[] = [
{
id: 100000005,
name: "Pick new planet and travel",
- },
+ }, // Plus planet initialisation missions
// Any resource collection missions...
diff --git a/app/components/(scenes)/planetScene/SwitchPlanet.tsx b/app/components/(scenes)/planetScene/SwitchPlanet.tsx
index 1adfeb38..6ff4d5b2 100644
--- a/app/components/(scenes)/planetScene/SwitchPlanet.tsx
+++ b/app/components/(scenes)/planetScene/SwitchPlanet.tsx
@@ -77,78 +77,78 @@ const planets = [
planetType: 'Arid',
initialisationMissionId: 400001,
},
- // {
- // id: 50,
- // name: "Jupiter",
- // color: "bg-orange-300",
- // stats: { gravity: "24.79 m/s²", temp: "-108°C" },
- // anomaly: 50,
- // planetType: 'Arid',
- // initialisationMissionId: null,
- // },
- // {
- // id: 55,
- // name: "Europa",
- // color: "bg-blue-200",
- // stats: { gravity: "1.31 m/s²", temp: "-160°C" },
- // anomaly: 51,
- // planetType: 'Arid',
- // initialisationMissionId: null,
- // },
- // {
- // id: 52,
- // name: "Io",
- // color: "bg-yellow-400",
- // stats: { gravity: "1.79 m/s²", temp: "-143°C" },
- // anomaly: 52,
- // planetType: 'Arid',
- // initialisationMissionId: null,
- // },
- // {
- // id: 51,
- // name: "Amalthea",
- // color: "bg-red-400",
- // stats: { gravity: "0.026 m/s²", temp: "-113°C" },
- // anomaly: 53,
- // planetType: 'Arid',
- // initialisationMissionId: null,
- // },
- // {
- // id: 60,
- // name: "Saturn",
- // color: "bg-yellow-600",
- // stats: { gravity: "10.44 m/s²", temp: "-139°C" },
- // anomaly: 60,
- // planetType: 'Arid',
- // initialisationMissionId: 600001,
- // },
- // {
- // id: 61,
- // name: "Enceladus",
- // color: "bg-white",
- // stats: { gravity: "0.113 m/s²", temp: "-201°C" },
- // anomaly: 61,
- // planetType: 'Arid',
- // initialisationMissionId: null,
- // },
- // {
- // id: 70,
- // name: "Uranus",
- // color: "bg-cyan-300",
- // stats: { gravity: "8.69 m/s²", temp: "-197°C" },
- // anomaly: 70,
- // planetType: 'Arid',
- // initialisationMissionId: 700001,
- // },
- // {
- // id: 80,
- // name: "Neptune",
- // color: "bg-blue-700",
- // stats: { gravity: "11.15 m/s²", temp: "-214°C" },
- // anomaly: 80,
- // planetType: 'Arid',
- // initialisationMissionId: 800001,
- // },
+ {
+ id: 50,
+ name: "Jupiter",
+ color: "bg-orange-300",
+ stats: { gravity: "24.79 m/s²", temp: "-108°C" },
+ anomaly: 50,
+ planetType: 'Arid',
+ initialisationMissionId: null,
+ },
+ {
+ id: 55,
+ name: "Europa",
+ color: "bg-blue-200",
+ stats: { gravity: "1.31 m/s²", temp: "-160°C" },
+ anomaly: 51,
+ planetType: 'Arid',
+ initialisationMissionId: null,
+ },
+ {
+ id: 52,
+ name: "Io",
+ color: "bg-yellow-400",
+ stats: { gravity: "1.79 m/s²", temp: "-143°C" },
+ anomaly: 52,
+ planetType: 'Arid',
+ initialisationMissionId: null,
+ },
+ {
+ id: 51,
+ name: "Amalthea",
+ color: "bg-red-400",
+ stats: { gravity: "0.026 m/s²", temp: "-113°C" },
+ anomaly: 53,
+ planetType: 'Arid',
+ initialisationMissionId: null,
+ },
+ {
+ id: 60,
+ name: "Saturn",
+ color: "bg-yellow-600",
+ stats: { gravity: "10.44 m/s²", temp: "-139°C" },
+ anomaly: 60,
+ planetType: 'Arid',
+ initialisationMissionId: 600001,
+ },
+ {
+ id: 61,
+ name: "Enceladus",
+ color: "bg-white",
+ stats: { gravity: "0.113 m/s²", temp: "-201°C" },
+ anomaly: 61,
+ planetType: 'Arid',
+ initialisationMissionId: null,
+ },
+ {
+ id: 70,
+ name: "Uranus",
+ color: "bg-cyan-300",
+ stats: { gravity: "8.69 m/s²", temp: "-197°C" },
+ anomaly: 70,
+ planetType: 'Arid',
+ initialisationMissionId: 700001,
+ },
+ {
+ id: 80,
+ name: "Neptune",
+ color: "bg-blue-700",
+ stats: { gravity: "11.15 m/s²", temp: "-214°C" },
+ anomaly: 80,
+ planetType: 'Arid',
+ initialisationMissionId: 800001,
+ },
];
const usePlanetSwitcher = (initialIndex = 0) => {
@@ -273,7 +273,7 @@ export function PlanetSwitcher() {
const moveItemsToNewPlanet = async (newPlanetId: number) => {
if (session?.user?.id) {
- const itemsToMove = [3108, 3107]; // Rocket and Launchpad item IDs
+ const itemsToMove = [3108, 3107];
try {
await Promise.all(
@@ -296,18 +296,29 @@ export function PlanetSwitcher() {
const handlePlanetClick = async (planet: any) => {
if (planet.anomaly !== activePlanet?.id) {
- await moveItemsToNewPlanet(planet.anomaly); // Move items before changing the planet
+ const { error: missonsError } = await supabase
+ .from('missions')
+ .insert([initialisePlanetMissionData]);
+
+ await moveItemsToNewPlanet(planet.anomaly);
updatePlanetLocation(planet.anomaly);
- }
+ };
};
const isVisited = classificationsByPlanet[currentPlanet.anomaly]?.length > 0;
const planetDetails = planetStats?.find((planet) => planet.id === currentPlanet.initialisationMissionId);
+ const initialisationMission = currentPlanet.initialisationMissionId;
+
+ const initialisePlanetMissionData = {
+ user: session?.user.id,
+ time_of_completion: new Date().toISOString(),
+ mission: initialisationMission,
+};
return (
-
+
You haven't visited this planet yet.
)}
- {planetDetails?.planetType ? (
-
- ) : (
-
Planet type information not available.
- )}
{planetDetails?.planetType ? (
) : (
diff --git a/app/components/(scenes)/planetScene/availableMissions.tsx b/app/components/(scenes)/planetScene/availableMissions.tsx
index 4ddd0eda..562f85a3 100644
--- a/app/components/(scenes)/planetScene/availableMissions.tsx
+++ b/app/components/(scenes)/planetScene/availableMissions.tsx
@@ -8,101 +8,190 @@ import {
physicsLabDataSources,
roverDataSources
} from '@/app/components/(structures)/Data/ZoodexDataSources';
+import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react';
+import { useActivePlanet } from '@/context/ActivePlanet';
const filterMissionsByPlanetType = (planetType: string, dataSources: any[]) => {
return dataSources.flatMap((source) => {
const filteredItems = source.items.filter((item: any) =>
item.compatiblePlanetTypes?.includes(planetType)
);
- console.log(`Filtered Items for ${planetType}:`, filteredItems);
return filteredItems;
});
- };
+};
interface MissionListProps {
planetType: string;
-}
+};
const MissionList: React.FC
= ({ planetType }) => {
- const zoodexMissions = filterMissionsByPlanetType(planetType, zoodexDataSources);
- const telescopeMissions = filterMissionsByPlanetType(planetType, telescopeDataSources);
- const lidarMissions = filterMissionsByPlanetType(planetType, lidarDataSources);
- const physicsLabMissions = filterMissionsByPlanetType(planetType, physicsLabDataSources);
- const roverMissions = filterMissionsByPlanetType(planetType, roverDataSources);
+ const supabase = useSupabaseClient();
+ const session = useSession();
+ const { activePlanet } = useActivePlanet();
+
+ const zoodexMissions = filterMissionsByPlanetType(planetType, zoodexDataSources);
+ const telescopeMissions = filterMissionsByPlanetType(planetType, telescopeDataSources);
+ const lidarMissions = filterMissionsByPlanetType(planetType, lidarDataSources);
+ // const physicsLabMissions = filterMissionsByPlanetType(planetType, physicsLabDataSources);
+ // const roverMissions = filterMissionsByPlanetType(planetType, roverDataSources);
- const missionCategories = [
- {
- id: 'zoodex',
- name: 'Zoodex Missions',
- missions: zoodexMissions.map((mission) => ({
- id: mission.id,
- title: mission.name,
- description: mission.description,
- })),
- },
- {
- id: 'telescope',
- name: 'Telescope Missions',
- missions: telescopeMissions.map((mission) => ({
- id: mission.id,
- title: mission.name,
- description: mission.description,
- })),
- },
- {
- id: 'lidar',
- name: 'Lidar Missions',
- missions: lidarMissions.map((mission) => ({
- id: mission.id,
- title: mission.name,
- description: mission.description,
- })),
- },
- {
- id: 'physicsLab',
- name: 'Physics Lab Missions',
- missions: physicsLabMissions.map((mission) => ({
- id: mission.id,
- title: mission.name,
- description: mission.description,
- })),
- },
- {
- id: 'rover',
- name: 'Rover Missions',
- missions: roverMissions.map((mission) => ({
- id: mission.id,
- title: mission.name,
- description: mission.description,
- })),
- },
- ];
+ const missionCategories = [
+ {
+ id: 'zoodex',
+ name: 'Animal Conservation & Tracking',
+ missions: zoodexMissions.map((mission) => ({
+ id: mission.id,
+ title: mission.name,
+ description: mission.description,
+ identifier: mission.identifier,
+ technology: mission.techId,
+ activeStructure: mission.activeStructure,
+ })),
+ },
+ {
+ id: 'telescope',
+ name: 'Space Investigations',
+ missions: telescopeMissions.map((mission) => ({
+ id: mission.id,
+ title: mission.name,
+ description: mission.description,
+ identifier: mission.identifier,
+ technology: mission.techId,
+ activeStructure: mission.activeStructure,
+ })),
+ },
+ {
+ id: 'lidar',
+ name: 'Climate & Meteorology',
+ missions: lidarMissions.map((mission) => ({
+ id: mission.id,
+ title: mission.name,
+ description: mission.description,
+ identifier: mission.identifier,
+ technology: mission.techId,
+ activeStructure: mission.activeStructure,
+ })),
+ },
+ // {
+ // id: 'physicsLab',
+ // name: 'Particle lab',
+ // missions: physicsLabMissions.map((mission) => ({
+ // id: mission.id,
+ // title: mission.name,
+ // description: mission.description,
+ // identifier: mission.identifier,
+ // technology: mission.techId,
+ // activeStructure: mission.activeStructure,
+ // })),
+ // },
+ // {
+ // id: 'rover',
+ // name: 'Surface landmarks',
+ // missions: roverMissions.map((mission) => ({
+ // id: mission.id,
+ // title: mission.name,
+ // description: mission.description,
+ // identifier: mission.identifier,
+ // technology: mission.techId,
+ // activeStructure: mission.activeStructure,
+ // })),
+ // },
+ ];
- return (
-
-
Available Missions
-
- {missionCategories.map((category) =>
- category.missions.length > 0 && (
-
-
{category.name}
-
- {category.missions.map((mission) => (
-
-
{mission.title}
-
{mission.description}
-
- ))}
-
+ const handleTravel = async (mission: any) => {
+ if (!session) {
+ return;
+ };
+
+ const techId = mission.techId || mission.technology;
+
+ if (!techId) {
+ console.error("Missing techId or technology for mission", mission);
+ return;
+ }
+
+ // Ensure mission has an identifier
+ if (!mission.identifier) {
+ console.error("Missing mission identifier", mission);
+ return;
+ }
+
+ // Correctly populate the configuration with the mission's identifier
+ const structureCreationData = {
+ owner: session.user.id,
+ item: mission.activeStructure,
+ quantity: 1,
+ notes: "Created for user's first classification",
+ anomaly: activePlanet?.id || 69,
+ configuration: {
+ "Uses": 10,
+ "missions unlocked": [mission.identifier], // Pass dynamic mission identifier
+ },
+ };
+
+ const initialMissionData = {
+ user: session.user.id,
+ time_of_completion: new Date().toISOString(),
+ mission: mission.id,
+ };
+
+ const researchedStructureData = {
+ user_id: session.user.id,
+ tech_type: mission.activeStructure,
+ tech_id: techId,
+ created_at: new Date().toISOString(),
+ };
+
+ try {
+ // const { error: missionError } = await supabase
+ // .from("missions")
+ // .insert([initialMissionData]);
+
+ // if (missionError) throw missionError;
+
+ const { error: inventoryError } = await supabase
+ .from('inventory')
+ .insert([structureCreationData]);
+
+ if (inventoryError) throw inventoryError;
+
+ const { error: researchedError } = await supabase
+ .from("researched")
+ .insert([researchedStructureData]);
+
+ if (researchedError) throw researchedError;
+
+ } catch (error: any) {
+ console.log("Error adding mission: ", error.message);
+ }
+ };
+
+ return (
+
+
Available Missions
+
+ {missionCategories.map((category) =>
+ category.missions.length > 0 && (
+
+
{category.name}
+
+ {category.missions.map((mission) => (
+
handleTravel(mission)}
+ >
+
{mission.title}
+
{mission.description}
+
+ ))}
+
+
+ )
+ )}
- )
- )}
-
-
- );
+
+ );
};
export default MissionList;
\ No newline at end of file
diff --git a/app/page.tsx b/app/page.tsx
index 7be14316..244f1aff 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -40,28 +40,27 @@ export default function Home() {
console.log(session?.user.id);
})
- // Mapping planet IDs to corresponding views
const planetViews: Record
= {
10: ,
20: ,
69: ,
- 70: ,
- 30: ,
- 31: ,
- 32: ,
- 40: ,
- 41: ,
- 42: ,
- 43: ,
- 50: ,
- 51: ,
- 52: ,
- 60: ,
- 61: ,
- // 70: ,
- 71: ,
- 80: ,
- 90: ,
+ 31: ,
+ 40: ,
+ 41: ,
+ 42: ,
+ 50: ,
+ 52: ,
+ 55: ,
+ 51: ,
+ 60: ,
+ 62: ,
+ 61: ,
+ 70: ,
+ 71: ,
+ 80: ,
+ 81: ,
+ 90: ,
+ // ,
};
if (!session) {
diff --git a/constants/Structures/Properties.tsx b/constants/Structures/Properties.tsx
index b10ca8d6..391ed349 100644
--- a/constants/Structures/Properties.tsx
+++ b/constants/Structures/Properties.tsx
@@ -316,7 +316,7 @@ export const StructuresConfig: StructureConfig = {
text: "Launch a rocket (travel)",
// dynamicComponent: ,
dynamicComponent: ,
- sizePercentage: 40,
+ sizePercentage: 100,
},
]
diff --git a/context/TravelContext.tsx b/context/TravelContext.tsx
new file mode 100644
index 00000000..4205dd2b
--- /dev/null
+++ b/context/TravelContext.tsx
@@ -0,0 +1,82 @@
+import React, { createContext, useContext, useCallback } from 'react';
+import { useSupabaseClient } from '@supabase/auth-helpers-react';
+import { useActivePlanet } from '@/context/ActivePlanet';
+
+interface TravelContextProps {
+ handleTravel: (mission: any, session: any) => Promise;
+};
+
+const TravelContext = createContext(undefined);
+
+export const TravelProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
+ const supabase = useSupabaseClient();
+ const { activePlanet } = useActivePlanet();
+
+ const handleTravel = useCallback(async (mission: any, session: any) => {
+ if (!session) {
+ return;
+ }
+
+ const initialMissionData = {
+ user: session.user.id,
+ time_of_completion: new Date().toISOString(),
+ mission: mission.id,
+ };
+
+ const structureCreationData = {
+ owner: session.user.id,
+ item: mission.activeStructure,
+ quantity: 1,
+ notes: "Created for user's first classification",
+ anomaly: activePlanet?.id || 69,
+ configuration: {
+ "Uses": 10,
+ "missions unlocked": [mission.identifier],
+ },
+ };
+
+ const researchedStructureData = {
+ user_id: session.user.id,
+ tech_type: mission.activeStructure,
+ tech_id: mission.techId,
+ created_at: new Date().toISOString(),
+ };
+
+ try {
+ const { error: missionError } = await supabase
+ .from("missions")
+ .insert([initialMissionData]);
+
+ if (missionError) throw missionError;
+
+ const { error: inventoryError } = await supabase
+ .from('inventory')
+ .insert([structureCreationData]);
+
+ if (inventoryError) throw inventoryError;
+
+ const { error: researchedError } = await supabase
+ .from("researched")
+ .insert([researchedStructureData]);
+
+ if (researchedError) throw researchedError;
+
+ } catch (error: any) {
+ console.log("Error adding mission: ", error.message);
+ }
+ }, [activePlanet, supabase]);
+
+ return (
+
+ {children}
+
+ );
+};
+
+export const useTravel = () => {
+ const context = useContext(TravelContext);
+ if (!context) {
+ throw new Error("useTravel must be used within a TravelProvider");
+ }
+ return context;
+};
\ No newline at end of file