littlejsengine 1.11.9 → 1.11.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/littlejs.d.ts +485 -492
- package/dist/littlejs.esm.js +548 -529
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +546 -525
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +502 -484
- package/examples/htmlMenu/game.js +11 -1
- package/examples/htmlMenu/index.html +1 -10
- package/examples/module/game.js +2 -2
- package/examples/shorts/base.html +1 -1
- package/examples/starter/build/index.html +2 -0
- package/examples/starter/build/index.js +1 -0
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/build.js +13 -3
- package/examples/starter/game.js +8 -1
- package/examples/starter/game.zip +0 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4834 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +102 -0
- package/examples/typescript/build.bat +5 -0
- package/examples/typescript/build.js +33 -0
- package/examples/typescript/game.js +102 -0
- package/examples/typescript/game.ts +134 -0
- package/examples/typescript/index.html +10 -0
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +8 -0
- package/package.json +1 -1
- package/plugins/newgrounds.js +44 -35
- package/plugins/postProcess.js +18 -4
- package/plugins/uiSystem.js +196 -30
- package/src/engine.js +21 -20
- package/src/engineAudio.js +59 -59
- package/src/engineDebug.js +44 -41
- package/src/engineDraw.js +58 -58
- package/src/engineExport.js +2 -4
- package/src/engineInput.js +40 -35
- package/src/engineMedals.js +21 -11
- package/src/engineObject.js +42 -35
- package/src/engineParticles.js +10 -10
- package/src/engineSettings.js +77 -82
- package/src/engineTileLayer.js +21 -21
- package/src/engineUtilities.js +150 -150
- package/src/engineWebGL.js +3 -3
package/src/engineDraw.js
CHANGED
|
@@ -61,10 +61,10 @@ let drawCount;
|
|
|
61
61
|
* Create a tile info object using a grid based system
|
|
62
62
|
* - This can take vecs or floats for easier use and conversion
|
|
63
63
|
* - If an index is passed in, the tile size and index will determine the position
|
|
64
|
-
* @param {
|
|
65
|
-
* @param {
|
|
66
|
-
* @param {
|
|
67
|
-
* @param {
|
|
64
|
+
* @param {Vector2|number} [pos=0] - Index of tile in sheet
|
|
65
|
+
* @param {Vector2|number} [size=tileSizeDefault] - Size of tile in pixels
|
|
66
|
+
* @param {number} [textureIndex] - Texture index to use
|
|
67
|
+
* @param {number} [padding] - How many pixels padding around tiles
|
|
68
68
|
* @return {TileInfo}
|
|
69
69
|
* @example
|
|
70
70
|
* tile(2) // a tile at index 2 using the default tile size of 16
|
|
@@ -108,8 +108,8 @@ class TileInfo
|
|
|
108
108
|
/** Create a tile info object
|
|
109
109
|
* @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
|
|
110
110
|
* @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
|
|
111
|
-
* @param {
|
|
112
|
-
* @param {
|
|
111
|
+
* @param {number} [textureIndex] - Texture index to use
|
|
112
|
+
* @param {number} [padding] - How many pixels padding around tiles
|
|
113
113
|
*/
|
|
114
114
|
constructor(pos=vec2(), size=tileSizeDefault, textureIndex=0, padding=0)
|
|
115
115
|
{
|
|
@@ -117,9 +117,9 @@ class TileInfo
|
|
|
117
117
|
this.pos = pos.copy();
|
|
118
118
|
/** @property {Vector2} - Size of tile in pixels */
|
|
119
119
|
this.size = size.copy();
|
|
120
|
-
/** @property {
|
|
120
|
+
/** @property {number} - Texture index to use */
|
|
121
121
|
this.textureIndex = textureIndex;
|
|
122
|
-
/** @property {
|
|
122
|
+
/** @property {number} - How many pixels padding around tiles */
|
|
123
123
|
this.padding = padding;
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -131,7 +131,7 @@ class TileInfo
|
|
|
131
131
|
{ return new TileInfo(this.pos.add(offset), this.size, this.textureIndex); }
|
|
132
132
|
|
|
133
133
|
/** Returns a copy of this tile offset by a number of animation frames
|
|
134
|
-
* @param {
|
|
134
|
+
* @param {number} frame - Offset to apply in animation frames
|
|
135
135
|
* @return {TileInfo}
|
|
136
136
|
*/
|
|
137
137
|
frame(frame)
|
|
@@ -203,11 +203,11 @@ function getCameraSize() { return mainCanvasSize.scale(1/cameraScale); }
|
|
|
203
203
|
* @param {Vector2} [size=(1,1)] - Size of the tile in world space
|
|
204
204
|
* @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
|
|
205
205
|
* @param {Color} [color=(1,1,1,1)] - Color to modulate with
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
206
|
+
* @param {number} [angle] - Angle to rotate by
|
|
207
|
+
* @param {boolean} [mirror] - If true image is flipped along the Y axis
|
|
208
208
|
* @param {Color} [additiveColor=(0,0,0,0)] - Additive color to be applied
|
|
209
|
-
* @param {
|
|
210
|
-
* @param {
|
|
209
|
+
* @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
210
|
+
* @param {boolean} [screenSpace=false] - If true the pos and size are in screen space
|
|
211
211
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
|
|
212
212
|
* @memberof Draw */
|
|
213
213
|
function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
|
|
@@ -282,9 +282,9 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
|
|
|
282
282
|
* @param {Vector2} pos
|
|
283
283
|
* @param {Vector2} [size=(1,1)]
|
|
284
284
|
* @param {Color} [color=(1,1,1,1)]
|
|
285
|
-
* @param {
|
|
286
|
-
* @param {
|
|
287
|
-
* @param {
|
|
285
|
+
* @param {number} [angle]
|
|
286
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
287
|
+
* @param {boolean} [screenSpace=false]
|
|
288
288
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
289
289
|
* @memberof Draw */
|
|
290
290
|
function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
|
|
@@ -295,10 +295,10 @@ function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
|
|
|
295
295
|
/** Draw colored line between two points
|
|
296
296
|
* @param {Vector2} posA
|
|
297
297
|
* @param {Vector2} posB
|
|
298
|
-
* @param {
|
|
298
|
+
* @param {number} [thickness]
|
|
299
299
|
* @param {Color} [color=(1,1,1,1)]
|
|
300
|
-
* @param {
|
|
301
|
-
* @param {
|
|
300
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
301
|
+
* @param {boolean} [screenSpace=false]
|
|
302
302
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
303
303
|
* @memberof Draw */
|
|
304
304
|
function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, context)
|
|
@@ -309,11 +309,11 @@ function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, contex
|
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
/** Draw colored polygon using passed in points
|
|
312
|
-
* @param {Array} points - Array of Vector2 points
|
|
312
|
+
* @param {Array<Vector2>} points - Array of Vector2 points
|
|
313
313
|
* @param {Color} [color=(1,1,1,1)]
|
|
314
|
-
* @param {
|
|
314
|
+
* @param {number} [lineWidth=0]
|
|
315
315
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
316
|
-
* @param {
|
|
316
|
+
* @param {boolean} [screenSpace=false]
|
|
317
317
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
318
318
|
* @memberof Draw */
|
|
319
319
|
function drawPoly(points, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
|
|
@@ -335,13 +335,13 @@ function drawPoly(points, color=new Color, lineWidth=0, lineColor=new Color(0,0,
|
|
|
335
335
|
|
|
336
336
|
/** Draw colored ellipse using passed in point
|
|
337
337
|
* @param {Vector2} pos
|
|
338
|
-
* @param {
|
|
339
|
-
* @param {
|
|
340
|
-
* @param {
|
|
338
|
+
* @param {number} [width=1]
|
|
339
|
+
* @param {number} [height=1]
|
|
340
|
+
* @param {number} [angle=0]
|
|
341
341
|
* @param {Color} [color=(1,1,1,1)]
|
|
342
|
-
* @param {
|
|
342
|
+
* @param {number} [lineWidth=0]
|
|
343
343
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
344
|
-
* @param {
|
|
344
|
+
* @param {boolean} [screenSpace=false]
|
|
345
345
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
346
346
|
* @memberof Draw */
|
|
347
347
|
function drawEllipse(pos, width=1, height=1, angle=0, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
|
|
@@ -368,11 +368,11 @@ function drawEllipse(pos, width=1, height=1, angle=0, color=new Color, lineWidth
|
|
|
368
368
|
|
|
369
369
|
/** Draw colored circle using passed in point
|
|
370
370
|
* @param {Vector2} pos
|
|
371
|
-
* @param {
|
|
371
|
+
* @param {number} [radius=1]
|
|
372
372
|
* @param {Color} [color=(1,1,1,1)]
|
|
373
|
-
* @param {
|
|
373
|
+
* @param {number} [lineWidth=0]
|
|
374
374
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
375
|
-
* @param {
|
|
375
|
+
* @param {boolean} [screenSpace=false]
|
|
376
376
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
377
377
|
* @memberof Draw */
|
|
378
378
|
function drawCircle(pos, radius=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
|
|
@@ -381,10 +381,10 @@ function drawCircle(pos, radius=1, color=new Color, lineWidth=0, lineColor=new C
|
|
|
381
381
|
/** Draw directly to a 2d canvas context in world space
|
|
382
382
|
* @param {Vector2} pos
|
|
383
383
|
* @param {Vector2} size
|
|
384
|
-
* @param {
|
|
385
|
-
* @param {
|
|
384
|
+
* @param {number} angle
|
|
385
|
+
* @param {boolean} mirror
|
|
386
386
|
* @param {Function} drawFunction
|
|
387
|
-
* @param {
|
|
387
|
+
* @param {boolean} [screenSpace=false]
|
|
388
388
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
|
|
389
389
|
* @memberof Draw */
|
|
390
390
|
function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, context=mainContext)
|
|
@@ -405,15 +405,15 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, conte
|
|
|
405
405
|
|
|
406
406
|
/** Draw text on main canvas in world space
|
|
407
407
|
* Automatically splits new lines into rows
|
|
408
|
-
* @param {
|
|
408
|
+
* @param {string} text
|
|
409
409
|
* @param {Vector2} pos
|
|
410
|
-
* @param {
|
|
410
|
+
* @param {number} [size]
|
|
411
411
|
* @param {Color} [color=(1,1,1,1)]
|
|
412
|
-
* @param {
|
|
412
|
+
* @param {number} [lineWidth]
|
|
413
413
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
414
414
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
415
|
-
* @param {
|
|
416
|
-
* @param {
|
|
415
|
+
* @param {string} [font=fontDefault]
|
|
416
|
+
* @param {number} [maxWidth]
|
|
417
417
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
|
|
418
418
|
* @memberof Draw */
|
|
419
419
|
function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font, maxWidth, context=mainContext)
|
|
@@ -423,15 +423,15 @@ function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, f
|
|
|
423
423
|
|
|
424
424
|
/** Draw text on overlay canvas in world space
|
|
425
425
|
* Automatically splits new lines into rows
|
|
426
|
-
* @param {
|
|
426
|
+
* @param {string} text
|
|
427
427
|
* @param {Vector2} pos
|
|
428
|
-
* @param {
|
|
428
|
+
* @param {number} [size]
|
|
429
429
|
* @param {Color} [color=(1,1,1,1)]
|
|
430
|
-
* @param {
|
|
430
|
+
* @param {number} [lineWidth]
|
|
431
431
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
432
432
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
433
|
-
* @param {
|
|
434
|
-
* @param {
|
|
433
|
+
* @param {string} [font=fontDefault]
|
|
434
|
+
* @param {number} [maxWidth]
|
|
435
435
|
* @memberof Draw */
|
|
436
436
|
function drawTextOverlay(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font, maxWidth)
|
|
437
437
|
{
|
|
@@ -440,15 +440,15 @@ function drawTextOverlay(text, pos, size=1, color, lineWidth=0, lineColor, textA
|
|
|
440
440
|
|
|
441
441
|
/** Draw text on overlay canvas in screen space
|
|
442
442
|
* Automatically splits new lines into rows
|
|
443
|
-
* @param {
|
|
443
|
+
* @param {string} text
|
|
444
444
|
* @param {Vector2} pos
|
|
445
|
-
* @param {
|
|
445
|
+
* @param {number} [size]
|
|
446
446
|
* @param {Color} [color=(1,1,1,1)]
|
|
447
|
-
* @param {
|
|
447
|
+
* @param {number} [lineWidth]
|
|
448
448
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
449
449
|
* @param {CanvasTextAlign} [textAlign]
|
|
450
|
-
* @param {
|
|
451
|
-
* @param {
|
|
450
|
+
* @param {string} [font=fontDefault]
|
|
451
|
+
* @param {number} [maxWidth]
|
|
452
452
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
|
|
453
453
|
* @memberof Draw */
|
|
454
454
|
function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, maxWidth=undefined, context=overlayContext)
|
|
@@ -474,8 +474,8 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
/** Enable normal or additive blend mode
|
|
477
|
-
* @param {
|
|
478
|
-
* @param {
|
|
477
|
+
* @param {boolean} [additive]
|
|
478
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
479
479
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
|
|
480
480
|
* @memberof Draw */
|
|
481
481
|
function setBlendMode(additive, useWebGL=glEnable, context)
|
|
@@ -542,10 +542,10 @@ class FontImage
|
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
/** Draw text in world space using the image font
|
|
545
|
-
* @param {
|
|
545
|
+
* @param {string} text
|
|
546
546
|
* @param {Vector2} pos
|
|
547
|
-
* @param {
|
|
548
|
-
* @param {
|
|
547
|
+
* @param {number} [scale=.25]
|
|
548
|
+
* @param {boolean} [center]
|
|
549
549
|
*/
|
|
550
550
|
drawText(text, pos, scale=1, center)
|
|
551
551
|
{
|
|
@@ -553,10 +553,10 @@ class FontImage
|
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
/** Draw text in screen space using the image font
|
|
556
|
-
* @param {
|
|
556
|
+
* @param {string} text
|
|
557
557
|
* @param {Vector2} pos
|
|
558
|
-
* @param {
|
|
559
|
-
* @param {
|
|
558
|
+
* @param {number} [scale]
|
|
559
|
+
* @param {boolean} [center]
|
|
560
560
|
*/
|
|
561
561
|
drawTextScreen(text, pos, scale=4, center)
|
|
562
562
|
{
|
|
@@ -594,7 +594,7 @@ class FontImage
|
|
|
594
594
|
// Display functions
|
|
595
595
|
|
|
596
596
|
/** Returns true if fullscreen mode is active
|
|
597
|
-
* @return {
|
|
597
|
+
* @return {boolean}
|
|
598
598
|
* @memberof Draw */
|
|
599
599
|
function isFullscreen() { return !!document.fullscreenElement; }
|
|
600
600
|
|
|
@@ -613,7 +613,7 @@ function toggleFullscreen()
|
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
/** Set the cursor style
|
|
616
|
-
* @param {
|
|
616
|
+
* @param {string} cursorStyle - CSS cursor style (auto, none, crosshair, etc)
|
|
617
617
|
* @memberof Draw */
|
|
618
618
|
function setCursor(cursorStyle = 'auto')
|
|
619
619
|
{
|
package/src/engineExport.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* - Export engine as a module
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export
|
|
7
|
+
{
|
|
8
8
|
// Engine
|
|
9
9
|
engineName,
|
|
10
10
|
engineVersion,
|
|
@@ -82,7 +82,6 @@ export {
|
|
|
82
82
|
medalDisplayTime,
|
|
83
83
|
medalDisplaySlideTime,
|
|
84
84
|
medalDisplaySize,
|
|
85
|
-
medalDisplayIconSize,
|
|
86
85
|
|
|
87
86
|
// Setters for globals
|
|
88
87
|
setCameraPos,
|
|
@@ -123,7 +122,6 @@ export {
|
|
|
123
122
|
setMedalDisplayTime,
|
|
124
123
|
setMedalDisplaySlideTime,
|
|
125
124
|
setMedalDisplaySize,
|
|
126
|
-
setMedalDisplayIconSize,
|
|
127
125
|
setMedalsPreventUnlock,
|
|
128
126
|
setShowWatermark,
|
|
129
127
|
setDebugKey,
|
package/src/engineInput.js
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
/** Returns true if device key is down
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
16
|
-
* @return {
|
|
14
|
+
* @param {string|number} key
|
|
15
|
+
* @param {number} [device]
|
|
16
|
+
* @return {boolean}
|
|
17
17
|
* @memberof Input */
|
|
18
18
|
function keyIsDown(key, device=0)
|
|
19
19
|
{
|
|
@@ -22,9 +22,9 @@ function keyIsDown(key, device=0)
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** Returns true if device key was pressed this frame
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
-
* @return {
|
|
25
|
+
* @param {string|number} key
|
|
26
|
+
* @param {number} [device]
|
|
27
|
+
* @return {boolean}
|
|
28
28
|
* @memberof Input */
|
|
29
29
|
function keyWasPressed(key, device=0)
|
|
30
30
|
{
|
|
@@ -33,9 +33,9 @@ function keyWasPressed(key, device=0)
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** Returns true if device key was released this frame
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
38
|
-
* @return {
|
|
36
|
+
* @param {string|number} key
|
|
37
|
+
* @param {number} [device]
|
|
38
|
+
* @return {boolean}
|
|
39
39
|
* @memberof Input */
|
|
40
40
|
function keyWasReleased(key, device=0)
|
|
41
41
|
{
|
|
@@ -58,22 +58,22 @@ function clearInput() { inputData = [[]]; touchGamepadButtons = []; }
|
|
|
58
58
|
|
|
59
59
|
/** Returns true if mouse button is down
|
|
60
60
|
* @function
|
|
61
|
-
* @param {
|
|
62
|
-
* @return {
|
|
61
|
+
* @param {number} button
|
|
62
|
+
* @return {boolean}
|
|
63
63
|
* @memberof Input */
|
|
64
64
|
const mouseIsDown = keyIsDown;
|
|
65
65
|
|
|
66
66
|
/** Returns true if mouse button was pressed
|
|
67
67
|
* @function
|
|
68
|
-
* @param {
|
|
69
|
-
* @return {
|
|
68
|
+
* @param {number} button
|
|
69
|
+
* @return {boolean}
|
|
70
70
|
* @memberof Input */
|
|
71
71
|
const mouseWasPressed = keyWasPressed;
|
|
72
72
|
|
|
73
73
|
/** Returns true if mouse button was released
|
|
74
74
|
* @function
|
|
75
|
-
* @param {
|
|
76
|
-
* @return {
|
|
75
|
+
* @param {number} button
|
|
76
|
+
* @return {boolean}
|
|
77
77
|
* @memberof Input */
|
|
78
78
|
const mouseWasReleased = keyWasReleased;
|
|
79
79
|
|
|
@@ -88,47 +88,53 @@ let mousePos = vec2();
|
|
|
88
88
|
let mousePosScreen = vec2();
|
|
89
89
|
|
|
90
90
|
/** Mouse wheel delta this frame
|
|
91
|
-
* @type {
|
|
91
|
+
* @type {number}
|
|
92
92
|
* @memberof Input */
|
|
93
93
|
let mouseWheel = 0;
|
|
94
94
|
|
|
95
95
|
/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
|
|
96
|
-
* @type {
|
|
96
|
+
* @type {boolean}
|
|
97
97
|
* @memberof Input */
|
|
98
98
|
let isUsingGamepad = false;
|
|
99
99
|
|
|
100
|
-
/** Prevents input continuing to the default browser handling (
|
|
101
|
-
* @type {
|
|
100
|
+
/** Prevents input continuing to the default browser handling (true by default)
|
|
101
|
+
* @type {boolean}
|
|
102
102
|
* @memberof Input */
|
|
103
|
-
let
|
|
103
|
+
let inputPreventDefault = true;
|
|
104
|
+
|
|
105
|
+
/** Prevents input continuing to the default browser handling
|
|
106
|
+
* This is useful to disable for html menus so the browser can handle input normally
|
|
107
|
+
* @param {boolean} preventDefault
|
|
108
|
+
* @memberof Input */
|
|
109
|
+
function setInputPreventDefault(preventDefault) { inputPreventDefault = preventDefault; }
|
|
104
110
|
|
|
105
111
|
/** Returns true if gamepad button is down
|
|
106
|
-
* @param {
|
|
107
|
-
* @param {
|
|
108
|
-
* @return {
|
|
112
|
+
* @param {number} button
|
|
113
|
+
* @param {number} [gamepad]
|
|
114
|
+
* @return {boolean}
|
|
109
115
|
* @memberof Input */
|
|
110
116
|
function gamepadIsDown(button, gamepad=0)
|
|
111
117
|
{ return keyIsDown(button, gamepad+1); }
|
|
112
118
|
|
|
113
119
|
/** Returns true if gamepad button was pressed
|
|
114
|
-
* @param {
|
|
115
|
-
* @param {
|
|
116
|
-
* @return {
|
|
120
|
+
* @param {number} button
|
|
121
|
+
* @param {number} [gamepad]
|
|
122
|
+
* @return {boolean}
|
|
117
123
|
* @memberof Input */
|
|
118
124
|
function gamepadWasPressed(button, gamepad=0)
|
|
119
125
|
{ return keyWasPressed(button, gamepad+1); }
|
|
120
126
|
|
|
121
127
|
/** Returns true if gamepad button was released
|
|
122
|
-
* @param {
|
|
123
|
-
* @param {
|
|
124
|
-
* @return {
|
|
128
|
+
* @param {number} button
|
|
129
|
+
* @param {number} [gamepad]
|
|
130
|
+
* @return {boolean}
|
|
125
131
|
* @memberof Input */
|
|
126
132
|
function gamepadWasReleased(button, gamepad=0)
|
|
127
133
|
{ return keyWasReleased(button, gamepad+1); }
|
|
128
134
|
|
|
129
135
|
/** Returns gamepad stick value
|
|
130
|
-
* @param {
|
|
131
|
-
* @param {
|
|
136
|
+
* @param {number} stick
|
|
137
|
+
* @param {number} [gamepad]
|
|
132
138
|
* @return {Vector2}
|
|
133
139
|
* @memberof Input */
|
|
134
140
|
function gamepadStick(stick, gamepad=0)
|
|
@@ -180,7 +186,6 @@ function inputInit()
|
|
|
180
186
|
if (inputWASDEmulateDirection)
|
|
181
187
|
inputData[0][remapKey(e.code)] = 3;
|
|
182
188
|
}
|
|
183
|
-
preventDefaultInput && e.preventDefault();
|
|
184
189
|
}
|
|
185
190
|
|
|
186
191
|
onkeyup = (e)=>
|
|
@@ -210,7 +215,7 @@ function inputInit()
|
|
|
210
215
|
isUsingGamepad = false;
|
|
211
216
|
inputData[0][e.button] = 3;
|
|
212
217
|
mousePosScreen = mouseEventToScreen(e);
|
|
213
|
-
e.button && e.preventDefault();
|
|
218
|
+
inputPreventDefault && e.button && e.preventDefault();
|
|
214
219
|
}
|
|
215
220
|
onmouseup = (e)=> inputData[0][e.button] = inputData[0][e.button] & 2 | 4;
|
|
216
221
|
onmousemove = (e)=> mousePosScreen = mouseEventToScreen(e);
|
|
@@ -331,7 +336,7 @@ function gamepadsUpdate()
|
|
|
331
336
|
///////////////////////////////////////////////////////////////////////////////
|
|
332
337
|
|
|
333
338
|
/** Pulse the vibration hardware if it exists
|
|
334
|
-
* @param {
|
|
339
|
+
* @param {number|Array} [pattern] - single value in ms or vibration interval array
|
|
335
340
|
* @memberof Input */
|
|
336
341
|
function vibrate(pattern=100)
|
|
337
342
|
{ vibrateEnable && !headlessMode && navigator && navigator.vibrate && navigator.vibrate(pattern); }
|
|
@@ -394,7 +399,7 @@ function touchInputInit()
|
|
|
394
399
|
wasTouching = touching;
|
|
395
400
|
|
|
396
401
|
// prevent default handling like copy and magnifier lens
|
|
397
|
-
if (document.hasFocus()) // allow document to get focus
|
|
402
|
+
if (inputPreventDefault && document.hasFocus()) // allow document to get focus
|
|
398
403
|
e.preventDefault();
|
|
399
404
|
|
|
400
405
|
// must return true so the document will get focus
|
package/src/engineMedals.js
CHANGED
|
@@ -104,7 +104,7 @@ class Medal
|
|
|
104
104
|
/** @property {String} - Icon for the medal */
|
|
105
105
|
this.icon = icon;
|
|
106
106
|
|
|
107
|
-
/** @property {
|
|
107
|
+
/** @property {boolean} - Is the medal unlocked? */
|
|
108
108
|
this.unlocked = false;
|
|
109
109
|
|
|
110
110
|
// load the source image if provided
|
|
@@ -134,8 +134,9 @@ class Medal
|
|
|
134
134
|
{
|
|
135
135
|
const context = overlayContext;
|
|
136
136
|
const width = min(medalDisplaySize.x, mainCanvas.width);
|
|
137
|
+
const height = medalDisplaySize.y;
|
|
137
138
|
const x = overlayCanvas.width - width;
|
|
138
|
-
const y = -
|
|
139
|
+
const y = -height*hidePercent;
|
|
139
140
|
|
|
140
141
|
// draw containing rect and clip to that region
|
|
141
142
|
context.save();
|
|
@@ -143,25 +144,34 @@ class Medal
|
|
|
143
144
|
context.fillStyle = new Color(.9,.9,.9).toString();
|
|
144
145
|
context.strokeStyle = new Color(0,0,0).toString();
|
|
145
146
|
context.lineWidth = 3;
|
|
146
|
-
context.rect(x, y, width,
|
|
147
|
+
context.rect(x, y, width, height);
|
|
147
148
|
context.fill();
|
|
148
149
|
context.stroke();
|
|
149
150
|
context.clip();
|
|
150
151
|
|
|
151
|
-
// draw the icon
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
// draw the icon
|
|
153
|
+
const gap = vec2(.1, .05).scale(height);
|
|
154
|
+
const medalDisplayIconSize = height - 2*gap.x;
|
|
155
|
+
this.renderIcon(vec2(x + gap.x + medalDisplayIconSize/2, y + height/2), medalDisplayIconSize);
|
|
156
|
+
|
|
157
|
+
// draw the name
|
|
158
|
+
const nameSize = height*.5;
|
|
159
|
+
const descriptionSize = height*.3;
|
|
160
|
+
const pos = vec2(x + medalDisplayIconSize + 2*gap.x, y + gap.y*2 + nameSize/2);
|
|
161
|
+
const textWidth = width - medalDisplayIconSize - 3*gap.x;
|
|
162
|
+
drawTextScreen(this.name, pos, nameSize, new Color(0,0,0), 0, undefined, 'left', undefined, textWidth);
|
|
163
|
+
|
|
164
|
+
// draw the description
|
|
165
|
+
pos.y = y + height - gap.y*2 - descriptionSize/2;
|
|
166
|
+
drawTextScreen(this.description, pos, descriptionSize, new Color(0,0,0), 0, undefined, 'left', undefined, textWidth);
|
|
157
167
|
context.restore();
|
|
158
168
|
}
|
|
159
169
|
|
|
160
170
|
/** Render the icon for a medal
|
|
161
171
|
* @param {Vector2} pos - Screen space position
|
|
162
|
-
* @param {Number}
|
|
172
|
+
* @param {Number} size - Screen space size
|
|
163
173
|
*/
|
|
164
|
-
renderIcon(pos, size
|
|
174
|
+
renderIcon(pos, size)
|
|
165
175
|
{
|
|
166
176
|
// draw the image or icon
|
|
167
177
|
if (this.image)
|