Skip to content

Commit 4f24a17

Browse files
committed
⛏️🚚 ↝ [SSG-76 SSG-70 SSG-77 SSP-39]: Mining for 29.11.2024 community expedition
1 parent 702f3ef commit 4f24a17

File tree

5 files changed

+204
-86
lines changed

5 files changed

+204
-86
lines changed

app/scenes/mars/page.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
44
import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react";
55
import { useActivePlanet } from "@/context/ActivePlanet";
66

7-
import { EarthActionSceneLayout, EarthViewLayout } from "@/components/(scenes)/planetScene/layout";
7+
import { EarthActionSceneLayout, EarthViewLayout, MarsActionSceneLayout } from "@/components/(scenes)/planetScene/layout";
88
import InitialisePlanet from "@/components/(scenes)/planetScene/initialisePlanet";
99
import StructuresOnPlanet, { AtmosphereStructuresOnPlanet, OrbitalStructuresOnPlanet } from "@/components/Structures/Structures";
1010
import { InventoryStructureItem } from "@/types/Items";
@@ -55,10 +55,10 @@ export default MarsView;
5555

5656
const MarsStructures: React.FC = () => {
5757
return (
58-
<EarthActionSceneLayout>
59-
<MiningComponentComponent />
60-
<StructureMissionGuide />
61-
</EarthActionSceneLayout>
58+
<MarsActionSceneLayout>
59+
<MiningComponentComponent />
60+
<StructureMissionGuide />
61+
</MarsActionSceneLayout>
6262
// <EarthViewLayout>
6363
// <div className="w-full">
6464
// <div className="flex flex-row space-y-4"></div>

components/(scenes)/planetScene/layout.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,19 @@ export const EarthActionSceneLayout: React.FC<PlanetActionSceneProps> = ({
217217
{children}
218218
</div>
219219
);
220+
};
221+
222+
export const MarsActionSceneLayout: React.FC<PlanetActionSceneProps> = ({
223+
children
224+
}) => {
225+
return (
226+
<div className="relative min-h-screen h-screen w-full flex flex-col">
227+
<img
228+
className="absolute inset-0 w-full h-full object-cover"
229+
src="/assets/Backdrops/View.jpeg"
230+
alt="Mars Background"
231+
/>
232+
{children}
233+
</div>
234+
);
220235
};

components/(scenes)/travel/SolarSystem.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,11 @@ export default function SwitchPlanet() {
583583
</div>
584584
)}
585585

586-
{!missionSelected && (
586+
{/* {!missionSelected && (
587587
<div className="p-4">
588588
<InventoryList anomaly={currentPlanetAnomaly} />
589589
</div>
590-
)}
590+
)} */}
591591
</div>
592592
</motion.div>
593593
)}

components/Inventory/items/ItemsOnPlanet.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const InventoryList = ({ anomaly }: InventoryListProps) => {
7575
return (
7676
<div className="grid grid-cols-3 gap-4">
7777
{filteredItems.length > 0 ? (
78-
filteredItems.map((item) => {
78+
filteredItems.map((item) => {
7979
const apiItem = inventoryItems.find(apiItem => apiItem.id === item.item);
8080
return (
8181
<div key={item.id} className="flex flex-col items-center p-4 border rounded">

components/mining-component.tsx

+181-78
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export function MiningComponentComponent() {
262262
owner: session.user.id,
263263
quantity: minedAmount,
264264
anomaly: activePlanet.id,
265-
configuration: { Uses: 1 },
265+
configuration: { Uses: 1, CommunityExpedition: "1 Mars 29 Nov 2024" },
266266
},
267267
])
268268
.select();
@@ -305,97 +305,200 @@ export function MiningComponentComponent() {
305305
}
306306
};
307307

308-
return (
309-
<div className="relative h-screen w-full overflow-hidden bg-gray-100 text-[#2C4F64] flex flex-col">
310-
<div className="flex justify-between items-center p-4">
311-
<h2 className="text-2xl font-bold">Mining Operations</h2>
312-
<Button
313-
onClick={toggleMap}
314-
variant="outline"
315-
className="text-[#ffffff] hover:bg-[#5FCBC3]/20"
316-
>
317-
Switch to {activeMap === '2D' ? '3D' : '2D'} Map
318-
</Button>
319-
</div>
320-
<div className="flex-grow flex flex-col md:flex-row overflow-hidden">
321-
<div className="w-full md:w-3/4 h-1/2 md:h-full relative">
322-
{activeMap === '2D' ? (
323-
<TopographicMap
324-
deposits={mineralDeposits}
325-
roverPosition={roverPosition}
326-
selectedDeposit={selectedDeposit}
327-
landmarks={landmarks}
328-
onLandmarkClick={handleLandmarkClick}
329-
onDepositSelect={handleDepositSelect}
330-
/>
331-
) : (
332-
<TerrainMap
333-
deposits={mineralDeposits}
334-
roverPosition={roverPosition}
335-
selectedDeposit={selectedDeposit}
336-
landmarks={landmarks}
337-
onLandmarkClick={handleLandmarkClick}
338-
/>
339-
)}
340-
</div>
341-
<div className="w-full md:w-1/4 h-1/2 md:h-full overflow-y-auto bg-white bg-opacity-90 p-4">
342-
<div className="space-y-4">
343-
{selectedDeposit ? (
344-
<div>
345-
<h3 className="text-lg font-semibold mb-2">Selected Deposit: {selectedDeposit.name}</h3>
346-
<p>Amount: {selectedDeposit.amount} units</p>
347-
<Button
348-
onClick={handleStartMining}
349-
disabled={isMining}
350-
className="w-full mt-4"
351-
>
352-
{isMining ? 'Mining...' : 'Start Mining'}
353-
</Button>
308+
return (
309+
<div className="fixed inset-0 flex items-center justify-center bg-gray-900 bg-opacity-50 z-50">
310+
<div className="relative w-[90%] h-[90%] bg-gray-100 text-[#2C4F64] flex flex-col rounded-lg overflow-hidden md:w-[90%] md:h-[90%] sm:w-full sm:h-full">
311+
<div className="flex justify-between items-center p-4 bg-white shadow">
312+
<h2 className="text-2xl font-bold">Mining Operations</h2>
313+
<Button
314+
onClick={toggleMap}
315+
variant="outline"
316+
className="text-[#ffffff] hover:bg-[#5FCBC3]/20"
317+
>
318+
Switch to {activeMap === '2D' ? '3D' : '2D'} Map
319+
</Button>
320+
</div>
321+
<div className="flex-grow flex flex-col md:flex-row overflow-hidden">
322+
<div className="w-full md:w-3/4 h-1/2 md:h-full relative">
323+
{activeMap === '2D' ? (
324+
<TopographicMap
325+
deposits={mineralDeposits}
326+
roverPosition={roverPosition}
327+
selectedDeposit={selectedDeposit}
328+
landmarks={landmarks}
329+
onLandmarkClick={handleLandmarkClick}
330+
onDepositSelect={handleDepositSelect}
331+
/>
332+
) : (
333+
<TerrainMap
334+
deposits={mineralDeposits}
335+
roverPosition={roverPosition}
336+
selectedDeposit={selectedDeposit}
337+
landmarks={landmarks}
338+
onLandmarkClick={handleLandmarkClick}
339+
/>
340+
)}
341+
</div>
342+
<div className="w-full md:w-1/4 h-1/2 md:h-full overflow-y-auto bg-white bg-opacity-90 p-4">
343+
<div className="space-y-4">
344+
{selectedDeposit ? (
345+
<div>
346+
<h3 className="text-lg font-semibold mb-2">Selected Deposit</h3>
347+
<p>{selectedDeposit.name}</p>
348+
<Button
349+
onClick={handleStartMining}
350+
className="mt-2 bg-green-500 hover:bg-green-600 text-white"
351+
>
352+
Start Mining
353+
</Button>
354+
</div>
355+
) : (
356+
<p className="text-gray-500">Select a deposit to start mining.</p>
357+
)}
354358
</div>
355-
) : (
359+
<div>
356360
<MineralDepositList
357361
deposits={mineralDeposits}
358362
onSelect={handleDepositSelect}
359363
selectedDeposit={selectedDeposit}
360364
/>
361-
)}
365+
<MineralDepositsGenerator />
366+
</div>
367+
<Inventory />
368+
</div>
362369
</div>
370+
{activeLandmark && (
371+
<div
372+
className="absolute inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50"
373+
onClick={closeModal}
374+
>
375+
<div
376+
className="bg-white rounded-lg p-4 max-w-md w-full"
377+
onClick={(e) => e.stopPropagation()}
378+
>
379+
<h3 className="text-xl font-bold">{activeLandmark.name}</h3>
380+
<p>{activeLandmark.description}</p>
381+
<Button
382+
onClick={closeModal}
383+
className="mt-4 bg-red-500 hover:bg-red-600 text-white"
384+
>
385+
Close
386+
</Button>
387+
</div>
388+
</div>
389+
)}
363390
</div>
364391
</div>
365-
<div className="bg-white bg-opacity-90 p-4 border-t border-gray-200">
366-
<Inventory />
367-
</div>
368-
{activeLandmark && (
369-
<LandmarkModal
370-
landmark={activeLandmark}
371-
isOpen={activeLandmark.isOpen}
372-
onClose={closeModal}
373-
/>
374-
)}
375-
</div>
376-
);
392+
);
377393
};
378394

379-
type LandmarkModalProps = {
380-
landmark: Landmark | null;
381-
isOpen: boolean;
382-
onClose: () => void;
383-
};
395+
// type LandmarkModalProps = {
396+
// landmark: Landmark | null;
397+
// isOpen: boolean;
398+
// onClose: () => void;
399+
// };
400+
401+
// const LandmarkModal: React.FC<LandmarkModalProps> = ({ landmark, isOpen, onClose }) => {
402+
// if (!isOpen || !landmark) return null;
403+
404+
// return (
405+
// <div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
406+
// <div className="bg-white rounded-lg shadow-lg max-w-md w-full p-6 relative">
407+
// <button
408+
// className="absolute top-3 right-3 text-gray-500 hover:text-gray-800"
409+
// onClick={onClose}
410+
// >
411+
// &times;
412+
// </button>
413+
// <h2 className="text-2xl font-bold mb-2">{landmark.name}</h2>
414+
// <p className="text-gray-700">{landmark.description}</p>
415+
// </div>
416+
// </div>
417+
// );
418+
// };
419+
420+
const MineralDepositsGenerator: React.FC = () => {
421+
const supabase = useSupabaseClient();
422+
const session = useSession();
423+
const { activePlanet } = useActivePlanet();
424+
425+
const [classificationsCount, setClassificationsCount] = useState(0);
426+
const [creatingDeposits, setCreatingDeposits] = useState(false);
427+
const [mineralDeposits, setMineralDeposits] = useState<any[]>([]); // Track created deposits
428+
const [notification, setNotification] = useState<string | null>(null);
429+
430+
const availableMinerals = [11, 13, 15, 16, 18, 19];
431+
432+
useEffect(() => {
433+
const fetchClassifications = async () => {
434+
if (!session?.user?.id || !activePlanet?.id) {
435+
console.error("User or activePlanet is undefined.");
436+
return;
437+
}
438+
const { data: classifications, error } = await supabase
439+
.from('classifications')
440+
.select('*')
441+
.eq('user', session.user.id)
442+
.eq('planet_id', activePlanet.id);
443+
444+
if (error) {
445+
console.error("Error fetching classifications:", error);
446+
} else {
447+
console.log("Fetched classifications:", classifications);
448+
// Make sure to set the classifications state correctly
449+
}
450+
};
451+
fetchClassifications();
452+
}, [session, activePlanet, supabase]);
453+
454+
const handleCreateDeposits = async () => {
455+
if (!session?.user?.id || !activePlanet?.id) {
456+
console.error("User or activePlanet is undefined.");
457+
return;
458+
}
459+
460+
// Randomly pick a mineral ID from availableMinerals
461+
const randomMineral = availableMinerals[Math.floor(Math.random() * availableMinerals.length)];
462+
463+
const newDeposit = {
464+
mineralconfiguration: {
465+
mineral: randomMineral, // Use the mineral ID (number)
466+
quantity: 100,
467+
icon_url: `https://example.com/mineral-icon-${randomMineral}.png`, // Assuming different icons for each mineral
468+
level: 1,
469+
uses: ['Mining', 'Excavation'],
470+
position: { x: Math.random() * 100, y: Math.random() * 100 } // Random position
471+
},
472+
owner: session.user.id,
473+
anomaly: activePlanet.id,
474+
};
475+
476+
const { data, error } = await supabase
477+
.from('mineralDeposits')
478+
.insert([newDeposit])
479+
.select();
480+
481+
if (error) {
482+
console.error("Error creating deposit:", error);
483+
return;
484+
}
384485

385-
const LandmarkModal: React.FC<LandmarkModalProps> = ({ landmark, isOpen, onClose }) => {
386-
if (!isOpen || !landmark) return null;
486+
console.log("Created new deposit:", data);
487+
// Optionally, update the local state to reflect the new deposit
488+
setMineralDeposits(prevDeposits => [
489+
...prevDeposits,
490+
{ ...newDeposit.mineralconfiguration, id: data[0].id }
491+
]);
492+
};
387493

388494
return (
389-
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
390-
<div className="bg-white rounded-lg shadow-lg max-w-md w-full p-6 relative">
391-
<button
392-
className="absolute top-3 right-3 text-gray-500 hover:text-gray-800"
393-
onClick={onClose}
394-
>
395-
&times;
396-
</button>
397-
<h2 className="text-2xl font-bold mb-2">{landmark.name}</h2>
398-
<p className="text-gray-700">{landmark.description}</p>
495+
<div className="mineral-deposits-container">
496+
<div className="content">
497+
<h2>Create Mineral Deposits</h2>
498+
<p>You have {classificationsCount} classifications. You can create up to 3 mineral deposits.</p>
499+
<Button onClick={handleCreateDeposits} disabled={creatingDeposits}>
500+
{creatingDeposits ? 'Creating...' : 'Create Deposits'}
501+
</Button>
399502
</div>
400503
</div>
401504
);

0 commit comments

Comments
 (0)