Skip to content

Commit

Permalink
🥉🦣 ↝ [SSG-32 SSG-31 SSC-17]: Fixing some bugs & improved mining scene…
Browse files Browse the repository at this point in the history
… w/ new inventory area
  • Loading branch information
Gizmotronn committed Oct 8, 2024
1 parent 55ec8c8 commit f432c4a
Show file tree
Hide file tree
Showing 22 changed files with 711 additions and 25 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/api/gameplay/missions/archive/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { MineralDepositsNoAction } from "@/components/(structures)/Mining/AvailableDeposits";
import { MineralDepositsNoAction } from "@/components/(structures)/Mining/Archive/AvailableDeposits";

interface UserMissionInstance {
id: number;
Expand Down
2 changes: 1 addition & 1 deletion app/api/gameplay/missions/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { MineralDepositsNoAction } from "@/components/(structures)/Mining/AvailableDeposits";
import { MineralDepositsNoAction } from "@/components/(structures)/Mining/Archive/AvailableDeposits";

export interface Mission {
id: number;
Expand Down
4 changes: 2 additions & 2 deletions app/auth/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function SupabaseAuthWrapper({ children }: { children: ReactNode }) {
{/* <Navbar /> */}
<div className="flex flex-col md:flex-row min-h-screen">
{/* Left Panel */}
<div className="md:w-1/2 w-full flex flex-col justify-center items-center bg-[#2C3A4A] p-10">
<div className="md:w-1/2 w-full flex flex-col justify-center items-center bg-gray-100 p-10">
<div className="w-full h-full relative">
<Image
src="https://qwbufbmxkjfaikoloudl.supabase.co/storage/v1/object/public/media/garden.png"
Expand All @@ -90,7 +90,7 @@ function SupabaseAuthWrapper({ children }: { children: ReactNode }) {
</Flexbox>
<p className="max-w-[600px] text-muted-foreground md:text-xl">Explore the cosmos & catalogue discoveries in different scientific disciplines</p>
<div className="max-w-md w-full mx-auto py-5">
<div className="bg-[#2C3A4A] p-8 rounded-lg shadow-lg">
<div className="bg-gray-100 p-8 rounded-lg shadow-lg">
{children}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/scenes/mining/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import React, { useState } from "react";
import { useActivePlanet } from "@/context/ActivePlanet";
import MineralDeposits from "@/components/(structures)/Mining/AvailableDeposits";
import { SelectMineralPanel } from "@/components/(structures)/Mining/MiningPanels";
import MineralDeposits from "@/components/(structures)/Mining/Archive/AvailableDeposits";
import { SelectMineralPanel } from "@/components/(structures)/Mining/Archive/MiningPanels";
import MineralsInventoryGrid from "@/components/(inventory)/mineralsPanel";

enum Step {
Expand Down
2 changes: 2 additions & 0 deletions app/tests/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use client";

import { MiningComponentComponent } from "@/components/(structures)/Mining/Mining";
import React from "react";

export default function TestPage() {
return (
<div>
<MiningComponentComponent />
</div>
);
};
2 changes: 1 addition & 1 deletion components/(dialogue)/helpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function TutorialPopup() {
};

return (
<div className="bg=[#2C3A4A]">
<div className="bg-[#2C3A4A]">
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
<Button size="icon" className="fixed bottom-4 bg-red-800 right-4 rounded-full">
Expand Down
1 change: 0 additions & 1 deletion components/(structures)/Auto/ActiveAutomaton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export function ActiveAutomatonForMining({

const mineralName = deposit.mineralconfiguration.mineral;

// Check if the power level is sufficient for mining water-ice
if (mineralName === "water" && powerLevel < 2) {
setErrorMessage(
"This automaton requires a Power level of 2 or greater to mine water. Please upgrade your automaton."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client";
"use client";

import React, { useEffect, useState } from 'react';
import { useActivePlanet } from '@/context/ActivePlanet';
Expand Down Expand Up @@ -51,9 +51,11 @@ const fetchInventoryItems = async (): Promise<InventoryItem[]> => {
};

const MineralDeposits: React.FC<{ onSelectDeposit: (deposit: MineralDepositData) => void }> = ({ onSelectDeposit }) => {
const { activePlanet } = useActivePlanet();
const session = useSession();
const supabase = useSupabaseClient();

const { activePlanet } = useActivePlanet();

const [mineralDeposits, setMineralDeposits] = useState<MineralDepositData[]>([]);
const [inventoryItems, setInventoryItems] = useState<InventoryItem[]>([]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import React, { useState, useEffect } from "react";
import { MineralDeposit } from "@/types/Items";
import { ActiveAutomatonForMining } from "../Auto/ActiveAutomaton";
import { ActiveAutomatonForMining } from "../../Auto/ActiveAutomaton";
import MineralDeposits from "./AvailableDeposits";
import MineralsInventoryGrid from "../../(inventory)/mineralsPanel";
import MineralsInventoryGrid from "../../../(inventory)/mineralsPanel";

interface CollectMineralPanelProps {
deposit: MineralDeposit;
}
};

interface InventoryItem {
id: number;
Expand All @@ -19,7 +19,7 @@ interface InventoryItem {
ItemCategory: string;
parentItem: number | null;
itemLevel: number;
}
};

export const SelectMineralPanel: React.FC<CollectMineralPanelProps> = ({ deposit }) => {
const [showAutomatonPanel, setShowAutomatonPanel] = useState(false);
Expand Down
173 changes: 173 additions & 0 deletions components/(structures)/Mining/ControlPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { useState, useEffect } from 'react'
import { Button } from "@/components/ui/button"
import { Truck } from 'lucide-react'
import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react'
import { useActivePlanet } from '@/context/ActivePlanet'

type Rover = {
id: string
name: string
speed: number
efficiency: number
miningLevel: number
}

type Props = {
rovers: Rover[]
selectedRover: Rover | null
onRoverSelect: (rover: Rover) => void
onStartMining: () => void
isMining: boolean
}

export function ControlPanel({ rovers = [], selectedRover, onRoverSelect, onStartMining, isMining }: Props) {
const [speed, setSpeed] = useState(10)
const [efficiency, setEfficiency] = useState(0.8)
const [miningLevel, setMiningLevel] = useState(1)

useEffect(() => {
if (selectedRover) {
setSpeed(selectedRover.speed)
setEfficiency(selectedRover.efficiency)
setMiningLevel(selectedRover.miningLevel)
}
}, [selectedRover])

const handleRoverSelect = (rover: Rover) => {
onRoverSelect(rover)
}

return (
<div className="h-full flex flex-col">
<h2 className="text-xl font-bold text-[#2C4F64] mb-4">Control Panel</h2>
<div className="overflow-y-auto flex-grow pr-2">
<div className="mb-4">
<h3 className="font-bold mb-2">Select Rover</h3>
<div className="grid grid-cols-2 gap-2">
{rovers.map(rover => (
<div
key={rover.id}
className={`p-2 rounded-lg cursor-pointer ${selectedRover?.id === rover.id ? 'bg-[#5FCBC3] text-white' : 'bg-gray-100'}`}
onClick={() => handleRoverSelect(rover)}
>
<div className="flex items-center space-x-2">
<Truck className="text-[#FFE3BA]" />
<span className="font-bold">{rover.name}</span>
</div>
</div>
))}
</div>
</div>

{selectedRover && (
<div className="space-y-4 mt-4">
<h3 className="font-bold mb-2">Customize Rover</h3>
<div>
<label className="block text-sm font-medium text-[#2C4F64]">Speed</label>
<input
type="range"
min={1}
max={20}
value={speed}
onChange={(e) => setSpeed(Number(e.target.value))}
className="my-2 w-full"
/>
<span className="text-sm text-[#2C4F64]">{speed}</span>
</div>
<div>
<label className="block text-sm font-medium text-[#2C4F64]">Efficiency</label>
<input
type="range"
min={0}
max={100}
value={efficiency * 100}
onChange={(e) => setEfficiency(Number(e.target.value) / 100)}
className="my-2 w-full"
/>
<span className="text-sm text-[#2C4F64]">{(efficiency * 100).toFixed(0)}%</span>
</div>
<div>
<label className="block text-sm font-medium text-[#2C4F64]">Mining Level</label>
<input
type="range"
min={1}
max={5}
value={miningLevel}
onChange={(e) => setMiningLevel(Number(e.target.value))}
className="my-2 w-full"
/>
<span className="text-sm text-[#2C4F64]">{miningLevel}</span>
</div>
</div>
)}

<AddMineralDeposits />

<Button
onClick={onStartMining}
disabled={isMining || !selectedRover}
className="w-full mt-4 bg-[#5FCBC3] text-white hover:bg-[#5FCBC3]/80"
>
{isMining ? 'Mining...' : 'Start Mining'}
</Button>
</div>
</div>
);
};



// test

function AddMineralDeposits() {
const supabase = useSupabaseClient();
const session = useSession();

const { activePlanet } = useActivePlanet();

const [isLoading, setIsLoading] = useState(false);
const mineral = 19;

const handleAddDeposits = async () => {
setIsLoading(true);

try {
const deposits = Array.from({ length: 3 }, () => ({
anomaly: activePlanet.id ? Number(activePlanet.id) : null,
owner: session?.user.id,
mineralconfiguration: {
mineral: mineral,
quantity: Math.floor(Math.random() * 100) + 1,
},
}));

const { data, error } = await supabase
.from("mineralDeposits")
.insert(deposits);

if (error) {
console.error("Error inserting mineral deposits: ", error.message);
throw error;
};

console.log("Mineral deposits added:", data);
} catch (error) {
console.error("Error adding mineral deposits:", error);
} finally {
setIsLoading(false);
};
};

return (
<div className="flex flex-col space-y-4 p-4 bg-gray-100 rounded-lg shadow">
<h3 className="font-bold text-[#2C4F64]">Add Mineral Deposits</h3>
<Button
onClick={handleAddDeposits}
disabled={isLoading}
className="bg-[#5FCBC3] text-white hover:bg-[#5FCBC3]/80"
>
{isLoading ? 'Adding...' : 'Add 3 Deposits'}
</Button>
</div>
);
};
54 changes: 54 additions & 0 deletions components/(structures)/Mining/Deposits.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use client";

import React from "react";
import { Diamond } from "lucide-react";

export type MineralDeposit = {
id: string;
mineral: string;
quantity: number;
availableAmount: number;
level: number;
uses: string[];
position: { x: number; y: number };
};

type Props = {
deposits: MineralDeposit[];
onSelect: (deposit: MineralDeposit) => void;
selectedDeposit: MineralDeposit | null;
};

export function MineralDepositList({ deposits, onSelect, selectedDeposit }: Props) {
const getIcon = (mineralId: string) => {
switch (mineralId) {
case "19":
return <Diamond className="text-[#FFE3BA]" />;
default:
return <Diamond className="text-[#FFE3BA]" />;
}
};

return (
<div className="h-full flex flex-col">
<h2 className="text-xl font-bold text-[#2C4F64] mb-4">Mineral Deposits</h2>
<div className="overflow-y-auto flex-grow pr-2">
{deposits.map((deposit) => (
<div
key={deposit.id}
className={`p-4 rounded-lg cursor-pointer mb-2 ${
selectedDeposit?.id === deposit.id ? "bg-[#5FCBC3] text-white" : "bg-gray-100"
}`}
onClick={() => onSelect(deposit)}
>
<div className="flex items-center space-x-2">
{getIcon(deposit.mineral)}
<h3 className="font-bold">Mineral {deposit.mineral}</h3>
</div>
<p>Quantity: {deposit.quantity}</p>
</div>
))}
</div>
</div>
);
}
Loading

0 comments on commit f432c4a

Please sign in to comment.