Skip to content

Commit 8c9db3d

Browse files
committed
🦧🛕 ↝ [SSG-70 SSG-71 SSG-72 SSP-33]: Updating & reviewing mining scene (f.e. only)
1 parent a42d5e5 commit 8c9db3d

File tree

4 files changed

+102
-179
lines changed

4 files changed

+102
-179
lines changed

app/scenes/mining/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function Mining() {
2121
<MiningComponent />
2222
<StructureMissionGuide />
2323
</EarthActionSceneLayout>
24-
);
24+
);
2525
};
2626

2727
function MiningScene() {

app/tests/page.tsx

+3-104
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export default function TestPage() {
88
return (
99
<StarnetLayout>
1010
<>
11-
<div style={{ width: "100vw", height: "100vh" }}>
12-
<TopographicMap />
13-
</div>
11+
<div style={{ width: "100vw", height: "100vh" }}>
12+
</div>
1413
</>
1514
</StarnetLayout>
1615
);
@@ -27,104 +26,4 @@ export default function TestPage() {
2726
},
2827
]} />
2928
30-
*/
31-
32-
import { Canvas } from "@react-three/fiber";
33-
import * as THREE from "three";
34-
import { createNoise2D } from "simplex-noise";
35-
import alea from "alea";
36-
37-
// Topographic shaders
38-
const topographicVertexShader = `
39-
varying vec2 vUv;
40-
varying float vElevation;
41-
42-
void main() {
43-
vUv = uv;
44-
vElevation = position.z;
45-
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
46-
}
47-
`;
48-
49-
const topographicFragmentShader = `
50-
varying vec2 vUv;
51-
varying float vElevation;
52-
uniform vec3 uBaseColor;
53-
uniform vec3 uContourColor;
54-
uniform float uBands;
55-
uniform float uContourWidth;
56-
57-
void main() {
58-
float elevation = vElevation;
59-
float bandedElevation = floor(elevation * uBands) / uBands;
60-
float nextBand = floor(elevation * uBands + 1.0) / uBands;
61-
float mixFactor = smoothstep(bandedElevation, nextBand, elevation);
62-
63-
float contourLine = 1.0 - smoothstep(0.0, uContourWidth, abs(mixFactor - 0.5));
64-
65-
vec3 finalColor = mix(uBaseColor, uContourColor, contourLine * 0.5);
66-
67-
gl_FragColor = vec4(finalColor, 1.0);
68-
}
69-
`;
70-
71-
type TerrainProps = {
72-
seed: number;
73-
heightScale: number;
74-
bands: number;
75-
baseColor: string;
76-
contourColor: string;
77-
};
78-
79-
const Terrain: React.FC<TerrainProps> = ({ seed, heightScale, bands, baseColor, contourColor }) => {
80-
const mesh = useRef<THREE.Mesh>(null); // Explicitly define mesh type
81-
const prng = useMemo(() => alea(seed), [seed]);
82-
const noise2D = useMemo(() => createNoise2D(prng), [prng]);
83-
84-
const geometry = useMemo(() => {
85-
const geo = new THREE.PlaneGeometry(20, 20, 200, 200);
86-
const positions = geo.attributes.position.array as Float32Array;
87-
88-
for (let i = 0; i < positions.length; i += 3) {
89-
const x = positions[i];
90-
const y = positions[i + 1];
91-
const noise = noise2D(x * 0.05, y * 0.05);
92-
positions[i + 2] = noise * heightScale;
93-
}
94-
95-
geo.computeVertexNormals();
96-
return geo;
97-
}, [noise2D, heightScale]);
98-
99-
const material = useMemo(() => {
100-
return new THREE.ShaderMaterial({
101-
vertexShader: topographicVertexShader,
102-
fragmentShader: topographicFragmentShader,
103-
uniforms: {
104-
uBaseColor: { value: new THREE.Color(baseColor) },
105-
uContourColor: { value: new THREE.Color(contourColor) },
106-
uBands: { value: bands },
107-
uContourWidth: { value: 0.1 },
108-
},
109-
});
110-
}, [baseColor, contourColor, bands]);
111-
112-
return (
113-
<mesh ref={mesh} geometry={geometry} material={material} rotation={[-Math.PI / 2, 0, 0]} />
114-
);
115-
};
116-
117-
const TopographicMap = () => {
118-
return (
119-
<Canvas>
120-
<ambientLight />
121-
<Terrain
122-
seed={42}
123-
heightScale={1}
124-
bands={40}
125-
baseColor="#F5F5DC" // Beige
126-
contourColor="#8B4513" // SaddleBrown
127-
/>
128-
</Canvas>
129-
);
130-
};
29+
*/

