littlejsengine 1.11.13 → 1.11.17

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.
Files changed (51) hide show
  1. package/dist/littlejs.d.ts +1306 -66
  2. package/dist/littlejs.esm.js +3097 -269
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +253 -265
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +155 -260
  7. package/examples/box2d/game.js +7 -10
  8. package/examples/box2d/gameObjects.js +33 -33
  9. package/examples/box2d/index.html +6 -6
  10. package/examples/box2d/scenes.js +28 -28
  11. package/examples/breakout/game.js +1 -4
  12. package/examples/breakout/index.html +4 -4
  13. package/examples/breakoutTutorial/index.html +2 -2
  14. package/examples/htmlMenu/game.js +3 -6
  15. package/examples/htmlMenu/index.html +2 -2
  16. package/examples/module/index.html +1 -1
  17. package/examples/particles/index.html +1 -1
  18. package/examples/platformer/game.js +0 -3
  19. package/examples/platformer/index.html +8 -8
  20. package/examples/puzzle/game.js +0 -3
  21. package/examples/puzzle/index.html +2 -2
  22. package/examples/shorts/base.html +1 -1
  23. package/examples/starter/build.js +4 -4
  24. package/examples/starter/index.html +13 -13
  25. package/examples/stress/index.html +3 -2
  26. package/examples/uiSystem/game.js +1 -7
  27. package/examples/uiSystem/index.html +3 -3
  28. package/package.json +3 -3
  29. package/plugins/box2d.js +1552 -640
  30. package/plugins/{Box2D_v2.3.1_min.wasm.js → box2d.wasm.js} +1 -1
  31. package/plugins/newgrounds.js +7 -8
  32. package/plugins/pluginExport.js +51 -0
  33. package/plugins/postProcess.js +94 -93
  34. package/plugins/uiSystem.js +145 -161
  35. package/plugins/zzfxm.js +163 -0
  36. package/src/engine.js +15 -20
  37. package/src/engineAudio.js +74 -204
  38. package/src/engineBuild.js +21 -3
  39. package/src/engineDebug.js +104 -6
  40. package/src/engineDraw.js +27 -14
  41. package/src/engineExport.js +12 -4
  42. package/src/engineParticles.js +6 -1
  43. package/src/engineRelease.js +6 -1
  44. package/src/engineSettings.js +2 -2
  45. package/src/engineUtilities.js +5 -11
  46. package/src/engineWebGL.js +19 -7
  47. package/examples/starter/build/index.html +0 -2
  48. package/examples/starter/build/index.js +0 -1
  49. package/examples/starter/build/tiles.png +0 -0
  50. package/examples/starter/game.zip +0 -0
  51. /package/plugins/{Box2D_v2.3.1_min.wasm.wasm → box2d.wasm.wasm} +0 -0
@@ -15,7 +15,7 @@ a.noExitRuntime&&(noExitRuntime=a.noExitRuntime);"object"!==typeof WebAssembly&&
15
15
  function wa(b,c,d){var f=c+d;for(d=c;b[d]&&!(d>=f);)++d;if(16<d-c&&b.subarray&&va)return va.decode(b.subarray(c,d));for(f="";c<d;){var y=b[c++];if(y&128){var oa=b[c++]&63;if(192==(y&224))f+=String.fromCharCode((y&31)<<6|oa);else{var ya=b[c++]&63;y=224==(y&240)?(y&15)<<12|oa<<6|ya:(y&7)<<18|oa<<12|ya<<6|b[c++]&63;65536>y?f+=String.fromCharCode(y):(y-=65536,f+=String.fromCharCode(55296|y>>10,56320|y&1023))}}else f+=String.fromCharCode(y)}return f}function xa(b){return b?wa(za,b,void 0):""}
16
16
  var Aa,za,Ba,Ca;function Da(b){Aa=b;a.HEAP8=new Int8Array(b);a.HEAP16=new Int16Array(b);a.HEAP32=Ba=new Int32Array(b);a.HEAPU8=za=new Uint8Array(b);a.HEAPU16=new Uint16Array(b);a.HEAPU32=new Uint32Array(b);a.HEAPF32=new Float32Array(b);a.HEAPF64=Ca=new Float64Array(b)}var Ea=a.INITIAL_MEMORY||16777216;if(sa=a.wasmMemory?a.wasmMemory:new WebAssembly.Memory({initial:Ea/65536,maximum:32768}))Aa=sa.buffer;Ea=Aa.byteLength;Da(Aa);Ba[6512]=5269088;
