-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateIndexFile.js
More file actions
468 lines (423 loc) · 13.8 KB
/
generateIndexFile.js
File metadata and controls
468 lines (423 loc) · 13.8 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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
// Dieses Script wird von settings.html aufgerufen, um eine neue index.html zu generieren
async function generateIndexFileFromSettings(config) {
// Vollständiges Template aus @index.html
const template = `<html>
<head>
<meta charset="UTF-8">
<title>Gluecksrad</title>
<link rel="stylesheet" href="main.css" type="text/css" />
<script type="text/javascript" src="Winwheel.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
<script>
// Konfiguration direkt eingebettet
const ACTION_ID = "b6e91213-a8fa-437e-8b46-a4208529fb45";
const blinkConfig = {
"duration": 10000,
"interval": 300,
"color": "#19cfe5"
};
const wheelMode = {
"mode": 1
};
const wheelConfig = {
"numSegments": 0,
"lineWidth": 9,
"strokeStyle": "#6441a5",
"outerRadius": 310,
"innerRadius": 80,
"textAlignment": "outer",
"textOrientation": "vertical",
"rotationAngle": 0,
"drawText": false,
"drawMode": "segmentImage",
"imageOverlay": true,
"imageDirection": "N",
"animation": {
"type": "spinToStop",
"duration": 35,
"spins": 25,
"callbackFinished": null,
"callbackAfter": null
},
"pins": {
"number": 16,
"outerRadius": 5,
"margin": 0,
"fillStyle": "#080808",
"strokeStyle": "#ffffff"
},
"textPadding": 16
};
const priceSegment = [
{
"image": "image/ToreRad2.png",
"fillStyle": "#009925",
"textFontSize": 16,
"textFillStyle": "#0000ff",
"prize": "Test1",
"message": "Geh aufs Ganze",
"text": "",
"probability": 14
},
{
"image": "image/Zonk3.png",
"fillStyle": "#d50f25",
"textFontSize": 16,
"textFillStyle": "black",
"prize": "Test2",
"message": "Zonk",
"text": "",
"probability": 12
},
{
"image": "image/FreeSpin2.png",
"fillStyle": "#ffff99",
"textFontSize": 16,
"textFillStyle": "black",
"prize": "Test3",
"message": "Free Spin",
"text": "",
"probability": 15
},
{
"image": "image/Zonk3.png",
"fillStyle": "#d50f25",
"textFontSize": 16,
"textFillStyle": "black",
"prize": "Test4",
"message": "Zonk",
"text": "",
"probability": 12
},
{
"image": "image/Pushups2.png",
"fillStyle": "#009925",
"textFontSize": 16,
"textFillStyle": "black",
"prize": "Test5",
"message": "Pushups",
"text": "",
"probability": 10
},
{
"image": "image/Zonk3.png",
"fillStyle": "#d50f25",
"textFontSize": 16,
"textFillStyle": "black",
"prize": "Test6",
"message": "Zonk",
"text": "",
"probability": 13
},
{
"image": "image/10KPoints2.png",
"fillStyle": "#ffff99",
"textFontSize": 16,
"textFillStyle": "black",
"prize": "Test7",
"message": "10000 GambaPoints",
"text": "",
"probability": 10
},
{
"image": "image/Zonk3.png",
"fillStyle": "#d50f25",
"textFontSize": 16,
"textFillStyle": "white",
"prize": "Test8",
"message": "Zonk",
"text": "",
"probability": 14
}
]; // (Hier steht der Segment-Array-Inhalt, wie im Original)
</script>
</head>
<body>
<!-- /* Kann beliebig erweitert werden */ -->
<div align="center">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="438" height="582" class="the_wheel" align="center" valign="center">
<canvas id="canvas" width="1000" height="1000" align="center" valign="center">
<p style="color: white;" align="center">Sorry, your browser doesn't support canvas. Please try another.</p>
</canvas>
</td>
</tr>
</table>
</div>
<script>
// Unterdrücke die GSAP Debug-Meldung '--- requestAnimationFrame ---'
const originalConsoleLog = console.log;
console.log = function(...args) {
if (args.length === 1 && typeof args[0] === 'string' && args[0].includes('--- requestAnimationFrame ---')) {
return;
}
originalConsoleLog.apply(console, args);
};
</script>
<script type="module">
// Websocket-Client für Streamerbot
const client = {
onData: (data) => {
console.log('Streamer.bot Data Received', data);
}
};
let ws;
let theWheel;
let segColors;
// Initialisiere das Rad sofort
function initWheel() {
// Setze die dynamischen Werte
wheelConfig.numSegments = priceSegment.length;
wheelConfig.rotationAngle = startRotation;
wheelConfig.animation.callbackFinished = alertPrize;
wheelConfig.animation.callbackAfter = drawColourTriangle;
// Setze die Segment-Größen basierend auf dem Modus
if (wheelMode.mode === 1) {
// Modus 1: Segmentgröße basierend auf Wahrscheinlichkeit (dynamisch)
const totalProbability = priceSegment.reduce((sum, seg) => sum + seg.probability, 0);
for (let i = 0; i < priceSegment.length; i++) {
priceSegment[i].size = 360 * (priceSegment[i].probability / totalProbability);
}
} else {
// Modus 2: Gleiche Segmentgröße (dynamisch)
const equalSize = 360 / priceSegment.length;
for (let i = 0; i < priceSegment.length; i++) {
priceSegment[i].size = equalSize;
}
}
// Erstelle das Wheel mit der Konfiguration
theWheel = new Winwheel({
...wheelConfig,
segments: priceSegment
});
// Initialisiere segColors nach der Wheel-Erstellung
segColors = theWheel.segments;
// Zeichne das Rad
theWheel.draw();
drawColourTriangle();
}
// Auslesen der vorherigen StopPosition
let startRotation = 0;
let oldStopAngle = localStorage.getItem('lastAngle');
if (oldStopAngle) {
let savedAngleJson = JSON.parse(oldStopAngle);
startRotation = savedAngleJson.Deg;
}
// Initialisiere das Rad sofort
initWheel();
function connectws() {
if ("WebSocket" in window) {
ws = new WebSocket("ws://127.0.0.1:8080");
bindEvents();
} else {
console.error("Ihr Browser unterstützt keine WebSockets.");
}
}
function bindEvents() {
ws.onopen = () => {
ws.send(JSON.stringify({
request: "Subscribe",
id: "StartListener",
events: {
general: ["Custom"]
}
}));
console.info("WebSocket connected and subscribed to Custom events.");
};
ws.onmessage = (event) => {
let wsdata;
try {
wsdata = JSON.parse(event.data);
} catch (err) {
console.error("Fehler beim Parsen der Nachricht:", err);
return;
}
handleWebSocketData(wsdata);
};
ws.onclose = () => {
console.error("WebSocket-Verbindung unerwartet geschlossen! Neuer Verbindungsversuch...");
setTimeout(connectws, 10000);
};
}
function handleWebSocketData(wsdata) {
if (wsdata.event && wsdata.event.source === "General" && wsdata.event.type === "Custom") {
let command = "";
if (typeof wsdata.data === "string") {
command = wsdata.data;
} else if (wsdata.data && typeof wsdata.data.data === "string") {
command = wsdata.data.data;
}
if (command === "glücksradStart") {
startGluecksrad();
}
}
}
function startGluecksrad() {
calculatePrize();
}
// Variablen, die vom Code in dieser Seite für die Steuerung der Leistung verwendet werden
let wheelPower = 0;
let wheelSpinning = false;
// Zeichnet das Dreieck als Pointer im Rad oben
function drawColourTriangle()
{
let ctx = theWheel.ctx;
ctx.strokeStyle = 'transparent';
ctx.fillStyle = 'transparent';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(515, 160);
ctx.lineTo(485, 160);
ctx.lineTo(500, 210);
ctx.lineTo(516, 160);
ctx.stroke();
ctx.fill();
}
function getRandomSegmentIndex(segments) {
const totalProbability = segments.reduce((sum, segment) => sum + segment.probability, 0);
const randomValue = Math.random() * totalProbability;
let cumulativeProbability = 0;
for (let i = 0; i < segments.length; i++) {
cumulativeProbability += segments[i].probability;
if (randomValue < cumulativeProbability) {
return i;
}
}
return segments.length - 1;
}
function calculatePrize()
{
const randomSegmentIndex = getRandomSegmentIndex(priceSegment);
// Überprüfe, ob das Segment existiert
if (randomSegmentIndex + 1 > theWheel.numSegments) {
console.error('Segment-Index außerhalb des gültigen Bereichs:', randomSegmentIndex + 1);
return;
}
// Berechne den Zielwinkel für das ausgewählte Segment
const sectorBegin = theWheel.segments[randomSegmentIndex + 1].startAngle + 1;
const sectorEnd = theWheel.segments[randomSegmentIndex + 1].endAngle - 1;
const randomOffset = Math.random() * (sectorEnd - sectorBegin) + sectorBegin;
// Debug-Ausgaben
const currentAngle = theWheel.getRotationPosition();
console.log('Aktuelle Position:', currentAngle);
console.log('Ausgewähltes Segment:', randomSegmentIndex + 1);
console.log('Sektor-Bereich:', sectorBegin, 'bis', sectorEnd);
console.log('Zufälliger Offset:', randomOffset);
// Stoppe aktuelle Animation falls vorhanden
if (theWheel.isSpinning) {
theWheel.stopAnimation(false);
}
// Setze die dynamischen Werte
wheelConfig.numSegments = priceSegment.length;
wheelConfig.rotationAngle = currentAngle;
wheelConfig.animation.callbackFinished = alertPrize;
wheelConfig.animation.callbackAfter = drawColourTriangle;
// Erstelle das Wheel neu
theWheel = new Winwheel({
...wheelConfig,
segments: priceSegment
});
// Setze den Zielwinkel
theWheel.animation.stopAngle = randomOffset;
// Debug-Ausgabe der Animation-Parameter
console.log('Animation-Parameter:', {
currentAngle: currentAngle,
targetAngle: randomOffset,
spins: wheelConfig.animation.spins,
duration: wheelConfig.animation.duration
});
drawColourTriangle();
// Starte die Animation
theWheel.startAnimation();
// Sende das Ergebnis an Streamerbot
ws.send(JSON.stringify({
request: 'DoAction',
id: 'DoAction',
action: {
id: ACTION_ID,
},
args: {
gewinnItem: priceSegment[randomSegmentIndex].prize,
gewinnText: priceSegment[randomSegmentIndex].message
}
}));
}
function startSpin()
{
if (wheelSpinning == false) {
theWheel.startAnimation();
wheelSpinning = true;
}
}
function alertPrize(indicatedSegment)
{
let winningSegmentNumber = theWheel.getIndicatedSegmentNumber();
let originalColor = theWheel.segments[winningSegmentNumber].fillStyle;
let blinkCount = 0;
let maxBlinks = Math.floor(blinkConfig.duration / blinkConfig.interval);
// Gewinnersegment einfärben
theWheel.segments[winningSegmentNumber].fillStyle = blinkConfig.color;
// Blinken starten
let blinkInterval = setInterval(function() {
if (blinkCount >= maxBlinks) {
clearInterval(blinkInterval);
theWheel.segments[winningSegmentNumber].fillStyle = originalColor;
theWheel.draw();
return;
}
if (theWheel.segments[winningSegmentNumber].fillStyle === blinkConfig.color) {
theWheel.segments[winningSegmentNumber].fillStyle = 'white';
} else {
theWheel.segments[winningSegmentNumber].fillStyle = blinkConfig.color;
}
theWheel.draw();
blinkCount++;
}, blinkConfig.interval);
theWheel.draw();
drawColourTriangle();
// Speichere die aktuelle Position
let anglePos = theWheel.getRotationPosition();
const jsonData = { "Deg": anglePos };
localStorage.setItem("lastAngle", JSON.stringify(jsonData));
}
// Initialisiere die Websocket-Verbindung erst nach der Wheel-Erstellung
connectws();
</script>
</body>
</html>`;
// Kopie der Konfiguration, damit das Original nicht verändert wird
const exportConfig = JSON.parse(JSON.stringify(config));
// Alle Segmente anpassen: image immer mit 'image/'
exportConfig.priceSegment = exportConfig.priceSegment.map(seg => ({
...seg,
image: seg.image ? (seg.image.startsWith('image/') ? seg.image : 'image/' + seg.image.replace(/^image[\\/]/, '')) : ''
}));
let result = template;
result = result.replace(
/const\s+ACTION_ID\s*=\s*"[^"]+";/,
`const ACTION_ID = "${exportConfig.actionId}";`
);
result = result.replace(
/const\s+blinkConfig\s*=\s*{[\s\S]*?};/,
`const blinkConfig = ${JSON.stringify(exportConfig.blinkConfig, null, 4)};`
);
result = result.replace(
/const\s+wheelMode\s*=\s*{[\s\S]*?};/,
`const wheelMode = ${JSON.stringify(exportConfig.wheelMode, null, 4)};`
);
result = result.replace(
/const\s+wheelConfig\s*=\s*{[\s\S]*?};/,
`const wheelConfig = ${JSON.stringify(exportConfig.wheelConfig, null, 4)};`
);
result = result.replace(
/const\s+priceSegment\s*=\s*\[[\s\S]*?\];/,
`const priceSegment = ${JSON.stringify(exportConfig.priceSegment, null, 4)};`
);
// Biete die Datei als Download an
const blob = new Blob([result], {type: 'text/html'});
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'index.html';
a.click();
}