Skip to content

Commit 8c18061

Browse files
authored
🍓🪶 ↝ [GP-16 GP-14 SGV2-141 SGV2-186]: Merge pull request #153 from Signal-K/GP-16-New-globe-component-interactive
🥬🍓 ↝ [GP-16 GP-14 SGV2-141 SGV2-186]: Interactive globe?
2 parents 2c0fdec + 576e946 commit 8c18061

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4103
-117
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
.pnp.js
77
.env
88

9+
citizen
10+
/citizen
11+
supabase
12+
/supabase
13+
914
# testing
1015
/coverage
1116
.env

components/Content/Inventory/UserOwnedItems.tsx

+71-1
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,80 @@ const OwnedItemsList: React.FC = () => {
8181
})}
8282
</div>
8383
);
84-
};
84+
};
8585

8686
export default OwnedItemsList;
8787

88+
interface InventoryItem {
89+
id: number;
90+
name: string;
91+
icon_url: string;
92+
quantity: number;
93+
}
94+
95+
export const ItemsVerticalList: React.FC = () => {
96+
const session = useSession();
97+
const [itemDetails, setItemDetails] = useState<InventoryItem[]>([]);
98+
const supabase = useSupabaseClient();
99+
100+
useEffect(() => {
101+
const fetchOwnedItems = async () => {
102+
try {
103+
if (!session) return;
104+
105+
const user = session.user.id;
106+
// Fetch owned items from the database
107+
const { data: ownedItemsData, error: ownedItemsError } = await supabase
108+
.from('inventoryUSERS')
109+
.select('*')
110+
.eq('owner', user)
111+
.gt('id', 20);
112+
113+
if (ownedItemsError) {
114+
throw ownedItemsError;
115+
}
116+
117+
if (ownedItemsData) {
118+
const itemIds = ownedItemsData.map(item => item.item);
119+
// Fetch details of owned items
120+
const { data: itemDetailsData, error: itemDetailsError } = await supabase
121+
.from('inventoryITEMS')
122+
.select('*')
123+
.in('id', itemIds);
124+
125+
if (itemDetailsError) {
126+
throw itemDetailsError;
127+
}
128+
129+
if (itemDetailsData) {
130+
setItemDetails(itemDetailsData);
131+
}
132+
}
133+
} catch (error) {
134+
console.error('Error fetching owned items:', error.message);
135+
}
136+
};
137+
138+
fetchOwnedItems();
139+
}, [session]);
140+
141+
return (
142+
<div className="w-full">
143+
{itemDetails.map(item => (
144+
<div key={item.id} className="flex items-center justify-between mb-2">
145+
<div className="flex items-center space-x-2">
146+
<div className="w-10 h-10 rounded-full overflow-hidden">
147+
<img src={item.icon_url} alt={item.name} className="w-full h-full object-cover" />
148+
</div>
149+
<p className="text-sm">{item.name}</p>
150+
</div>
151+
<p className="text-sm">x{item.quantity}</p>
152+
</div>
153+
))}
154+
</div>
155+
);
156+
};
157+
88158
export const SectorStructureOwned: React.FC<{ sectorid: string }> = ({ sectorid }) => {
89159
const supabase = useSupabaseClient();
90160
const session = useSession();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { useEffect, useRef } from "react";
2+
import * as THREE from "three";
3+
import { Sprite, SpriteMaterial, TextureLoader } from "three";
4+
import { useFrame } from "@react-three/fiber";
5+
6+
interface Landmass {
7+
lat: number;
8+
lng: number;
9+
imageURL: string;
10+
onClickFunction: () => void;
11+
}
12+
13+
interface ClickableImagesProps {
14+
landmasses: Landmass[];
15+
}
16+
17+
function ClickableImages({ landmasses }: ClickableImagesProps) {
18+
const groupRef = useRef<THREE.Group | null>(null);
19+
20+
useEffect(() => {
21+
if (groupRef.current) {
22+
landmasses.forEach((landmass) => {
23+
const { lat, lng, imageURL, onClickFunction } = landmass;
24+
25+
// Load texture
26+
const textureLoader = new TextureLoader();
27+
const texture = textureLoader.load(imageURL);
28+
29+
// Create a sprite with the texture
30+
const spriteMaterial = new SpriteMaterial({ map: texture });
31+
const sprite = new Sprite(spriteMaterial);
32+
33+
// Set the size of the sprite
34+
const size = 8; // Adjust size as needed (e.g. 8 for Tailwind scale)
35+
sprite.scale.set(size, size, 1);
36+
37+
// Convert lat/lng to 3D coordinates
38+
const radius = 100; // Adjust radius as needed
39+
const phi = (90 - lat) * (Math.PI / 180);
40+
const theta = lng * (Math.PI / 180);
41+
sprite.position.set(
42+
radius * Math.sin(phi) * Math.cos(theta),
43+
radius * Math.cos(phi),
44+
radius * Math.sin(phi) * Math.sin(theta)
45+
);
46+
47+
// Create a click handler for the sprite
48+
const handleClick = (event: any) => {
49+
event.stopPropagation();
50+
onClickFunction();
51+
};
52+
53+
// Add event listener to the sprite for the 'click' event
54+
sprite.addEventListener('click', handleClick);
55+
56+
// Add the sprite to the group
57+
groupRef.current.add(sprite);
58+
});
59+
}
60+
}, [landmasses]);
61+
62+
// Use useFrame hook to continuously update the scene if needed
63+
useFrame(() => {
64+
// Add any animation logic here if required
65+
});
66+
67+
return <group ref={groupRef} />;
68+
}
69+
70+
export default ClickableImages;

components/Content/Planets/GalleryList.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ const PlanetGalleryWithSectors: React.FC = () => {
122122
let query = supabase
123123
.from('basePlanets')
124124
.select('*')
125-
.order('created_at', { ascending: false })
126-
.limit(200);
125+
.order('created_at', { ascending: true })
126+
.limit(3); // Set this to be owned planets
127127

128128
const { data, error } = await query;
129129

@@ -302,12 +302,12 @@ export const Garden: React.FC<GardenProps> = ({ onClose }) => {
302302
<div className={`fixed inset-x-0 bottom-0 flex justify-center transition-transform duration-300 ${isOpen ? 'translate-y-0' : 'translate-y-full'}`}>
303303
<div className="bg-cover bg-center w-full sm:max-w-screen-lg sm:w-full max-h-96vh overflow-y-auto shadow-lg relative rounded-t-3xl">
304304
<div style={{ backgroundImage: `url('/garden.png')` }} className="bg-cover bg-center h-96vh flex items-center justify-center relative rounded-t-3xl">
305-
<button
305+
{/* <button
306306
onClick={handleClose}
307307
className="absolute top-4 right-4 px-4 py-2 bg-gray-200 text-gray-800 rounded"
308308
>
309309
Close
310-
</button>
310+
</button> */}
311311
<PlanetGalleryWithSectors />
312312
</div>
313313
</div>

0 commit comments

Comments
 (0)