-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
275 lines (226 loc) · 9.85 KB
/
script.js
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
264
265
266
267
268
269
270
271
272
273
274
275
class GameBrowser {
constructor() {
document.querySelector('.game-carousel')?.remove();
this.gameList = document.createElement('div');
this.gameList.className = 'game-carousel';
this.gameList.innerHTML = `
<button class="nav-arrow prev"></button>
<button class="nav-arrow next"></button>
<div class="carousel-container"></div>
<div class="carousel-dots"></div>
`;
this.carouselContainer = this.gameList.querySelector('.carousel-container');
this.dotsContainer = this.gameList.querySelector('.carousel-dots');
this.currentIndex = 0;
this.isTransitioning = false;
document.querySelector('main').appendChild(this.gameList);
this.setupNavigation();
this.initializeGames();
}
setupNavigation() {
const prevButton = this.gameList.querySelector('.prev');
const nextButton = this.gameList.querySelector('.next');
prevButton.addEventListener('click', () => this.navigate(-1));
nextButton.addEventListener('click', () => this.navigate(1));
}
navigate(direction) {
const slides = this.carouselContainer.children;
if (slides.length < 2) return;
const currentSlide = slides[this.currentIndex];
this.currentIndex = (this.currentIndex + direction + slides.length) % slides.length;
const nextSlide = slides[this.currentIndex];
currentSlide.style.display = 'none';
nextSlide.style.display = 'block';
this.updateDots();
}
updateDots() {
const dots = this.dotsContainer.children;
for (let i = 0; i < dots.length; i++) {
dots[i].classList.toggle('active', i === this.currentIndex);
}
}
initializeGames() {
const games = [
{
folder: 'sva',
title: 'SANTA VS THE AIRFORCE',
description: 'It all started with a simple question, who would win?',
thumbnail: 'https://i.imgur.com/DyQLrfJ.gif'
},
{
folder: 'noseas',
title: 'NO SEAS',
description: 'A game inspired by the Google dino, taken to new levels.',
thumbnail: 'https://i.imgur.com/K5aoSLw.gif'
},
{
folder: 'blahaj',
title: 'BLAHAJ RUNNER',
description: 'Featuring Ikea\'s Blahaj, this game is a runner with a twist.',
thumbnail: 'https://i.imgur.com/fwOkgCq.png'
}
];
this.renderGameCarousel(games);
}
renderGameCarousel(games) {
games.forEach((game, index) => {
const slide = document.createElement('div');
slide.className = 'game-slide';
slide.dataset.game = game.folder;
if (index !== 0) {
slide.style.display = 'none';
}
slide.innerHTML = `
<div class="game-thumbnail" style="background-image: url('${game.thumbnail}')"></div>
<div class="game-info">
<h3>${game.title}</h3>
<p>${game.description}</p>
<button class="play-button">Play Now</button>
</div>
`;
this.carouselContainer.appendChild(slide);
const dot = document.createElement('div');
dot.className = 'dot' + (index === 0 ? ' active' : '');
dot.addEventListener('click', () => {
if (this.currentIndex === index) return;
const direction = index > this.currentIndex ? 1 : -1;
this.currentIndex = index - direction;
this.navigate(direction);
});
this.dotsContainer.appendChild(dot);
});
this.carouselContainer.addEventListener('click', (e) => {
if (e.target.classList.contains('play-button')) {
const gameCard = e.target.closest('.game-slide');
if (gameCard) {
this.startGame(gameCard);
}
}
});
}
startGame(gameCard) {
const gameFolder = gameCard.dataset.game;
this.loadGame(gameFolder);
}
loadGame(gameFolder) {
console.log('Loading game:', gameFolder);
const iframe = document.createElement('iframe');
iframe.style.width = '100%';
iframe.style.height = '100%';
iframe.style.border = 'none';
iframe.src = `games/${gameFolder}/index.html`;
this.currentIframe = iframe;
this.gameList.innerHTML = '';
const gameContainer = document.createElement('div');
gameContainer.className = 'game-container';
if (gameFolder === 'blahaj') {
console.log('Adding Blahaj class');
gameContainer.classList.add('blahaj-container');
}
// Create wrapper for fullscreen
const fullscreenWrapper = document.createElement('div');
fullscreenWrapper.className = 'fullscreen-wrapper';
// Create controls container
const controls = document.createElement('div');
controls.className = 'game-controls';
// Add fullscreen button
const fullscreenBtn = document.createElement('button');
fullscreenBtn.className = 'control-button fullscreen-btn';
fullscreenBtn.innerHTML = '⛶';
fullscreenBtn.addEventListener('click', () => {
if (!document.fullscreenElement) {
fullscreenWrapper.requestFullscreen();
document.addEventListener('keydown', this.preventSpaceScroll);
} else {
document.exitFullscreen();
document.removeEventListener('keydown', this.preventSpaceScroll);
}
});
// Add library button
const libraryBtn = document.createElement('button');
libraryBtn.className = 'control-button library-btn';
libraryBtn.innerHTML = '≣';
const showLibrary = () => {
// Create overlay to pause the game
const pauseOverlay = document.createElement('div');
pauseOverlay.className = 'pause-overlay';
fullscreenWrapper.appendChild(pauseOverlay);
// Show library
const libraryOverlay = document.createElement('div');
libraryOverlay.className = 'library-overlay';
const miniCarousel = document.createElement('div');
miniCarousel.className = 'mini-carousel';
// Add active state to library button
libraryBtn.classList.add('active');
const games = [
{
folder: 'sva',
title: 'Santa vs The Airforce',
thumbnail: 'https://i.imgur.com/DyQLrfJ.gif'
},
{
folder: 'noseas',
title: 'No Seas',
thumbnail: 'https://i.imgur.com/K5aoSLw.gif'
},
{
folder: 'blahaj',
title: 'Blahaj Adventure',
thumbnail: 'https://i.imgur.com/fwOkgCq.png'
}
];
games.forEach(game => {
const gameThumb = document.createElement('div');
gameThumb.className = 'mini-game-thumb';
gameThumb.style.backgroundImage = `url('${game.thumbnail}')`;
gameThumb.addEventListener('click', () => {
this.loadGame(game.folder);
libraryOverlay.remove();
pauseOverlay.remove();
libraryBtn.classList.remove('active');
});
const gameTitle = document.createElement('div');
gameTitle.className = 'mini-game-title';
gameTitle.textContent = game.title;
gameThumb.appendChild(gameTitle);
miniCarousel.appendChild(gameThumb);
});
libraryOverlay.appendChild(miniCarousel);
fullscreenWrapper.appendChild(libraryOverlay);
// Close library when library button is clicked again
const closeLibrary = () => {
libraryOverlay.remove();
pauseOverlay.remove();
libraryBtn.classList.remove('active');
libraryBtn.removeEventListener('click', closeLibrary);
libraryBtn.addEventListener('click', showLibrary);
};
libraryBtn.removeEventListener('click', showLibrary);
libraryBtn.addEventListener('click', closeLibrary);
};
libraryBtn.addEventListener('click', showLibrary);
controls.appendChild(fullscreenBtn);
controls.appendChild(libraryBtn);
// Append everything to the fullscreen wrapper
fullscreenWrapper.appendChild(iframe);
fullscreenWrapper.appendChild(controls);
gameContainer.appendChild(fullscreenWrapper);
this.gameList.appendChild(gameContainer);
// Handle fullscreen change
document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) {
document.removeEventListener('keydown', this.preventSpaceScroll);
}
});
}
exitGame() {
window.gameBrowser = new GameBrowser();
}
}
document.addEventListener('DOMContentLoaded', () => {
window.gameBrowser = new GameBrowser();
});
document.getElementById('homeButton').addEventListener('click', (e) => {
e.preventDefault();
window.gameBrowser = new GameBrowser();
});