citizen

components/mining-component.tsx

+97-73
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,85 @@
1-
import { useState, useEffect } from 'react';
2-
import { MineralDepositList } from './Structures/Mining/Deposits';
3-
import { ControlPanel } from './Structures/Mining/ControlPanel';
4-
// import { TerrainMap } from './terrain-map';
5-
import { Inventory } from './Inventory';
1+
import { useState, useEffect } from 'react'
2+
import { MineralDepositList } from './MineralDepositList'
3+
import { TopographicMap } from './TopographicMap'
4+
import { TerrainMap } from './TerrainMap'
5+
import { Inventory } from './Inventory'
6+
import { Button } from "@/components/ui/button"
67

78
type MineralDeposit = {
89
id: string
910
name: string
1011
amount: number
11-
availableAmount: number
12-
level: number
13-
uses: string[]
1412
position: { x: number; y: number }
15-
};
13+
}
1614

1715
type Rover = {
1816
id: string
1917
name: string
2018
speed: number
2119
efficiency: number
2220
miningLevel: number
23-
};
21+
}
2422

2523
type InventoryItem = {
2624
id: string
2725
name: string
2826
amount: number
29-
};
27+
}
28+
29+
type Landmark = {
30+
id: string
31+
name: string
32+
description: string
33+
position: { x: number; y: number }
34+
isOpen: boolean
35+
}
36+
37+
const MINERALS = ['Iron', 'Copper', 'Coal', 'Nickel']
38+
39+
const LANDMARKS: Landmark[] = [
40+
{ id: '1', name: 'Base Camp', description: 'Main operations center for the mining colony.', position: { x: 10, y: 10 }, isOpen: false },
41+
{ id: '2', name: 'Power Plant', description: 'Generates power for the entire mining operation.', position: { x: 80, y: 30 }, isOpen: false },
42+
{ id: '3', name: 'Research Lab', description: 'Conducts studies on Martian geology and potential life.', position: { x: 30, y: 70 }, isOpen: false },
43+
]
3044

