From ca9fe1138eb1168acd73c7353641e1d375ee1188 Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Mon, 22 Apr 2024 13:20:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=84=F0=9F=91=A9=F0=9F=8F=BB=E2=80=8D?= =?UTF-8?q?=F0=9F=A6=BD=20=E2=86=9D=20[SGV2-21]:=20We=20can=20now=20deploy?= =?UTF-8?q?=20rovers,=20but=20we=20can't=20fetch=20those=20deployments=20a?= =?UTF-8?q?fter=20a=20refresh=20-=20yet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Gameplay/Automatons/BuildRover.tsx | 8 ++- components/Gameplay/Explore/CollectItem.tsx | 64 +++++++++++++------ pages/tests/onboarding.tsx | 10 +-- 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/components/Gameplay/Automatons/BuildRover.tsx b/components/Gameplay/Automatons/BuildRover.tsx index 36e07432..785a3c32 100644 --- a/components/Gameplay/Automatons/BuildRover.tsx +++ b/components/Gameplay/Automatons/BuildRover.tsx @@ -88,7 +88,7 @@ export default function BuildFirstRover() { ); }; -export function ViewRovers() { +export function ViewRovers({ onRoverSelect }: { onRoverSelect?: (rover: any) => void }) { const supabase = useSupabaseClient(); const session = useSession(); @@ -165,8 +165,12 @@ export function ViewRovers() {

{rover.name}

+ {onRoverSelect && ( + + )} ))} ); -}; \ No newline at end of file +}; +; \ No newline at end of file diff --git a/components/Gameplay/Explore/CollectItem.tsx b/components/Gameplay/Explore/CollectItem.tsx index 9f026e86..5c384da2 100644 --- a/components/Gameplay/Explore/CollectItem.tsx +++ b/components/Gameplay/Explore/CollectItem.tsx @@ -7,8 +7,7 @@ export default function CollectItemFromSector() { const session = useSession(); const [userSectors, setUserSectors] = useState([]); - const [selectedSector, setSelectedSector] = useState(null); - const [selectedRover, setSelectedRover] = useState(null); + const [selectedSectorId, setSelectedSectorId] = useState(''); const [timeOfDeploy, setTimeOfDeploy] = useState(null); const [isDeployed, setIsDeployed] = useState(false); const [reward, setReward] = useState(0); @@ -36,27 +35,54 @@ export default function CollectItemFromSector() { } }; - const handleSectorSelect = (sector: any) => { - setSelectedSector(sector); + const handleSectorSelect = (sectorId: string) => { + setSelectedSectorId(sectorId); }; - const handleRoverSelect = (rover: any) => { - setSelectedRover(rover); - }; + const deployRover = async () => { + if (!selectedSectorId) { + console.error("Please select a sector before deploying a rover."); + return; + } + + // Check if the user owns the selected sector + const ownedSector = userSectors.find(sector => sector.id === selectedSectorId); + if (!ownedSector) { + console.error("You don't own the selected sector."); + return; + }; + + try { + // Update inventoryUSERS table + const { data, error } = await supabase + .from("inventoryUSERS") + .update({ + planetSector: selectedSectorId, + time_of_deploy: new Date().toISOString() + }) + .eq("owner", session?.user?.id); + + if (error) { + throw error; + } + + // Set deployment status + setTimeOfDeploy(new Date()); + setIsDeployed(true); + } catch (error) { + console.error("Error deploying rover:", error.message); + }; - const deployRover = () => { - // Set the time of deployment to the current time - setTimeOfDeploy(new Date()); - setIsDeployed(true); + // Update this so that it can pull already deployed rovers }; const calculateReward = () => { - // Calculate the time difference between the current time and the time of deployment + // Calculate the reward based on deployment time if (timeOfDeploy) { const currentTime = new Date(); const timeDifference = currentTime.getTime() - timeOfDeploy.getTime(); // Convert milliseconds to hours - const hoursDeployed = timeDifference / (1000 * 60 * 60); + const hoursDeployed = timeDifference / (1000 * 60 ); // * 60 -> for one hour/item // For now, let's say 1 item per hour setReward(Math.min(Math.floor(hoursDeployed), 6)); } @@ -74,21 +100,19 @@ export default function CollectItemFromSector() {

User Sectors

    {userSectors.map(sector => ( -
  • handleSectorSelect(sector)}> +
  • handleSectorSelect(sector.id)}> {sector.id} - {sector.name} - {sector.deposit}
  • ))}

Selected Sector

- {selectedSector && ( + {selectedSectorId && (
-

ID: {selectedSector.id}

-

Name: {selectedSector.name}

-

Deposit: {selectedSector.deposit}

+

ID: {selectedSectorId}

+ {/* Display other sector details if needed */}
)}

Deploy Rover

-

Reward

{isDeployed && ( @@ -100,4 +124,4 @@ export default function CollectItemFromSector() { )} ); -} \ No newline at end of file +} diff --git a/pages/tests/onboarding.tsx b/pages/tests/onboarding.tsx index 9ff6bf39..7e066f27 100644 --- a/pages/tests/onboarding.tsx +++ b/pages/tests/onboarding.tsx @@ -1,5 +1,6 @@ import BuildFirstRover, { ViewRovers } from "../../components/Gameplay/Automatons/BuildRover"; import { PickYourPlanet } from "../../components/Gameplay/Chapter 1/onboarding"; +import CollectItemFromSector from "../../components/Gameplay/Explore/CollectItem"; import { MissionList } from "../../components/Gameplay/mission-list"; import Layout from "../../components/_Core/Section/Layout"; @@ -24,10 +25,11 @@ export default function OnboardingTest() { } `} - - - - + {/* */} + {/* */} + {/* */} + + {/* */} ); }; \ No newline at end of file