littlejsengine 1.6.6 → 1.7.1
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 +76 -53
- package/build/littlejs.d.ts +154 -136
- package/build/littlejs.esm.js +461 -305
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +452 -291
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +2317 -2168
- 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/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 +12 -12
- package/examples/platformer/gamePlayer.js +2 -2
- package/examples/platformer/index.html +8 -8
- package/examples/puzzle/game.js +5 -3
- 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 +5 -7
- 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 +2 -2
- package/src/engine.js +3 -3
- package/src/engineAudio.js +44 -16
- package/src/engineBuild.bat +2 -132
- package/src/engineBuild.js +156 -0
- package/src/engineDebug.js +25 -15
- package/src/engineDraw.js +62 -53
- package/src/engineExport.js +7 -12
- package/src/engineInput.js +27 -35
- package/src/engineObject.js +15 -13
- package/src/engineParticles.js +6 -6
- package/src/engineRelease.js +1 -3
- package/src/engineSettings.js +1 -0
- package/src/engineTileLayer.js +31 -18
- package/src/engineUtilities.js +161 -93
- package/src/engineWebGL.js +63 -27
- package/examples/electron/build.bat +0 -52
|
@@ -1,89 +1,94 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
//
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
LittleJS.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
83
|
-
function
|
|
84
|
-
// draw
|
|
85
|
-
LittleJS.
|
|
86
|
-
}
|
|
87
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
/*
|
|
2
|
+
Little TypeScript Demo
|
|
3
|
+
- A simple starter project
|
|
4
|
+
- Builds to a JavaScript file from TypeScript
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
// import module
|
|
8
|
+
import * as LittleJS from '../../build/littlejs.esm.js';
|
|
9
|
+
const { Vector2, Color, Timer, vec2 } = LittleJS;
|
|
10
|
+
// sound effects
|
|
11
|
+
const sound_click = new LittleJS.Sound([1, .5]);
|
|
12
|
+
// medals
|
|
13
|
+
const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
14
|
+
LittleJS.medalsInit('Hello World');
|
|
15
|
+
// game variables
|
|
16
|
+
let particleEmitter;
|
|
17
|
+
let gameTimer = new Timer;
|
|
18
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
19
|
+
function gameInit() {
|
|
20
|
+
// create tile collision and visible tile layer
|
|
21
|
+
LittleJS.initTileCollision(vec2(32, 16));
|
|
22
|
+
const pos = new Vector2;
|
|
23
|
+
const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
|
|
24
|
+
// get level data from the tiles image
|
|
25
|
+
const imageLevelDataRow = 1;
|
|
26
|
+
const mainContext = LittleJS.mainContext;
|
|
27
|
+
mainContext.drawImage(LittleJS.tileImage, 0, 0);
|
|
28
|
+
for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
|
|
29
|
+
for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;) {
|
|
30
|
+
const imageData = mainContext.getImageData(pos.x, 16 * (imageLevelDataRow + 1) - pos.y - 1, 1, 1).data;
|
|
31
|
+
if (imageData[0]) {
|
|
32
|
+
const tileIndex = 1;
|
|
33
|
+
const direction = LittleJS.randInt(4);
|
|
34
|
+
const mirror = LittleJS.randInt(2) ? true : false;
|
|
35
|
+
const color = LittleJS.randColor();
|
|
36
|
+
const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
37
|
+
tileLayer.setData(pos, data);
|
|
38
|
+
LittleJS.setTileCollisionData(pos, 1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
tileLayer.redraw();
|
|
42
|
+
// move camera to center of collision
|
|
43
|
+
LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
|
|
44
|
+
// enable gravity
|
|
45
|
+
LittleJS.setGravity(-.01);
|
|
46
|
+
// create particle emitter
|
|
47
|
+
const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0, 9));
|
|
48
|
+
particleEmitter = new LittleJS.ParticleEmitter(center, 0, // emitPos, emitAngle
|
|
49
|
+
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
|
|
50
|
+
0, vec2(16), // tileIndex, tileSize
|
|
51
|
+
new Color(1, 1, 1), new Color(0, 0, 0), // colorStartA, colorStartB
|
|
52
|
+
new Color(1, 1, 1, 0), new Color(0, 0, 0, 0), // colorEndA, colorEndB
|
|
53
|
+
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
54
|
+
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
55
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
56
|
+
);
|
|
57
|
+
particleEmitter.elasticity = .3; // bounce when it collides
|
|
58
|
+
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
59
|
+
// start the game timer
|
|
60
|
+
gameTimer.set();
|
|
61
|
+
}
|
|
62
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
63
|
+
function gameUpdate() {
|
|
64
|
+
if (LittleJS.mouseWasPressed(0)) {
|
|
65
|
+
// play sound when mouse is pressed
|
|
66
|
+
sound_click.play(LittleJS.mousePos);
|
|
67
|
+
// change particle color and set to fade out
|
|
68
|
+
particleEmitter.colorStartA = new Color;
|
|
69
|
+
particleEmitter.colorStartB = LittleJS.randColor();
|
|
70
|
+
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
|
|
71
|
+
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
|
|
72
|
+
// unlock medals
|
|
73
|
+
medal_example.unlock();
|
|
74
|
+
}
|
|
75
|
+
// move particles to mouse location if on screen
|
|
76
|
+
if (LittleJS.mousePosScreen.x)
|
|
77
|
+
particleEmitter.pos = LittleJS.mousePos;
|
|
78
|
+
}
|
|
79
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
80
|
+
function gameUpdatePost() {
|
|
81
|
+
}
|
|
82
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
83
|
+
function gameRender() {
|
|
84
|
+
// draw a grey square in the background without using webgl
|
|
85
|
+
LittleJS.drawRect(LittleJS.cameraPos, LittleJS.tileCollisionSize.add(vec2(5)), new Color(.2, .2, .2), 0, false);
|
|
86
|
+
}
|
|
87
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
88
|
+
function gameRenderPost() {
|
|
89
|
+
// draw to overlay canvas for hud rendering
|
|
90
|
+
LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
|
|
91
|
+
}
|
|
92
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
93
|
+
// Startup LittleJS Engine
|
|
94
|
+
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
|
|
@@ -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?1701 type=module></script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "littlejsengine",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.01",
|
|
4
4
|
"description": "LittleJS - Tiny and Fast HTML5 Game Engine",
|
|
5
5
|
"main": "build/littlejs.esm.js",
|
|
6
6
|
"repository": {
|
|
@@ -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
|
@@ -30,7 +30,7 @@ const engineName = 'LittleJS';
|
|
|
30
30
|
* @type {String}
|
|
31
31
|
* @default
|
|
32
32
|
* @memberof Engine */
|
|
33
|
-
const engineVersion = '1.
|
|
33
|
+
const engineVersion = '1.7.01';
|
|
34
34
|
|
|
35
35
|
/** Frames per second to update objects
|
|
36
36
|
* @type {Number}
|
|
@@ -120,7 +120,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
120
120
|
// set canvas style
|
|
121
121
|
const styleCanvas = 'position:absolute;' +
|
|
122
122
|
'top:50%;left:50%;transform:translate(-50%,-50%);' + // center the canvas
|
|
123
|
-
(canvasPixelated?'image-rendering:pixelated':'');
|
|
123
|
+
(canvasPixelated?'image-rendering:pixelated':''); // set pixelated rendering
|
|
124
124
|
(glCanvas||mainCanvas).style = mainCanvas.style = overlayCanvas.style = styleCanvas;
|
|
125
125
|
|
|
126
126
|
gameInit();
|
|
@@ -128,7 +128,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
128
128
|
};
|
|
129
129
|
|
|
130
130
|
// frame time tracking
|
|
131
|
-
let frameTimeLastMS = 0, frameTimeBufferMS, averageFPS;
|
|
131
|
+
let frameTimeLastMS = 0, frameTimeBufferMS = 0, averageFPS = 0;
|
|
132
132
|
|
|
133
133
|
// main update loop
|
|
134
134
|
function engineUpdate(frameTimeMS=0)
|
package/src/engineAudio.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LittleJS Audio System
|
|
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
|
|
3
|
+
* - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
|
|
4
|
+
* - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
|
|
5
5
|
* - Caches sounds and music for fast playback
|
|
6
6
|
* - Can attenuate and apply stereo panning to sounds
|
|
7
7
|
* - Ability to play mp3, ogg, and wave files
|
|
8
|
-
* - Speech synthesis
|
|
8
|
+
* - Speech synthesis functions
|
|
9
9
|
* @namespace Audio
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -39,12 +39,15 @@ class Sound
|
|
|
39
39
|
/** @property {Number} - At what percentage of range should it start tapering off */
|
|
40
40
|
this.taper = taper;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
this.randomness =
|
|
44
|
-
zzfxSound[1] = 0;
|
|
42
|
+
/** @property {Number} - How much to randomize frequency each time sound plays */
|
|
43
|
+
this.randomness = 0;
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (zzfxSound)
|
|
46
|
+
{
|
|
47
|
+
// generate zzfx sound now for fast playback
|
|
48
|
+
this.randomness = zzfxSound[1] || (zzfxSound[1] = 0);
|
|
49
|
+
this.cachedSamples = zzfxSound && zzfxG(...zzfxSound);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
/** Play the sound
|
|
@@ -56,7 +59,7 @@ class Sound
|
|
|
56
59
|
*/
|
|
57
60
|
play(pos, volume=1, pitch=1, randomnessScale=1)
|
|
58
61
|
{
|
|
59
|
-
if (!soundEnable) return;
|
|
62
|
+
if (!soundEnable || !this.cachedSamples) return;
|
|
60
63
|
|
|
61
64
|
let pan;
|
|
62
65
|
if (pos)
|
|
@@ -89,12 +92,36 @@ class Sound
|
|
|
89
92
|
* @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
|
|
90
93
|
*/
|
|
91
94
|
playNote(semitoneOffset, pos, volume)
|
|
95
|
+
{ return this.play(pos, volume, 2**(semitoneOffset/12), 0); }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Sound Wave Object - Stores a wave sound for later use and can be played positionally
|
|
100
|
+
*/
|
|
101
|
+
class SoundWave extends Sound
|
|
102
|
+
{
|
|
103
|
+
/** Create a sound object and cache the wave file for later use
|
|
104
|
+
* @param {String} waveFilename - Filename of wave file to load
|
|
105
|
+
* @param {Number} [randomness=.05] - How much to randomize frequency each time sound plays
|
|
106
|
+
* @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
|
|
107
|
+
* @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
|
|
108
|
+
*/
|
|
109
|
+
constructor(waveFilename, randomness=.05, range, taper)
|
|
92
110
|
{
|
|
111
|
+
super(0, range, taper);
|
|
112
|
+
this.randomness = randomness;
|
|
113
|
+
|
|
93
114
|
if (!soundEnable) return;
|
|
115
|
+
if (!soundWaveDecoderContext)
|
|
116
|
+
soundDecoderContext = new AudioContext;
|
|
94
117
|
|
|
95
|
-
|
|
118
|
+
fetch(waveFilename)
|
|
119
|
+
.then(response => response.arrayBuffer())
|
|
120
|
+
.then(arrayBuffer => soundWaveDecoderContext.decodeAudioData(arrayBuffer))
|
|
121
|
+
.then(audioBuffer => this.cachedSamples = audioBuffer.getChannelData(0));
|
|
96
122
|
}
|
|
97
123
|
}
|
|
124
|
+
let soundDecoderContext; // audio context used only to decode audio files
|
|
98
125
|
|
|
99
126
|
/**
|
|
100
127
|
* Music Object - Stores a zzfx music track for later use
|
|
@@ -237,16 +264,17 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
|
|
|
237
264
|
{
|
|
238
265
|
if (!soundEnable) return;
|
|
239
266
|
|
|
240
|
-
// create audio context
|
|
267
|
+
// create audio context if needed
|
|
241
268
|
if (!audioContext)
|
|
242
269
|
audioContext = new AudioContext;
|
|
243
270
|
|
|
244
|
-
// fix stalled audio
|
|
245
|
-
audioContext.resume();
|
|
246
|
-
|
|
247
271
|
// prevent sounds from building up if they can't be played
|
|
248
272
|
if (audioContext.state != 'running')
|
|
273
|
+
{
|
|
274
|
+
// fix stalled audio
|
|
275
|
+
audioContext.resume();
|
|
249
276
|
return;
|
|
277
|
+
}
|
|
250
278
|
|
|
251
279
|
// create buffer and source
|
|
252
280
|
const buffer = audioContext.createBuffer(sampleChannels.length, sampleChannels[0].length, zzfxR),
|
|
@@ -438,7 +466,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
438
466
|
patternChannel = patterns[patternIndex][channelIndex] || [0, 0, 0];
|
|
439
467
|
|
|
440
468
|
// check if there are more channels
|
|
441
|
-
hasMore
|
|
469
|
+
hasMore ||= !!patterns[patternIndex][channelIndex];
|
|
442
470
|
|
|
443
471
|
// get next offset, use the length of first channel
|
|
444
472
|
nextSampleOffset = outSampleOffset + (patterns[patternIndex][0].length - 2 - !notFirstBeat) * beatLength;
|
|
@@ -451,7 +479,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
451
479
|
|
|
452
480
|
// stop if end, different instrument or new note
|
|
453
481
|
stop = i == patternChannel.length + isSequenceEnd - 1 && isSequenceEnd ||
|
|
454
|
-
instrument != (patternChannel[0] || 0)
|
|
482
|
+
instrument != (patternChannel[0] || 0) || note | 0;
|
|
455
483
|
|
|
456
484
|
// fill buffer with samples for previous beat, most cpu intensive part
|
|
457
485
|
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
|