@enigma-lake/tower-play-controller-sdk 2.0.14 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -311
- package/dist/components/AutoManualPlayStateProvider/AutoManualPlayStateContext.d.ts +9 -1
- package/dist/components/base/Button/buttonStyle.d.ts +5 -0
- package/dist/components/base/Cashout/cashoutBehavior.d.ts +27 -0
- package/dist/components/hooks/playAmount.d.ts +5 -0
- package/dist/components/hooks/usePlayController.d.ts +2 -0
- package/dist/components/hooks/useSpacebarButtonTrigger.d.ts +8 -0
- package/dist/components/index.d.ts +2 -2
- package/dist/index.d.ts +55 -1
- package/dist/index.mjs +219 -151
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/gameMode.d.ts +4 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/playController.d.ts +15 -0
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import React, { createContext, useContext, useRef,
|
|
2
|
+
import React, { createContext, useContext, useRef, useCallback, useEffect, useMemo, useState, Fragment as Fragment$1 } from 'react';
|
|
3
3
|
import cx$1 from 'classnames';
|
|
4
4
|
import { Currency, sendSetUserCurrencyEvent, sendSetUserCurrencyEventV2, setToggleGameWidgetsVisibility, setToggleGameWidgetsExpansion, getUserInformationEvent, EVENTS, sendOpenHighPlayModalEvent } from '@enigma-lake/zoot-platform-sdk';
|
|
5
5
|
import { Menu, MenuButton, MenuItems, MenuItem, Switch as Switch$1 } from '@headlessui/react';
|
|
@@ -40,19 +40,8 @@ const format = (value, decimals) => {
|
|
|
40
40
|
if (isNaN(num)) {
|
|
41
41
|
return value;
|
|
42
42
|
}
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const normalized = match ? raw : num.toFixed(decimals + 6);
|
|
46
|
-
const parts = normalized.split(".");
|
|
47
|
-
const sign = parts[0]?.startsWith("-") ? "-" : "";
|
|
48
|
-
const integerPart = parts[0]?.replace("-", "") ?? "0";
|
|
49
|
-
const fractionPart = parts[1] ?? "";
|
|
50
|
-
const truncatedFraction = fractionPart
|
|
51
|
-
.slice(0, decimals)
|
|
52
|
-
.padEnd(decimals, "0");
|
|
53
|
-
const truncated = Number(decimals > 0
|
|
54
|
-
? `${sign}${integerPart}.${truncatedFraction}`
|
|
55
|
-
: `${sign}${integerPart}`);
|
|
43
|
+
const factor = Math.pow(10, decimals);
|
|
44
|
+
const truncated = Math.trunc(num * factor) / factor;
|
|
56
45
|
return truncated.toLocaleString("en-US", {
|
|
57
46
|
minimumFractionDigits: decimals,
|
|
58
47
|
maximumFractionDigits: decimals,
|
|
@@ -71,6 +60,11 @@ var AUTO_PLAY_STATE;
|
|
|
71
60
|
AUTO_PLAY_STATE["SELECTING"] = "selecting";
|
|
72
61
|
AUTO_PLAY_STATE["PLAYING"] = "playing";
|
|
73
62
|
})(AUTO_PLAY_STATE || (AUTO_PLAY_STATE = {}));
|
|
63
|
+
var DOUBLE_OR_NOTHING_STATE;
|
|
64
|
+
(function (DOUBLE_OR_NOTHING_STATE) {
|
|
65
|
+
DOUBLE_OR_NOTHING_STATE["IDLE"] = "idle";
|
|
66
|
+
DOUBLE_OR_NOTHING_STATE["PROGRESS"] = "progress";
|
|
67
|
+
})(DOUBLE_OR_NOTHING_STATE || (DOUBLE_OR_NOTHING_STATE = {}));
|
|
74
68
|
|
|
75
69
|
var WIDGET;
|
|
76
70
|
(function (WIDGET) {
|
|
@@ -78,15 +72,64 @@ var WIDGET;
|
|
|
78
72
|
WIDGET["SIDE"] = "side";
|
|
79
73
|
})(WIDGET || (WIDGET = {}));
|
|
80
74
|
|
|
75
|
+
const isManualCashoutDisabled = ({ disabledController, isPlaying, cashoutDisabled, }) => disabledController || !isPlaying || cashoutDisabled;
|
|
76
|
+
const createManualCashoutClickHandler = ({ cashoutDisabled, onCashout, }) => {
|
|
77
|
+
return () => {
|
|
78
|
+
if (cashoutDisabled) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
onCashout();
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const canAutoplaySpaceTrigger = ({ state, cashoutDisabled, isDisabled, }) => {
|
|
85
|
+
return state === AUTO_PLAY_STATE.PLAYING ? !cashoutDisabled : !isDisabled;
|
|
86
|
+
};
|
|
87
|
+
const isAutoplayButtonDisabled = ({ state, cashoutDisabled, isDisabled, isValidPlayAmount, }) => {
|
|
88
|
+
return state === AUTO_PLAY_STATE.PLAYING
|
|
89
|
+
? cashoutDisabled
|
|
90
|
+
: isDisabled || !isValidPlayAmount;
|
|
91
|
+
};
|
|
92
|
+
const createAutoplayButtonAction = ({ state, cashoutDisabled, onStopPlay, onPlay, }) => {
|
|
93
|
+
return () => {
|
|
94
|
+
if (state === AUTO_PLAY_STATE.PLAYING) {
|
|
95
|
+
if (cashoutDisabled) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
onStopPlay();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
onPlay();
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
81
105
|
const AutoManualPlayStateContext = createContext(undefined);
|
|
82
106
|
const useAutoManualPlayState = () => {
|
|
83
107
|
const context = useContext(AutoManualPlayStateContext);
|
|
84
108
|
if (!context) {
|
|
85
|
-
throw new Error("
|
|
109
|
+
throw new Error("useAutoManualPlayState must be used within AutoManualPlayProvider");
|
|
86
110
|
}
|
|
87
111
|
return context;
|
|
88
112
|
};
|
|
89
113
|
|
|
114
|
+
const getNextPlayAmount = ({ currentAmount, defaultBetOptions, direction, }) => {
|
|
115
|
+
if (!defaultBetOptions.length) {
|
|
116
|
+
return currentAmount;
|
|
117
|
+
}
|
|
118
|
+
const sorted = [...defaultBetOptions].sort((a, b) => a - b);
|
|
119
|
+
const currentIndex = sorted.findIndex((value) => value === currentAmount);
|
|
120
|
+
if (currentIndex !== -1) {
|
|
121
|
+
const targetIndex = currentIndex + direction;
|
|
122
|
+
if (targetIndex >= 0 && targetIndex < sorted.length) {
|
|
123
|
+
return sorted[targetIndex];
|
|
124
|
+
}
|
|
125
|
+
return sorted[currentIndex];
|
|
126
|
+
}
|
|
127
|
+
sorted.push(currentAmount);
|
|
128
|
+
sorted.sort((a, b) => a - b);
|
|
129
|
+
const insertedIndex = sorted.indexOf(currentAmount);
|
|
130
|
+
return sorted[insertedIndex + direction] ?? currentAmount;
|
|
131
|
+
};
|
|
132
|
+
|
|
90
133
|
/**
|
|
91
134
|
* Type guard: full mode (risk + autoplay enabled)
|
|
92
135
|
*
|
|
@@ -100,7 +143,7 @@ function isFullMode(config) {
|
|
|
100
143
|
const usePlayController = () => {
|
|
101
144
|
const { config, autoPlay: { setNumberOfPlays, numberOfPlays, setPlayedRounds, playedRounds, selection, setState, state, }, playValues: { displayPlayAmountView, setDisplayPlayAmountView, togglePlayAmountView, }, } = useAutoManualPlayState();
|
|
102
145
|
const { current } = config.currencyOptions;
|
|
103
|
-
const { isPlaying, canCashout, disabledController, playHook, totalBalance } = config.playOptions;
|
|
146
|
+
const { isPlaying, canCashout, disabledCashout = false, disabledController, playHook, totalBalance, } = config.playOptions;
|
|
104
147
|
// --- Autoplay-related values only valid in full mode ---
|
|
105
148
|
const autoplayEnabled = isFullMode(config);
|
|
106
149
|
const showAutoPlayToast = autoplayEnabled
|
|
@@ -169,31 +212,15 @@ const usePlayController = () => {
|
|
|
169
212
|
if (isDisabled()) {
|
|
170
213
|
return;
|
|
171
214
|
}
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
215
|
+
const options = playLimits?.[current.code]?.defaultBetOptions ?? [];
|
|
216
|
+
if (!options.length) {
|
|
174
217
|
return;
|
|
175
218
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// If current isn't exactly in list, insert it logically
|
|
182
|
-
sorted.push(playAmount);
|
|
183
|
-
sorted.sort((a, b) => a - b);
|
|
184
|
-
const idx = sorted.indexOf(playAmount);
|
|
185
|
-
newAmount = sorted[idx + direction] ?? playAmount;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
const targetIdx = currentIndex + direction;
|
|
189
|
-
if (targetIdx >= 0 && targetIdx < sorted.length) {
|
|
190
|
-
newAmount = sorted[targetIdx];
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// clamp if out of bounds
|
|
194
|
-
newAmount = sorted[currentIndex];
|
|
195
|
-
}
|
|
196
|
-
}
|
|
219
|
+
const newAmount = getNextPlayAmount({
|
|
220
|
+
currentAmount: playAmount,
|
|
221
|
+
defaultBetOptions: options,
|
|
222
|
+
direction,
|
|
223
|
+
});
|
|
197
224
|
setPlayAmount(newAmount);
|
|
198
225
|
};
|
|
199
226
|
const onChangeAmount = (playValue) => {
|
|
@@ -220,6 +247,7 @@ const usePlayController = () => {
|
|
|
220
247
|
isDisabled,
|
|
221
248
|
onPlay: config.onPlay,
|
|
222
249
|
canCashout,
|
|
250
|
+
cashoutDisabled: disabledCashout,
|
|
223
251
|
},
|
|
224
252
|
// autoplay
|
|
225
253
|
autoPlay: {
|
|
@@ -227,6 +255,7 @@ const usePlayController = () => {
|
|
|
227
255
|
state,
|
|
228
256
|
onPlay: handleAutoPlay,
|
|
229
257
|
onStopPlay: stopAutoplay,
|
|
258
|
+
cashoutDisabled: disabledCashout,
|
|
230
259
|
},
|
|
231
260
|
// UI state for play amount view
|
|
232
261
|
playValues: {
|
|
@@ -237,7 +266,7 @@ const usePlayController = () => {
|
|
|
237
266
|
};
|
|
238
267
|
};
|
|
239
268
|
|
|
240
|
-
var styles_button = {"base":"Button-module__base___muNxk","base__theme-ghost":"Button-module__base__theme-ghost___I5-LJ","base__theme-primary":"Button-module__base__theme-primary___Zuswb","base__state-disabled":"Button-module__base__state-disabled___EU5tH","buttonPlayAmount":"Button-module__buttonPlayAmount___GMy3F","buttonCashout":"Button-module__buttonCashout___LG-Yr","buttonPlayAmount__active":"Button-module__buttonPlayAmount__active___e0nGe","buttonCashout__active":"Button-module__buttonCashout__active___qnE3h","buttonSweeps":"Button-module__buttonSweeps___0snDQ","buttonSweeps__active":"Button-module__buttonSweeps__active___PXIFH","buttonGold":"Button-module__buttonGold___DAj-d","buttonGold__active":"Button-module__buttonGold__active___vsi7m","buttonDefault":"Button-module__buttonDefault___QENXy","buttonDefault__active":"Button-module__buttonDefault__active___oS6gd"};
|
|
269
|
+
var styles_button = {"base":"Button-module__base___muNxk","base__theme-ghost":"Button-module__base__theme-ghost___I5-LJ","base__theme-primary":"Button-module__base__theme-primary___Zuswb","base__state-disabled":"Button-module__base__state-disabled___EU5tH","buttonPlayAmount":"Button-module__buttonPlayAmount___GMy3F","buttonCashout":"Button-module__buttonCashout___LG-Yr","buttonPlayAmount__active":"Button-module__buttonPlayAmount__active___e0nGe","buttonCashout__active":"Button-module__buttonCashout__active___qnE3h","buttonSweeps":"Button-module__buttonSweeps___0snDQ","buttonSweeps__active":"Button-module__buttonSweeps__active___PXIFH","buttonGold":"Button-module__buttonGold___DAj-d","buttonGold__active":"Button-module__buttonGold__active___vsi7m","buttonDefault":"Button-module__buttonDefault___QENXy","buttonDefault__active":"Button-module__buttonDefault__active___oS6gd","buttonDON":"Button-module__buttonDON___ROWdX","buttonDON__active":"Button-module__buttonDON__active___QeoiQ","buttonDON__disabled":"Button-module__buttonDON__disabled___98v7-","buttonDON__title":"Button-module__buttonDON__title___sbNMd","buttonDON__subtitle":"Button-module__buttonDON__subtitle___sgpdf","buttonDON__content":"Button-module__buttonDON__content___sJ-pz","buttonRow":"Button-module__buttonRow___gYuQ0","buttonRow__cashout":"Button-module__buttonRow__cashout___8QZ-4","buttonRow__don":"Button-module__buttonRow__don___tYZKN"};
|
|
241
270
|
|
|
242
271
|
const themes = {
|
|
243
272
|
primary: "primary",
|
|
@@ -348,57 +377,45 @@ const PlayAmountControl = ({ isDisabled }) => {
|
|
|
348
377
|
state === AUTO_PLAY_STATE.PLAYING, onClick: handleTogglePlayAmount, children: jsx(SelectMenu, { disabled: isDisabled() }) }), jsx(Button, { className: styles_group.groupItem, onClick: () => adjustPlayAmount({ direction: -1 }), theme: "ghost", disabled: isDisabled(), children: jsx("span", { className: styles_group.x2, children: "-" }) }), jsx(Button, { className: styles_group.groupItem, onClick: () => adjustPlayAmount({ direction: 1 }), theme: "ghost", disabled: isDisabled(), children: jsx("span", { className: cx$1(styles_group.x2, styles_group.last), children: "+" }) })] }));
|
|
349
378
|
};
|
|
350
379
|
|
|
380
|
+
const getDefaultButtonClassName = (currencyCode, styles) => {
|
|
381
|
+
if (currencyCode === Currency.GOLD) {
|
|
382
|
+
return styles.buttonGold;
|
|
383
|
+
}
|
|
384
|
+
if (currencyCode === Currency.SWEEPS) {
|
|
385
|
+
return styles.buttonSweeps;
|
|
386
|
+
}
|
|
387
|
+
return styles.buttonDefault;
|
|
388
|
+
};
|
|
389
|
+
const getActiveButtonClassName = (currencyCode, styles) => {
|
|
390
|
+
if (currencyCode === Currency.GOLD) {
|
|
391
|
+
return styles.buttonGold__active;
|
|
392
|
+
}
|
|
393
|
+
if (currencyCode === Currency.SWEEPS) {
|
|
394
|
+
return styles.buttonSweeps__active;
|
|
395
|
+
}
|
|
396
|
+
return styles.buttonDefault__active;
|
|
397
|
+
};
|
|
398
|
+
|
|
351
399
|
var AUTOPLAY_LABEL;
|
|
352
400
|
(function (AUTOPLAY_LABEL) {
|
|
353
401
|
AUTOPLAY_LABEL["START"] = "START AUTOPLAY";
|
|
354
402
|
AUTOPLAY_LABEL["STOP"] = "STOP AUTOPLAY";
|
|
355
403
|
})(AUTOPLAY_LABEL || (AUTOPLAY_LABEL = {}));
|
|
356
404
|
|
|
357
|
-
const
|
|
358
|
-
const { config } = useAutoManualPlayState();
|
|
359
|
-
const { isValidPlayAmount, playValues: { displayPlayAmountView, togglePlayAmountView }, autoPlay: { isDisabled, state, onPlay, onStopPlay }, } = usePlayController();
|
|
360
|
-
const { current } = config.currencyOptions;
|
|
361
|
-
const roleButton = GAME_MODE.AUTOPLAY;
|
|
362
|
-
const buttonLabel = state === AUTO_PLAY_STATE.PLAYING
|
|
363
|
-
? AUTOPLAY_LABEL.STOP
|
|
364
|
-
: AUTOPLAY_LABEL.START;
|
|
365
|
-
const activeClassName = useMemo(() => {
|
|
366
|
-
if (current.code === Currency.GOLD) {
|
|
367
|
-
return styles_button.buttonGold__active;
|
|
368
|
-
}
|
|
369
|
-
if (current.code === Currency.SWEEPS) {
|
|
370
|
-
return styles_button.buttonSweeps__active;
|
|
371
|
-
}
|
|
372
|
-
return styles_button.buttonDefault__active;
|
|
373
|
-
}, [current.code]);
|
|
374
|
-
const defaultClassName = useMemo(() => {
|
|
375
|
-
if (buttonLabel === AUTOPLAY_LABEL.STOP) {
|
|
376
|
-
return styles_button.buttonCashout;
|
|
377
|
-
}
|
|
378
|
-
if (current.code === Currency.GOLD) {
|
|
379
|
-
return styles_button.buttonGold;
|
|
380
|
-
}
|
|
381
|
-
if (current.code === Currency.SWEEPS) {
|
|
382
|
-
return styles_button.buttonSweeps;
|
|
383
|
-
}
|
|
384
|
-
return styles_button.buttonDefault;
|
|
385
|
-
}, [buttonLabel, current.code]);
|
|
405
|
+
const useSpacebarButtonTrigger = ({ roleButton, activeClassName, canTrigger, }) => {
|
|
386
406
|
const handleKeyPress = useCallback((event) => {
|
|
387
407
|
if (event.code !== "Space") {
|
|
388
408
|
return;
|
|
389
409
|
}
|
|
390
410
|
const button = selectButton(roleButton);
|
|
391
|
-
if (!button) {
|
|
411
|
+
if (!button || !canTrigger()) {
|
|
392
412
|
return;
|
|
393
413
|
}
|
|
394
414
|
event.preventDefault();
|
|
395
415
|
event.stopPropagation();
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
button.click();
|
|
400
|
-
}
|
|
401
|
-
}, [activeClassName, isDisabled, roleButton, state]);
|
|
416
|
+
addPressedClass(roleButton, activeClassName);
|
|
417
|
+
button.click();
|
|
418
|
+
}, [activeClassName, canTrigger, roleButton]);
|
|
402
419
|
const handleKeyUp = useCallback((event) => {
|
|
403
420
|
if (event.code !== "Space") {
|
|
404
421
|
return;
|
|
@@ -419,10 +436,44 @@ const AutoPlayController = () => {
|
|
|
419
436
|
window.removeEventListener("keyup", handleKeyUp, true);
|
|
420
437
|
};
|
|
421
438
|
}, [handleKeyPress, handleKeyUp]);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const AutoPlayController = () => {
|
|
442
|
+
const { config } = useAutoManualPlayState();
|
|
443
|
+
const { isValidPlayAmount, playValues: { displayPlayAmountView, togglePlayAmountView }, autoPlay: { isDisabled, state, onPlay, onStopPlay, cashoutDisabled }, } = usePlayController();
|
|
444
|
+
const { current } = config.currencyOptions;
|
|
445
|
+
const roleButton = GAME_MODE.AUTOPLAY;
|
|
446
|
+
const buttonLabel = state === AUTO_PLAY_STATE.PLAYING
|
|
447
|
+
? AUTOPLAY_LABEL.STOP
|
|
448
|
+
: AUTOPLAY_LABEL.START;
|
|
449
|
+
const activeClassName = getActiveButtonClassName(current.code, styles_button);
|
|
450
|
+
const defaultClassName = useMemo(() => {
|
|
451
|
+
if (buttonLabel === AUTOPLAY_LABEL.STOP) {
|
|
452
|
+
return styles_button.buttonCashout;
|
|
453
|
+
}
|
|
454
|
+
return getDefaultButtonClassName(current.code, styles_button);
|
|
455
|
+
}, [buttonLabel, current.code]);
|
|
456
|
+
useSpacebarButtonTrigger({
|
|
457
|
+
roleButton,
|
|
458
|
+
activeClassName,
|
|
459
|
+
canTrigger: () => canAutoplaySpaceTrigger({
|
|
460
|
+
state,
|
|
461
|
+
cashoutDisabled,
|
|
462
|
+
isDisabled: isDisabled(),
|
|
463
|
+
}),
|
|
464
|
+
});
|
|
465
|
+
const isButtonDisabled = isAutoplayButtonDisabled({
|
|
466
|
+
state,
|
|
467
|
+
cashoutDisabled,
|
|
468
|
+
isDisabled: isDisabled(),
|
|
469
|
+
isValidPlayAmount,
|
|
470
|
+
});
|
|
471
|
+
const buttonAction = useMemo(() => createAutoplayButtonAction({
|
|
472
|
+
state,
|
|
473
|
+
cashoutDisabled,
|
|
474
|
+
onStopPlay,
|
|
475
|
+
onPlay,
|
|
476
|
+
}), [cashoutDisabled, onPlay, onStopPlay, state]);
|
|
426
477
|
const handleTogglePlayAmount = useCallback(() => {
|
|
427
478
|
setToggleGameWidgetsVisibility();
|
|
428
479
|
togglePlayAmountView();
|
|
@@ -468,80 +519,71 @@ const useIsRunningExternal = () => {
|
|
|
468
519
|
};
|
|
469
520
|
|
|
470
521
|
const ManualPlayController = () => {
|
|
471
|
-
const { config } = useAutoManualPlayState();
|
|
522
|
+
const { config, doubleOrNothing } = useAutoManualPlayState();
|
|
472
523
|
const { isRunningExternal } = useIsRunningExternal();
|
|
473
|
-
const { isValidPlayAmount, playValues: { displayPlayAmountView, togglePlayAmountView }, manualPlay: { isDisabled, onPlay, canCashout }, } = usePlayController();
|
|
524
|
+
const { isValidPlayAmount, playValues: { displayPlayAmountView, togglePlayAmountView }, manualPlay: { isDisabled, onPlay, canCashout, cashoutDisabled }, } = usePlayController();
|
|
474
525
|
const { current } = config.currencyOptions;
|
|
475
526
|
const roleButton = GAME_MODE.MANUAL;
|
|
476
|
-
const activeClassName =
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return styles_button.buttonDefault__active;
|
|
484
|
-
}, [current.code]);
|
|
485
|
-
const defaultClassName = useMemo(() => {
|
|
486
|
-
if (current.code === Currency.GOLD) {
|
|
487
|
-
return styles_button.buttonGold;
|
|
488
|
-
}
|
|
489
|
-
if (current.code === Currency.SWEEPS) {
|
|
490
|
-
return styles_button.buttonSweeps;
|
|
491
|
-
}
|
|
492
|
-
return styles_button.buttonDefault;
|
|
493
|
-
}, [current.code]);
|
|
494
|
-
const handleKeyPress = useCallback((event) => {
|
|
495
|
-
if (event.code !== "Space") {
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
const button = selectButton(roleButton);
|
|
499
|
-
if (!button || isDisabled()) {
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
event.preventDefault();
|
|
503
|
-
event.stopPropagation();
|
|
504
|
-
addPressedClass(roleButton, activeClassName);
|
|
505
|
-
button.click();
|
|
506
|
-
}, [roleButton, isDisabled, activeClassName]);
|
|
507
|
-
const handleKeyUp = useCallback((event) => {
|
|
508
|
-
if (event.code !== "Space") {
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const button = selectButton(roleButton);
|
|
512
|
-
if (!button) {
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
event.preventDefault();
|
|
516
|
-
event.stopPropagation();
|
|
517
|
-
removePressedClass(roleButton, activeClassName);
|
|
518
|
-
}, [roleButton, activeClassName]);
|
|
519
|
-
useEffect(() => {
|
|
520
|
-
window.addEventListener("keydown", handleKeyPress, true);
|
|
521
|
-
window.addEventListener("keyup", handleKeyUp, true);
|
|
522
|
-
return () => {
|
|
523
|
-
window.removeEventListener("keydown", handleKeyPress, true);
|
|
524
|
-
window.removeEventListener("keyup", handleKeyUp, true);
|
|
525
|
-
};
|
|
526
|
-
}, [handleKeyPress, handleKeyUp]);
|
|
527
|
+
const activeClassName = getActiveButtonClassName(current.code, styles_button);
|
|
528
|
+
const defaultClassName = getDefaultButtonClassName(current.code, styles_button);
|
|
529
|
+
useSpacebarButtonTrigger({
|
|
530
|
+
roleButton,
|
|
531
|
+
activeClassName,
|
|
532
|
+
canTrigger: () => !isDisabled(),
|
|
533
|
+
});
|
|
527
534
|
const isButtonDisabled = isDisabled() || !isValidPlayAmount;
|
|
528
535
|
const handleTogglePlayAmount = useCallback(() => {
|
|
529
536
|
setToggleGameWidgetsVisibility();
|
|
530
537
|
togglePlayAmountView();
|
|
531
538
|
setToggleGameWidgetsExpansion();
|
|
532
539
|
}, [togglePlayAmountView]);
|
|
540
|
+
const handleDoubleOrNothingClick = useCallback(() => {
|
|
541
|
+
if (config.playOptions.disabledController) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (!config.doubleOrNothing?.display) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (config.doubleOrNothing?.disabled) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
doubleOrNothing.startDoubleOrNothing();
|
|
551
|
+
}, [
|
|
552
|
+
config.playOptions.disabledController,
|
|
553
|
+
config.doubleOrNothing?.display,
|
|
554
|
+
config.doubleOrNothing?.disabled,
|
|
555
|
+
doubleOrNothing,
|
|
556
|
+
]);
|
|
557
|
+
const handleCashoutClick = useMemo(() => createManualCashoutClickHandler({
|
|
558
|
+
cashoutDisabled,
|
|
559
|
+
onCashout: config.onCashout,
|
|
560
|
+
}), [cashoutDisabled, config.onCashout]);
|
|
533
561
|
const renderButton = useMemo(() => {
|
|
534
562
|
if (displayPlayAmountView) {
|
|
535
563
|
return (jsx(Button, { className: styles_button.buttonPlayAmount, onClick: handleTogglePlayAmount, roleType: roleButton, children: "SELECT PLAY AMOUNT" }));
|
|
536
564
|
}
|
|
537
565
|
if (canCashout) {
|
|
538
|
-
|
|
539
|
-
|
|
566
|
+
const isCashoutDisabled = isManualCashoutDisabled({
|
|
567
|
+
disabledController: config.playOptions.disabledController,
|
|
568
|
+
isPlaying: config.playOptions.isPlaying,
|
|
569
|
+
cashoutDisabled,
|
|
570
|
+
});
|
|
571
|
+
const showDoubleOrNothing = !!config.doubleOrNothing?.display;
|
|
572
|
+
const isDoubleOrNothingDisabled = isCashoutDisabled ||
|
|
573
|
+
!!config.doubleOrNothing?.disabled ||
|
|
574
|
+
doubleOrNothing.state === DOUBLE_OR_NOTHING_STATE.PROGRESS;
|
|
575
|
+
return (jsxs("div", { className: styles_button.buttonRow, children: [jsxs(Button, { disabled: isCashoutDisabled, className: cx$1(styles_button.buttonCashout, {
|
|
576
|
+
[styles_button.buttonRow__cashout]: showDoubleOrNothing,
|
|
577
|
+
}), onClick: handleCashoutClick, roleType: roleButton, children: [isRunningExternal ? "COLLECT" : "CASHOUT", " ", format(current.possibleWin ?? 0, current.decimals), " ", current.abbr] }), showDoubleOrNothing ? (jsx(Button, { disabled: isDoubleOrNothingDisabled, className: cx$1(styles_button.buttonDON, styles_button.buttonRow__don, {
|
|
578
|
+
[styles_button.buttonDON__disabled]: isDoubleOrNothingDisabled,
|
|
579
|
+
}), onClick: handleDoubleOrNothingClick, roleType: roleButton, children: jsxs("div", { className: styles_button.buttonDON__content, children: [jsx("p", { className: styles_button.buttonDON__title, children: "DOUBLE" }), jsx("p", { className: styles_button.buttonDON__subtitle, children: "OR NOTHING" })] }) })) : null] }));
|
|
540
580
|
}
|
|
541
581
|
return (jsx(Button, { disabled: isButtonDisabled, className: defaultClassName, onClick: onPlay, roleType: roleButton, children: "PLAY NOW" }));
|
|
542
582
|
}, [
|
|
543
583
|
canCashout,
|
|
544
|
-
|
|
584
|
+
cashoutDisabled,
|
|
585
|
+
config.doubleOrNothing?.disabled,
|
|
586
|
+
config.doubleOrNothing?.display,
|
|
545
587
|
config.playOptions.disabledController,
|
|
546
588
|
config.playOptions.isPlaying,
|
|
547
589
|
current.abbr,
|
|
@@ -549,11 +591,14 @@ const ManualPlayController = () => {
|
|
|
549
591
|
current.possibleWin,
|
|
550
592
|
defaultClassName,
|
|
551
593
|
displayPlayAmountView,
|
|
594
|
+
doubleOrNothing.state,
|
|
595
|
+
handleDoubleOrNothingClick,
|
|
596
|
+
handleCashoutClick,
|
|
552
597
|
handleTogglePlayAmount,
|
|
553
598
|
isButtonDisabled,
|
|
599
|
+
isRunningExternal,
|
|
554
600
|
onPlay,
|
|
555
601
|
roleButton,
|
|
556
|
-
isRunningExternal,
|
|
557
602
|
]);
|
|
558
603
|
return (jsxs(Fragment, { children: [jsx(PlayAmountControl, { isDisabled: isDisabled || displayPlayAmountView }), renderButton] }));
|
|
559
604
|
};
|
|
@@ -838,11 +883,16 @@ const PlayValueList = () => {
|
|
|
838
883
|
const AutoManualPlayProvider = ({ children, config, }) => {
|
|
839
884
|
const [mode, setMode] = useState(GAME_MODE.MANUAL);
|
|
840
885
|
const [autoplayState, setAutoplayState] = useState(AUTO_PLAY_STATE.IDLE);
|
|
886
|
+
const [doubleOrNothingState, setDoubleOrNothingState] = useState(DOUBLE_OR_NOTHING_STATE.IDLE);
|
|
841
887
|
const [isAutoPlaying, setIsAutoPlaying] = useState(false);
|
|
842
888
|
const [playedRounds, setPlayedRounds] = useState(0);
|
|
843
889
|
const [numberOfPlays, setNumberOfPlays] = useState(AUTOPLAY_DEFAULT_PLAY_ROUNDS_COUNT);
|
|
844
890
|
const [selection, setSelection] = useState([]);
|
|
845
891
|
const [displayPlayAmountView, setDisplayPlayAmountView] = useState(false);
|
|
892
|
+
const isControllerDisabled = config.playOptions.disabledController;
|
|
893
|
+
const isGamePlaying = config.playOptions.isPlaying;
|
|
894
|
+
const isAutoplayPlaying = autoplayState === AUTO_PLAY_STATE.PLAYING;
|
|
895
|
+
const isSimplified = config.withoutRiskAndAutoplay === true;
|
|
846
896
|
const togglePlayAmountView = useCallback(() => {
|
|
847
897
|
setDisplayPlayAmountView((v) => !v);
|
|
848
898
|
}, []);
|
|
@@ -857,6 +907,20 @@ const AutoManualPlayProvider = ({ children, config, }) => {
|
|
|
857
907
|
setAutoplayState(AUTO_PLAY_STATE.IDLE);
|
|
858
908
|
setIsAutoPlaying(false);
|
|
859
909
|
}, []);
|
|
910
|
+
const startDoubleOrNothing = useCallback(() => {
|
|
911
|
+
if (config.doubleOrNothing?.disabled) {
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
setDoubleOrNothingState(DOUBLE_OR_NOTHING_STATE.PROGRESS);
|
|
915
|
+
config.doubleOrNothing?.onDoubleOrNothingOpen();
|
|
916
|
+
}, [config.doubleOrNothing]);
|
|
917
|
+
const stopDoubleOrNothing = useCallback(() => {
|
|
918
|
+
if (config.doubleOrNothing?.disabled) {
|
|
919
|
+
return null;
|
|
920
|
+
}
|
|
921
|
+
setDoubleOrNothingState(DOUBLE_OR_NOTHING_STATE.IDLE);
|
|
922
|
+
config.doubleOrNothing?.onDoubleOrNothingClose();
|
|
923
|
+
}, [config.doubleOrNothing]);
|
|
860
924
|
const updateAutoplayState = useCallback((newState) => setAutoplayState(newState), []);
|
|
861
925
|
const playManualMode = useCallback(() => {
|
|
862
926
|
setMode(GAME_MODE.MANUAL);
|
|
@@ -864,20 +928,19 @@ const AutoManualPlayProvider = ({ children, config, }) => {
|
|
|
864
928
|
}, []);
|
|
865
929
|
const resetState = useCallback(() => {
|
|
866
930
|
setMode(GAME_MODE.MANUAL);
|
|
931
|
+
setDoubleOrNothingState(DOUBLE_OR_NOTHING_STATE.IDLE);
|
|
867
932
|
setAutoplayState(AUTO_PLAY_STATE.IDLE);
|
|
868
933
|
setPlayedRounds(0);
|
|
869
934
|
setNumberOfPlays(0);
|
|
870
935
|
setSelection([]);
|
|
871
936
|
}, []);
|
|
872
937
|
const toggleMode = useCallback(() => {
|
|
873
|
-
if (
|
|
874
|
-
config.playOptions.disabledController ||
|
|
875
|
-
autoplayState === AUTO_PLAY_STATE.PLAYING) {
|
|
938
|
+
if (isGamePlaying || isControllerDisabled || isAutoplayPlaying) {
|
|
876
939
|
return;
|
|
877
940
|
}
|
|
878
941
|
setNumberOfPlays(AUTOPLAY_DEFAULT_PLAY_ROUNDS_COUNT);
|
|
879
942
|
setMode((prevMode) => prevMode === GAME_MODE.MANUAL ? GAME_MODE.AUTOPLAY : GAME_MODE.MANUAL);
|
|
880
|
-
}, [
|
|
943
|
+
}, [isAutoplayPlaying, isControllerDisabled, isGamePlaying]);
|
|
881
944
|
const updateSelection = useCallback((values) => {
|
|
882
945
|
if (!isAutoPlaying) {
|
|
883
946
|
setSelection(values);
|
|
@@ -886,6 +949,7 @@ const AutoManualPlayProvider = ({ children, config, }) => {
|
|
|
886
949
|
const contextValue = useMemo(() => ({
|
|
887
950
|
mode,
|
|
888
951
|
config,
|
|
952
|
+
withoutRiskAndAutoplay: config.withoutRiskAndAutoplay,
|
|
889
953
|
manual: { playManualMode },
|
|
890
954
|
autoPlay: {
|
|
891
955
|
state: autoplayState,
|
|
@@ -902,6 +966,11 @@ const AutoManualPlayProvider = ({ children, config, }) => {
|
|
|
902
966
|
setNumberOfPlays,
|
|
903
967
|
setState: setAutoplayState,
|
|
904
968
|
},
|
|
969
|
+
doubleOrNothing: {
|
|
970
|
+
state: doubleOrNothingState,
|
|
971
|
+
startDoubleOrNothing,
|
|
972
|
+
stopDoubleOrNothing,
|
|
973
|
+
},
|
|
905
974
|
reset: resetState,
|
|
906
975
|
toggleMode,
|
|
907
976
|
playValues: {
|
|
@@ -922,12 +991,14 @@ const AutoManualPlayProvider = ({ children, config, }) => {
|
|
|
922
991
|
stopAutoplay,
|
|
923
992
|
updateSelection,
|
|
924
993
|
updateAutoplayState,
|
|
994
|
+
doubleOrNothingState,
|
|
995
|
+
startDoubleOrNothing,
|
|
996
|
+
stopDoubleOrNothing,
|
|
925
997
|
resetState,
|
|
926
998
|
toggleMode,
|
|
927
999
|
displayPlayAmountView,
|
|
928
1000
|
togglePlayAmountView,
|
|
929
1001
|
]);
|
|
930
|
-
const isSimplified = config.withoutRiskAndAutoplay === true;
|
|
931
1002
|
return (jsxs(AutoManualPlayStateContext.Provider, { value: contextValue, children: [typeof children === "function" ? children(contextValue) : children, config.playOptions.displayController && (jsx("div", { className: cx$1(styles_ui.base, styles_ui.betForm), style: {
|
|
932
1003
|
"--play-bottom": config.panel.bottom ?? 0,
|
|
933
1004
|
"--play-panel-bg": hexToRgb(config.panel.bgColorHex ?? "#01243A"),
|
|
@@ -935,19 +1006,16 @@ const AutoManualPlayProvider = ({ children, config, }) => {
|
|
|
935
1006
|
"--play-panel-bg-opacity": config.panel.bgColorOpacity ?? 0.5,
|
|
936
1007
|
}, children: jsxs("div", { className: cx$1(styles_ui.container), children: [jsx(PlayValueList, {}), !isSimplified ? (jsxs("div", { className: cx$1(styles_ui.auto), children: [jsx(DifficultySelector, { playOptions: {
|
|
937
1008
|
...config.playOptions,
|
|
938
|
-
disabledMenu: config.playOptions.
|
|
939
|
-
|
|
940
|
-
}, dropdownConfig: config.dropdown }), jsx(InputWithSwitch, { value: numberOfPlays === Infinity ? 0 : numberOfPlays, type: "number", onChange: (e) => setNumberOfPlays(Number(e.currentTarget.value)), placeholder: "Number of Plays", min: 0, max: 99, disabled: config.playOptions.disabledController ||
|
|
941
|
-
mode === GAME_MODE.MANUAL, switcherConfig: {
|
|
1009
|
+
disabledMenu: isControllerDisabled || config.playOptions.disabledMenu,
|
|
1010
|
+
}, dropdownConfig: config.dropdown }), jsx(InputWithSwitch, { value: numberOfPlays === Infinity ? 0 : numberOfPlays, type: "number", onChange: (e) => setNumberOfPlays(Number(e.currentTarget.value)), placeholder: "Number of Plays", min: 0, max: 99, disabled: isControllerDisabled || mode === GAME_MODE.MANUAL, switcherConfig: {
|
|
942
1011
|
onSwitch: toggleMode,
|
|
943
|
-
isPlaying: isAutoPlaying ||
|
|
1012
|
+
isPlaying: isAutoPlaying || isGamePlaying,
|
|
944
1013
|
enabled: mode !== GAME_MODE.MANUAL,
|
|
945
|
-
disabled:
|
|
946
|
-
autoplayState === AUTO_PLAY_STATE.PLAYING,
|
|
1014
|
+
disabled: isControllerDisabled || isAutoplayPlaying,
|
|
947
1015
|
}, children: jsx("span", { className: cx$1({
|
|
948
1016
|
[styles_ui.disabled]: mode !== GAME_MODE.AUTOPLAY ||
|
|
949
1017
|
numberOfPlays !== Infinity ||
|
|
950
|
-
|
|
1018
|
+
isAutoplayPlaying,
|
|
951
1019
|
}), children: "\u221E" }) })] })) : null, mode === GAME_MODE.MANUAL ? (jsx(ManualPlayController, {})) : (jsx(AutoPlayController, {})), jsx(WidgetContainer, { state: autoplayState, displayPlayAmountView: displayPlayAmountView, widgets: {
|
|
952
1020
|
left: config.leftWidgets,
|
|
953
1021
|
center: config.centerWidgets,
|
|
@@ -955,5 +1023,5 @@ const AutoManualPlayProvider = ({ children, config, }) => {
|
|
|
955
1023
|
} })] }) }))] }));
|
|
956
1024
|
};
|
|
957
1025
|
|
|
958
|
-
export { AUTO_PLAY_STATE, AutoManualPlayProvider, GAME_MODE, WIDGET, format };
|
|
1026
|
+
export { AUTO_PLAY_STATE, AutoManualPlayProvider, DOUBLE_OR_NOTHING_STATE, GAME_MODE, WIDGET, canAutoplaySpaceTrigger, createAutoplayButtonAction, createManualCashoutClickHandler, format, isAutoplayButtonDisabled, isManualCashoutDisabled };
|
|
959
1027
|
//# sourceMappingURL=index.mjs.map
|