forked from VIDAKHOSHPEY22/Nebula-Works
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
263 lines (220 loc) · 8.45 KB
/
script.js
File metadata and controls
263 lines (220 loc) · 8.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// Authentication System
class AuthSystem {
constructor() {
this.users = [
{ email: "yalda@nebula.works", password: "starlight", name: "Yalda", role: "user" },
{ email: "vida@nebula.works", password: "moonshine", name: "Vida", role: "user" },
{ email: "admin@nebula.works", password: "quantum", name: "Admin", role: "admin" }
];
this.currentUser = null;
}
login(email, password) {
const user = this.users.find(u => u.email === email && u.password === password);
if (user) {
this.currentUser = user;
localStorage.setItem('currentUser', JSON.stringify(user));
return true;
}
return false;
}
logout() {
this.currentUser = null;
localStorage.removeItem('currentUser');
}
isAuthenticated() {
return this.currentUser !== null;
}
isAdmin() {
return this.currentUser?.role === 'admin';
}
}
const auth = new AuthSystem();
// 3D Planet Viewer
class PlanetViewer {
constructor(containerId) {
this.container = document.getElementById(containerId);
if (!this.container) return;
this.initThreeJS();
this.loadPlanets();
}
initThreeJS() {
// Scene setup
this.scene = new THREE.Scene();
this.scene.background = new THREE.Color(0x050510);
// Camera
this.camera = new THREE.PerspectiveCamera(
75,
this.container.clientWidth / this.container.clientHeight,
0.1,
1000
);
this.camera.position.z = 5;
// Renderer
this.renderer = new THREE.WebGLRenderer({ antialias: true });
this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
this.container.appendChild(this.renderer.domElement);
// Lights
const ambientLight = new THREE.AmbientLight(0x404040);
this.scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(1, 1, 1);
this.scene.add(directionalLight);
// Animation loop
this.animate();
}
loadPlanets() {
const loader = new THREE.GLTFLoader();
const planetFiles = ['planet1.glb', 'planet2.glb', 'planet3.glb'];
planetFiles.forEach((file, index) => {
loader.load(`assets/${file}`, (gltf) => {
const planet = gltf.scene;
planet.position.x = (index - 1) * 2.5;
planet.scale.set(0.5, 0.5, 0.5);
this.scene.add(planet);
// Store reference for animation
if (!this.planets) this.planets = [];
this.planets.push(planet);
});
});
}
animate() {
requestAnimationFrame(() => this.animate());
if (this.planets) {
this.planets.forEach((planet, index) => {
planet.rotation.y += 0.005 * (index + 1);
});
}
this.renderer.render(this.scene, this.camera);
}
}
// Dashboard Functions
class Dashboard {
constructor() {
this.initDateTime();
this.initMissions();
this.initCalendar();
this.initSystemStatus();
}
initDateTime() {
const updateTime = () => {
const now = new Date();
document.getElementById('station-time').textContent = now.toLocaleString('en-US', {
weekday: 'long',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
};
updateTime();
setInterval(updateTime, 1000);
}
initMissions() {
const missions = [
{ id: 1, title: "Analyze telescope data", status: "pending" },
{ id: 2, title: "Update navigation system", status: "in-progress" },
{ id: 3, title: "Calibrate sensors", status: "completed" },
{ id: 4, title: "Test ion engines", status: "pending" }
];
const missionsList = document.getElementById('missions-list');
missions.forEach(mission => {
const missionItem = document.createElement('div');
missionItem.className = 'mission-item';
missionItem.innerHTML = `
<div class="mission-status status-${mission.status}"></div>
<span>${mission.title}</span>
`;
missionsList.appendChild(missionItem);
});
}
initCalendar() {
const events = [
{ id: 1, day: "15", month: "JUN", title: "Satellite Launch", description: "NW-247 to orbit" },
{ id: 2, day: "22", month: "JUN", title: "Team Meeting", description: "Quarterly review" },
{ id: 3, day: "30", month: "JUN", title: "System Maintenance", description: "6-hour window" }
];
const calendarEvents = document.getElementById('calendar-events');
events.forEach(event => {
const eventItem = document.createElement('div');
eventItem.className = 'event-item';
eventItem.innerHTML = `
<div class="event-date">
<span class="day">${event.day}</span>
<span class="month">${event.month}</span>
</div>
<div class="event-info">
<h3>${event.title}</h3>
<p>${event.description}</p>
</div>
`;
calendarEvents.appendChild(eventItem);
});
}
initSystemStatus() {
// Oxygen gauge
const oxygenGauge = document.getElementById('oxygen-gauge');
oxygenGauge.style.background = `conic-gradient(var(--secondary) ${95}%, var(--dark) 0%)`;
// Power gauge
const powerGauge = document.getElementById('power-gauge');
powerGauge.style.background = `conic-gradient(var(--secondary) ${78}%, var(--dark) 0%)`;
// Fuel gauge
const fuelGauge = document.getElementById('fuel-gauge');
fuelGauge.style.background = `conic-gradient(var(--secondary) ${65}%, var(--dark) 0%)`;
}
}
// Initialize based on current page
document.addEventListener('DOMContentLoaded', () => {
// Check for authenticated user
const savedUser = localStorage.getItem('currentUser');
if (savedUser) {
auth.currentUser = JSON.parse(savedUser);
}
// Initialize planet viewer on auth page
if (document.body.classList.contains('auth-page')) {
new PlanetViewer('planet-viewer');
// Login form
document.getElementById('login-form').addEventListener('submit', (e) => {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
if (auth.login(email, password)) {
window.location.href = auth.isAdmin() ? 'admin.html' : 'dashboard.html';
} else {
alert('Invalid credentials. Please try again.');
}
});
}
// Initialize dashboard if on dashboard page
if (document.querySelector('.content')) {
// Show current user
if (auth.currentUser) {
document.getElementById('username').textContent = auth.currentUser.name;
document.getElementById('user-avatar').textContent = auth.currentUser.name.charAt(0);
}
new Dashboard();
new PlanetViewer('planet-display');
}
// Create stars background
createStars();
});
// Stars background animation
function createStars() {
const starsContainer = document.getElementById('stars');
if (!starsContainer) return;
const starsCount = 200;
for (let i = 0; i < starsCount; i++) {
const star = document.createElement('div');
star.classList.add('star');
// Random size
const size = Math.random() * 3;
star.style.width = `${size}px`;
star.style.height = `${size}px`;
// Random position
star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 100}%`;
// Random animation duration
star.style.setProperty('--duration', `${5 + Math.random() * 10}s`);
starsContainer.appendChild(star);
}
}