@@ -102,6 +102,15 @@ const SlotMachine: React.FC = () => {
102
102
[ finalSlotScreen ]
103
103
) ;
104
104
105
+ const getTimerForNewSpin = ( slotResult : SlotScreenResult ) : number => {
106
+ const noResults = Object . entries ( slotResult ) . every (
107
+ ( [ key , value ] : [ string , SlotScreenResult [ keyof SlotScreenResult ] ] ) =>
108
+ ! value || ( Array . isArray ( value ) && ! value . length )
109
+ ) ;
110
+
111
+ return noResults ? 100 : ANIMATE_RESULTS_DURATION ;
112
+ } ;
113
+
105
114
const onSpinningEnd = useCallback ( ( ) => {
106
115
slotWheelSound . pause ( ) ;
107
116
let slotResult : SlotScreenResult = getScreenResult ( finalSlotScreen ) ;
@@ -121,20 +130,27 @@ const SlotMachine: React.FC = () => {
121
130
}
122
131
const action = { type : SPIN_ENDED , payload : slotResult } ;
123
132
dispatch ( action ) ;
133
+ const timeToNewSpin : number = getTimerForNewSpin ( slotResult ) ;
124
134
125
- if ( ! credits ) {
126
- openModal ( ModalType . RESET , { hasNoCredits : true } ) ;
127
- return ;
128
- }
135
+ // shuffle reels for next spinning
136
+ /* const shuffledReels = getShuffledReels();
137
+ setReels(prevReels =>
138
+ prevReels.map((reel, index) => [
139
+ ...reel.slice(0, ROW_NUMBER),
140
+ ...shuffledReels[index].slice(ROW_NUMBER),
141
+ ])
142
+ ); */
129
143
130
144
setTimeout ( ( ) => {
145
+ const updatedCredits : number = credits + slotResult . winAmount ;
146
+ if ( ! updatedCredits ) {
147
+ openModal ( ModalType . RESET , { hasNoCredits : true } ) ;
148
+ }
131
149
dispatch ( { type : NEW_SPIN_PREPARED } ) ;
132
- // setFinalSlotScreens([]);
133
- // TODO remove added symbols from array and shuffle the non visible symbols
134
150
if ( isAutoSpinOn ) {
135
151
onSpin ( ) ;
136
152
}
137
- } , ANIMATE_RESULTS_DURATION ) ;
153
+ } , timeToNewSpin ) ;
138
154
} , [
139
155
dispatch ,
140
156
isSoundOn ,
0 commit comments