@@ -21,7 +21,6 @@ class EventHandler {
2121 this . setState ( "menu" ) ;
2222 document . exitPointerLock =
2323 document . exitPointerLock || document . mozExitPointerLock ;
24- //Mouse wheel change inventory
2524 var focus = 0 ;
2625 this . game . inv_bar . setFocus ( focus ) ;
2726 $ ( window ) . on ( "wheel" , function ( e ) {
@@ -35,41 +34,34 @@ class EventHandler {
3534 _this . game . inv_bar . setFocus ( focus ) ;
3635 }
3736 } ) ;
38- //Keydown
3937 $ ( document ) . on ( "keydown" , function ( z ) {
4038 _this . keys [ z . code ] = true ;
41- //Digits
4239 for ( var i = 1 ; i < 10 ; i ++ ) {
4340 if ( z . code === `Digit${ i } ` && _this . gameState === "gameLock" ) {
4441 _this . game . inv_bar . setFocus ( i - 1 ) ;
4542 focus = i - 1 ;
4643 }
4744 }
48- //Klawisz Escape
4945 if ( z . code === "Escape" && _this . gameState === "inventory" ) {
5046 _this . setState ( "menu" ) ;
5147 }
52- //Strzałki
5348 if ( z . code === "ArrowUp" && _this . gameState === "chat" ) {
5449 _this . game . chat . chatGoBack ( ) ;
5550 }
5651 if ( z . code === "ArrowDown" && _this . gameState === "chat" ) {
5752 _this . game . chat . chatGoForward ( ) ;
5853 }
59- //Klawisz Enter
6054 if ( z . code === "Enter" && _this . gameState === "chat" ) {
6155 _this . game . chat . command ( $ ( ".com_i" ) . val ( ) ) ;
6256 $ ( ".com_i" ) . val ( "" ) ;
6357 }
64- //Klawisz E
6558 if (
6659 z . code === "KeyE" &&
6760 _this . gameState !== "chat" &&
6861 _this . gameState !== "menu"
6962 ) {
7063 _this . setState ( "inventory" ) ;
7164 }
72- //Klawisz T lub /
7365 if (
7466 ( z . code === "KeyT" || z . code === "Slash" ) &&
7567 _this . gameState === "gameLock"
@@ -80,7 +72,6 @@ class EventHandler {
8072 _this . setState ( "chat" ) ;
8173 z . preventDefault ( ) ;
8274 }
83- //Klawisz `
8475 if ( z . code === "Backquote" ) {
8576 z . preventDefault ( ) ;
8677 if (
@@ -96,13 +87,10 @@ class EventHandler {
9687 if ( z . code === "Escape" && _this . gameState === "chat" ) {
9788 _this . setState ( "menu" ) ;
9889 }
99-
100- //Flying
10190 if ( z . code === "KeyF" ) {
10291 _this . game . flying = ! _this . game . flying ;
10392 _this . game . socket . emit ( "fly" , _this . game . flying ) ;
10493 }
105- //Wysyłanie state'u do serwera
10694 if (
10795 _this . controls [ z . code ] !== undefined &&
10896 _this . gameState === "gameLock"
@@ -111,7 +99,7 @@ class EventHandler {
11199 switch ( _this . controls [ z . code ] ) {
112100 case "sprint" :
113101 var to = {
114- fov : _this . game . fov ,
102+ fov : _this . game . fov . sprint ,
115103 } ;
116104 new TWEEN . Tween ( _this . game . camera )
117105 . to ( to , 200 )
@@ -129,15 +117,14 @@ class EventHandler {
129117 }
130118 }
131119 } ) ;
132- //Keyup
133120 $ ( document ) . on ( "keyup" , function ( z ) {
134121 delete _this . keys [ z . code ] ;
135122 if ( _this . controls [ z . code ] !== undefined ) {
136123 _this . game . socket . emit ( "move" , _this . controls [ z . code ] , false ) ;
137124 switch ( _this . controls [ z . code ] ) {
138125 case "sprint" :
139126 var to = {
140- fov : _this . game . fov ,
127+ fov : _this . game . fov . normal ,
141128 } ;
142129 new TWEEN . Tween ( _this . game . camera )
143130 . to ( to , 200 )
@@ -155,34 +142,27 @@ class EventHandler {
155142 }
156143 }
157144 } ) ;
158- //Play game button
159145 $ ( ".gameOn" ) . on ( "click" , function ( ) {
160146 _this . setState ( "game" ) ;
161147 } ) ;
162- //Window onblur
163148 window . onblur = function ( ) {
164149 Object . keys ( _this . controls ) . forEach ( function ( el ) {
165150 _this . game . socket . emit ( "move" , _this . controls [ el ] , false ) ;
166151 } ) ;
167152 } ;
168- //Pointerlock
169153 var lockChangeAlert = function ( ) {
170154 if (
171155 document . pointerLockElement === _this . game . canvas ||
172156 document . mozPointerLockElement === _this . game . canvas
173157 ) {
174- //Lock
175158 if ( _this . gameState === "game" ) {
176159 _this . setState ( "gameLock" ) ;
177160 }
178- } else {
179- //Unlock
180- if (
181- _this . gameState === "gameLock" &&
182- _this . gameState !== "inventory"
183- ) {
184- _this . setState ( "menu" ) ;
185- }
161+ } else if (
162+ _this . gameState === "gameLock" &&
163+ _this . gameState !== "inventory"
164+ ) {
165+ _this . setState ( "menu" ) ;
186166 }
187167 } ;
188168 document . addEventListener ( "pointerlockchange" , lockChangeAlert , false ) ;
0 commit comments