littlejsengine 1.19.3 → 1.20.0

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 (50) hide show
  1. package/FAQ.md +841 -820
  2. package/README.md +29 -25
  3. package/dist/littlejs.d.ts +2455 -935
  4. package/dist/littlejs.esm.js +30344 -21110
  5. package/dist/littlejs.esm.min.js +4 -3
  6. package/dist/littlejs.js +30259 -21052
  7. package/dist/littlejs.min.js +2 -2
  8. package/dist/littlejs.release.js +26567 -20455
  9. package/package.json +10 -5
  10. package/plugins/audioEffects.js +28 -24
  11. package/plugins/box2d.js +2516 -2073
  12. package/plugins/drawUtilities.js +206 -31
  13. package/plugins/gltf.js +740 -0
  14. package/plugins/jsconfig.json +19 -0
  15. package/plugins/lightSystem.js +719 -332
  16. package/plugins/math3d.js +58 -17
  17. package/plugins/medalSystem.js +326 -280
  18. package/plugins/newgrounds.js +400 -199
  19. package/plugins/pathFinder.js +208 -175
  20. package/plugins/pluginExport.js +15 -0
  21. package/plugins/postProcess.js +56 -13
  22. package/plugins/render3d.js +1643 -1577
  23. package/plugins/render3dDebug.js +109 -0
  24. package/plugins/render3dExtras.js +1754 -0
  25. package/plugins/render3dVoxels.js +502 -0
  26. package/plugins/textureSheet.js +496 -458
  27. package/plugins/threejs.js +183 -163
  28. package/plugins/tweakables.js +411 -0
  29. package/plugins/tweenSystem.js +263 -145
  30. package/plugins/uiSystem.js +2024 -1687
  31. package/plugins/zzfxm.js +159 -159
  32. package/src/engine.js +191 -75
  33. package/src/engineAudio.js +229 -125
  34. package/src/engineBuild.mjs +289 -256
  35. package/src/engineDebug.js +912 -742
  36. package/src/engineDraw.js +295 -193
  37. package/src/engineEditor.js +2431 -0
  38. package/src/engineExport.js +12 -0
  39. package/src/engineInput.js +1462 -1293
  40. package/src/engineMath.js +1274 -1252
  41. package/src/engineObject.js +194 -80
  42. package/src/engineParticles.js +583 -532
  43. package/src/engineRelease.js +67 -45
  44. package/src/engineSettings.js +77 -29
  45. package/src/engineTileLayer.js +995 -741
  46. package/src/engineUtilities.js +19 -13
  47. package/src/engineWebGL.js +239 -82
  48. package/src/jsconfig.json +17 -13
  49. package/plugins/box2d.wasm.js +0 -630
  50. package/plugins/box2d.wasm.wasm +0 -0
@@ -6,7 +6,7 @@
6
6
  * - File saving (text, canvas, data URLs)
7
7
  * - Native share dialog support
8
8
  * - Local storage save data management
9
- * - Gradient noise (1D and 2D)
9
+ * - Value noise (1D and 2D)
10
10
  * @namespace Utilities
11
11
  */
12
12
 
@@ -32,7 +32,9 @@ class Timer
32
32
  ASSERT(timeLeft === undefined || isNumber(timeLeft), 'Constructed Timer is invalid.', timeLeft);
33
33
  this.useRealTime = useRealTime;
34
34
  const globalTime = this.getGlobalTime();
35
+ /** @type {number|undefined} */
35
36
  this.time = timeLeft === undefined ? undefined : globalTime + timeLeft;
37
+ /** @type {number|undefined} */
36
38
  this.setTime = timeLeft;
37
39
  }
38
40
 
@@ -108,7 +110,7 @@ class Timer
108
110
  * @memberof Utilities */
109
111
  function formatTime(t)
110
112
  {
111
- const signStr = t < 0 ? '-' : '';
113
+ const signStr = t <= -1 ? '-' : ''; // no sign when it shows 0:00
112
114
  t = abs(t)|0;
113
115
  return signStr + (t/60|0) + ':' + (t%60<10?'0':'') + t%60;
114
116
  }
@@ -122,7 +124,9 @@ async function fetchJSON(url)
122
124
  const response = await fetch(url);
123
125
  if (!response.ok)
124
126
  throw new Error(`Failed to fetch JSON from ${url}: ${response.status} ${response.statusText}`);
125
- return response.json();
127
+ const json = await response.json();
128
+ editorJSONFetched(url, json); // debug builds remember the file a level came from, to save it by that name
129
+ return json;
126
130
  }
