Skip to content

Commit

Permalink
🐫🏞️ ↝ [SSM-27]: Updating completed mission component to take more var…
Browse files Browse the repository at this point in the history
…iables into calculation accounts
  • Loading branch information
Gizmotronn committed Oct 17, 2024
1 parent 9d5528f commit 42c58f6
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/api/gameplay/missions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const missions: Mission[] = [
name: 'Research spaceship',
},
{
id: 100000042,
id: 100000042,
name: "Research launchpad",
},
{
Expand Down
2 changes: 1 addition & 1 deletion app/auth/UserProfileFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function ProfileCard() {

fetchProfile();
}, [session]);

const handleFieldChange = (e: { target: { name: any; value: any; }; }) => {
const { name, value } = e.target;
setProfile((prevProfile) => ({
Expand Down
2 changes: 2 additions & 0 deletions app/tests/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { ExoplanetTransitHunter } from "@/components/Projects/Telescopes/Exoplan
import SwitchPlanet from "@/components/(scenes)/travel/SolarSystem";
import { MissionProgressionComponent } from "@/components/Missions/PathwayGuide";
import CompletedMissions from "@/components/Missions/CompletedMissions";
import { UnownedSurfaceStructures } from "@/components/Structures/Build/EditMode";

export default function TestPage() {
return (
<div className="1">
{/* <MissionProgressionComponent /> */}
<UnownedSurfaceStructures />
<CompletedMissions />
</div>
);
Expand Down
108 changes: 74 additions & 34 deletions components/Missions/CompletedMissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import React, { useEffect, useState } from "react";
import { CheckCircle } from "lucide-react";
import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react";
import { AdvancedTechTreeComponent } from "../Structures/Research/TechTree";
import { UnownedSurfaceStructures } from "../Structures/Build/EditMode";
import LaunchpadStatus from "../Structures/Launchpad/LaunchpadStatus";
import SwitchPlanet from "../(scenes)/travel/SolarSystem";
import { DataSourcesModal } from "../Data/unlockNewDataSources";

type Planet = "Earth" | "Mars" | "Mercury" | "New Planet";
type Mission = {
Expand All @@ -15,8 +20,13 @@ type Mission = {
type MissionRoute = {
id: string;
title: string;
routeId: number[];
mission: string;
routeId?: number[];
mission?: string;
researchStructureId?: number;
inventoryStructureId?: number;
route?: string;
infoText?: string;
component?: React.ReactNode;
};

const planetColors: Record<Planet, string> = {
Expand All @@ -35,68 +45,98 @@ const missionsData: Record<PlayStyle, Partial<Record<Planet, MissionRoute[]>>> =
mission: '10000001',
},
{ id: 'pick', title: 'Pick your first classification', routeId: [10000002], mission: '10000002' },
{ id: 'tutorial1', title: "Complete a tutorial for your classification", routeId: [3000001, 3000003, 3000009, 3000002, 3000004, 30000027, 3000005], mission: '3000001',},
{ id: 'research', title: 'Research the launchpad', routeId: [100000042], mission: '100000042'},
{ id: 'owl', title: 'Classify some burrowing owls', routeId: [100000035], mission: '100000035', },
{ id: 'penguin', title: 'Take a look at some penguins', routeId: [200000010], mission: '200000010', },
{ id: 'build', title: 'Build the launchpad', routeId: [100000044], mission: '100000044', },
{ id: 'tutorial1', title: "Complete a tutorial for your classification", routeId: [3000001, 3000003, 3000009, 3000002, 3000004, 30000027, 3000005], mission: '3000001',
infoText: "To complete classifications, return to your planet page and click on the structure icon to review the data", route: "/",},
{
id: 'researchStation', title: "Create a Research Station", component: <UnownedSurfaceStructures />, inventoryStructureId: 3106,
},
{ id: 'research', title: 'Research the launchpad', routeId: [100000042], mission: '100000042', researchStructureId: 3107, component: <AdvancedTechTreeComponent />},
{ id: 'owl', title: 'Classify some burrowing owls', routeId: [100000035], mission: '100000035',
infoText: 'Return to the planet page and use the Zoodex structure to classify burrowing owls', route: "/",
},
{ id: 'penguin', title: 'Take a look at some penguins', routeId: [200000010], mission: '200000010',
infoText: 'Return to the planet page and use the Zoodex structure to classify penguins', route: "/",
},
{ id: 'build', title: 'Build the launchpad', routeId: [100000044], mission: '100000044', inventoryStructureId: 3107, component: <UnownedSurfaceStructures />, },
],
Mars: [
{ id: 'travel', title: 'Travel to Mars', routeId: [400001], mission: '400001', },
{ id: 'fuel', title: 'Collect fuel', routeId: [200000013], mission: '200000013' },
{ id: 'fuels', title: 'Add fuel to your rocket', routeId: [200000014], mission: '200000014', },
{ id: 'telescope', title: 'Build a telescope', routeId: [200000015], mission: '200000015', },
{ id: 'research_ph', title: 'Research the Planet Hunters module', routeId: [200000016], mission: '200000016', },
{ id: 'fuel', title: 'Collect fuel', routeId: [200000013], mission: '200000013', route: "/mining", },
{ id: 'fuels', title: 'Add fuel to your rocket', routeId: [200000014], mission: '200000014', component: <LaunchpadStatus /> },
{ id: 'telescopeResearch', title: 'Research the telescope', routeId: [200000015], mission: '200000015', researchStructureId: 3103, component: <AdvancedTechTreeComponent />, },
{ id: 'telescope', title: 'Build a telescope', routeId: [200000015], mission: '200000015', inventoryStructureId: 3103, component: <UnownedSurfaceStructures />, },
{ id: 'research_ph', title: 'Research the Planet Hunters module', routeId: [200000016], mission: '200000016', component: <DataSourcesModal structureId="3103" structure="Telescope" /> },
],
'New Planet': [
{ id: 'discover', title: 'Discover a new planet', routeId: [30000001], mission: '30000001', },
{ id: 'travel_new', title: 'Travel to the new planet', routeId: [300000012], mission: '300000012', },
{ id: 'discover', title: 'Discover a new planet', routeId: [30000001], mission: '30000001',
infoText: 'Return to the planet page and click on the telescope structure to discover new planets', route: "/",
},
{ id: 'travel_new', title: 'Travel to the new planet', routeId: [300000012], mission: '300000012', component: <SwitchPlanet />, },
],
},
astronomer: {
Earth: [
{ id: 'start', title: 'Start the game', routeId: [10000001], mission: '10000001', },
{ id: 'pick', title: 'Pick your first classification', routeId: [10000002], mission: '10000002', },
{ id: 'tutorial1', title: "Complete a tutorial for your classification", routeId: [3000001, 3000003, 3000009, 3000002, 3000004, 30000027, 3000005], mission: '3000001', },
{ id: 'research', title: 'Research the launchpad', routeId: [100000042], mission: '100000042', },
{ id: 'build', title: 'Build the launchpad', routeId: [100000044], mission: '100000044', },
{ id: 'tutorial1', title: "Complete a tutorial for your classification", routeId: [3000001, 3000003, 3000009, 3000002, 3000004, 30000027, 3000005], mission: '3000001',
infoText: "To complete classifications, return to your planet page and click on the structure icon to review the data", route: "/", },
{
id: 'researchStation', title: "Create a Research Station", component: <UnownedSurfaceStructures />, inventoryStructureId: 3106,
},
{ id: 'research', title: 'Research the launchpad', routeId: [100000042], mission: '100000042', researchStructureId: 3107, component: <AdvancedTechTreeComponent /> },
{ id: 'build', title: 'Build the launchpad', routeId: [100000044], mission: '100000044', inventoryStructureId: 3107, component: <UnownedSurfaceStructures />, },
],
Mars: [
{ id: 'travel', title: 'Travel to Mars', routeId: [400001], mission: '400001', },
{ id: 'telescope', title: 'Build a telescope', routeId: [200000015], mission: '200000015', },
{ id: 'minor_planet', title: 'Complete the Minor Planet classification', routeId: [20000004], mission: '20000004', },
{ id: 'telescopeResearch', title: 'Research the telescope', routeId: [200000015], mission: '200000015', researchStructureId: 3103, component: <AdvancedTechTreeComponent />, },
{ id: 'telescope', title: 'Build a telescope', routeId: [200000015], mission: '200000015', inventoryStructureId: 3103, component: <UnownedSurfaceStructures />, },
{ id: 'minor_planet', title: 'Complete the Minor Planet classification', routeId: [20000004], mission: '20000004',
infoText: "Return to the planet page and click on the telescope structure to discover asteroid anomalies", route: "/",
},
],
Mercury: [
{ id: 'travel_mercury', title: 'Travel to Mercury', routeId: [100001], mission: '100001', },
{ id: 'sunspots', title: 'Discover sunspots', routeId: [3000003], mission: '3000003', },
{ id: 'fuel', title: 'Collect fuel', routeId: [200000013], mission: '200000013', },
{ id: 'research_ph', title: 'Research the Planet Hunters module', routeId: [200000016], mission: '200000016', },
{ id: 'fuel', title: 'Collect fuel', routeId: [200000013], mission: '200000013', route: "/mining", },
{ id: 'fuels', title: 'Add fuel to your rocket', routeId: [200000014], mission: '200000014', component: <LaunchpadStatus /> },
{ id: 'research_ph', title: 'Research the Planet Hunters module', routeId: [200000016], mission: '200000016', component: <DataSourcesModal structureId="3103" structure="Telescope" /> },
],
'New Planet': [
{ id: 'discover', title: 'Discover a new planet', routeId: [30000001], mission: '30000001', },
{ id: 'travel_new', title: 'Travel to the new planet', routeId: [300000012], mission: '300000012', },
{ id: 'discover', title: 'Discover a new planet', routeId: [30000001], mission: '30000001',
infoText: 'Return to the planet page and click on the telescope structure to discover new planets', route: "/",
},
{ id: 'travel_new', title: 'Travel to the new planet', routeId: [300000012], mission: '300000012', component: <SwitchPlanet />, },
],
},
meteorologist: {
Earth: [
{ id: 'start', title: 'Start the game', routeId: [10000001], mission: '10000001', },
{ id: 'pick', title: 'Pick your first classification', routeId: [10000002], mission: '10000002', },
{ id: 'tutorial1', title: "Complete a tutorial for your classification", routeId: [3000001, 3000003, 3000009, 3000002, 3000004, 30000027, 3000005], mission: '3000001'},
{ id: 'research', title: 'Research the launchpad', routeId: [100000042], mission: '100000042', },
{ id: 'build', title: 'Build the launchpad', routeId: [100000044], mission: '100000044', },
{ id: 'tutorial1', title: "Complete a tutorial for your classification", routeId: [3000001, 3000003, 3000009, 3000002, 3000004, 30000027, 3000005], mission: '3000001',
infoText: "To complete classifications, return to your planet page and click on the structure icon to review the data", route: "/"
},
{ id: 'telescope', title: 'Build a LIDAR module', routeId: [200000017], mission: '200000017', },
{ id: 'clouds', title: 'Classify clouds', routeId: [3000010], mission: '3000010', },
{
id: 'researchStation', title: "Create a Research Station", component: <UnownedSurfaceStructures />, inventoryStructureId: 3106,
},
{ id: 'research', title: 'Research the launchpad', routeId: [100000042], mission: '100000042', researchStructureId: 3107, component: <AdvancedTechTreeComponent /> },
{ id: 'build', title: 'Build the launchpad', routeId: [100000044], mission: '100000044', inventoryStructureId: 3107, component: <UnownedSurfaceStructures />, },
],
Mars: [
{ id: 'travel', title: 'Travel to Mars', routeId: [400001], mission: '400001', },
{ id: 'telescope', title: 'Build a LIDAR module', routeId: [200000017], mission: '200000017', },
{ id: 'cloud_data', title: 'Classify some Martian clouds', routeId: [100000034], mission: '100000034', },
{ id: 'fuel', title: 'Collect fuel', routeId: [200000013], mission: '200000013', },
{ id: 'telescope', title: 'Build a telescope', routeId: [200000015], mission: '200000015', },
{ id: 'research_ph', title: 'Research the Planet Hunters module', routeId: [200000016], mission: '200000016', },
{ id: 'fuel', title: 'Collect fuel', routeId: [200000013], mission: '200000013', route: "/mining", },
{ id: 'fuels', title: 'Add fuel to your rocket', routeId: [200000014], mission: '200000014', component: <LaunchpadStatus /> },
{ id: 'telescopeResearch', title: 'Research the telescope', routeId: [200000015], mission: '200000015', researchStructureId: 3103, component: <AdvancedTechTreeComponent />, },
{ id: 'telescope', title: 'Build a telescope', routeId: [200000015], mission: '200000015', inventoryStructureId: 3103, component: <UnownedSurfaceStructures />, },
{ id: 'research_ph', title: 'Research the Planet Hunters module', routeId: [200000016], mission: '200000016', component: <DataSourcesModal structureId="3103" structure="Telescope" /> },
],
'New Planet': [
{ id: 'discover', title: 'Discover a new planet', routeId: [30000001], mission: '30000001', },
{ id: 'travel_new', title: 'Travel to the new planet', routeId: [300000012], mission: '300000012', },
{ id: 'discover', title: 'Discover a new planet', routeId: [30000001], mission: '30000001',
infoText: 'Return to the planet page and click on the telescope structure to discover new planets', route: "/",
},
{ id: 'travel_new', title: 'Travel to the new planet', routeId: [300000012], mission: '300000012', component: <SwitchPlanet />, },
],
},
};
Expand Down Expand Up @@ -159,9 +199,9 @@ export default function CompletedMissions() {
const planetMissions = missionsData[playStyle as PlayStyle][planet as Planet];
if (planetMissions) {
allMissionsList.push(...planetMissions);
}
}
}
};
};
};

