Skip to content

Commit

Permalink
🥋🖼️ ↝ [SGV2-89]: Travel buddy with basic orientation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Jun 23, 2024
1 parent 6c75df7 commit 39fd96f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 179 deletions.
104 changes: 0 additions & 104 deletions components/Gameplay/Inventory/Structures/Mining.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,110 +35,6 @@ interface MiningStructureModalProps {
missionId: number;
};

export function MeteorologyToolPlaceable() {
const supabase = useSupabaseClient();
const session = useSession();

const { activePlanet } = useActivePlanet();

const [userStructure, setUserStructure] = useState<{ ownedItem: OwnedItem; structure: UserStructure; id: number; time_of_deploy?: string }[]>([]);

const [loading, setLoading] = useState<boolean>(false);

async function fetchData() {
if (session && activePlanet) {
try {
const { data: ownedItemsData, error: ownedItemsError } = await supabase
.from("inventory")
.select("id, item, quantity, notes, time_of_deploy")
.eq("anomaly", activePlanet.id)
.eq("owner", session?.user?.id)
.eq("item", 26);

if (ownedItemsError) {
throw ownedItemsError;
}

if (ownedItemsData && ownedItemsData.length > 0) {
const ownedItem = ownedItemsData[0];

const { data: structureData, error: structureError } = await supabase
.from("inventory")
.select("*")
.eq("item", ownedItem.item)
.limit(1);

if (structureError) {
throw structureError;
}

if (structureData && structureData.length > 0) {
const structure = structureData[0];
setUserStructure([{ ownedItem, structure, id: structure.id }]);
};
};
} catch (error: any) {
console.error(error);
};
}
}

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
// const imageUrl = `${supabaseUrl}/storage/v1/object/public/citiCloud/${activePlanet?.id}/cloud.png`;
const imageUrl = `${supabaseUrl}/storage/v1/object/public/citiAnomalies/${activePlanet?.id}/cloud.png`;
http://127.0.0.1:54321/storage/v1/object/public/citiAnomalies/2/cloud.png

useEffect(() => {
fetchData();
}, [session, activePlanet, supabase]);

return (
<>
{userStructure.length > 0 && (
<div className="bg-white text-gray-900 p-8 rounded-xl shadow-lg max-w-4xl mx-auto">
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
<div>
<img src={imageUrl} alt={`Active Planet ${activePlanet?.id}`} />
<img src='http://127.0.0.1:54321/storage/v1/object/sign/avatars/1.png?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJhdmF0YXJzLzEucG5nIiwiaWF0IjoxNzE4OTI3NzY3LCJleHAiOjE3MTk1MzI1Njd9.L6h_gjtTp7epJc6Kg9--xjsEdeUdrGuAb9tq39RLy2o&t=2024-06-20T23%3A56%3A07.051Z' alt={`Active Planet ${activePlanet?.id}`} />
{/* <CreateCloudClassification assetMentioned={imageUrl} /> */}
<CreateFirstMeteorologyClassification assetMentioned={imageUrl} />
</div>
<div>
<div className="bg-gray-100 p-6 rounded-xl grid grid-cols-2 gap-6">
<span className="font-medium">In Production</span>
<div className="flex items-center gap-3">
<GemIcon className="w-7 h-7 text-indigo-500" />
<span className="font-medium">Coal</span>
<div className="text-right text-lg font-medium">0</div>
</div>
<div className="flex items-center gap-3">
<CuboidIcon className="w-7 h-7 text-amber-500" />
<span className="font-medium">Silicon</span>
<div className="text-right text-lg font-medium">0</div>
</div>
<div className="flex items-center gap-3">
<LeafIcon className="w-7 h-7 text-green-500" />
<span className="font-medium">Organics</span>
<div className="text-right text-lg font-medium">0</div>
</div>
<div className="flex items-center gap-3">
<BoltIcon className="w-7 h-7 text-yellow-500" />
<span className="font-medium">Energy</span>
<div className="text-right text-lg font-medium">0</div>
</div>
</div>
</div>
</div>
</div>
)}
</>
);
};

interface MiningStationPlaceableProps {
missionId: number;
}

