@@ -3,7 +3,7 @@ import { Cookies } from "./cookies";
3
3
import { Picker } from "emoji-picker-element" ;
4
4
import { GameContainer } from "./gameContainer" ;
5
5
import * as bus from "./bus" ;
6
- import { Matrix } from "@babylonjs/core" ;
6
+ import { ContainerAssetTask , Matrix , SubEmitter } from "@babylonjs/core" ;
7
7
8
8
const secretShips = [ "ship_secret" , "ship_zed" ] ;
9
9
@@ -59,44 +59,48 @@ bus.on("pageReady", function () {
59
59
} ) ;
60
60
61
61
window . addEventListener ( "keydown" , ( { key } ) => {
62
- if ( key . toLowerCase ( ) == "s" ) {
63
- Controls . boostKeyboard = true ;
64
- sendControlPacket ( ) ;
65
- }
66
- if ( key == " " ) {
67
- Controls . shootKeyboard = true ;
68
- sendControlPacket ( ) ;
69
- }
70
-
71
- if ( key . toLowerCase ( ) == "m" ) {
72
- bus . emit ( "mapShow" ) ;
62
+ if ( Controls . container ?. alive ) {
63
+ switch ( key . toLowerCase ( ) ) {
64
+ case "s" :
65
+ Controls . boostKeyboard = true ;
66
+ sendControlPacket ( ) ;
67
+ break ;
68
+ case " " :
69
+ Controls . shootKeyboard = true ;
70
+ sendControlPacket ( ) ;
71
+ break ;
72
+ }
73
73
}
74
74
75
-
76
- if ( key . toLowerCase ( ) == "e" && document . body . classList . contains ( "alive" ) ) {
77
- // Autofire
78
- Controls . toggleAutofire ( ) ;
79
- }
75
+ if ( Controls . container ?. alive || Controls . container ?. spectating ) {
76
+ switch ( key . toLowerCase ( ) ) {
77
+ case "m" :
78
+ Controls . toggleMapView ( ) ;
79
+ break ;
80
+ case "e" :
81
+ Controls . toggleAutofire ( ) ;
82
+ break ;
83
+ }
84
+ }
80
85
} ) ;
81
86
82
87
window . addEventListener ( "keyup" , ( { key } ) => {
83
- if ( key . toLowerCase ( ) == "s" ) {
84
- Controls . boostKeyboard = false ;
85
- sendControlPacket ( ) ;
86
- }
87
- if ( key == " " ) {
88
- Controls . shootKeyboard = false ;
89
- sendControlPacket ( ) ;
90
- }
91
-
92
- if ( key . toLowerCase ( ) == "m" ) {
93
- bus . emit ( "mapHide" ) ;
88
+ if ( Controls . container ?. alive ) {
89
+ switch ( key . toLowerCase ( ) ) {
90
+ case "s" :
91
+ Controls . boostKeyboard = false ;
92
+ sendControlPacket ( ) ;
93
+ break ;
94
+ case " " :
95
+ Controls . shootKeyboard = false ;
96
+ sendControlPacket ( ) ;
97
+ break ;
98
+ }
94
99
}
95
-
96
100
} ) ;
97
101
98
102
document . body . addEventListener ( "contextmenu" , ( e ) => {
99
- if ( document . body . classList . contains ( " alive" ) ) {
103
+ if ( Controls . container ?. alive ) {
100
104
e . preventDefault ( ) ;
101
105
return false ;
102
106
}
@@ -153,6 +157,7 @@ export const Controls = {
153
157
154
158
spectateControl : "" as string | undefined ,
155
159
spectateDebounce : false ,
160
+ mapView : false ,
156
161
157
162
requestPointerLock ( ) {
158
163
console . log ( 'requesting lock' ) ;
@@ -191,10 +196,18 @@ export const Controls = {
191
196
autofTgg . innerHTML = "OFF" ;
192
197
}
193
198
sendControlPacket ( ) ;
199
+ } ,
200
+
201
+ toggleMapView ( ) {
202
+ if ( ! Controls . mapView )
203
+ bus . emit ( 'mapShow' ) ;
204
+ else
205
+ bus . emit ( 'mapHide' ) ;
206
+
207
+ Controls . mapView = ! Controls . mapView ;
194
208
}
195
209
} ;
196
210
197
-
198
211
bus . on ( 'postrender' , ( gametime ) => {
199
212
Controls . pointerSpeed += Math . abs ( Controls . mouseX - Controls . previousMouseX ) + Math . abs ( Controls . mouseY - Controls . previousMouseY ) ;
200
213
Controls . pointerSpeed *= 0.9 ;
@@ -208,7 +221,7 @@ function sendControlPacket() {
208
221
}
209
222
210
223
function mouseUp ( this : any , ev : MouseEvent ) : any {
211
-
224
+
212
225
switch ( ev . button ) {
213
226
case 2 :
214
227
Controls . boostPointer = false ;
@@ -220,8 +233,7 @@ function mouseUp(this: any, ev: MouseEvent): any {
220
233
sendControlPacket ( ) ;
221
234
}
222
235
223
- function spectateActionNext ( )
224
- {
236
+ function spectateActionNext ( ) {
225
237
console . log ( 'spectate next' ) ;
226
238
Controls . spectateControl = "action:next" ;
227
239
sendControlPacket ( ) ;
@@ -249,14 +261,13 @@ function mouseMove(this: any, ev: MouseEvent): any {
249
261
let scale = 1.5 ;
250
262
251
263
if ( Controls . container ! . pointerLocked ) {
252
-
264
+
253
265
Controls . mouseX += ev . movementX * scale ;
254
266
Controls . mouseY -= ev . movementY * scale ;
255
267
Controls . mouseX = Math . max ( Math . min ( Controls . mouseX , rect . width * scale ) , - rect . width * scale ) ;
256
268
Controls . mouseY = Math . max ( Math . min ( Controls . mouseY , rect . height * scale ) , - rect . height * scale ) ;
257
269
}
258
- else
259
- {
270
+ else {
260
271
const container = Controls . container ! ;
261
272
const ray = container . scene . createPickingRay ( ev . clientX , ev . clientY , Matrix . Identity ( ) , container . camera ) ;
262
273
const pos = ray . intersectsAxis ( "y" , 100 ) ;
@@ -279,13 +290,13 @@ export function registerContainer(container: GameContainer): void {
279
290
joystick = new VirtualJoystick ( {
280
291
container : document . getElementById ( "nipple-zone" ) ! ,
281
292
} ) ;
282
-
293
+
283
294
document . body . classList . add ( 'touchscreen' ) ;
284
-
295
+
285
296
Controls . container ! . touchscreen = true ;
286
297
Controls . toggleAutofire ( ) ;
287
298
}
288
-
299
+
289
300
joystick . onExtraTap ( ( x : number , y : number ) => {
290
301
const ray = container . scene . createPickingRay ( x , y , Matrix . Identity ( ) , container . camera ) ;
291
302
const pos = ray . intersectsAxis ( "y" , 100 ) ;
0 commit comments