@@ -7,14 +7,14 @@ import {
77 VIEW_STATE ,
88 WEBVIEW_MESSAGES ,
99} from "../../constants" ;
10+ import { ViewStateContext } from "../../context" ;
11+ import "../../styles/Simulator.css" ;
1012import "../../styles/Simulator.css" ;
1113import PlayLogo from "../../svgs/play_svg" ;
1214import StopLogo from "../../svgs/stop_svg" ;
1315import { sendMessage } from "../../utils/MessageUtils" ;
1416import ActionBar from "../simulator/ActionBar" ;
1517import { BUTTONS_KEYS , ClueImage } from "./ClueImage" ;
16- import "../../styles/Simulator.css" ;
17- import { ViewStateContext } from "../../context" ;
1818
1919export const DEFAULT_CLUE_STATE : IClueState = {
2020 buttons : { button_a : false , button_b : false } ,
@@ -128,7 +128,6 @@ export class ClueSimulator extends React.Component<any, IState> {
128128 eventTriggers = { {
129129 onMouseDown : this . onMouseDown ,
130130 onMouseUp : this . onMouseUp ,
131- onMouseLeave : this . onMouseLeave ,
132131 onKeyEvent : this . onKeyEvent ,
133132 } }
134133 displayMessage = { this . state . clue . displayMessage }
@@ -194,76 +193,67 @@ export class ClueSimulator extends React.Component<any, IState> {
194193 } ,
195194 } ) ;
196195 } ;
196+
197197 protected onMouseUp = ( event : Event , key : string ) => {
198198 event . preventDefault ( ) ;
199199 this . handleButtonClick ( key , false ) ;
200200 } ;
201+
201202 protected onMouseDown = ( event : Event , key : string ) => {
202203 event . preventDefault ( ) ;
203204 this . handleButtonClick ( key , true ) ;
204205 } ;
205- protected onMouseLeave = ( event : Event , key : string ) => {
206- event . preventDefault ( ) ;
207- console . log ( `To implement onMouseLeave ${ key } ` ) ;
208- } ;
206+
209207 protected onKeyEvent ( event : KeyboardEvent , active : boolean , key : string ) {
210208 event . stopPropagation ( ) ;
211209 if (
212210 [ event . code , event . key ] . includes ( CONSTANTS . KEYBOARD_KEYS . ENTER ) &&
213211 this . context === VIEW_STATE . RUNNING
214212 ) {
215213 this . handleButtonClick ( key , active ) ;
216- if ( this . imageRef . current ) {
217- if ( key === BUTTONS_KEYS . BTN_A ) {
218- this . imageRef . current . updateButtonAttributes (
219- BUTTONS_KEYS . BTN_A ,
220- active
221- ) ;
222- } else if ( key === BUTTONS_KEYS . BTN_B ) {
223- this . imageRef . current . updateButtonAttributes (
224- BUTTONS_KEYS . BTN_B ,
225- active
226- ) ;
227- } else if ( key === BUTTONS_KEYS . BTN_AB ) {
228- this . imageRef . current . updateButtonAttributes (
229- BUTTONS_KEYS . BTN_AB ,
230- active
231- ) ;
232- }
214+ if ( key === BUTTONS_KEYS . BTN_A ) {
215+ this . imageRef . current ?. updateButtonAttributes (
216+ BUTTONS_KEYS . BTN_A ,
217+ active
218+ ) ;
219+ } else if ( key === BUTTONS_KEYS . BTN_B ) {
220+ this . imageRef . current ?. updateButtonAttributes (
221+ BUTTONS_KEYS . BTN_B ,
222+ active
223+ ) ;
224+ } else if ( key === BUTTONS_KEYS . BTN_AB ) {
225+ this . imageRef . current ?. updateButtonAttributes (
226+ BUTTONS_KEYS . BTN_AB ,
227+ active
228+ ) ;
233229 }
234230 } else if (
235231 [ event . code , event . key ] . includes ( CONSTANTS . KEYBOARD_KEYS . A ) &&
236232 this . context === VIEW_STATE . RUNNING
237233 ) {
238234 this . handleButtonClick ( BUTTONS_KEYS . BTN_A , active ) ;
239- if ( this . imageRef . current ) {
240- this . imageRef . current . updateButtonAttributes (
241- BUTTONS_KEYS . BTN_A ,
242- active
243- ) ;
244- }
235+ this . imageRef . current ?. updateButtonAttributes (
236+ BUTTONS_KEYS . BTN_A ,
237+ active
238+ ) ;
245239 } else if (
246240 [ event . code , event . key ] . includes ( CONSTANTS . KEYBOARD_KEYS . B ) &&
247241 this . context === VIEW_STATE . RUNNING
248242 ) {
249243 this . handleButtonClick ( BUTTONS_KEYS . BTN_B , active ) ;
250- if ( this . imageRef . current ) {
251- this . imageRef . current . updateButtonAttributes (
252- BUTTONS_KEYS . BTN_B ,
253- active
254- ) ;
255- }
244+ this . imageRef . current ?. updateButtonAttributes (
245+ BUTTONS_KEYS . BTN_B ,
246+ active
247+ ) ;
256248 } else if (
257249 [ event . code , event . key ] . includes ( CONSTANTS . KEYBOARD_KEYS . C ) &&
258250 this . context === VIEW_STATE . RUNNING
259251 ) {
260252 this . handleButtonClick ( BUTTONS_KEYS . BTN_AB , active ) ;
261- if ( this . imageRef . current ) {
262- this . imageRef . current . updateButtonAttributes (
263- BUTTONS_KEYS . BTN_AB ,
264- active
265- ) ;
266- }
253+ this . imageRef . current ?. updateButtonAttributes (
254+ BUTTONS_KEYS . BTN_AB ,
255+ active
256+ ) ;
267257 } else if ( event . key === CONSTANTS . KEYBOARD_KEYS . CAPITAL_F ) {
268258 this . togglePlayClick ( ) ;
269259 } else if ( event . key === CONSTANTS . KEYBOARD_KEYS . CAPITAL_R ) {
0 commit comments