import { Images } from "./assets" ; import { Button } from "./button" ; import { gameState , GameState } from "./gamestate" ; const Keys = { KEY_CONSOLE : 0 , KEY_1 : 49 , KEY_2 : 50 , KEY_3 : 51 , KEY_4 : 52 , KEY_5 : 53 , KEY_6 : 54 , KEY_7 : 55 , KEY_8 : 56 , KEY_9 : 57 , KEY_0 : 48 , KEY_Q : 81 , KEY_W : 87 , KEY_E : 69 , KEY_R : 82 , KEY_T : 84 , KEY_Y : 89 , KEY_U : 85 , KEY_I : 73 , KEY_O : 79 , KEY_P : 80 , KEY_A : 65 , KEY_S : 83 , KEY_D : 68 , KEY_F : 70 , KEY_G : 71 , KEY_H : 72 , KEY_J : 74 , KEY_K : 75 , KEY_L : 76 , KEY_Z : 90 , KEY_X : 88 , KEY_C : 67 , KEY_V : 86 , KEY_B : 66 , KEY_N : 78 , KEY_M : 77 , } ; const KeyToText = { } ; KeyToText [ Keys . KEY_CONSOLE ] = "§" ; KeyToText [ Keys . KEY_1 ] = "1" ; KeyToText [ Keys . KEY_2 ] = "2" ; KeyToText [ Keys . KEY_3 ] = "3" ; KeyToText [ Keys . KEY_4 ] = "4" ; KeyToText [ Keys . KEY_5 ] = "5" ; KeyToText [ Keys . KEY_6 ] = "6" ; KeyToText [ Keys . KEY_7 ] = "7" ; KeyToText [ Keys . KEY_8 ] = "8" ; KeyToText [ Keys . KEY_9 ] = "9" ; KeyToText [ Keys . KEY_0 ] = "0" ; KeyToText [ Keys . KEY_Q ] = "Q" ; KeyToText [ Keys . KEY_W ] = "W" ; KeyToText [ Keys . KEY_E ] = "E" ; KeyToText [ Keys . KEY_R ] = "R" ; KeyToText [ Keys . KEY_T ] = "T" ; KeyToText [ Keys . KEY_Y ] = "Y" ; KeyToText [ Keys . KEY_U ] = "U" ; KeyToText [ Keys . KEY_I ] = "I" ; KeyToText [ Keys . KEY_O ] = "O" ; KeyToText [ Keys . KEY_P ] = "P" ; KeyToText [ Keys . KEY_A ] = "A" ; KeyToText [ Keys . KEY_S ] = "S" ; KeyToText [ Keys . KEY_D ] = "D" ; KeyToText [ Keys . KEY_F ] = "F" ; KeyToText [ Keys . KEY_G ] = "G" ; KeyToText [ Keys . KEY_H ] = "H" ; KeyToText [ Keys . KEY_J ] = "J" ; KeyToText [ Keys . KEY_K ] = "K" ; KeyToText [ Keys . KEY_L ] = "L" ; KeyToText [ Keys . KEY_Z ] = "Z" ; KeyToText [ Keys . KEY_X ] = "X" ; KeyToText [ Keys . KEY_C ] = "C" ; KeyToText [ Keys . KEY_V ] = "V" ; KeyToText [ Keys . KEY_B ] = "B" ; KeyToText [ Keys . KEY_N ] = "N" ; KeyToText [ Keys . KEY_M ] = "M" ; const LEFT_ARROW = 0 ; const RIGHT_ARROW = 1 ; const UP_ARROW = 2 ; const DOWN_ARROW = 3 ; let Gui ; let buttonSet ; let navButtonSet ; let exploreButtonSet ; let menuButtonSet ; const buttons = [ ] ; const navButtons = [ ] ; const exploreButtons = [ ] ; const menuButtons = [ ] ; let keyDownValid ; export class Input { static get keyDownValid ( ) { return keyDownValid ; } static set keyDownValid ( valid ) { keyDownValid = valid ; } static get buttons ( ) { return buttons ; } static get navButtons ( ) { return navButtons ; } static get exploreButtons ( ) { return exploreButtons ; } static get menuButtons ( ) { return menuButtons ; } static get exploreButtonSet ( ) { return exploreButtonSet ; } static get menuButtonSet ( ) { return menuButtonSet ; } public static Init ( gui ) { Gui = gui ; window . onkeydown = Input . Keydown ; window . onkeyup = Input . Keyup ; keyDownValid = true ; buttonSet = Gui . canvas . set ( ) ; navButtonSet = Gui . canvas . set ( ) ; exploreButtonSet = Gui . canvas . set ( ) ; menuButtonSet = Gui . canvas . set ( ) ; Input . InitButtons ( ) ; Input . InitMenuButtons ( ) ; } public static InitButtons ( ) { const offset = { x : 270 , y : 600 } ; let button ; for ( let y = 0 ; y < 3 ; y ++ ) { for ( let x = 0 ; x < 4 ; x ++ ) { button = new Button ( Gui , { x : offset . x + 162 * x , y : offset . y + 40 * y , w : 155 , h : 35 } , "Button" + ( x + y * 5 ) , undefined , true , Images . imgButtonEnabled , Images . imgButtonDisabled ) ; buttons . push ( button ) ; buttonSet . push ( button . set ) ; } button = new Button ( Gui , { x : offset . x + 162 * 4 , y : offset . y + 40 * y , w : 75 , h : 35 } , "Nav" + y , undefined , true , Images . imgNavButtonEnabled , Images . imgNavButtonDisabled ) ; navButtons . push ( button ) ; navButtonSet . push ( button . set ) ; } for ( let y = 0 ; y < 8 ; y ++ ) { button = new Button ( Gui , { x : 1100 , y : 375 + 40 * y , w : 155 , h : 35 } , "Exp" + y , undefined , true , Images . imgButtonEnabled , Images . imgButtonDisabled , true ) ; exploreButtons . push ( button ) ; exploreButtonSet . push ( button . set ) ; } button = new Button ( Gui , { x : 150 , y : 590 , w : 50 , h : 50 } , "" , undefined , true , Images . imgWaitEnabled , Images . imgWaitDisabled ) ; exploreButtons . push ( button ) ; exploreButtonSet . push ( button . set ) ; button = new Button ( Gui , { x : 150 , y : 590 , w : 50 , h : 50 } , "" , undefined , true , Images . imgSleepEnabled , Images . imgSleepDisabled ) ; exploreButtons . push ( button ) ; exploreButtonSet . push ( button . set ) ; button = new Button ( Gui , { x : 210 , y : 590 , w : 50 , h : 50 } , "" , undefined , true , Images . imgSearchEnabled , Images . imgSearchDisabled ) ; exploreButtons . push ( button ) ; exploreButtonSet . push ( button . set ) ; } public static InitMenuButtons ( ) { const offset = { x : 15 , y : 620 } ; const button = new Button ( Gui , { x : 10 , y : 10 , w : 155 , h : 35 } , "DATA" , undefined , true , Images . imgButtonEnabled , Images . imgButtonDisabled ) ; menuButtons . push ( button ) ; menuButtonSet . push ( button . set ) ; } public static RenderExploreButtonGlow ( ) { for ( const button of exploreButtons ) { if ( ! button . image . is_visible ( ) ) { continue ; } if ( ! button . glow ) { continue ; } if ( button === Gui . GetLastSubmenu ( ) ) { button . glow . show ( ) ; } else { button . glow . hide ( ) ; } } } public static Keydown ( event ) { if ( ! Input . keyDownValid ) { return true ; } switch ( gameState ) { case GameState . Game : for ( const button of menuButtons ) { button . HandleKeydown ( event . keyCode ) ; } for ( const button of exploreButtons ) { button . HandleKeydown ( event . keyCode ) ; } case GameState . Event : case GameState . Credits : case GameState . Combat : case GameState . Cavalcade : for ( const button of buttons ) { button . HandleKeydown ( event . keyCode ) ; } for ( const button of navButtons ) { button . HandleKeydown ( event . keyCode ) ; } break ; } return true ; } public static Keyup ( event ) { return true ; } constructor ( ) { } } export { Keys } ;