Changeset 285c3cc for components/blackjack
- Timestamp:
- 06/16/22 17:01:08 (2 years ago)
- Branches:
- main
- Children:
- 9bd09b0
- Parents:
- ebf5e04
- Location:
- components/blackjack
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
components/blackjack/BlackjackHeader.jsx
rebf5e04 r285c3cc 41 41 })); 42 42 43 axios.get(`/api/ postgre?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(postgreRes => {44 if ( postgreRes.data?.success) {43 axios.get(`/api/blackjack?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 44 if (res.data?.success) { 45 45 dispatch(setPlayer({ 46 46 ...playerState.player, 47 displayName: postgreRes.data?.displayName,48 session_id: postgreRes.data?.session_id,49 credits: postgreRes.data?.credits,47 displayName: res.data?.displayName, 48 session_id: res.data?.session_id, 49 credits: res.data?.credits, 50 50 })); 51 51 52 axios.get(`/api/blackjack?action=get_player_info_on_enter&session_id=${localStorage.CAESSINO_SESSION_ID}`).then(res => { 53 if (res.data?.success) { 54 dispatch(setGame({ 55 ...playerState.game, 56 status: res.data?.status, 57 playerCards: res.data?.playerCards, 58 dealerCards: res.data?.dealerCards, 59 })) 60 61 dispatch(setStyle({ 62 ...styleState.style, 63 displayLoadingScreen: false, 64 })) 65 66 if (parseInt(res.data?.status.toString().substr(1, 1)) == 5) { 67 dispatch(setBlackjack({ 68 ...styleState.blackjack, 69 inputControls: { 70 ...styleState.blackjack.inputControls, 71 initialBet: { 72 ...styleState.blackjack.inputControls.initialBet, 73 chosenCredits: parseInt(res.data?.initialBet), 74 }, 75 sideBet: { 76 ...styleState.blackjack.inputControls.sideBet, 77 chosenCredits: 0, 78 } 79 }, 80 displays: { 81 ...styleState.blackjack.displays, 82 initialBet: false, 83 hitStand: true, 84 } 85 })) 86 87 if (res.data?.outcome === 'player_busted') { 88 dispatch(setStyle({ 89 ...styleState.style, 90 alert: { 91 show: true, 92 title: 'You busted!', 93 subtitle: `You lost $${-1*res.data?.earnings}`, 94 button: { 95 text: 'Play again', 96 action: 'play_again', 97 } 98 } 99 })) 100 } 101 else if (res.data?.outcome === 'dealer_busted') { 102 dispatch(setStyle({ 103 ...styleState.style, 104 alert: { 105 show: true, 106 title: 'Dealer busted!', 107 subtitle: `You won $${res.data?.earnings}`, 108 button: { 109 text: 'Play again', 110 action: 'play_again', 111 } 112 } 113 })) 114 } 115 else if (res.data?.outcome === 'player_won') { 116 dispatch(setStyle({ 117 ...styleState.style, 118 alert: { 119 show: true, 120 title: 'You won!', 121 subtitle: `You won $${res.data?.earnings}`, 122 button: { 123 text: 'Play again', 124 action: 'play_again', 125 } 126 } 127 })) 128 } 129 else if (res.data?.outcome === 'player_lost') { 130 dispatch(setStyle({ 131 ...styleState.style, 132 alert: { 133 show: true, 134 title: 'You lost!', 135 subtitle: `You lost $${-1*res.data?.earnings}`, 136 button: { 137 text: 'Play again', 138 action: 'play_again', 139 } 140 } 141 })) 142 } 143 else if (res.data?.outcome === 'draw') { 144 dispatch(setStyle({ 145 ...styleState.style, 146 alert: { 147 show: true, 148 title: 'Draw!', 149 subtitle: `You got your $${res.data?.earnings} back`, 150 button: { 151 text: 'Play again', 152 action: 'play_again', 153 } 154 } 155 })) 156 } 157 } 158 159 if (parseInt(res.data?.status.toString().substr(1, 1)) == 4) { 160 dispatch(setBlackjack({ 161 ...styleState.blackjack, 162 inputControls: { 163 ...styleState.blackjack.inputControls, 164 initialBet: { 165 ...styleState.blackjack.inputControls.initialBet, 166 chosenCredits: parseInt(res.data?.initialBet), 167 }, 168 sideBet: { 169 ...styleState.blackjack.inputControls.sideBet, 170 chosenCredits: 0, 171 } 172 }, 173 displays: { 174 ...styleState.blackjack.displays, 175 initialBet: false, 176 hitStand: true, 177 } 178 })) 179 } 180 181 if (parseInt(res.data?.status.toString().substr(1, 1)) == 3) { 182 dispatch(setBlackjack({ 183 ...styleState.blackjack, 184 inputControls: { 185 ...styleState.blackjack.inputControls, 186 initialBet: { 187 ...styleState.blackjack.inputControls.initialBet, 188 chosenCredits: parseInt(res.data?.initialBet), 189 }, 190 sideBet: { 191 ...styleState.blackjack.inputControls.sideBet, 192 chosenCredits: parseInt(res.data?.sideBet), 193 } 194 }, 195 displays: { 196 ...styleState.blackjack.displays, 197 initialBet: false, 198 hitStand: true, 199 } 200 })) 201 } 202 203 if (parseInt(res.data?.status.toString().substr(1, 1)) == 2) { 204 dispatch(setBlackjack({ 205 ...styleState.blackjack, 206 inputControls: { 207 ...styleState.blackjack.inputControls, 208 initialBet: { 209 ...styleState.blackjack.inputControls.initialBet, 210 chosenCredits: parseInt(res.data?.initialBet), 211 } 212 }, 213 displays: { 214 ...styleState.blackjack.displays, 215 initialBet: false, 216 sideBet: true, 217 } 218 })) 219 } 220 221 if (parseInt(res.data?.status.toString().substr(1, 1)) == 1) { 222 dispatch(setBlackjack({ 223 ...styleState.blackjack, 224 inputControls: { 225 ...styleState.blackjack.inputControls, 226 initialBet: { 227 ...styleState.blackjack.inputControls.initialBet, 228 chosenCredits: parseInt(postgreRes.data?.credits/2), 229 } 230 }, 231 })) 232 } 233 } 234 }); 52 dispatch(setGame({ 53 ...playerState.game, 54 status: res.data?.status, 55 playerCards: res.data?.playerCards, 56 dealerCards: res.data?.dealerCards, 57 })) 58 59 dispatch(setStyle({ 60 ...styleState.style, 61 displayLoadingScreen: false, 62 })) 63 64 if (parseInt(res.data?.status.toString().substr(1, 1)) == 5) { 65 dispatch(setBlackjack({ 66 ...styleState.blackjack, 67 inputControls: { 68 ...styleState.blackjack.inputControls, 69 initialBet: { 70 ...styleState.blackjack.inputControls.initialBet, 71 chosenCredits: parseInt(res.data?.initialBet), 72 }, 73 sideBet: { 74 ...styleState.blackjack.inputControls.sideBet, 75 chosenCredits: 0, 76 } 77 }, 78 displays: { 79 ...styleState.blackjack.displays, 80 initialBet: false, 81 hitStand: true, 82 } 83 })) 84 85 if (res.data?.outcome === 'player_busted') { 86 dispatch(setStyle({ 87 ...styleState.style, 88 alert: { 89 show: true, 90 title: 'You busted!', 91 subtitle: `You lost $${-1*res.data?.earnings}`, 92 button: { 93 text: 'Play again', 94 action: 'play_again', 95 } 96 } 97 })) 98 } 99 else if (res.data?.outcome === 'dealer_busted') { 100 dispatch(setStyle({ 101 ...styleState.style, 102 alert: { 103 show: true, 104 title: 'Dealer busted!', 105 subtitle: `You won $${res.data?.earnings}`, 106 button: { 107 text: 'Play again', 108 action: 'play_again', 109 } 110 } 111 })) 112 } 113 else if (res.data?.outcome === 'player_won') { 114 dispatch(setStyle({ 115 ...styleState.style, 116 alert: { 117 show: true, 118 title: 'You won!', 119 subtitle: `You won $${res.data?.earnings}`, 120 button: { 121 text: 'Play again', 122 action: 'play_again', 123 } 124 } 125 })) 126 } 127 else if (res.data?.outcome === 'player_lost') { 128 dispatch(setStyle({ 129 ...styleState.style, 130 alert: { 131 show: true, 132 title: 'You lost!', 133 subtitle: `You lost $${-1*res.data?.earnings}`, 134 button: { 135 text: 'Play again', 136 action: 'play_again', 137 } 138 } 139 })) 140 } 141 else if (res.data?.outcome === 'draw') { 142 dispatch(setStyle({ 143 ...styleState.style, 144 alert: { 145 show: true, 146 title: 'Draw!', 147 subtitle: `You got your $${res.data?.earnings} back`, 148 button: { 149 text: 'Play again', 150 action: 'play_again', 151 } 152 } 153 })) 154 } 155 } 156 157 if (parseInt(res.data?.status.toString().substr(1, 1)) == 4) { 158 dispatch(setBlackjack({ 159 ...styleState.blackjack, 160 inputControls: { 161 ...styleState.blackjack.inputControls, 162 initialBet: { 163 ...styleState.blackjack.inputControls.initialBet, 164 chosenCredits: parseInt(res.data?.initialBet), 165 }, 166 sideBet: { 167 ...styleState.blackjack.inputControls.sideBet, 168 chosenCredits: 0, 169 } 170 }, 171 displays: { 172 ...styleState.blackjack.displays, 173 initialBet: false, 174 hitStand: true, 175 } 176 })) 177 } 178 179 if (parseInt(res.data?.status.toString().substr(1, 1)) == 3) { 180 dispatch(setBlackjack({ 181 ...styleState.blackjack, 182 inputControls: { 183 ...styleState.blackjack.inputControls, 184 initialBet: { 185 ...styleState.blackjack.inputControls.initialBet, 186 chosenCredits: parseInt(res.data?.initialBet), 187 }, 188 sideBet: { 189 ...styleState.blackjack.inputControls.sideBet, 190 chosenCredits: parseInt(res.data?.sideBet), 191 } 192 }, 193 displays: { 194 ...styleState.blackjack.displays, 195 initialBet: false, 196 hitStand: true, 197 } 198 })) 199 } 200 201 if (parseInt(res.data?.status.toString().substr(1, 1)) == 2) { 202 dispatch(setBlackjack({ 203 ...styleState.blackjack, 204 inputControls: { 205 ...styleState.blackjack.inputControls, 206 initialBet: { 207 ...styleState.blackjack.inputControls.initialBet, 208 chosenCredits: parseInt(res.data?.initialBet), 209 } 210 }, 211 displays: { 212 ...styleState.blackjack.displays, 213 initialBet: false, 214 sideBet: true, 215 } 216 })) 217 } 218 219 if (parseInt(res.data?.status.toString().substr(1, 1)) == 1) { 220 dispatch(setBlackjack({ 221 ...styleState.blackjack, 222 inputControls: { 223 ...styleState.blackjack.inputControls, 224 initialBet: { 225 ...styleState.blackjack.inputControls.initialBet, 226 chosenCredits: parseInt(postgreRes.data?.credits/2), 227 } 228 }, 229 })) 230 } 235 231 } 236 232 else { -
components/blackjack/PlayButtons.jsx
rebf5e04 r285c3cc 44 44 45 45 function placeInitialBetClicked() { 46 axios.get(`/api/postgre?action=take_credits&session_id=${localStorage.CAESSINO_SESSION_ID}&credits=${styleState.blackjack.inputControls.initialBet.chosenCredits}`).then(postgreRes => { 47 if (postgreRes.data?.success) { 48 axios.get(`/api/blackjack?action=make_initial_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.initialBet.chosenCredits}`).then(res => { 49 if (res.data?.success) { 50 dispatch(setGame({ 51 ...playerState.game, 52 status: res.data?.status, 53 })) 54 55 dispatch(setPlayer({ 56 ...playerState.player, 57 credits: postgreRes.data?.credits, 58 })) 59 60 dispatch(setBlackjack({ 61 ...styleState.blackjack, 62 displays: { 63 ...styleState.blackjack.displays, 64 initialBet: false, 65 sideBet: true, 66 } 67 })) 68 } 69 }); 46 axios.get(`/api/blackjack?action=make_initial_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.initialBet.chosenCredits}`).then(res => { 47 if (res.data?.success) { 48 dispatch(setGame({ 49 ...playerState.game, 50 status: res.data?.status, 51 })) 52 53 dispatch(setPlayer({ 54 ...playerState.player, 55 credits: res.data?.credits, 56 })) 57 58 dispatch(setBlackjack({ 59 ...styleState.blackjack, 60 displays: { 61 ...styleState.blackjack.displays, 62 initialBet: false, 63 sideBet: true, 64 } 65 })) 70 66 } 71 67 }); … … 149 145 150 146 function placeSideBetClicked() { 151 axios.get(`/api/postgre?action=take_credits&session_id=${localStorage.CAESSINO_SESSION_ID}&credits=${styleState.blackjack.inputControls.sideBet.chosenCredits}`).then(postgreRes => { 152 if (postgreRes.data?.success) { 153 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${playerState.game.sideBetName}`).then(res => { 154 if (res.data?.success) { 155 dispatch(setGame({ 156 ...playerState.game, 157 status: res.data?.status, 158 })) 159 160 dispatch(setPlayer({ 161 ...playerState.player, 162 credits: postgreRes.data?.credits, 163 })) 164 165 dispatch(setBlackjack({ 166 ...styleState.blackjack, 167 displays: { 168 ...styleState.blackjack.displays, 169 sideBetsChooseCreditsModal: false, 170 sideBet: false, 171 hitStand: true, 172 } 173 })) 174 175 getCards(); 176 } 177 }); 147 axios.get(`/api/blackjack?action=make_side_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&bet=${styleState.blackjack.inputControls.sideBet.chosenCredits}&betName=${playerState.game.sideBetName}`).then(res => { 148 if (res.data?.success) { 149 dispatch(setGame({ 150 ...playerState.game, 151 status: res.data?.status, 152 })) 153 154 dispatch(setPlayer({ 155 ...playerState.player, 156 credits: res.data?.credits, 157 })) 158 159 dispatch(setBlackjack({ 160 ...styleState.blackjack, 161 displays: { 162 ...styleState.blackjack.displays, 163 sideBetsChooseCreditsModal: false, 164 sideBet: false, 165 hitStand: true, 166 } 167 })) 168 169 getCards(); 178 170 } 179 171 });
Note:
See TracChangeset
for help on using the changeset viewer.