From 745d7109f449e5deb30706e47a6a98791ec7feb7 Mon Sep 17 00:00:00 2001 From: Liam Arbuckle Date: Wed, 22 Nov 2023 19:31:50 +1100 Subject: [PATCH] =?UTF-8?q?=E2=9A=BD=EF=B8=8E=F0=9F=91=A8=F0=9F=8F=BB?= =?UTF-8?q?=E2=80=8D=E2=9C=88=EF=B8=8F=20=E2=86=9D=20Attempting=20to=20cre?= =?UTF-8?q?ate=20sectors=20with=20more=20than=20just=20iron/coal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Planets/Activities/SectorSetup.tsx | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/components/Content/Planets/Activities/SectorSetup.tsx b/components/Content/Planets/Activities/SectorSetup.tsx index cf70a02b..77ec92c8 100644 --- a/components/Content/Planets/Activities/SectorSetup.tsx +++ b/components/Content/Planets/Activities/SectorSetup.tsx @@ -38,23 +38,55 @@ export default function CreateBasePlanetSector() { const createSector = async () => { if (session) { fetchUserPlanet(); + + // Array of available resources + const resources = ["Silicates", "Alloy", "Iron", "Fuel", "Water", "Coal"]; + + // Randomly choose a resource + const chosenResource = resources[Math.floor(Math.random() * resources.length)]; + + // Get the corresponding row from inventoryITEMS + let depositRowId; + if (chosenResource === "Coal") { + depositRowId = 11; // Row ID for Coal + } else if (chosenResource === "Silicates") { + depositRowId = 13; // Row ID for Silicates + } else { + // You can add similar conditions for other resources if needed + // depositRowId = 1; // Default to a row ID (you may want to adjust this) + depositRowId = 13; + } + + // Fetch the corresponding row from inventoryITEMS + const { data: depositData, error: depositError } = await supabase + .from('inventoryITEMS') + .select('name, icon_url') + .eq('id', depositRowId) + .single(); + + if (depositError) { + console.error(depositError); + return; + } + + // Set the deposit and coverUrl based on the chosen resource const response = await supabase.from('basePlanetSectors').upsert([ { anomaly: userPlanet, owner: session?.user?.id, - deposit: "Iron", // Start off with Iron as a default resource - coverUrl: "https://mars.nasa.gov/mars2020-raw-images/pub/ods/surface/sol/00090/ids/edr/browse/edl/EBE_0090_0674952393_193ECM_N0040048EDLC00090_0030LUJ01_1200.jpg", // Do we set this to be a supabase storage asset in prod? + deposit: depositData?.name || "Unknown Resource", + coverUrl: depositData?.icon_url || "https://example.com/default-image.jpg", explored: false, }, ]); - + if (response.error) { console.error(response.error); } else { - - }; - }; - }; + // Handle success if needed + } + } + }; return (