17
17
  function Fa(b){for(;0<b.length;){var c=b.shift();if("function"==typeof c)c(a);else{var d=c.ev;"number"===typeof d?void 0===c.Au?a.dynCall_v(d):a.dynCall_vi(d,c.Au):d(void 0===c.Au?null:c.Au)}}}var Ga=[],Ha=[],Ia=[],Ja=[],Ka=!1;function La(){var b=a.preRun.shift();Ga.unshift(b)}var Ma=0,Na=null,Oa=null;a.preloadedImages={};a.preloadedAudios={};
18
- function na(b){if(a.onAbort)a.onAbort(b);b+="";pa(b);qa(b);ua=!0;throw new WebAssembly.RuntimeError("abort("+b+"). Build with -s ASSERTIONS=1 for more info.");}function Pa(b){var c=Qa;return String.prototype.startsWith?c.startsWith(b):0===c.indexOf(b)}function Ra(){return Pa("data:application/octet-stream;base64,")}var Qa="Box2D_v2.3.1_min.wasm.wasm";if(!Ra()){var Sa=Qa;Qa=a.locateFile?a.locateFile(Sa,ia):ia+Sa}
18
+ function na(b){if(a.onAbort)a.onAbort(b);b+="";pa(b);qa(b);ua=!0;throw new WebAssembly.RuntimeError("abort("+b+"). Build with -s ASSERTIONS=1 for more info.");}function Pa(b){var c=Qa;return String.prototype.startsWith?c.startsWith(b):0===c.indexOf(b)}function Ra(){return Pa("data:application/octet-stream;base64,")}var Qa="box2d.wasm.wasm";if(!Ra()){var Sa=Qa;Qa=a.locateFile?a.locateFile(Sa,ia):ia+Sa}
19
19
  function Ta(){try{if(ra)return new Uint8Array(ra);if(ka)return ka(Qa);throw"both async and sync fetching of the wasm failed";}catch(b){na(b)}}function Ua(){return ra||!da&&!ea||"function"!==typeof fetch||Pa("file://")?new Promise(function(b){b(Ta())}):fetch(Qa,{credentials:"same-origin"}).then(function(b){if(!b.ok)throw"failed to load wasm binary file at '"+Qa+"'";return b.arrayBuffer()}).catch(function(){return Ta()})}