const MiningStationPlaceable: React.FC<MiningStructureModalProps> = ({ isOpen, onClose, ownedItem, structure }) => {
const supabase = useSupabaseClient();
const session = useSession();
Expand Down
5 changes: 0 additions & 5 deletions components/Gameplay/Inventory/Structures/Structure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ interface UserStructure {
// Function (what is executed upon click)
};

interface StructureSelectProps {
onStructureSelected: (structure: UserStructure) => void;
activeSectorId: number;
};

export const PlacedStructureSingle: React.FC<{ ownedItem: OwnedItem; structure: UserStructure; style: any; }> = ({ ownedItem, structure, style }) => {
const [isModalOpen, setIsModalOpen] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,72 +33,6 @@ interface MeteorologyToolModalProps {
structure: UserStructure;
};

export function MeteorologyToolModalPlaceable() {
const supabase = useSupabaseClient();
const session = useSession();
const { activePlanet } = useActivePlanet();
const [userStructures, setUserStructures] = useState<{ ownedItem: OwnedItem; structure: UserStructure }[]>([]);
const [loading, setLoading] = useState(false);

async function fetchData() {
if (!session || !activePlanet) return;

setLoading(true);

try {
const { data: ownedItemsData, error: ownedItemsError } = await supabase
.from("inventory")
.select("id, item, quantity, notes, anomaly")
.eq("anomaly", activePlanet.id)
.eq("item", 26)
.eq("owner", session.user.id);

if (ownedItemsError) throw ownedItemsError;

if (ownedItemsData && ownedItemsData.length > 0) {
const ownedItem: OwnedItem = ownedItemsData[0];

const { data: structureData, error: structureError } = await supabase
.from("inventory")
.select("*")
.eq("id", ownedItem.item)
.limit(1);

if (structureError) throw structureError;

if (structureData && structureData.length > 0) {
const structure = structureData[0];
setUserStructures([{ ownedItem, structure }]);
console.log(ownedItem)
console.log(structure)
}
}
} catch (error: any) {
console.error("Error fetching data:", error);
} finally {
setLoading(false);
}
}

useEffect(() => {
fetchData();
}, [session, activePlanet]);

return (
<>
{userStructures.length > 0 && (
<MeteorologyToolModal
isOpen={true}
onClose={() => setUserStructures([])}
ownedItem={userStructures[0].ownedItem}
structure={userStructures[0].structure}
/>
)}
</>
);
}


export const MeteorologyToolModal: React.FC<MeteorologyToolModalProps> = ({ isOpen, onClose, ownedItem, structure }) => {
const { activePlanet } = useActivePlanet();
const [isActionDone, setIsActionDone] = useState(false);
Expand Down Expand Up @@ -180,8 +114,7 @@ function BatteryIcon(props: any) {
<line x1="22" x2="22" y1="11" y2="13" />
</svg>
)
}

};

function BoltIcon(props: any) {
return (
Expand Down
23 changes: 21 additions & 2 deletions components/Gameplay/Inventory/UserPlanets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import FirstClassification from "@/Classifications/FirstClassification";
import UserAnomaliesComponent from "@/components/Content/Anomalies/YourAnomalies";
import { DeleteMineralsAtEndOfMission } from "./Counters";
import ExampleComponent from "./Structures/structure-borderline";
import TravelBuddy from "@/components/Utilities/TravelBuddy";

interface ActivePlanetContextValue {
activePlanet: UserPlanetData | null;
Expand Down Expand Up @@ -61,9 +62,21 @@ export interface UserPlanetData {
const UserPlanetPage = () => {
const supabase = useSupabaseClient();
const session = useSession();

const { activePlanet } = useActivePlanet() || {};

const [missionCompletionStatus, setMissionCompletionStatus] = useState(new Map());
const [userInventory, setUserInventory] = useState(new Set());

const [isModalOpen, setIsModalOpen] = useState(false);

const openModal = () => {
setIsModalOpen(true);
};

const closeModal = () => {
setIsModalOpen(false);
};

useEffect(() => {
const fetchMissionCompletionStatus = async () => {
Expand Down Expand Up @@ -175,7 +188,13 @@ const UserPlanetPage = () => {
};

const renderUtilitiesContext = () => {
if (missionCompletionStatus.has(8)) {
if (missionCompletionStatus.has(21)) {
return (
<>
<TravelBuddy isOpen={isModalOpen} onClose={closeModal} />
</>
)
} else if (missionCompletionStatus.has(8)) {
return (
<>
<DeleteMineralsAtEndOfMission />
Expand All @@ -185,7 +204,7 @@ const UserPlanetPage = () => {
{!userInventory.has(32) && <CraftStructure structureId={32} />}
</>
);
} else {
}else {
return null;
}
};
Expand Down
63 changes: 63 additions & 0 deletions components/Utilities/TravelBuddy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use client";

import React, { useState } from "react";
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
import { useActivePlanet } from "@/context/ActivePlanet";

interface TravelBuddyProps {
isOpen: boolean;
onClose: () => void;
}

const TravelBuddy: React.FC<TravelBuddyProps> = ({ isOpen, onClose }) => {
const supabase = useSupabaseClient();
const session = useSession();
const { activePlanet } = useActivePlanet();

return (
isOpen ? (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
<div className="bg-white rounded-lg p-4 w-full max-w-lg mx-auto shadow-lg">
<div className="flex justify-between items-center">
<h2 className="text-xl font-bold">Travel buddy</h2>
<button className="btn btn-square btn-outline" onClick={onClose}>
</button>
</div>
<div className="flex flex-col items-center mt-4">
<p></p>
<div className="bg-white text-gray-900 p-8 rounded-xl shadow-lg max-w-4xl mx-auto mt-4">
<div>
You can now visit other planets
</div>
</div>
</div>
</div>
</div>
) : null
);
};

const TravelBuddyButton: React.FC = () => {
const [isOpen, setIsOpen] = useState(false);

const handleOpen = () => {
setIsOpen(true);
};

const handleClose = () => {
setIsOpen(false);
};

return (
<div>
<button onClick={handleOpen} className="flex items-center space-x-2 p-2 bg-blue-500 text-white rounded-lg shadow-md hover:bg-blue-600">
<span>🚀</span>
<span>Things to do</span>
</button>
<TravelBuddy isOpen={isOpen} onClose={handleClose} />
</div>
);
};

export default TravelBuddyButton;

0 comments on commit 39fd96f

Please sign in to comment.