Skip to content

Commit 8ffd3e3

Browse files
committed
update engine
1 parent 9b32cac commit 8ffd3e3

File tree

2 files changed

+71
-64
lines changed

2 files changed

+71
-64
lines changed

public/js/litecanvas.js

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var assert = (condition, message = "Assertion failed") => {
2828
if (!condition) throw new Error(message);
2929
};
30-
var version = "0.98.4";
30+
var version = "0.99.0";
3131
function litecanvas(settings = {}) {
3232
const root = window, math = Math, TWO_PI = math.PI * 2, raf = requestAnimationFrame, _browserEventListeners = [], on = (elem, evt, callback) => {
3333
elem.addEventListener(evt, callback, false);
@@ -43,7 +43,7 @@
4343
keyboardEvents: true
4444
};
4545
settings = Object.assign(defaults, settings);
46-
let _initialized = false, _canvas, _scale = 1, _ctx, _outline_fix = 0.5, _timeScale = 1, _lastFrameTime, _fpsInterval = 1e3 / 60, _accumulated, _rafid, _fontFamily = "sans-serif", _fontSize = 20, _rngSeed = Date.now(), _colorPalette = defaultPalette, _colorPaletteState = [], _defaultSound = [0.5, 0, 1750, , , 0.3, 1, , , , 600, 0.1], _coreEvents = "init,update,draw,tap,untap,tapping,tapped,resized", _mathFunctions = "PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,trunc,min,max,pow,sqrt,sign,exp", _eventListeners = {};
46+
let _initialized = false, _paused = true, _canvas, _scale = 1, _ctx, _outline_fix = 0.5, _timeScale = 1, _lastFrameTime, _fpsInterval = 1e3 / 60, _accumulated, _rafid, _fontFamily = "sans-serif", _fontSize = 20, _rngSeed = Date.now(), _colorPalette = defaultPalette, _colorPaletteState = [], _defaultSound = [0.5, 0, 1750, , , 0.3, 1, , , , 600, 0.1], _coreEvents = "init,update,draw,tap,untap,tapping,tapped,resized", _mathFunctions = "PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,trunc,min,max,pow,sqrt,sign,exp", _eventListeners = {};
4747
const instance = {
4848
/** @type {number} */
4949
W: 0,
@@ -988,7 +988,7 @@
988988
_fpsInterval = 1e3 / ~~value;
989989
},
990990
/**
991-
* Returns information about that engine instance.
991+
* Returns information about the engine instance.
992992
*
993993
* @param {number|string} index
994994
* @returns {any}
@@ -1021,43 +1021,32 @@
10211021
_rngSeed,
10221022
// 10
10231023
_fontSize,
1024-
// 11
1025-
_fontFamily
1024+
// 11
1025+
_fontFamily,
1026+
// 12
1027+
_colorPaletteState
10261028
];
10271029
const data = { index, value: internals[index] };
10281030
instance.emit("stat", data);
10291031
return data.value;
10301032
},
1031-
/**
1032-
* Stops the litecanvas instance and remove all event listeners.
1033-
*/
1034-
quit() {
1035-
instance.pause();
1036-
instance.emit("quit");
1037-
_eventListeners = {};
1038-
for (const removeListener of _browserEventListeners) {
1039-
removeListener();
1040-
}
1041-
if (settings.global) {
1042-
for (const key in instance) {
1043-
delete root[key];
1044-
}
1045-
delete root.ENGINE;
1046-
}
1047-
_initialized = false;
1048-
},
10491033
/**
10501034
* Pauses the engine loop (update & draw).
10511035
*/
10521036
pause() {
1037+
_paused = true;
10531038
cancelAnimationFrame(_rafid);
1054-
_rafid = 0;
10551039
},
10561040
/**
10571041
* Resumes (if paused) the engine loop.
10581042
*/
10591043
resume() {
1060-
if (_initialized && !_rafid) {
1044+
DEV: assert(
1045+
_initialized,
1046+
'[litecanvas] resume() cannot be called before the "init" event and neither after the quit() function'
1047+
);
1048+
if (_initialized && _paused) {
1049+
_paused = false;
10611050
_accumulated = _fpsInterval;
10621051
_lastFrameTime = Date.now();
10631052
_rafid = raf(drawFrame);
@@ -1069,7 +1058,26 @@
10691058
* @returns {boolean}
10701059
*/
10711060
paused() {
1072-
return !_rafid;
1061+
return _paused;
1062+
},
1063+
/**
1064+
* Shutdown the litecanvas instance and remove all event listeners.
1065+
*/
1066+
quit() {
1067+
instance.emit("quit");
1068+
instance.pause();
1069+
_initialized = false;
1070+
_eventListeners = {};
1071+
for (const removeListener of _browserEventListeners) {
1072+
removeListener();
1073+
}
1074+
if (settings.global) {
1075+
for (const key in instance) {
1076+
delete root[key];
1077+
}
1078+
delete root.ENGINE;
1079+
}
1080+
DEV: console.warn("[litecanvas] quit() terminated a Litecanvas instance.");
10731081
}
10741082
};
10751083
for (const k of _mathFunctions.split(",")) {
@@ -1421,7 +1429,7 @@
14211429
if ("loading" === document.readyState) {
14221430
on(root, "DOMContentLoaded", () => raf(init));
14231431
} else {
1424-
raf(init);
1432+
_rafid = raf(init);
14251433
}
14261434
return instance;
14271435
}
@@ -2245,55 +2253,54 @@
22452253
window.pluginFrameRateMeter = E;
22462254
})();
22472255
(() => {
2248-
var C = [[24, 60, 60, 24, 24, , 24], [54, 54, , , , , ,], [54, 54, 127, 54, 127, 54, 54], [12, 62, 3, 30, 48, 31, 12], [, 99, 51, 24, 12, 102, 99], [28, 54, 28, 110, 59, 51, 110], [6, 6, 3, , , , ,], [24, 12, 6, 6, 6, 12, 24], [6, 12, 24, 24, 24, 12, 6], [, 102, 60, 255, 60, 102, ,], [, 12, 12, 63, 12, 12, ,], [, , , , , 12, 12, 6], [, , , 63, , , ,], [, , , , , 12, 12], [96, 48, 24, 12, 6, 3, 1], [62, 99, 115, 123, 111, 103, 62], [12, 14, 12, 12, 12, 12, 63], [30, 51, 48, 28, 6, 51, 63], [30, 51, 48, 28, 48, 51, 30], [56, 60, 54, 51, 127, 48, 120], [63, 3, 31, 48, 48, 51, 30], [28, 6, 3, 31, 51, 51, 30], [63, 51, 48, 24, 12, 12, 12], [30, 51, 51, 30, 51, 51, 30], [30, 51, 51, 62, 48, 24, 14], [, 12, 12, , , 12, 12], [, 12, 12, , , 12, 12, 6], [24, 12, 6, 3, 6, 12, 24], [, , 63, , , 63, ,], [6, 12, 24, 48, 24, 12, 6], [30, 51, 48, 24, 12, , 12], [62, 99, 123, 123, 123, 3, 30], [12, 30, 51, 51, 63, 51, 51], [63, 102, 102, 62, 102, 102, 63], [60, 102, 3, 3, 3, 102, 60], [31, 54, 102, 102, 102, 54, 31], [127, 70, 22, 30, 22, 70, 127], [127, 70, 22, 30, 22, 6, 15], [60, 102, 3, 3, 115, 102, 124], [51, 51, 51, 63, 51, 51, 51], [30, 12, 12, 12, 12, 12, 30], [120, 48, 48, 48, 51, 51, 30], [103, 102, 54, 30, 54, 102, 103], [15, 6, 6, 6, 70, 102, 127], [99, 119, 127, 127, 107, 99, 99], [99, 103, 111, 123, 115, 99, 99], [28, 54, 99, 99, 99, 54, 28], [63, 102, 102, 62, 6, 6, 15], [30, 51, 51, 51, 59, 30, 56], [63, 102, 102, 62, 54, 102, 103], [30, 51, 7, 14, 56, 51, 30], [63, 45, 12, 12, 12, 12, 30], [51, 51, 51, 51, 51, 51, 63], [51, 51, 51, 51, 51, 30, 12], [99, 99, 99, 107, 127, 119, 99], [99, 99, 54, 28, 28, 54, 99], [51, 51, 51, 30, 12, 12, 30], [127, 99, 49, 24, 76, 102, 127], [30, 6, 6, 6, 6, 6, 30], [3, 6, 12, 24, 48, 96, 64], [30, 24, 24, 24, 24, 24, 30], [8, 28, 54, 99, , , ,], [, , , , , , , 255], [12, 12, 24, , , , ,], [, , 30, 48, 62, 51, 110], [7, 6, 6, 62, 102, 102, 59], [, , 30, 51, 3, 51, 30], [56, 48, 48, 62, 51, 51, 110], [, , 30, 51, 63, 3, 30], [28, 54, 6, 15, 6, 6, 15], [, , 110, 51, 51, 62, 48, 31], [7, 6, 54, 110, 102, 102, 103], [12, , 14, 12, 12, 12, 30], [48, , 48, 48, 48, 51, 51, 30], [7, 6, 102, 54, 30, 54, 103], [14, 12, 12, 12, 12, 12, 30], [, , 51, 127, 127, 107, 99], [, , 31, 51, 51, 51, 51], [, , 30, 51, 51, 51, 30], [, , 59, 102, 102, 62, 6, 15], [, , 110, 51, 51, 62, 48, 120], [, , 59, 110, 102, 6, 15], [, , 62, 3, 30, 48, 31], [8, 12, 62, 12, 12, 44, 24], [, , 51, 51, 51, 51, 110], [, , 51, 51, 51, 30, 12], [, , 99, 107, 127, 127, 54], [, , 99, 54, 28, 54, 99], [, , 51, 51, 51, 62, 48, 31], [, , 63, 25, 12, 38, 63], [56, 12, 12, 7, 12, 12, 56], [24, 24, 24, , 24, 24, 24], [7, 12, 12, 56, 12, 12, 7], [110, 59, , , , , ,]], F = (e, s, p = 3) => {
2249-
for (let t = 0; t < 8; t++) for (let c = 0; c < 8; c++) (s[t] | 0) & 1 << c && e.rectfill(c, t, 1, 1, p);
2250-
}, h = { id: "basic", chars: C, first: 33, w: 8, h: 8, render: F };
2251-
var S = [[34, 32, 32], [85, 0, 0], [87, 87, 80], [99, 103, 32], [84, 33, 80], [99, 101, 96], [34, 0, 0], [33, 17, 32], [36, 68, 32], [82, 80, 0], [2, 114, 0], [0, 0, 33], [0, 112, 0], [0, 0, 16], [68, 33, 16], [117, 85, 112], [50, 34, 112], [116, 113, 112], [116, 116, 112], [85, 116, 64], [113, 116, 112], [113, 117, 112], [116, 68, 64], [117, 117, 112], [117, 116, 112], [0, 32, 32], [0, 32, 33], [66, 18, 64], [7, 7, 0], [18, 66, 16], [116, 96, 32], [37, 81, 96], [37, 117, 80], [53, 53, 48], [97, 17, 96], [53, 85, 48], [113, 49, 112], [113, 49, 16], [97, 85, 96], [85, 117, 80], [114, 34, 112], [68, 69, 32], [85, 53, 80], [17, 17, 112], [87, 117, 80], [117, 85, 80], [37, 85, 32], [117, 113, 16], [101, 83, 96], [53, 53, 80], [97, 116, 48], [114, 34, 32], [85, 85, 112], [85, 82, 32], [85, 119, 80], [85, 37, 80], [85, 34, 32], [116, 33, 112], [98, 34, 96], [17, 36, 64], [50, 34, 48], [37, 0, 0], [0, 0, 112], [18, 0, 0], [6, 85, 96], [19, 85, 48], [6, 17, 96], [70, 85, 96], [2, 83, 96], [66, 114, 32], [2, 86, 66], [17, 53, 80], [2, 2, 32], [2, 2, 33], [21, 53, 80], [34, 34, 64], [5, 117, 80], [3, 85, 80], [2, 85, 32], [3, 85, 49], [6, 85, 100], [2, 81, 16], [6, 20, 48], [39, 34, 64], [5, 85, 96], [5, 82, 32], [5, 87, 80], [5, 34, 80], [5, 86, 66], [7, 65, 112], [98, 18, 96], [34, 34, 32], [50, 66, 48], [3, 96, 0]], P = (e, s, p = 3) => {
2256+
var C = [[24, 60, 60, 24, 24, , 24], [54, 54, , , , , ,], [54, 54, 127, 54, 127, 54, 54], [12, 62, 3, 30, 48, 31, 12], [, 99, 51, 24, 12, 102, 99], [28, 54, 28, 110, 59, 51, 110], [6, 6, 3, , , , ,], [24, 12, 6, 6, 6, 12, 24], [6, 12, 24, 24, 24, 12, 6], [, 102, 60, 255, 60, 102, ,], [, 12, 12, 63, 12, 12, ,], [, , , , , 12, 12, 6], [, , , 63, , , ,], [, , , , , 12, 12], [96, 48, 24, 12, 6, 3, 1], [62, 99, 115, 123, 111, 103, 62], [12, 14, 12, 12, 12, 12, 63], [30, 51, 48, 28, 6, 51, 63], [30, 51, 48, 28, 48, 51, 30], [56, 60, 54, 51, 127, 48, 120], [63, 3, 31, 48, 48, 51, 30], [28, 6, 3, 31, 51, 51, 30], [63, 51, 48, 24, 12, 12, 12], [30, 51, 51, 30, 51, 51, 30], [30, 51, 51, 62, 48, 24, 14], [, 12, 12, , , 12, 12], [, 12, 12, , , 12, 12, 6], [24, 12, 6, 3, 6, 12, 24], [, , 63, , , 63, ,], [6, 12, 24, 48, 24, 12, 6], [30, 51, 48, 24, 12, , 12], [62, 99, 123, 123, 123, 3, 30], [12, 30, 51, 51, 63, 51, 51], [63, 102, 102, 62, 102, 102, 63], [60, 102, 3, 3, 3, 102, 60], [31, 54, 102, 102, 102, 54, 31], [127, 70, 22, 30, 22, 70, 127], [127, 70, 22, 30, 22, 6, 15], [60, 102, 3, 3, 115, 102, 124], [51, 51, 51, 63, 51, 51, 51], [30, 12, 12, 12, 12, 12, 30], [120, 48, 48, 48, 51, 51, 30], [103, 102, 54, 30, 54, 102, 103], [15, 6, 6, 6, 70, 102, 127], [99, 119, 127, 127, 107, 99, 99], [99, 103, 111, 123, 115, 99, 99], [28, 54, 99, 99, 99, 54, 28], [63, 102, 102, 62, 6, 6, 15], [30, 51, 51, 51, 59, 30, 56], [63, 102, 102, 62, 54, 102, 103], [30, 51, 7, 14, 56, 51, 30], [63, 45, 12, 12, 12, 12, 30], [51, 51, 51, 51, 51, 51, 63], [51, 51, 51, 51, 51, 30, 12], [99, 99, 99, 107, 127, 119, 99], [99, 99, 54, 28, 28, 54, 99], [51, 51, 51, 30, 12, 12, 30], [127, 99, 49, 24, 76, 102, 127], [30, 6, 6, 6, 6, 6, 30], [3, 6, 12, 24, 48, 96, 64], [30, 24, 24, 24, 24, 24, 30], [8, 28, 54, 99, , , ,], [, , , , , , , 255], [12, 12, 24, , , , ,], [, , 30, 48, 62, 51, 110], [7, 6, 6, 62, 102, 102, 59], [, , 30, 51, 3, 51, 30], [56, 48, 48, 62, 51, 51, 110], [, , 30, 51, 63, 3, 30], [28, 54, 6, 15, 6, 6, 15], [, , 110, 51, 51, 62, 48, 31], [7, 6, 54, 110, 102, 102, 103], [12, , 14, 12, 12, 12, 30], [48, , 48, 48, 48, 51, 51, 30], [7, 6, 102, 54, 30, 54, 103], [14, 12, 12, 12, 12, 12, 30], [, , 51, 127, 127, 107, 99], [, , 31, 51, 51, 51, 51], [, , 30, 51, 51, 51, 30], [, , 59, 102, 102, 62, 6, 15], [, , 110, 51, 51, 62, 48, 120], [, , 59, 110, 102, 6, 15], [, , 62, 3, 30, 48, 31], [8, 12, 62, 12, 12, 44, 24], [, , 51, 51, 51, 51, 110], [, , 51, 51, 51, 30, 12], [, , 99, 107, 127, 127, 54], [, , 99, 54, 28, 54, 99], [, , 51, 51, 51, 62, 48, 31], [, , 63, 25, 12, 38, 63], [56, 12, 12, 7, 12, 12, 56], [24, 24, 24, , 24, 24, 24], [7, 12, 12, 56, 12, 12, 7], [110, 59, , , , , ,]], F = (e, s, m = 3) => {
2257+
for (let t = 0; t < 8; t++) for (let l = 0; l < 8; l++) (s[t] | 0) & 1 << l && e.rectfill(l, t, 1, 1, m);
2258+
}, v = { id: "basic", chars: C, first: 33, w: 8, h: 8, render: F };
2259+
var S = [[34, 32, 32], [85, 0, 0], [87, 87, 80], [99, 103, 32], [84, 33, 80], [99, 101, 96], [34, 0, 0], [33, 17, 32], [36, 68, 32], [82, 80, 0], [2, 114, 0], [0, 0, 33], [0, 112, 0], [0, 0, 16], [68, 33, 16], [117, 85, 112], [50, 34, 112], [116, 113, 112], [116, 116, 112], [85, 116, 64], [113, 116, 112], [113, 117, 112], [116, 68, 64], [117, 117, 112], [117, 116, 112], [0, 32, 32], [0, 32, 33], [66, 18, 64], [7, 7, 0], [18, 66, 16], [116, 96, 32], [37, 81, 96], [37, 117, 80], [53, 53, 48], [97, 17, 96], [53, 85, 48], [113, 49, 112], [113, 49, 16], [97, 85, 96], [85, 117, 80], [114, 34, 112], [68, 69, 32], [85, 53, 80], [17, 17, 112], [87, 117, 80], [117, 85, 80], [37, 85, 32], [117, 113, 16], [101, 83, 96], [53, 53, 80], [97, 116, 48], [114, 34, 32], [85, 85, 112], [85, 82, 32], [85, 119, 80], [85, 37, 80], [85, 34, 32], [116, 33, 112], [98, 34, 96], [17, 36, 64], [50, 34, 48], [37, 0, 0], [0, 0, 112], [18, 0, 0], [6, 85, 96], [19, 85, 48], [6, 17, 96], [70, 85, 96], [2, 83, 96], [66, 114, 32], [2, 86, 66], [17, 53, 80], [2, 2, 32], [2, 2, 33], [21, 53, 80], [34, 34, 64], [5, 117, 80], [3, 85, 80], [2, 85, 32], [3, 85, 49], [6, 85, 100], [2, 81, 16], [6, 20, 48], [39, 34, 64], [5, 85, 96], [5, 82, 32], [5, 87, 80], [5, 34, 80], [5, 86, 66], [7, 65, 112], [98, 18, 96], [34, 34, 32], [50, 66, 48], [3, 96, 0]], P = (e, s, m = 3) => {
22522260
for (y = 0; y < 6; y++) for (x = 0; x < 4; x++) {
22532261
let t = ~~(y / 2);
2254-
(y % 2 ? s[t] & 15 : s[t] >> 4) & 1 << x && e.rectfill(x, y, 1, 1, p);
2255-
}
2256-
}, g = { id: "mini", chars: S, first: 33, w: 4, h: 6, render: P };
2257-
var k = plugin = (e, { cache: s = true } = {}) => {
2258-
let p = e.text, t = e.textsize, c = e.textalign, z = e.textfont, i = s ? /* @__PURE__ */ new Map() : null, u = 1, r = null, N = (a) => {
2259-
u = ~~Math.round(a);
2260-
}, I = () => console.warn("[litecanvas/plugin-pixel-font] textalign() has not yet been implemented for pixel fonts"), w = (a, m, n, l = 3) => {
2261-
e.push(), e.translate(a, m), e.scale(u), r.render(e, n, l), e.pop();
2262-
}, A = (a, m, n, l = 3) => {
2263-
if (n += "", !u || !n.length) return;
2264-
let o = u * r.w, b = u * (r.h || r.w);
2265-
for (let f = 0; f < n.length; f++) {
2266-
let _ = n[f], E = _.charCodeAt(), d = r.chars[E - r.first];
2267-
if (d) if (s) {
2268-
let v = `${r.id}:${_}:${~~l}:${o}`;
2269-
i.has(v) || i.set(v, e.paint(o, b, () => {
2270-
w(0, 0, d, ~~l);
2262+
(y % 2 ? s[t] & 15 : s[t] >> 4) & 1 << x && e.rectfill(x, y, 1, 1, m);
2263+
}
2264+
}, h = { id: "mini", chars: S, first: 33, w: 4, h: 6, render: P };
2265+
var _ = plugin = (e, { cache: s = true } = {}) => {
2266+
let m = e.text, t = e.textsize, l = e.textalign, k = e.textfont, o = s ? /* @__PURE__ */ new Map() : null, c = 1, r = null, g = (a) => {
2267+
c = ~~Math.round(a);
2268+
}, z = () => console.warn("[litecanvas/plugin-pixel-font] textalign() has not yet been implemented for pixel fonts"), N = (a, u, n, i = 3) => {
2269+
e.push(), e.translate(a, u), e.scale(c), r.render(e, n, i), e.pop();
2270+
}, I = (a, u, n, i = 3) => {
2271+
if (e.stat(12) == null) throw "renderPixelText requires Litecanvas v0.99 or later";
2272+
if (n += "", !c || !n.length) return;
2273+
let b = c * r.w, A = c * (r.h || r.w);
2274+
for (let p = 0; p < n.length; p++) {
2275+
let w = n[p], E = w.charCodeAt(), f = r.chars[E - r.first];
2276+
if (f) if (s) {
2277+
let d = [r.id, w, ~~i, b, e.stat(12).join(",")].join(":");
2278+
o.has(d) || o.set(d, e.paint(b, A, () => {
2279+
N(0, 0, f, ~~i);
22712280
}));
2272-
let T = i.get(v);
2273-
e.image(a, m, T);
2274-
} else w(a, m, d, l);
2275-
a += o;
2281+
let T = o.get(d);
2282+
e.image(a, u, T);
2283+
} else N(a, u, f, i);
2284+
a += b;
22762285
}
22772286
};
22782287
if (s) {
2279-
let m = setInterval(() => {
2280-
i.clear();
2288+
let u = setInterval(() => {
2289+
o.clear();
22812290
}, 6e4);
22822291
e.listen("quit", () => {
2283-
clearInterval(m), i.clear();
2292+
clearInterval(u), o.clear();
22842293
});
2285-
let n = e.palc;
2286-
e.def("palc", (o, b) => (i.clear(), n(o, b)));
2287-
let l = e.pal;
2288-
e.def("pal", (o) => (i.clear(), l(o)));
2294+
let n = e.pal;
2295+
e.def("pal", (i) => (o.clear(), n(i)));
22892296
}
22902297
return { textfont: (a) => {
2291-
typeof a == "object" ? (e.def("text", A), e.def("textsize", N), e.def("textalign", I), r = a, N(u || 1)) : (e.def("text", p), e.def("textsize", t), e.def("textalign", c), z(a));
2298+
typeof a == "object" ? (e.def("text", I), e.def("textsize", g), e.def("textalign", z), r = a, g(c || 1)) : (e.def("text", m), e.def("textsize", t), e.def("textalign", l), k(a));
22922299
} };
22932300
};
2294-
window.pluginPixelFont = k;
2295-
window.PIXEL_FONT_MINI = g;
2296-
window.PIXEL_FONT_BASIC = h;
2301+
window.pluginPixelFont = _;
2302+
window.PIXEL_FONT_MINI = h;
2303+
window.PIXEL_FONT_BASIC = v;
22972304
})();
22982305
})();
22992306
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */

public/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "2025.8.8.2";
2+
const version = "2025.8.10.0";
33

44
const precacheResources = [
55
"/",

0 commit comments

Comments
 (0)