littlejsengine 1.19.3 → 1.21.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.
- package/FAQ.md +841 -820
- package/README.md +29 -25
- package/dist/littlejs.d.ts +2857 -955
- package/dist/littlejs.esm.js +33428 -20995
- package/dist/littlejs.esm.min.js +4 -3
- package/dist/littlejs.js +33386 -20996
- package/dist/littlejs.min.js +2 -2
- package/dist/littlejs.release.js +27841 -20422
- package/package.json +10 -5
- package/plugins/audioEffects.js +28 -24
- package/plugins/box2d.js +2516 -2073
- package/plugins/drawUtilities.js +206 -31
- package/plugins/gltf.js +786 -0
- package/plugins/jsconfig.json +19 -0
- package/plugins/lightSystem.js +719 -332
- package/plugins/math3d.js +148 -27
- package/plugins/medalSystem.js +326 -280
- package/plugins/newgrounds.js +400 -199
- package/plugins/pathFinder.js +208 -175
- package/plugins/pluginExport.js +25 -0
- package/plugins/postProcess.js +96 -24
- package/plugins/render3d.js +2067 -1632
- package/plugins/render3dDebug.js +110 -0
- package/plugins/render3dEditor.js +1812 -0
- package/plugins/render3dExtras.js +1948 -0
- package/plugins/render3dLevel.js +189 -0
- package/plugins/render3dVoxels.js +514 -0
- package/plugins/sceneSystem.js +58 -0
- package/plugins/textureSheet.js +496 -458
- package/plugins/threejs.js +183 -163
- package/plugins/tweakables.js +411 -0
- package/plugins/tweenSystem.js +265 -145
- package/plugins/uiSystem.js +2024 -1687
- package/plugins/zzfxm.js +159 -159
- package/src/engine.js +378 -97
- package/src/engineAudio.js +231 -127
- package/src/engineBuild.mjs +292 -256
- package/src/engineDebug.js +967 -743
- package/src/engineDraw.js +391 -198
- package/src/engineEditor.js +2452 -0
- package/src/engineExport.js +18 -0
- package/src/engineInput.js +1466 -1293
- package/src/engineLogo.js +19 -0
- package/src/engineMath.js +1274 -1252
- package/src/engineObject.js +197 -82
- package/src/engineParticles.js +583 -532
- package/src/engineRelease.js +79 -45
- package/src/engineSettings.js +115 -29
- package/src/engineTileLayer.js +995 -741
- package/src/engineUtilities.js +19 -13
- package/src/engineWebGL.js +239 -82
- package/src/jsconfig.json +17 -13
- package/plugins/box2d.wasm.js +0 -630
- package/plugins/box2d.wasm.wasm +0 -0
package/src/engineUtilities.js
CHANGED
|
@@ -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
|
-
* -
|
|
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
|
|
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
|
-
|
|
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 {
|
|
207
|
-
* @return {
|
|
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
|
|
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 {
|
|
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 {
|
|
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
|
|
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
|
|
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
|
|
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}
|