3145
export function MiningComponentComponent() {
3246
const [mineralDeposits, setMineralDeposits] = useState<MineralDeposit[]>([])
33-
const [rovers, setRovers] = useState<Rover[]>([])
47+
const [rover, setRover] = useState<Rover | null>(null)
3448
const [selectedDeposit, setSelectedDeposit] = useState<MineralDeposit | null>(null)
35-
const [selectedRover, setSelectedRover] = useState<Rover | null>(null)
3649
const [roverPosition, setRoverPosition] = useState<{ x: number; y: number } | null>(null)
3750
const [inventory, setInventory] = useState<InventoryItem[]>([])
3851
const [isMining, setIsMining] = useState(false)
3952
const [activeMap, setActiveMap] = useState<'2D' | '3D'>('2D')
53+
const [landmarks, setLandmarks] = useState<Landmark[]>(LANDMARKS)
4054

4155
useEffect(() => {
42-
setMineralDeposits([
43-
{ id: '1', name: 'Iron', amount: 1000, availableAmount: 500, level: 1, uses: ['Construction', 'Tools'], position: { x: 200, y: 150 } },
44-
{ id: '2', name: 'Copper', amount: 800, availableAmount: 400, level: 2, uses: ['Electronics', 'Wiring'], position: { x: 400, y: 300 } },
45-
{ id: '3', name: 'Gold', amount: 500, availableAmount: 200, level: 3, uses: ['Electronics', 'Jewelry'], position: { x: 300, y: 200 } },
46-
{ id: '4', name: 'Titanium', amount: 600, availableAmount: 300, level: 2, uses: ['Aerospace', 'Medical'], position: { x: 500, y: 250 } },
47-
{ id: '5', name: 'Platinum', amount: 400, availableAmount: 150, level: 4, uses: ['Catalysts', 'Electronics'], position: { x: 150, y: 350 } },
48-
])
49-
setRovers([
50-
{ id: '1', name: 'Rover A', speed: 10, efficiency: 0.8, miningLevel: 1 },
51-
{ id: '2', name: 'Rover B', speed: 15, efficiency: 0.7, miningLevel: 2 },
52-
{ id: '3', name: 'Rover C', speed: 12, efficiency: 0.9, miningLevel: 3 },
53-
{ id: '4', name: 'Rover D', speed: 18, efficiency: 0.6, miningLevel: 4 },
54-
])
55-
setInventory([
56-
{ id: '1', name: 'Iron', amount: 0 },
57-
{ id: '2', name: 'Copper', amount: 0 },
58-
{ id: '3', name: 'Gold', amount: 0 },
59-
{ id: '4', name: 'Titanium', amount: 0 },
60-
{ id: '5', name: 'Platinum', amount: 0 },
61-
])
56+
const generateDeposits = () => {
57+
const deposits: MineralDeposit[] = []
58+
for (let i = 0; i < 4; i++) {
59+
const mineral = MINERALS[Math.floor(Math.random() * MINERALS.length)]
60+
deposits.push({
61+
id: `${i + 1}`,
62+
name: mineral,
63+
amount: Math.floor(Math.random() * 500) + 500,
64+
position: { x: Math.random() * 80 + 10, y: Math.random() * 80 + 10 },
65+
})
66+
}
67+
return deposits
68+
}
69+
70+
setMineralDeposits(generateDeposits())
71+
setRover({ id: '1', name: 'Mars Rover', speed: 15, efficiency: 0.8, miningLevel: 2 })
72+
setInventory(MINERALS.map((mineral, index) => ({ id: `${index + 1}`, name: mineral, amount: 0 })))
6273
}, [])
6374

6475
const handleDepositSelect = (deposit: MineralDeposit) => {
6576
setSelectedDeposit(deposit)
6677
}
6778

68-
const handleRoverSelect = (rover: Rover) => {
69-
setSelectedRover(rover)
70-
}
71-
7279
const handleStartMining = () => {
73-
if (selectedDeposit && selectedRover) {
80+
if (selectedDeposit && rover) {
7481
setIsMining(true)
75-
setRoverPosition({ x: 50, y: 50 }) // Start position
82+
setRoverPosition({ x: 5, y: 5 }) // Start position
7683

7784
const duration = 5000 // 5 seconds to reach deposit
7885
const startTime = Date.now()
@@ -82,18 +89,19 @@ export function MiningComponentComponent() {
8289
const progress = Math.min(elapsedTime / duration, 1)
8390

8491
setRoverPosition({
85-
x: 50 + (selectedDeposit.position.x - 50) * progress,
86-
y: 50 + (selectedDeposit.position.y - 50) * progress
92+
x: 5 + (selectedDeposit.position.x - 5) * progress,
93+
y: 5 + (selectedDeposit.position.y - 5) * progress
8794
})
8895

8996
if (progress < 1) {
9097
requestAnimationFrame(animateRover)
9198
} else {
9299
// At deposit, start mining
93100
setTimeout(() => {
94-
setRoverPosition({ x: 50, y: 50 }) // Return to base
101+
setRoverPosition({ x: 5, y: 5 }) // Return to base
95102
setIsMining(false)
96103
updateInventory(selectedDeposit.name, 50) // Add mined resources to inventory
104+
setSelectedDeposit(null) // Reset selected deposit
97105
}, 5000) // 5 seconds at deposit
98106
}
99107
}
@@ -112,53 +120,69 @@ export function MiningComponentComponent() {
112120
setActiveMap(prev => prev === '2D' ? '3D' : '2D')
113121
}
114122

123+
const handleLandmarkClick = (id: string) => {
124+
setLandmarks(prev => prev.map(landmark =>
125+
landmark.id === id ? { ...landmark, isOpen: !landmark.isOpen } : landmark
126+
))
127+
}
128+
115129
return (
116-
<div className="flex flex-col h-screen bg-gray-100 text-[#2C4F64]">
117-
<div className="flex-1 p-4 overflow-hidden flex flex-col">
118-
<div className="mb-4 flex-shrink-0">
119-
<div className="flex justify-between items-center mb-2">
120-
<h2 className="text-2xl font-bold">Mars Mining Operation</h2>
121-
<button
122-
onClick={toggleMap}
123-
className="px-4 py-2 bg-[#5FCBC3] text-white rounded hover:bg-[#5FCBC3]/80"
124-
>
125-
Switch to {activeMap === '2D' ? '3D' : '2D'} Map
126-
</button>
127-
</div>
128-
{/* {activeMap === '2D' ? (
130+
<div className="relative h-screen w-full overflow-hidden bg-gray-100 text-[#2C4F64] flex flex-col">
131+
<div className="flex justify-between items-center p-4">
132+
<h2 className="text-2xl font-bold">Mars Mining Operation</h2>
133+
<Button
134+
onClick={toggleMap}
135+
variant="outline"
136+
className="text-[#2C4F64] hover:bg-[#5FCBC3]/20"
137+
>
138+
Switch to {activeMap === '2D' ? '3D' : '2D'} Map
139+
</Button>
140+
</div>
141+
<div className="flex-grow flex flex-col md:flex-row overflow-hidden">
142+
<div className="w-full md:w-3/4 h-1/2 md:h-full relative">
143+
{activeMap === '2D' ? (
129144
<TopographicMap
130145
deposits={mineralDeposits}
131146
roverPosition={roverPosition}
132147
selectedDeposit={selectedDeposit}
148+
landmarks={landmarks}
149+
onLandmarkClick={handleLandmarkClick}
133150
/>
134151
) : (
135152
<TerrainMap
136153
deposits={mineralDeposits}
137154
roverPosition={roverPosition}
138155
selectedDeposit={selectedDeposit}
156+
landmarks={landmarks}
157+
onLandmarkClick={handleLandmarkClick}
139158
/>
140-
)} */}
159+
)}
141160
</div>
142-
<div className="grid grid-cols-2 gap-4 flex-grow overflow-hidden">
143-
{/* <div className="bg-white rounded-lg p-4 shadow overflow-hidden flex flex-col">
144-
<MineralDepositList
145-
deposits={mineralDeposits}
146-
onSelect={handleDepositSelect}
147-
selectedDeposit={selectedDeposit}
148-
/>
161+
<div className="w-full md:w-1/4 h-1/2 md:h-full overflow-y-auto bg-white bg-opacity-90 p-4">
162+
<div className="space-y-4">
163+
{selectedDeposit ? (
164+
<div>
165+
<h3 className="text-lg font-semibold mb-2">Selected Deposit: {selectedDeposit.name}</h3>
166+
<p>Amount: {selectedDeposit.amount} units</p>
167+
<Button
168+
onClick={handleStartMining}
169+
disabled={isMining}
170+
className="w-full mt-4"
171+
>
172+
{isMining ? 'Mining...' : 'Start Mining'}
173+
</Button>
174+
</div>
175+
) : (
176+
<MineralDepositList
177+
deposits={mineralDeposits}
178+
onSelect={handleDepositSelect}
179+
selectedDeposit={selectedDeposit}
180+
/>
181+
)}
149182
</div>
150-
<div className="bg-white rounded-lg p-4 shadow overflow-hidden flex flex-col">
151-
<ControlPanel
152-
rovers={rovers}
153-
selectedRover={selectedRover}
154-
onRoverSelect={handleRoverSelect}
155-
onStartMining={handleStartMining}
156-
isMining={isMining}
157-
/>
158-
</div> */}
159183
</div>
160184
</div>
161-
<div className="h-24 bg-white p-4 shadow flex-shrink-0">
185+
<div className="bg-white bg-opacity-90 p-4 border-t border-gray-200">
162186
<Inventory inventory={inventory} />
163187
</div>
164188
</div>

0 commit comments

Comments
 (0)