20
20
  var Va={1156:function(b,c){b=a.getCache(a.JSDestructionListener)[b];if(!b.hasOwnProperty("SayGoodbyeJoint"))throw"a JSImplementation must implement all functions, you forgot JSDestructionListener::SayGoodbyeJoint.";b.SayGoodbyeJoint(c)},1414:function(b,c){b=a.getCache(a.JSDestructionListener)[b];if(!b.hasOwnProperty("SayGoodbyeFixture"))throw"a JSImplementation must implement all functions, you forgot JSDestructionListener::SayGoodbyeFixture.";b.SayGoodbyeFixture(c)},1840:function(b,c){b=a.getCache(a.JSQueryCallback)[b];
21
21
  if(!b.hasOwnProperty("ReportFixture"))throw"a JSImplementation must implement all functions, you forgot JSQueryCallback::ReportFixture.";return b.ReportFixture(c)},2104:function(b,c,d,f,y){b=a.getCache(a.JSRayCastCallback)[b];if(!b.hasOwnProperty("ReportFixture"))throw"a JSImplementation must implement all functions, you forgot JSRayCastCallback::ReportFixture.";return b.ReportFixture(c,d,f,y)},2400:function(b,c){b=a.getCache(a.JSContactListener)[b];if(!b.hasOwnProperty("BeginContact"))throw"a JSImplementation must implement all functions, you forgot JSContactListener::BeginContact.";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * LittleJS Newgrounds API
3
3
  * - NewgroundsMedal extends Medal with Newgrounds API functionality
4
- * - Call newgroundsInit to enable Newgrounds functionality
4
+ * - Call new NewgroundsPlugin() to setup Newgrounds
5
5
  * - Uses CryptoJS for encryption if optional cipher is provided
6
6
  * - Keeps connection alive and logs views
7
7
  * - Functions to interact with scoreboards
@@ -11,14 +11,13 @@
11
11
  'use strict';
12
12
 
13
13
  /** Global Newgrounds object
14
- * @type {Newgrounds}
14
+ * @type {NewgroundsPlugin}
15
15
  * @memberof Medal */
16
16
  let newgrounds;
17
17
 
18
18
  ///////////////////////////////////////////////////////////////////////////////
19
19
  /**
20
20
  * Newgrounds medal auto unlocks in newgrounds API
21
- * Particle Emitter - Spawns particles with the given settings
22
21
  * @extends Medal
23
22
  */
24
23
  class NewgroundsMedal extends Medal
@@ -45,7 +44,7 @@ class NewgroundsMedal extends Medal
45
44
  /**
46
45
  * Newgrounds API object
47
46
  */
48
- class Newgrounds
47
+ class NewgroundsPlugin
49
48
  {
50
49
  /** Create the global newgrounds object
51
50
  * @param {string} app_id - The newgrounds App ID
@@ -54,7 +53,7 @@ class Newgrounds
54
53
  * @example
55
54
  * // create the newgrounds object, replace the app id with your own
56
55
  * const app_id = 'your_app_id_here';
57
- * new Newgrounds(app_id);
56
+ * new NewgroundsPlugin(app_id);
58
57
  */
59
58
  constructor(app_id, cipher, cryptoJS)
60
59
  {
@@ -102,8 +101,8 @@ class Newgrounds
102
101
  this.scoreboards = scoreboardResult ? scoreboardResult.result.data.scoreboards : [];
103
102
  debugMedals && console.log(this.scoreboards);
104
103
 
105
- // keep the session alive with a ping every 5 minutes
106
- const keepAliveMS = 5 * 60 * 1e3;
104
+ // keep the session alive with a ping every minute
105
+ const keepAliveMS = 60 * 1e3;
107
106
  setInterval(()=>this.call('Gateway.ping', 0, true), keepAliveMS);
108
107
  }
109
108
 
@@ -175,4 +174,4 @@ class Newgrounds
175
174
  debugMedals && console.log(xmlHttp.responseText);
176
175
  return xmlHttp.responseText && JSON.parse(xmlHttp.responseText);
177
176
  }
178
- }
177
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * LittleJS Module Plugins Export
3
+ */
4
+
5
+ 'use strict';
6
+
7
+ export
8
+ {
9
+ // Newgrounds
10
+ newgrounds,
11
+ NewgroundsPlugin,
12
+ NewgroundsMedal,
13
+
14
+ // Post Process
15
+ postProcess,
16
+ PostProcessPlugin,
17
+
18
+ // ZzFXMusic
19
+ ZzFXMusic,
20
+
21
+ // UI System
22
+ uiSystem,
23
+ UISystemPlugin,
24
+ UIObject,
25
+ UIText,
26
+ UITile,
27
+ UIButton,
28
+ UICheckbox,
29
+ UIScrollbar,
30
+
31
+ // Box2D Physics
32
+ box2d,
33
+ box2dDebug,
34
+ box2dEngineInit,
35
+ Box2dPlugin,
36
+ Box2dObject,
37
+ Box2dRaycastResult,
38
+ Box2dJoint,
39
+ Box2dTargetJoint,
40
+ Box2dDistanceJoint,
41
+ Box2dPinJoint,
42
+ Box2dRopeJoint,
43
+ Box2dRevoluteJoint,
44
+ Box2dGearJoint,
45
+ Box2dPrismaticJoint,
46
+ Box2dWheelJoint,
47
+ Box2dWeldJoint,
48
+ Box2dFrictionJoint,
49
+ Box2dPulleyJoint,
50
+ Box2dMotorJoint,
51
+ };
@@ -1,115 +1,116 @@
1
1
  /**
2
2
  * LittleJS Post Processing Plugin
3
3
  * - Supports shadertoy style post processing shaders
4
- * - call initPostProcess to set it up
5
- * @namespace PostProcessPlugin
4
+ * - call new new PostProcessPlugin() to setup post processing
5
+ * - can be enabled to pass other canvases through a final shader
6
6
  */
7
7
 
8
8
  'use strict';
9
9
 
10
10
  ///////////////////////////////////////////////////////////////////////////////
11
- // post processing - can be enabled to pass other canvases through a final shader
12
11
 
13
- /** Shader for post processing
14
- * @type {WebGLProgram}
15
- * @memberof PostProcessPlugin */
16
- let glPostShader;
12
+ /** Global Post Process plugin object
13
+ * @type {PostProcessPlugin} */
14
+ let postProcess;
17
15
 
18
- /** Texture for post processing
19
- * @type {WebGLTexture}
20
- * @memberof PostProcessPlugin */
21
- let glPostTexture;
16
+ /////////////////////////////////////////////////////////////////////////
17
+ /**
18
+ * UI System Global Object
19
+ */
20
+ class PostProcessPlugin
21
+ {
22
+ /** Create global post processing shader
23
+ * @param {string} shaderCode
24
+ * @param {boolean} [includeOverlay]
25
+ * @example
26
+ * // create the post process plugin object
27
+ * new PostProcessPlugin(shaderCode);
28
+ */
29
+ constructor(shaderCode, includeOverlay=false)
30
+ {
31
+ ASSERT(!postProcess, 'Post process already initialized');
32
+ postProcess = this;
22
33
 
23
- /** Should overlay canvas be included in post processing
24
- * @type {boolean}
25
- * @memberof PostProcessPlugin */
26
- let glPostIncludeOverlay;
34
+ if (headlessMode) return;
35
+ if (!shaderCode) // default shader pass through
36
+ shaderCode = 'void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}';
27
37
 
28
- /** Set up a post processing shader
29
- * @param {string} shaderCode
30
- * @param {boolean} [includeOverlay]
31
- * @memberof PostProcessPlugin */
32
- function initPostProcess(shaderCode, includeOverlay=false)
33
- {
34
- ASSERT(!glPostShader, 'can only have 1 post effects shader');
35
- if (headlessMode) return;
36
-
37
- if (!shaderCode) // default shader pass through
38
- shaderCode = 'void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}';
38
+ /** @property {WebGLProgram} - Shader for post processing */
39
+ this.shader = glCreateProgram(
40
+ '#version 300 es\n' + // specify GLSL ES version
41
+ 'precision highp float;'+ // use highp for better accuracy
42
+ 'in vec2 p;'+ // position
43
+ 'void main(){'+ // shader entry point
44
+ 'gl_Position=vec4(p+p-1.,1,1);'+ // set position
45
+ '}' // end of shader
46
+ ,
47
+ '#version 300 es\n' + // specify GLSL ES version
48
+ 'precision highp float;'+ // use highp for better accuracy
49
+ 'uniform sampler2D iChannel0;'+ // input texture
50
+ 'uniform vec3 iResolution;'+ // size of output texture
51
+ 'uniform float iTime;'+ // time
52
+ 'out vec4 c;'+ // out color
53
+ '\n' + shaderCode + '\n'+ // insert custom shader code
54
+ 'void main(){'+ // shader entry point
55
+ 'mainImage(c,gl_FragCoord.xy);'+ // call post process function
56
+ 'c.a=1.;'+ // always use full alpha
57
+ '}' // end of shader
58
+ );
39
59
 
40
- // create the shader
41
- glPostShader = glCreateProgram(
42
- '#version 300 es\n' + // specify GLSL ES version
43
- 'precision highp float;'+ // use highp for better accuracy
44
- 'in vec2 p;'+ // position
45
- 'void main(){'+ // shader entry point
46
- 'gl_Position=vec4(p+p-1.,1,1);'+ // set position
47
- '}' // end of shader
48
- ,
49
- '#version 300 es\n' + // specify GLSL ES version
50
- 'precision highp float;'+ // use highp for better accuracy
51
- 'uniform sampler2D iChannel0;'+ // input texture
52
- 'uniform vec3 iResolution;'+ // size of output texture
53
- 'uniform float iTime;'+ // time
54
- 'out vec4 c;'+ // out color
55
- '\n' + shaderCode + '\n'+ // insert custom shader code
56
- 'void main(){'+ // shader entry point
57
- 'mainImage(c,gl_FragCoord.xy);'+ // call post process function
58
- 'c.a=1.;'+ // always use full alpha
59
- '}' // end of shader
60
- );
60
+ /** @property {WebGLTexture} - Texture for post processing */
61
+ this.texture = glCreateTexture();
61
62
 
62
- // create buffer and texture
63
- glPostTexture = glCreateTexture(undefined);
64
- glPostIncludeOverlay = includeOverlay;
63
+ /** @property {boolean} - Should overlay canvas be included in post processing */
64
+ this.includeOverlay = includeOverlay;
65
65
 
66
- // Render the post processing shader, called automatically by the engine
67
- engineAddPlugin(undefined, postProcessRender);
68
- function postProcessRender()
69
- {
70
- if (headlessMode) return;
71
-
72
- // prepare to render post process shader
73
- if (glEnable)
66
+ // Render the post processing shader, called automatically by the engine
67
+ engineAddPlugin(undefined, postProcessRender);
68
+ function postProcessRender()
74
69
  {
75
- glFlush(); // clear out the buffer
76
- mainContext.drawImage(glCanvas, 0, 0); // copy to the main canvas
77
- }
78
- else
79
- {
80
- // set the viewport
81
- glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
82
- }
70
+ if (headlessMode) return;
71
+
72
+ // prepare to render post process shader
73
+ if (glEnable)
74
+ {
75
+ glFlush(); // clear out the buffer
76
+ mainContext.drawImage(glCanvas, 0, 0); // copy to the main canvas
77
+ }
78
+ else
79
+ {
80
+ // set the viewport
81
+ glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
82
+ }
83
83
 
84
- if (glPostIncludeOverlay)
85
- {
86
- // copy overlay canvas so it will be included in post processing
87
- mainContext.drawImage(overlayCanvas, 0, 0);
88
- overlayCanvas.width |= 0;
89
- }
84
+ if (postProcess.includeOverlay)
85
+ {
86
+ // copy overlay canvas so it will be included in post processing
87
+ mainContext.drawImage(overlayCanvas, 0, 0);
88
+ overlayCanvas.width |= 0;
89
+ }
90
90
 
91
- // setup shader program to draw one triangle
92
- glContext.useProgram(glPostShader);
93
- glContext.bindBuffer(glContext.ARRAY_BUFFER, glGeometryBuffer);
94
- glContext.pixelStorei(glContext.UNPACK_FLIP_Y_WEBGL, 1);
95
- glContext.disable(glContext.BLEND);
91
+ // setup shader program to draw one triangle
92
+ glContext.useProgram(postProcess.shader);
93
+ glContext.bindBuffer(glContext.ARRAY_BUFFER, glGeometryBuffer);
94
+ glContext.pixelStorei(glContext.UNPACK_FLIP_Y_WEBGL, 1);
95
+ glContext.disable(glContext.BLEND);
96
96
 
97
- // set textures, pass in the 2d canvas and gl canvas in separate texture channels
98
- glContext.activeTexture(glContext.TEXTURE0);
99
- glContext.bindTexture(glContext.TEXTURE_2D, glPostTexture);
100
- glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, mainCanvas);
97
+ // set textures, pass in the 2d canvas and gl canvas in separate texture channels
98
+ glContext.activeTexture(glContext.TEXTURE0);
99
+ glContext.bindTexture(glContext.TEXTURE_2D, postProcess.texture);
100
+ glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, mainCanvas);
101
101
 
102
- // set vertex position attribute
103
- const vertexByteStride = 8;
104
- const pLocation = glContext.getAttribLocation(glPostShader, 'p');
105
- glContext.enableVertexAttribArray(pLocation);
106
- glContext.vertexAttribPointer(pLocation, 2, glContext.FLOAT, false, vertexByteStride, 0);
102
+ // set vertex position attribute
103
+ const vertexByteStride = 8;
104
+ const pLocation = glContext.getAttribLocation(postProcess.shader, 'p');
105
+ glContext.enableVertexAttribArray(pLocation);
106
+ glContext.vertexAttribPointer(pLocation, 2, glContext.FLOAT, false, vertexByteStride, 0);
107
107
 
108
- // set uniforms and draw
109
- const uniformLocation = (name)=>glContext.getUniformLocation(glPostShader, name);
110
- glContext.uniform1i(uniformLocation('iChannel0'), 0);
111
- glContext.uniform1f(uniformLocation('iTime'), time);
112
- glContext.uniform3f(uniformLocation('iResolution'), mainCanvas.width, mainCanvas.height, 1);
113
- glContext.drawArrays(glContext.TRIANGLE_STRIP, 0, 4);
108
+ // set uniforms and draw
109
+ const uniformLocation = (name)=>glContext.getUniformLocation(postProcess.shader, name);
110
+ glContext.uniform1i(uniformLocation('iChannel0'), 0);
111
+ glContext.uniform1f(uniformLocation('iTime'), time);
112
+ glContext.uniform3f(uniformLocation('iResolution'), mainCanvas.width, mainCanvas.height, 1);
113
+ glContext.drawArrays(glContext.TRIANGLE_STRIP, 0, 4);
114
+ }
114
115
  }
115
- }
116
+ }