-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathbookEventHandlerMap.ts
More file actions
171 lines (159 loc) · 6.9 KB
/
bookEventHandlerMap.ts
File metadata and controls
171 lines (159 loc) · 6.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
import _ from 'lodash';
import { recordBookEvent, checkIsMultipleRevealEvents, type BookEventHandlerMap } from 'utils-book';
import { stateBet, stateUi } from 'state-shared';
import { sequence } from 'utils-shared/sequence';
import { eventEmitter } from './eventEmitter';
import { playBookEvent } from './utils';
import { winLevelMap, type WinLevel, type WinLevelData } from './winLevelMap';
import { stateGame, stateGameDerived } from './stateGame.svelte';
import type { BookEvent, BookEventOfType, BookEventContext } from './typesBookEvent';
import type { Position } from './types';
import config from './config';
const winLevelSoundsPlay = ({ winLevelData }: { winLevelData: WinLevelData }) => {
if (winLevelData?.alias === 'max') eventEmitter.broadcastAsync({ type: 'uiHide' });
if (winLevelData?.sound?.sfx) {
eventEmitter.broadcast({ type: 'soundOnce', name: winLevelData.sound.sfx });
}
if (winLevelData?.sound?.bgm) {
eventEmitter.broadcast({ type: 'soundMusic', name: winLevelData.sound.bgm });
}
if (winLevelData?.type === 'big') {
eventEmitter.broadcast({ type: 'soundLoop', name: 'sfx_bigwin_coinloop' });
}
};
const winLevelSoundsStop = () => {
eventEmitter.broadcast({ type: 'soundStop', name: 'sfx_bigwin_coinloop' });
if (stateBet.activeBetModeKey === 'SUPERSPIN' || stateGame.gameType === 'freegame') {
// check if SUPERSPIN, when finishing a bet.
eventEmitter.broadcast({ type: 'soundMusic', name: 'bgm_freespin' });
} else {
eventEmitter.broadcast({ type: 'soundMusic', name: 'bgm_main' });
}
eventEmitter.broadcastAsync({ type: 'uiShow' });
};
const animateSymbols = async ({ positions }: { positions: Position[] }) => {
eventEmitter.broadcast({ type: 'boardShow' });
await eventEmitter.broadcastAsync({
type: 'boardWithAnimateSymbols',
symbolPositions: positions,
});
};
export const bookEventHandlerMap: BookEventHandlerMap<BookEvent, BookEventContext> = {
reveal: async (bookEvent: BookEventOfType<'reveal'>, { bookEvents }: BookEventContext) => {
const isBonusGame = checkIsMultipleRevealEvents({ bookEvents });
if (isBonusGame) {
eventEmitter.broadcast({ type: 'stopButtonEnable' });
recordBookEvent({ bookEvent });
}
stateGame.gameType = bookEvent.gameType;
await stateGameDerived.enhancedBoard.spin({
revealEvent: bookEvent,
paddingBoard: config.paddingReels[bookEvent.gameType],
});
eventEmitter.broadcast({ type: 'soundScatterCounterClear' });
},
winInfo: async (bookEvent: BookEventOfType<'winInfo'>) => {
eventEmitter.broadcast({ type: 'soundOnce', name: 'sfx_winlevel_small' });
await sequence(bookEvent.wins, async (win) => {
await animateSymbols({ positions: win.positions });
});
},
setTotalWin: async (bookEvent: BookEventOfType<'setTotalWin'>) => {
stateBet.winBookEventAmount = bookEvent.amount;
},
freeSpinTrigger: async (bookEvent: BookEventOfType<'freeSpinTrigger'>) => {
// animate scatters
eventEmitter.broadcast({ type: 'soundOnce', name: 'sfx_scatter_win_v2' });
await animateSymbols({ positions: bookEvent.positions });
// show free spin intro
eventEmitter.broadcast({ type: 'soundOnce', name: 'sfx_superfreespin' });
await eventEmitter.broadcastAsync({ type: 'uiHide' });
await eventEmitter.broadcastAsync({ type: 'transition' });
eventEmitter.broadcast({ type: 'freeSpinIntroShow' });
eventEmitter.broadcast({ type: 'soundOnce', name: 'jng_intro_fs' });
eventEmitter.broadcast({ type: 'soundMusic', name: 'bgm_freespin' });
await eventEmitter.broadcastAsync({
type: 'freeSpinIntroUpdate',
totalFreeSpins: bookEvent.totalFs,
});
stateGame.gameType = 'freegame';
eventEmitter.broadcast({ type: 'freeSpinIntroHide' });
eventEmitter.broadcast({ type: 'boardFrameGlowShow' });
eventEmitter.broadcast({ type: 'freeSpinCounterShow' });
stateUi.freeSpinCounterShow = true;
eventEmitter.broadcast({
type: 'freeSpinCounterUpdate',
current: undefined,
total: bookEvent.totalFs,
});
stateUi.freeSpinCounterTotal = bookEvent.totalFs;
await eventEmitter.broadcastAsync({ type: 'uiShow' });
await eventEmitter.broadcastAsync({ type: 'drawerButtonShow' });
eventEmitter.broadcast({ type: 'drawerFold' });
},
updateFreeSpin: async (bookEvent: BookEventOfType<'updateFreeSpin'>) => {
eventEmitter.broadcast({ type: 'freeSpinCounterShow' });
stateUi.freeSpinCounterShow = true;
eventEmitter.broadcast({
type: 'freeSpinCounterUpdate',
current: bookEvent.amount + 1,
total: bookEvent.total,
});
stateUi.freeSpinCounterCurrent = bookEvent.amount + 1;
stateUi.freeSpinCounterTotal = bookEvent.total;
},
freeSpinEnd: async (bookEvent: BookEventOfType<'freeSpinEnd'>) => {
const winLevelData = winLevelMap[bookEvent.winLevel as WinLevel];
await eventEmitter.broadcastAsync({ type: 'uiHide' });
stateGame.gameType = 'basegame';
eventEmitter.broadcast({ type: 'boardFrameGlowHide' });
eventEmitter.broadcast({ type: 'freeSpinOutroShow' });
eventEmitter.broadcast({ type: 'soundOnce', name: 'sfx_youwon_panel' });
winLevelSoundsPlay({ winLevelData });
await eventEmitter.broadcastAsync({
type: 'freeSpinOutroCountUp',
amount: bookEvent.amount,
winLevelData,
});
winLevelSoundsStop();
eventEmitter.broadcast({ type: 'freeSpinOutroHide' });
eventEmitter.broadcast({ type: 'freeSpinCounterHide' });
stateUi.freeSpinCounterShow = false;
await eventEmitter.broadcastAsync({ type: 'transition' });
await eventEmitter.broadcastAsync({ type: 'uiShow' });
await eventEmitter.broadcastAsync({ type: 'drawerUnfold' });
eventEmitter.broadcast({ type: 'drawerButtonHide' });
},
setWin: async (bookEvent: BookEventOfType<'setWin'>) => {
const winLevelData = winLevelMap[bookEvent.winLevel as WinLevel];
eventEmitter.broadcast({ type: 'winShow' });
winLevelSoundsPlay({ winLevelData });
await eventEmitter.broadcastAsync({
type: 'winUpdate',
amount: bookEvent.amount,
winLevelData,
});
winLevelSoundsStop();
eventEmitter.broadcast({ type: 'winHide' });
},
finalWin: async (bookEvent: BookEventOfType<'finalWin'>) => {
// Do nothing
},
// customised
createBonusSnapshot: async (bookEvent: BookEventOfType<'createBonusSnapshot'>) => {
const { bookEvents } = bookEvent;
function findLastBookEvent<T>(type: T) {
return _.findLast(bookEvents, (bookEvent) => bookEvent.type === type) as
| BookEventOfType<T>
| undefined;
}
const lastFreeSpinTriggerEvent = findLastBookEvent('freeSpinTrigger' as const);
const lastUpdateFreeSpinEvent = findLastBookEvent('updateFreeSpin' as const);
const lastSetTotalWinEvent = findLastBookEvent('setTotalWin' as const);
const lastUpdateGlobalMultEvent = findLastBookEvent('updateGlobalMult' as const);
if (lastFreeSpinTriggerEvent) await playBookEvent(lastFreeSpinTriggerEvent, { bookEvents });
if (lastUpdateFreeSpinEvent) playBookEvent(lastUpdateFreeSpinEvent, { bookEvents });
if (lastSetTotalWinEvent) playBookEvent(lastSetTotalWinEvent, { bookEvents });
if (lastUpdateGlobalMultEvent) playBookEvent(lastUpdateGlobalMultEvent, { bookEvents });
},
};