setAllMissions(allMissionsList);
fetchCompletedMissions();
Expand Down
39 changes: 39 additions & 0 deletions components/Structures/Launchpad/LaunchpadStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,52 @@ export default function LaunchpadStatus() {
fetchFuel();
}, [session, activePlanet, supabase]);

const [hasMission200000014, setHasMission200000014] = useState<boolean>(false);

useEffect(() => {
const checkMission = async () => {
if (!session) return;

const { data, error } = await supabase
.from("missions")
.select("*")
.eq("user", session.user.id)
.eq("mission", 200000014)
.single();

if (error) {
console.error("Error fetching mission 200000014:", error);
return;
};

setHasMission200000014(!!data);
};

checkMission();
}, [session]);

const handleAddFuel = async () => {
if (!launchpad || fuelAvailable <= 0) return;

setIsAddingFuel(true);

// Define how much fuel to add (for example, 10 units)
const fuelToAdd = Math.min(10, fuelAvailable);
const missionData = {
user: session?.user?.id,
time_of_completion: new Date().toISOString(),
mission: 200000014,
};

if (!hasMission200000014) {
const { error: updateMissionError } = await supabase
.from("missions")
.insert([missionData]);

if (updateMissionError) {
console.error("Error updating mission 200000013: ", updateMissionError);
};
};

try {
// Update the launchpad fuel capacity
Expand Down
52 changes: 47 additions & 5 deletions components/Structures/Mining/Mining.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,38 @@ export function MiningComponentComponent() {

const handleDepositSelect = (deposit: MineralDeposit) => {
setSelectedDeposit(deposit)
}
};

const handleRoverSelect = (rover: Rover) => {
setSelectedRover(rover)
}
};

const [hasMission200000013, setHasMission200000013] = useState(false);

useEffect(() => {
if (!session) return;
const fetchMission = async () => {
try {
const { data, error } = await supabase
.from("missions")
.select("*")
.eq("user", session.user.id)
.eq("mission", 200000013)
.single();

if (error) {
console.error("Error fetching mission 200000013:", error);
return;
};

setHasMission200000013(data !== null);
} catch (error: any) {
console.error("Error fetching mission 200000013: ", error);
};
}

fetchMission();
}, [session]);

const handleStartMining = async () => {
if (selectedDeposit && selectedRover && session) {
Expand Down Expand Up @@ -111,7 +138,6 @@ export function MiningComponentComponent() {
const { mineral, quantity } = selectedDeposit;

try {
// Check if the item already exists in the inventory for the user
const { data: existingItem, error: fetchError } = await supabase
.from('inventory')
.select('*')
Expand All @@ -121,7 +147,23 @@ export function MiningComponentComponent() {

if (fetchError) {
console.error('Error fetching inventory item:', fetchError);
}
};

const missionData = {
user: session?.user?.id,
time_of_completion: new Date().toISOString(),
mission: 200000013,
};

if (!hasMission200000013) {
const { error: updateMissionError } = await supabase
.from("missions")
.insert([missionData]);

if (updateMissionError) {
console.error("Error updating mission 200000013: ", updateMissionError);
};
}

if (existingItem) {
// Update the existing item quantity
Expand Down Expand Up @@ -162,7 +204,7 @@ export function MiningComponentComponent() {
};

requestAnimationFrame(animateRover);
}
};
};

return (
Expand Down
6 changes: 3 additions & 3 deletions components/Structures/Research/TechTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export function AdvancedTechTreeComponent() {
category: 'Automatons' as TechCategory,
requiresMission: automaton.requiresMission || null,
})),
]
];

setTechnologies(combinedTechnologies)
}
};

const fetchUserStructures = async () => {
if (!userId || !activePlanet?.id) return;
Expand All @@ -86,7 +86,7 @@ export function AdvancedTechTreeComponent() {
if (researchError) {
console.error('Error fetching user structures:', researchError);
return;
}
};

console.log('Research Data:', researchData); // Log research data for debugging

Expand Down
2 changes: 1 addition & 1 deletion constants/Structures/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const StructuresConfig: StructureConfig = {
// },
// {
// icon: <BookAudioIcon className="w-6 h-6 text-[#5e81ac]" />,
// text: "My discoveries",
// text: "My discoveries",
// dynamicComponent: <ClassificationViewer classificationType="lidar" />,
// },
],
Expand Down

0 comments on commit 42c58f6

Please sign in to comment.