-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_gambit_wheel.html
More file actions
422 lines (362 loc) · 14.9 KB
/
Copy pathgame_gambit_wheel.html
File metadata and controls
422 lines (362 loc) · 14.9 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Game Picker Wheel</title>
<script type="module" src='/client_management.js'></script>
<style>
body {
font-family: sans-serif;
margin: auto;
align-content: center;
text-align: center;
}
body>* {
max-width: 50rem !important;
}
#wheel-wrapper {
width: 100%;
max-width: 600px;
aspect-ratio: 1 / 1;
margin: 1.5rem auto;
position: relative;
text-align: center;
}
#wheelCanvas {
width: 100%;
height: 100%;
display: block;
cursor: pointer;
}
/* Triangle on the right (3 o'clock position) */
#marker {
position: absolute;
top: 50%;
right: 0;
margin-top: -0.9rem;
width: 0;
height: 0;
border-top: 1.0rem solid transparent;
border-bottom: 1.0rem solid transparent;
border-right: 1.6rem solid red;
z-index: 10;
text-align: center;
user-select: none;
}
.stepCompleted {
background-color: #77f;
}
.stepNext {
background-color: #c70;
}
@keyframes gradientShift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
#result {
margin: auto;
padding: 0.8rem;
background-size: 200% 200%;
animation: gradientShift 5s ease infinite;
color: white;
text-shadow: 1px 1px 2px black;
border-radius: 8px;
width: fit-content;
}
#remaining-list {
margin: 1.5rem auto;
padding: 0;
list-style: none;
max-width: 30rem;
text-align: left;
}
#remaining-list li {
display: flex;
justify-content: space-between;
align-items: center;
background: #222;
color: #fff;
padding: 0.5rem 1rem;
margin-bottom: 0.4rem;
border-radius: 4px;
}
#remaining-list button {
background: #c70;
color: white;
border: none;
border-radius: 4px;
padding: 0.2rem 0.6rem;
cursor: pointer;
font-weight: bold;
}
#remaining-list button:hover {
background: #e90;
}
</style>
</head>
<body>
<h2>Steam Collection Wheel</h2>
<input type="file" id="fileInput" accept=".json" class="stepNext">
<br><br>
<details style="
border-radius: 0.7rem;
margin: auto;
margin-bottom: 2rem;
text-align: center;
background-color: #222;
border: 0.1rem solid #aaa;
padding: 1rem;
">
<summary>where do i find the file? click here!</summary>
<table>
<thead>
<p>the file you are looking for is <span style="font-weight:bold;">"cloud-storage-namespace-1.json"</span></p>
<aside>hint: if it doesn't work, generally whatever file has the largest size is likely the file you need</aside>
<tr>
<th>Platform</th>
<th>Base Directory Path</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Windows</strong></td>
<td><code>C:\Program Files (x86)\Steam\userdata\(YOUR_USER_CODE)\config\cloudstorage\</code></td>
</tr>
<tr>
<td><strong>macOS</strong></td>
<td><code>~/Library/Application Support/Steam/userdata/(YOUR_USER_CODE)/config/cloudstorage/</code></td>
</tr>
<tr>
<td><strong>Linux (Native)</strong></td>
<td><code>~/.local/share/Steam/userdata/(YOUR_USER_CODE)/config/cloudstorage/</code></td>
</tr>
<tr>
<td><strong>Linux (Flatpak)</strong></td>
<td><code>~/.var/app/com.valvesoftware.Steam/.local/share/Steam/userdata/(YOUR_USER_CODE)/config/cloudstorage/</code></td>
</tr>
</tbody>
</table>
</details>
<select id="categorySelect" disabled>
<option>Select a category...</option>
</select>
<button id="spinBtn" disabled>Spin the Wheel!</button>
<div id="wheel-wrapper">
<div id="marker"></div>
<canvas id="wheelCanvas" width="600" height="600"></canvas>
</div>
<h3 id="result"></h3>
<ul id="remaining-list"></ul>
<script>
let collections = {};
let activeWheelItems = [];
let currentPalette = [];
let rotationAngle = 0;
let angularVelocity = 0;
let isSpinning = false;
let gameNameCache = {};
let fetchQueue = Promise.resolve();
const canvas = document.getElementById('wheelCanvas');
const ctx = canvas.getContext('2d');
const spinBtn = document.getElementById('spinBtn');
const resultDisplay = document.getElementById('result');
const categorySelect = document.getElementById('categorySelect');
const fileInput = document.getElementById('fileInput');
const remainingList = document.getElementById('remaining-list');
const palettes = [
['#FFB3BA', '#FFDFBA', '#FFFFBA', '#BAFFC9', '#BAE1FF', '#E1BAFF'],
['#000000', '#FFFFFF'],
['#FF00FF', '#00FFFF', '#FFFF00'],
['#0077BE', '#00A86B', '#E0F7FA'],
['#FF5733', '#C70039', '#900C3F', '#581845']
];
document.addEventListener('DOMContentLoaded', () => {
fileInput.value = "";
drawWheel();
});
function getContrastYIQ(hexcolor){
const r = parseInt(hexcolor.substr(1,2),16);
const g = parseInt(hexcolor.substr(3,2),16);
const b = parseInt(hexcolor.substr(5,2),16);
return (((r*299)+(g*587)+(b*114))/1000 >= 128) ? 'black' : 'white';
}
async function getGameTitle(appId) {
if (gameNameCache[appId]) return gameNameCache[appId];
fetchQueue = fetchQueue.then(async () => {
if (gameNameCache[appId]) return;
try {
const targetUrl = `https://store.steampowered.com/api/appdetails?appids=${appId}&l=english`;
const response = await fetch(`https://corsproxy.io/?url=${encodeURIComponent(targetUrl)}`);
const data = await response.json();
if (data[appId] && data[appId].success) {
gameNameCache[appId] = data[appId].data.name;
} else {
gameNameCache[appId] = `App ID: ${appId}`;
}
} catch (err) {
gameNameCache[appId] = `App ID: ${appId}`;
}
drawWheel();
updateRemainingList();
});
return gameNameCache[appId] || `App ID: ${appId}`;
}
function updateRemainingList() {
remainingList.innerHTML = '';
activeWheelItems.forEach((appId) => {
const li = document.createElement('li');
const title = gameNameCache[appId] || `App ID: ${appId}`;
li.innerHTML = `<span>${title}</span>`;
const removeBtn = document.createElement('button');
removeBtn.textContent = '-';
removeBtn.onclick = () => removeGame(appId);
li.appendChild(removeBtn);
remainingList.appendChild(li);
});
}
function removeGame(appId) {
activeWheelItems = activeWheelItems.filter(id => id !== appId);
drawWheel();
updateRemainingList();
if (activeWheelItems.length === 0) {
spinBtn.disabled = true;
resultDisplay.innerHTML = "No games left on the wheel!";
}
}
function drawWheel() {
const centerX = 300, centerY = 300, radius = 280;
const items = activeWheelItems;
ctx.clearRect(0, 0, 600, 600);
if (items.length === 0) {
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
ctx.fillStyle = '#333333';
ctx.fill();
ctx.fillStyle = 'white';
ctx.textAlign = 'center';
ctx.font = 'bold 1.6rem sans-serif';
ctx.fillText('No category selected yet', centerX, centerY);
return;
}
const sliceAngle = (2 * Math.PI) / items.length;
ctx.save();
ctx.translate(centerX, centerY);
ctx.rotate(rotationAngle);
for (let i = 0; i < items.length; i++) {
const item = items[i];
const startAngle = i * sliceAngle;
const color = currentPalette[i % currentPalette.length];
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.arc(0, 0, radius, startAngle, startAngle + sliceAngle);
ctx.closePath();
ctx.fillStyle = color;
ctx.fill();
ctx.stroke();
ctx.save();
ctx.rotate(startAngle + sliceAngle / 2);
ctx.textAlign = "right";
ctx.fillStyle = getContrastYIQ(color);
ctx.font = "bold 14px sans-serif";
if (!gameNameCache[item]) {
getGameTitle(item);
}
const displayName = gameNameCache[item] || String(item);
ctx.fillText(displayName.substring(0, 15) + (displayName.length > 15 ? "..." : ""), radius - 10, 5);
ctx.restore();
}
ctx.restore();
}
function animate() {
if (isSpinning) {
rotationAngle += angularVelocity;
angularVelocity *= 0.95;
if (Math.abs(angularVelocity) < 0.001) {
isSpinning = false;
angularVelocity = 0;
determineWinner();
}
drawWheel();
requestAnimationFrame(animate);
}
}
async function determineWinner() {
const items = activeWheelItems;
if (!items || items.length === 0) return;
const sliceAngle = (2 * Math.PI) / items.length;
let normalizedAngle = (-rotationAngle % (2 * Math.PI) + 2 * Math.PI) % (2 * Math.PI);
const winningIndex = Math.floor(normalizedAngle / sliceAngle) % items.length;
const appId = items[winningIndex];
const title = await getGameTitle(appId);
resultDisplay.innerHTML = `Result: <a href="https://store.steampowered.com/app/${appId}" target="_blank">${title}</a>`;
}
fileInput.addEventListener('change', (e) => {
const reader = new FileReader();
reader.onload = (event) => {
const data = JSON.parse(event.target.result);
collections = {};
data.forEach(item => {
if (item[0]?.startsWith('user-collections.')) {
try {
const val = JSON.parse(item[1].value);
const games = val.added || [];
collections[val.name] = games;
} catch(e) {}
}
});
const allNames = Object.keys(collections);
const active = allNames.filter(n => collections[n].length > 0).sort((a, b) => a.localeCompare(b));
const empty = allNames.filter(n => collections[n].length === 0).sort((a, b) => a.localeCompare(b));
categorySelect.innerHTML = '<option>Select a category...</option>';
active.forEach(name => categorySelect.add(new Option(name, name)));
empty.forEach(name => categorySelect.add(new Option(`<empty> ${name}`, name)));
categorySelect.disabled = false;
};
reader.readAsText(e.target.files[0]);
fileInput.classList.replace("stepNext", "stepCompleted");
categorySelect.classList.add("stepNext");
});
categorySelect.addEventListener('change', () => {
const selectedCat = categorySelect.value;
const categoryGames = collections[selectedCat];
if (!categoryGames) return;
// Apply explicit length check and random selection logic
if (categoryGames.length > 10) {
let pool = [...categoryGames];
activeWheelItems = [];
for (let i = 0; i < 10; i++) {
const randomIndex = Math.floor(Math.random() * pool.length);
activeWheelItems.push(pool.splice(randomIndex, 1)[0]);
}
} else {
activeWheelItems = [...categoryGames];
}
currentPalette = palettes[Math.floor(Math.random() * palettes.length)];
rotationAngle = 0;
drawWheel();
updateRemainingList();
spinBtn.disabled = false;
spinBtn.style.backgroundColor = "";
resultDisplay.style.backgroundImage = `linear-gradient(45deg, ${currentPalette.join(', ')})`;
categorySelect.classList.replace("stepNext", "stepCompleted");
spinBtn.classList.add("stepNext");
});
spinBtn.addEventListener('click', () => {
if (isSpinning) return;
const items = activeWheelItems;
if (!items || items.length === 0) return;
const winningIndex = Math.floor(Math.random() * items.length);
const sliceAngle = (2 * Math.PI) / items.length;
const targetSliceCenter = (winningIndex * sliceAngle) + (sliceAngle / 2);
const extraSpins = (5 + Math.floor(Math.random() * 5)) * 2 * Math.PI;
let currentDelta = extraSpins + targetSliceCenter;
rotationAngle = -currentDelta;
angularVelocity = currentDelta * 0.08;
isSpinning = true;
resultDisplay.innerHTML = "Spinning...";
requestAnimationFrame(animate);
});
</script>
</body>
</html>