littlejsengine 1.6.4 → 1.6.92
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 +61 -41
- package/build/littlejs.d.ts +160 -165
- package/build/littlejs.esm.js +451 -367
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +408 -314
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +2573 -2470
- package/examples/breakout/game.js +5 -1
- package/examples/breakout/index.html +5 -5
- package/examples/breakoutTutorial/README.md +6 -6
- package/examples/breakoutTutorial/game.js +3 -0
- package/examples/breakoutTutorial/index.html +3 -3
- package/examples/electron/build.js +105 -0
- package/examples/electron/game.js +4 -2
- package/examples/electron/index.html +13 -2
- package/examples/electron/package.json +5 -3
- package/examples/empty/game.js +3 -1
- package/examples/empty/index.html +1 -1
- package/examples/favicon.png +0 -0
- package/examples/js13k/build.bat +2 -0
- package/examples/js13k/build.js +110 -0
- package/examples/js13k/game.js +109 -0
- package/examples/js13k/index.html +18 -0
- package/examples/js13k/tiles.png +0 -0
- package/examples/module/game.js +9 -3
- package/examples/module/index.html +2 -2
- package/examples/particles/index.html +7 -13
- package/examples/platformer/game.js +5 -2
- package/examples/platformer/gameEffects.js +1 -2
- package/examples/platformer/gamePlayer.js +2 -2
- package/examples/platformer/index.html +8 -8
- package/examples/puzzle/game.js +6 -4
- package/examples/puzzle/index.html +4 -4
- package/examples/starter/build.bat +2 -78
- package/examples/starter/build.js +109 -0
- package/examples/starter/game.js +4 -1
- package/examples/starter/index.html +15 -18
- package/examples/stress/index.html +2 -4
- package/examples/typescript/build.bat +2 -14
- package/examples/typescript/build.js +31 -0
- package/examples/typescript/game.js +94 -89
- package/examples/typescript/game.ts +9 -3
- package/examples/typescript/index.html +2 -2
- package/package.json +3 -3
- package/src/engine.js +30 -31
- package/src/engineAudio.js +44 -20
- package/src/engineBuild.bat +2 -132
- package/src/engineBuild.js +143 -0
- package/src/engineDebug.js +21 -32
- package/src/engineDraw.js +36 -28
- package/src/engineExport.js +41 -51
- package/src/engineInput.js +33 -20
- package/src/engineMedals.js +31 -8
- package/src/engineObject.js +34 -32
- package/src/engineParticles.js +9 -12
- package/src/engineRelease.js +18 -20
- package/src/engineSettings.js +4 -4
- package/src/engineTileLayer.js +49 -32
- package/src/engineUtilities.js +96 -74
- package/src/engineWebGL.js +8 -8
- package/examples/electron/build.bat +0 -52
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
|
|
2
|
+
Little TypeScript Demo
|
|
3
|
+
- A simple starter project
|
|
4
|
+
- Builds to a JavaScript file from TypeScript
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
'use strict';
|
|
6
8
|
|
|
7
9
|
// import module
|
|
8
10
|
import * as LittleJS from '../../build/littlejs.esm.js';
|
|
9
|
-
const {Color, vec2} = LittleJS;
|
|
11
|
+
const {Vector2, Color, Timer, vec2} = LittleJS;
|
|
10
12
|
|
|
11
13
|
// sound effects
|
|
12
14
|
const sound_click = new LittleJS.Sound([1,.5]);
|
|
@@ -17,13 +19,14 @@ LittleJS.medalsInit('Hello World');
|
|
|
17
19
|
|
|
18
20
|
// game variables
|
|
19
21
|
let particleEmitter: LittleJS.ParticleEmitter;
|
|
22
|
+
let gameTimer = new Timer;
|
|
20
23
|
|
|
21
24
|
///////////////////////////////////////////////////////////////////////////////
|
|
22
25
|
function gameInit()
|
|
23
26
|
{
|
|
24
27
|
// create tile collision and visible tile layer
|
|
25
28
|
LittleJS.initTileCollision(vec2(32, 16));
|
|
26
|
-
const pos =
|
|
29
|
+
const pos = new Vector2;
|
|
27
30
|
const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
|
|
28
31
|
|
|
29
32
|
// get level data from the tiles image
|
|
@@ -67,6 +70,9 @@ function gameInit()
|
|
|
67
70
|
);
|
|
68
71
|
particleEmitter.elasticity = .3; // bounce when it collides
|
|
69
72
|
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
73
|
+
|
|
74
|
+
// start the game timer
|
|
75
|
+
gameTimer.set();
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
<!DOCTYPE html><head>
|
|
2
2
|
<title>Little TypeScript Demo</title>
|
|
3
3
|
<meta name=viewport content=width=device-width,height=device-height,initial-scale=1,maximum-scale=1>
|
|
4
4
|
<meta name=apple-mobile-web-app-capable content=yes>
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- Add your game scripts here -->
|
|
10
|
-
<script src=game.js?
|
|
10
|
+
<script src=game.js?1691 type=module></script>
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "littlejsengine",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.92",
|
|
4
4
|
"description": "LittleJS - Tiny and Fast HTML5 Game Engine",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "build/littlejs.esm.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/KilledByAPixel/LittleJS.git"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/KilledByAPixel/LittleJS",
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "
|
|
26
|
+
"build": "node src/engineBuild.js"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"google-closure-compiler": "~20230502.0.0",
|
package/src/engine.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* LittleJS Engine Globals
|
|
1
|
+
/**
|
|
2
|
+
* LittleJS - The Tiny JavaScript Game Engine That Can!
|
|
3
|
+
* MIT License - Copyright 2021 Frank Force
|
|
4
|
+
*
|
|
5
|
+
* Engine Features
|
|
6
|
+
* - Object oriented system with base class engine object
|
|
7
|
+
* - Base class object handles update, physics, collision, rendering, etc
|
|
8
|
+
* - Engine helper classes and functions like Vector2, Color, and Timer
|
|
9
|
+
* - Super fast rendering system for tile sheets
|
|
10
|
+
* - Sound effects audio with zzfx and music with zzfxm
|
|
11
|
+
* - Input processing system with gamepad and touchscreen support
|
|
12
|
+
* - Tile layer rendering and collision system
|
|
13
|
+
* - Particle effect system
|
|
14
|
+
* - Medal system tracks and displays achievements
|
|
15
|
+
* - Debug tools and debug rendering system
|
|
16
|
+
* - Post processing effects
|
|
17
|
+
* - Call engineInit() to start it up!
|
|
22
18
|
* @namespace Engine
|
|
23
19
|
*/
|
|
24
20
|
|
|
@@ -34,7 +30,7 @@ const engineName = 'LittleJS';
|
|
|
34
30
|
* @type {String}
|
|
35
31
|
* @default
|
|
36
32
|
* @memberof Engine */
|
|
37
|
-
const engineVersion = '1.6.
|
|
33
|
+
const engineVersion = '1.6.92';
|
|
38
34
|
|
|
39
35
|
/** Frames per second to update objects
|
|
40
36
|
* @type {Number}
|
|
@@ -104,10 +100,11 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
104
100
|
debug && (tileImage.onload=()=>ASSERT(1)); // tile sheet can not reloaded
|
|
105
101
|
|
|
106
102
|
// setup html
|
|
107
|
-
const styleBody = 'margin:0;overflow:hidden;
|
|
108
|
-
';
|
|
109
|
-
'
|
|
110
|
-
'
|
|
103
|
+
const styleBody = 'margin:0;overflow:hidden;' + // fill the window
|
|
104
|
+
'background:#000;' + // set background color
|
|
105
|
+
'touch-action:none;' + // prevent mobile pinch to resize
|
|
106
|
+
'user-select:none;' + // prevent mobile hold to select
|
|
107
|
+
'-webkit-user-select:none'; // compatibility for ios
|
|
111
108
|
document.body.style = styleBody;
|
|
112
109
|
document.body.appendChild(mainCanvas = document.createElement('canvas'));
|
|
113
110
|
mainContext = mainCanvas.getContext('2d');
|
|
@@ -120,8 +117,10 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
120
117
|
document.body.appendChild(overlayCanvas = document.createElement('canvas'));
|
|
121
118
|
overlayContext = overlayCanvas.getContext('2d');
|
|
122
119
|
|
|
123
|
-
// set canvas style
|
|
124
|
-
const styleCanvas = 'position:absolute;
|
|
120
|
+
// set canvas style
|
|
121
|
+
const styleCanvas = 'position:absolute;' +
|
|
122
|
+
'top:50%;left:50%;transform:translate(-50%,-50%);' + // center the canvas
|
|
123
|
+
(canvasPixelated?'image-rendering:pixelated':''); // set pixelated rendering
|
|
125
124
|
(glCanvas||mainCanvas).style = mainCanvas.style = overlayCanvas.style = styleCanvas;
|
|
126
125
|
|
|
127
126
|
gameInit();
|
|
@@ -129,7 +128,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
129
128
|
};
|
|
130
129
|
|
|
131
130
|
// frame time tracking
|
|
132
|
-
let frameTimeLastMS = 0, frameTimeBufferMS, averageFPS;
|
|
131
|
+
let frameTimeLastMS = 0, frameTimeBufferMS = 0, averageFPS;
|
|
133
132
|
|
|
134
133
|
// main update loop
|
|
135
134
|
function engineUpdate(frameTimeMS=0)
|
|
@@ -254,7 +253,7 @@ function enginePreRender()
|
|
|
254
253
|
mainCanvasSize = vec2(mainCanvas.width, mainCanvas.height);
|
|
255
254
|
|
|
256
255
|
// disable smoothing for pixel art
|
|
257
|
-
mainContext.imageSmoothingEnabled = !
|
|
256
|
+
mainContext.imageSmoothingEnabled = !canvasPixelated;
|
|
258
257
|
|
|
259
258
|
// setup gl rendering if enabled
|
|
260
259
|
glEnable && glPreRender();
|
|
@@ -268,7 +267,7 @@ function engineObjectsUpdate()
|
|
|
268
267
|
engineObjectsCollide = engineObjects.filter(o=>o.collideSolidObjects);
|
|
269
268
|
|
|
270
269
|
// recursive object update
|
|
271
|
-
|
|
270
|
+
function updateObject(o)
|
|
272
271
|
{
|
|
273
272
|
if (!o.destroyed)
|
|
274
273
|
{
|
package/src/engineAudio.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LittleJS Audio System
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
3
|
+
* - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - Sound Effect Generator
|
|
4
|
+
* - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - Music System
|
|
5
|
+
* - Caches sounds and music for fast playback
|
|
6
|
+
* - Can attenuate and apply stereo panning to sounds
|
|
7
|
+
* - Ability to play mp3, ogg, and wave files
|
|
8
|
+
* - Speech synthesis wrapper functions
|
|
9
|
+
* @namespace Audio
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
'use strict';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Sound Object - Stores a zzfx sound for later use and can be played positionally
|
|
15
|
-
*
|
|
16
|
-
* <
|
|
16
|
+
*
|
|
17
|
+
* <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
|
|
17
18
|
* @example
|
|
18
19
|
* // create a sound
|
|
19
20
|
* const sound_example = new Sound([.5,.5]);
|
|
@@ -97,8 +98,8 @@ class Sound
|
|
|
97
98
|
|
|
98
99
|
/**
|
|
99
100
|
* Music Object - Stores a zzfx music track for later use
|
|
100
|
-
*
|
|
101
|
-
* <
|
|
101
|
+
*
|
|
102
|
+
* <a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a>
|
|
102
103
|
* @example
|
|
103
104
|
* // create some music
|
|
104
105
|
* const music_example = new Music(
|
|
@@ -208,14 +209,15 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
|
|
|
208
209
|
|
|
209
210
|
/** Stop all queued speech
|
|
210
211
|
* @memberof Audio */
|
|
211
|
-
|
|
212
|
+
function speakStop() {speechSynthesis && speechSynthesis.cancel();}
|
|
212
213
|
|
|
213
214
|
/** Get frequency of a note on a musical scale
|
|
214
215
|
* @param {Number} semitoneOffset - How many semitones away from the root note
|
|
215
216
|
* @param {Number} [rootNoteFrequency=220] - Frequency at semitone offset 0
|
|
216
217
|
* @return {Number} - The frequency of the note
|
|
217
218
|
* @memberof Audio */
|
|
218
|
-
|
|
219
|
+
function getNoteFrequency(semitoneOffset, rootFrequency=220)
|
|
220
|
+
{ return rootFrequency * 2**(semitoneOffset/12); }
|
|
219
221
|
|
|
220
222
|
///////////////////////////////////////////////////////////////////////////////
|
|
221
223
|
|
|
@@ -273,12 +275,12 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
|
|
|
273
275
|
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.2.0 by Frank Force
|
|
274
276
|
|
|
275
277
|
/** Generate and play a ZzFX sound
|
|
276
|
-
*
|
|
277
|
-
* <
|
|
278
|
+
*
|
|
279
|
+
* <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
|
|
278
280
|
* @param {Array} zzfxSound - Array of ZzFX parameters, ex. [.5,.5]
|
|
279
|
-
* @return {
|
|
281
|
+
* @return {AudioBufferSourceNode} - The audio node of the sound played
|
|
280
282
|
* @memberof Audio */
|
|
281
|
-
|
|
283
|
+
function zzfx(...zzfxSound) { return playSamples([zzfxG(...zzfxSound)]); }
|
|
282
284
|
|
|
283
285
|
/** Sample rate used for all ZzFX sounds
|
|
284
286
|
* @default 44100
|
|
@@ -286,7 +288,29 @@ const zzfx = (...zzfxSound) => playSamples([zzfxG(...zzfxSound)]);
|
|
|
286
288
|
const zzfxR = 44100;
|
|
287
289
|
|
|
288
290
|
/** Generate samples for a ZzFX sound
|
|
289
|
-
* @
|
|
291
|
+
* @param {Number} [volume=1] - Volume scale (percent)
|
|
292
|
+
* @param {Number} [randomness=.05] - How much to randomize frequency (percent Hz)
|
|
293
|
+
* @param {Number} [frequency=220] - Frequency of sound (Hz)
|
|
294
|
+
* @param {Number} [attack=0] - Attack time, how fast sound starts (seconds)
|
|
295
|
+
* @param {Number} [sustain=0] - Sustain time, how long sound holds (seconds)
|
|
296
|
+
* @param {Number} [release=.1] - Release time, how fast sound fades out (seconds)
|
|
297
|
+
* @param {Number} [shape=0] - Shape of the sound wave
|
|
298
|
+
* @param {Number} [shapeCurve=1] - Squarenes of wave (0=square, 1=normal, 2=pointy)
|
|
299
|
+
* @param {Number} [slide=0] - How much to slide frequency (kHz/s)
|
|
300
|
+
* @param {Number} [deltaSlide=0] - How much to change slide (kHz/s/s)
|
|
301
|
+
* @param {Number} [pitchJump=0] - Frequency of pitch jump (Hz)
|
|
302
|
+
* @param {Number} [pitchJumpTime=0] - Time of pitch jump (seconds)
|
|
303
|
+
* @param {Number} [repeatTime=0] - Resets some parameters periodically (seconds)
|
|
304
|
+
* @param {Number} [noise=0] - How much random noise to add (percent)
|
|
305
|
+
* @param {Number} [modulation=0] - Frequency of modulation wave, negative flips phase (Hz)
|
|
306
|
+
* @param {Number} [bitCrush=0] - Resamples at a lower frequency in (samples*100)
|
|
307
|
+
* @param {Number} [delay=0] - Overlap sound with itself for reverb and flanger effects (seconds)
|
|
308
|
+
* @param {Number} [sustainVolume=1] - Volume level for sustain (percent)
|
|
309
|
+
* @param {Number} [decay=0] - Decay time, how long to reach sustain after attack (seconds)
|
|
310
|
+
* @param {Number} [tremolo=0] - Trembling effect, rate controlled by repeat time (precent)
|
|
311
|
+
* @return {Array} - Array of audio samples
|
|
312
|
+
* @memberof Audio
|
|
313
|
+
*/
|
|
290
314
|
function zzfxG
|
|
291
315
|
(
|
|
292
316
|
// parameters
|
|
@@ -376,7 +400,7 @@ function zzfxG
|
|
|
376
400
|
* @param {Array} patterns - Array of pattern data
|
|
377
401
|
* @param {Array} sequence - Array of pattern indexes
|
|
378
402
|
* @param {Number} [BPM=125] - Playback speed of the song in BPM
|
|
379
|
-
* @
|
|
403
|
+
* @return {Array} - Left and right channel sample data
|
|
380
404
|
* @memberof Audio */
|
|
381
405
|
function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
382
406
|
{
|
|
@@ -414,7 +438,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
414
438
|
patternChannel = patterns[patternIndex][channelIndex] || [0, 0, 0];
|
|
415
439
|
|
|
416
440
|
// check if there are more channels
|
|
417
|
-
hasMore
|
|
441
|
+
hasMore ||= !!patterns[patternIndex][channelIndex];
|
|
418
442
|
|
|
419
443
|
// get next offset, use the length of first channel
|
|
420
444
|
nextSampleOffset = outSampleOffset + (patterns[patternIndex][0].length - 2 - !notFirstBeat) * beatLength;
|
|
@@ -427,7 +451,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
427
451
|
|
|
428
452
|
// stop if end, different instrument or new note
|
|
429
453
|
stop = i == patternChannel.length + isSequenceEnd - 1 && isSequenceEnd ||
|
|
430
|
-
instrument != (patternChannel[0] || 0)
|
|
454
|
+
instrument != (patternChannel[0] || 0) || note;
|
|
431
455
|
|
|
432
456
|
// fill buffer with samples for previous beat, most cpu intensive part
|
|
433
457
|
for (j = 0; j < beatLength && notFirstBeat;
|
package/src/engineBuild.bat
CHANGED
|
@@ -1,132 +1,2 @@
|
|
|
1
|
-
rem
|
|
2
|
-
|
|
3
|
-
rem Run npm install first to install required dependencies
|
|
4
|
-
|
|
5
|
-
rem --- BUILD ENGINE DEBUG ---
|
|
6
|
-
|
|
7
|
-
set BUILD_FOLDER=build
|
|
8
|
-
set ENGINE_NAME=littlejs
|
|
9
|
-
|
|
10
|
-
pushd ..
|
|
11
|
-
|
|
12
|
-
rem remove old files
|
|
13
|
-
rmdir /s /q %BUILD_FOLDER%
|
|
14
|
-
mkdir %BUILD_FOLDER%
|
|
15
|
-
pushd %BUILD_FOLDER%
|
|
16
|
-
|
|
17
|
-
rem --- BUILD ENGINE ALL ---
|
|
18
|
-
|
|
19
|
-
set OUTPUT_FILENAME=%ENGINE_NAME%.js
|
|
20
|
-
|
|
21
|
-
rem combine code
|
|
22
|
-
type ..\src\engineDebug.js >> %OUTPUT_FILENAME%
|
|
23
|
-
echo.>> %OUTPUT_FILENAME%
|
|
24
|
-
type ..\src\engineUtilities.js >> %OUTPUT_FILENAME%
|
|
25
|
-
echo.>> %OUTPUT_FILENAME%
|
|
26
|
-
type ..\src\engineSettings.js >> %OUTPUT_FILENAME%
|
|
27
|
-
echo.>> %OUTPUT_FILENAME%
|
|
28
|
-
type ..\src\engineObject.js >> %OUTPUT_FILENAME%
|
|
29
|
-
echo.>> %OUTPUT_FILENAME%
|
|
30
|
-
type ..\src\engineDraw.js >> %OUTPUT_FILENAME%
|
|
31
|
-
echo.>> %OUTPUT_FILENAME%
|
|
32
|
-
type ..\src\engineInput.js >> %OUTPUT_FILENAME%
|
|
33
|
-
echo.>> %OUTPUT_FILENAME%
|
|
34
|
-
type ..\src\engineAudio.js >> %OUTPUT_FILENAME%
|
|
35
|
-
echo.>> %OUTPUT_FILENAME%
|
|
36
|
-
type ..\src\engineTileLayer.js >> %OUTPUT_FILENAME%
|
|
37
|
-
echo.>> %OUTPUT_FILENAME%
|
|
38
|
-
type ..\src\engineParticles.js >> %OUTPUT_FILENAME%
|
|
39
|
-
echo.>> %OUTPUT_FILENAME%
|
|
40
|
-
type ..\src\engineMedals.js >> %OUTPUT_FILENAME%
|
|
41
|
-
echo.>> %OUTPUT_FILENAME%
|
|
42
|
-
type ..\src\engineWebGL.js >> %OUTPUT_FILENAME%
|
|
43
|
-
echo.>> %OUTPUT_FILENAME%
|
|
44
|
-
type ..\src\engine.js >> %OUTPUT_FILENAME%
|
|
45
|
-
echo.>> %OUTPUT_FILENAME%
|
|
46
|
-
|
|
47
|
-
rem --- BUILD ENGINE RELEASE ---
|
|
48
|
-
|
|
49
|
-
set OUTPUT_FILENAME=%ENGINE_NAME%.release.js
|
|
50
|
-
|
|
51
|
-
rem combine code
|
|
52
|
-
type ..\src\engineRelease.js >> %OUTPUT_FILENAME%
|
|
53
|
-
echo.>> %OUTPUT_FILENAME%
|
|
54
|
-
type ..\src\engineUtilities.js >> %OUTPUT_FILENAME%
|
|
55
|
-
echo.>> %OUTPUT_FILENAME%
|
|
56
|
-
type ..\src\engineSettings.js >> %OUTPUT_FILENAME%
|
|
57
|
-
echo.>> %OUTPUT_FILENAME%
|
|
58
|
-
type ..\src\engine.js >> %OUTPUT_FILENAME%
|
|
59
|
-
echo.>> %OUTPUT_FILENAME%
|
|
60
|
-
type ..\src\engineObject.js >> %OUTPUT_FILENAME%
|
|
61
|
-
echo.>> %OUTPUT_FILENAME%
|
|
62
|
-
type ..\src\engineDraw.js >> %OUTPUT_FILENAME%
|
|
63
|
-
echo.>> %OUTPUT_FILENAME%
|
|
64
|
-
type ..\src\engineInput.js >> %OUTPUT_FILENAME%
|
|
65
|
-
echo.>> %OUTPUT_FILENAME%
|
|
66
|
-
type ..\src\engineAudio.js >> %OUTPUT_FILENAME%
|
|
67
|
-
echo.>> %OUTPUT_FILENAME%
|
|
68
|
-
type ..\src\engineTileLayer.js >> %OUTPUT_FILENAME%
|
|
69
|
-
echo.>> %OUTPUT_FILENAME%
|
|
70
|
-
type ..\src\engineParticles.js >> %OUTPUT_FILENAME%
|
|
71
|
-
echo.>> %OUTPUT_FILENAME%
|
|
72
|
-
type ..\src\engineMedals.js >> %OUTPUT_FILENAME%
|
|
73
|
-
echo.>> %OUTPUT_FILENAME%
|
|
74
|
-
type ..\src\engineWebGL.js >> %OUTPUT_FILENAME%
|
|
75
|
-
echo.>> %OUTPUT_FILENAME%
|
|
76
|
-
|
|
77
|
-
rem --- BUILD ENGINE MINIFIED ---
|
|
78
|
-
|
|
79
|
-
set OUTPUT_FILENAME=%ENGINE_NAME%.min.js
|
|
80
|
-
|
|
81
|
-
rem start with release build
|
|
82
|
-
copy %ENGINE_NAME%.release.js %OUTPUT_FILENAME%
|
|
83
|
-
|
|
84
|
-
rem check code with closure
|
|
85
|
-
move %OUTPUT_FILENAME% %OUTPUT_FILENAME%.temp
|
|
86
|
-
call npx google-closure-compiler --js=%OUTPUT_FILENAME%.temp --js_output_file=%OUTPUT_FILENAME% --language_out=ECMASCRIPT_2021 --warning_level=VERBOSE --jscomp_off=*
|
|
87
|
-
del %OUTPUT_FILENAME%.temp
|
|
88
|
-
if %ERRORLEVEL% NEQ 0 (
|
|
89
|
-
pause
|
|
90
|
-
exit /b %ERRORLEVEL%
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
rem lightly minify with uglify
|
|
94
|
-
call npx uglifyjs -o %OUTPUT_FILENAME% -- %OUTPUT_FILENAME%
|
|
95
|
-
if %ERRORLEVEL% NEQ 0 (
|
|
96
|
-
pause
|
|
97
|
-
exit /b %ERRORLEVEL%
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
rem --- BUILD ENGINE ESM MODULE ---
|
|
101
|
-
|
|
102
|
-
set OUTPUT_FILENAME=%ENGINE_NAME%.esm.js
|
|
103
|
-
type %ENGINE_NAME%.js >> %OUTPUT_FILENAME%
|
|
104
|
-
echo.>> %OUTPUT_FILENAME%
|
|
105
|
-
type ..\src\engineExport.js >> %OUTPUT_FILENAME%
|
|
106
|
-
echo.>> %OUTPUT_FILENAME%
|
|
107
|
-
|
|
108
|
-
rem --- BUILD ENGINE ESM MODULE RELEASE ---
|
|
109
|
-
|
|
110
|
-
set OUTPUT_FILENAME=%ENGINE_NAME%.esm.min.js
|
|
111
|
-
type %ENGINE_NAME%.min.js >> %OUTPUT_FILENAME%
|
|
112
|
-
echo.>> %OUTPUT_FILENAME%
|
|
113
|
-
type ..\src\engineExport.js >> %OUTPUT_FILENAME%
|
|
114
|
-
echo.>> %OUTPUT_FILENAME%
|
|
115
|
-
|
|
116
|
-
rem lightly minify with uglify
|
|
117
|
-
call npx uglifyjs -o %OUTPUT_FILENAME% -- %OUTPUT_FILENAME%
|
|
118
|
-
if %ERRORLEVEL% NEQ 0 (
|
|
119
|
-
pause
|
|
120
|
-
exit /b %ERRORLEVEL%
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
rem --- BUILD TYPESCRIPT DEFINITIONS ---
|
|
124
|
-
|
|
125
|
-
call npx tsc %ENGINE_NAME%.esm.js --declaration --allowJs --emitDeclarationOnly --outFile %ENGINE_NAME%.d.ts
|
|
126
|
-
if %ERRORLEVEL% NEQ 0 (
|
|
127
|
-
pause
|
|
128
|
-
exit /b %ERRORLEVEL%
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
popd
|
|
132
|
-
popd
|
|
1
|
+
rem LittleJS Build Script
|
|
2
|
+
call npm run build
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LittleJS Build System
|
|
5
|
+
* - Combine input files
|
|
6
|
+
* - Run custom build steps
|
|
7
|
+
* - Check for errors
|
|
8
|
+
* - Output to build folder
|
|
9
|
+
* @namespace Build
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const ENGINE_NAME = 'littlejs';
|
|
13
|
+
const BUILD_FOLDER = 'build';
|
|
14
|
+
const SOURCE_FOLDER = 'src';
|
|
15
|
+
const engineSourceFiles =
|
|
16
|
+
[
|
|
17
|
+
`${SOURCE_FOLDER}/engineUtilities.js`,
|
|
18
|
+
`${SOURCE_FOLDER}/engineSettings.js`,
|
|
19
|
+
`${SOURCE_FOLDER}/engineObject.js`,
|
|
20
|
+
`${SOURCE_FOLDER}/engineDraw.js`,
|
|
21
|
+
`${SOURCE_FOLDER}/engineInput.js`,
|
|
22
|
+
`${SOURCE_FOLDER}/engineAudio.js`,
|
|
23
|
+
`${SOURCE_FOLDER}/engineTileLayer.js`,
|
|
24
|
+
`${SOURCE_FOLDER}/engineParticles.js`,
|
|
25
|
+
`${SOURCE_FOLDER}/engineMedals.js`,
|
|
26
|
+
`${SOURCE_FOLDER}/engineWebGL.js`,
|
|
27
|
+
`${SOURCE_FOLDER}/engine.js`,
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
console.log('Choo Choo... Building LittleJS Engine!');
|
|
31
|
+
const startTime = Date.now();
|
|
32
|
+
const fs = require('node:fs');
|
|
33
|
+
const child_process = require('node:child_process');
|
|
34
|
+
|
|
35
|
+
try
|
|
36
|
+
{
|
|
37
|
+
// Setup build folder
|
|
38
|
+
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
39
|
+
fs.mkdirSync(BUILD_FOLDER);
|
|
40
|
+
}
|
|
41
|
+
catch (e) { handleError(e, 'Failed to create build folder!'); }
|
|
42
|
+
|
|
43
|
+
Build
|
|
44
|
+
(
|
|
45
|
+
'Build Engine -- all',
|
|
46
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.js`,
|
|
47
|
+
[`${SOURCE_FOLDER}/engineDebug.js`].concat(engineSourceFiles)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
Build
|
|
51
|
+
(
|
|
52
|
+
'Build Engine -- release',
|
|
53
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
|
|
54
|
+
[`${SOURCE_FOLDER}/engineRelease.js`].concat(engineSourceFiles)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
Build
|
|
58
|
+
(
|
|
59
|
+
'Build Engine -- minified',
|
|
60
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.min.js`,
|
|
61
|
+
[`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`],
|
|
62
|
+
[closureCompilerStep, uglifyBuildStep]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
Build
|
|
66
|
+
(
|
|
67
|
+
'Build Engine -- ESM',
|
|
68
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.esm.js`,
|
|
69
|
+
[`${BUILD_FOLDER}/${ENGINE_NAME}.js`, `${SOURCE_FOLDER}/engineExport.js`],
|
|
70
|
+
[typeScriptBuildStep]
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
Build
|
|
74
|
+
(
|
|
75
|
+
'Build Engine -- ESM minified release',
|
|
76
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.esm.min.js`,
|
|
77
|
+
[`${BUILD_FOLDER}/${ENGINE_NAME}.min.js`, `${SOURCE_FOLDER}/engineExport.js`],
|
|
78
|
+
[uglifyBuildStep]
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
console.log(`Engine built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|
|
82
|
+
|
|
83
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
84
|
+
|
|
85
|
+
// A single build with its own source files, build steps, and output file
|
|
86
|
+
// - each build step is a callback that accepts a single filename
|
|
87
|
+
function Build(message, outputFile, files=[], buildSteps=[])
|
|
88
|
+
{
|
|
89
|
+
console.log(message);
|
|
90
|
+
|
|
91
|
+
// copy files into a buffer
|
|
92
|
+
let buffer = '';
|
|
93
|
+
for (const file of files)
|
|
94
|
+
buffer += fs.readFileSync(file) + '\n';
|
|
95
|
+
|
|
96
|
+
// output file
|
|
97
|
+
fs.writeFileSync(outputFile, buffer, {flag: 'w+'});
|
|
98
|
+
|
|
99
|
+
// execute build steps in order
|
|
100
|
+
for (const buildStep of buildSteps)
|
|
101
|
+
buildStep(outputFile);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Process with Closure Compiler to minify and check for errors
|
|
105
|
+
function closureCompilerStep(filename)
|
|
106
|
+
{
|
|
107
|
+
const filenameTemp = filename + '.tmp';
|
|
108
|
+
fs.copyFileSync(filename, filenameTemp);
|
|
109
|
+
try
|
|
110
|
+
{
|
|
111
|
+
child_process.execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --language_out=ECMASCRIPT_2021 --warning_level=VERBOSE --jscomp_off=*`);
|
|
112
|
+
fs.rmSync(filenameTemp);
|
|
113
|
+
}
|
|
114
|
+
catch (e) { handleError(e, 'Failed to run Closure Compiler step!'); }
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Process with Uglify to minify
|
|
118
|
+
function uglifyBuildStep(filename)
|
|
119
|
+
{
|
|
120
|
+
try
|
|
121
|
+
{
|
|
122
|
+
child_process.execSync(`npx uglifyjs ${filename} -o ${filename}`);
|
|
123
|
+
}
|
|
124
|
+
catch (e) { handleError(e,'Failed to run Uglify minification step!'); }
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// Build TypeScript definitions
|
|
128
|
+
function typeScriptBuildStep(filename)
|
|
129
|
+
{
|
|
130
|
+
try
|
|
131
|
+
{
|
|
132
|
+
child_process.execSync(`npx tsc ${filename} --declaration --allowJs --emitDeclarationOnly --outFile ${BUILD_FOLDER}/${ENGINE_NAME}.d.ts`);
|
|
133
|
+
}
|
|
134
|
+
catch (e) { handleError(e, 'Failed to run TypeScript build step!'); }
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// display the error and exit
|
|
138
|
+
function handleError(e,message)
|
|
139
|
+
{
|
|
140
|
+
console.error(e);
|
|
141
|
+
console.error(message);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|