127
131
 
128
132
  ///////////////////////////////////////////////////////////////////////////////
@@ -133,7 +137,7 @@ async function fetchJSON(url)
133
137
  * @param {string} [type]
134
138
  * @memberof Utilities */
135
139
  function saveText(text, filename='text', type='text/plain')
136
- { saveDataURL(URL.createObjectURL(new Blob([text], {'type':type})), filename); }
140
+ { saveDataURL(URL.createObjectURL(new Blob([text], {'type':type})), filename, 1e3); } // freed once the download has it
137
141
 
138
142
  /** Create an offscreen canvas to draw into, and return its 2D context
139
143
  * - The canvas is context.canvas, which is what TextureInfo and the like take
@@ -196,15 +200,17 @@ function shareURL(title, url, callback)
196
200
  {
197
201
  ASSERT(isStringLike(title), 'shareURL requires title string');
198
202
  ASSERT(isStringLike(url), 'shareURL requires url string');
199
- navigator.share?.({title, url}).then(()=>callback?.());
203
+ navigator.share?.({title, url}).then(()=>callback?.(), ()=>{}); // a player who cancels is not an error
200
204
  }
201
205
 
202
206
  ///////////////////////////////////////////////////////////////////////////////
203
207
 
204
208
  /** Read save data from local storage
209
+ * - The result has the type of defaultSaveData, or any when there is none
210
+ * @template {Object<string, any>} [T=any]
205
211
  * @param {string} saveName - unique name for the game/save
206
- * @param {Object} [defaultSaveData] - default values, result is {...default, ...loaded} so this must be an object
207
- * @return {Object}
212
+ * @param {T} [defaultSaveData] - default values, result is {...default, ...loaded} so this must be an object
213
+ * @return {T}
208
214
  * @memberof Utilities */
209
215
  function readSaveData(saveName, defaultSaveData)
210
216
  {
@@ -220,7 +226,7 @@ function readSaveData(saveName, defaultSaveData)
220
226
  let loadedData = {};
221
227
  try
222
228
  {
223
- const data = localStorage[saveName];
229
+ const data = localStorage.getItem(saveName); // not the brackets, a name like 'key' or 'length' is a Storage member
224
230
  if (data)
225
231
  {
226
232
  try { loadedData = JSON.parse(data); }
@@ -228,18 +234,18 @@ function readSaveData(saveName, defaultSaveData)
228
234
  }
229
235
  }
230
236
  catch { LOG('readSaveData: localStorage unavailable — using defaults'); }
231
- return { ...defaultSaveData, ...loadedData };
237
+ return { .../** @type {object} */ (defaultSaveData), ...loadedData };
232
238
  }
233
239
 
234
240
  /** Write save data to local storage
235
241
  * @param {string} saveName - unique name for the game/save
236
- * @param {Object} saveData - object containing data to be saved
242
+ * @param {object} saveData - object containing data to be saved
237
243
  * @memberof Utilities */
238
244
  function writeSaveData(saveName, saveData)
239
245
  {
240
246
  ASSERT(isStringLike(saveName), 'writeSaveData requires saveName string');
241
247
  // tolerate localStorage being unavailable or quota exceeded
242
- try { localStorage[saveName] = JSON.stringify(saveData); }
248
+ try { localStorage.setItem(saveName, JSON.stringify(saveData)); }
243
249
  catch { LOG('writeSaveData: failed to write', saveName); }
244
250
  }
245
251
 
@@ -256,7 +262,7 @@ function noiseHash(i)
256
262
  return (h >>> 0) / 2**32;
257
263
  }
258
264
 
259
- /** 1D gradient noise — returns a smooth value in [0, 1] for any real x.
265
+ /** 1D value noise — returns a smooth value in [0, 1] for any real x.
260
266
  * Integer inputs land on deterministic lattice values; non-integer inputs
261
267
  * are interpolated with smoothStep for C1 continuity.
262
268
  * @param {number} x
@@ -268,7 +274,7 @@ function noise1D(x)
268
274
  return lerp(noiseHash(i), noiseHash(i + 1), smoothStep(x - i));
269
275
  }
270
276
 
271
- /** 2D gradient noise — returns a smooth value in [0, 1] for any real (x, y).
277
+ /** 2D value noise — returns a smooth value in [0, 1] for any real (x, y).
272
278
  * @param {number} x
273
279
  * @param {number} y
274
280
  * @return {number}