Skip to content

Commit 8ddee14

Browse files
committed
update engine
1 parent a7ee231 commit 8ddee14

File tree

2 files changed

+28
-49
lines changed

2 files changed

+28
-49
lines changed

public/litecanvas.js

+27-48
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
animate: true
4646
};
4747
settings = Object.assign(defaults, settings);
48-
let _initialized = false, _plugins = [], _canvas = settings.canvas || document.createElement("canvas"), _animated = settings.animate, _scale = 1, _ctx, _outline_fix = 0.5, _timeScale = 1, _lastFrameTime, _deltaTime = 1 / 60, _accumulated = 0, _rafid, _fontFamily = "sans-serif", _fontSize = 18, _rng_seed = Date.now(), _global = settings.global, _events = {
48+
let _initialized = false, _plugins = [], _canvas = settings.canvas || document.createElement("canvas"), _animated = settings.animate, _scale = 1, _ctx, _outline_fix = 0.5, _timeScale = 1, _lastFrameTime, _deltaTime = 1 / 60, _accumulated = 0, _rafid, _fontFamily = "sans-serif", _fontSize = 20, _rng_seed = Date.now(), _global = settings.global, _events = {
4949
init: null,
5050
update: null,
5151
draw: null,
@@ -902,27 +902,6 @@
902902
root[key] = value;
903903
}
904904
},
905-
/**
906-
* Resizes the game canvas and emit the "resized" event
907-
*
908-
* @param {number} width
909-
* @param {number} height
910-
*/
911-
resize(width, height) {
912-
DEV: assert(
913-
isFinite(width) && width > 0,
914-
"resize: 1st param must be a number"
915-
);
916-
DEV: assert(
917-
isFinite(height) && height > 0,
918-
"resize: 2nd param must be a number"
919-
);
920-
instance.setvar("WIDTH", _canvas.width = width);
921-
instance.setvar("HEIGHT", _canvas.height = height);
922-
instance.setvar("CENTERX", instance.WIDTH / 2);
923-
instance.setvar("CENTERY", instance.HEIGHT / 2);
924-
onResize();
925-
},
926905
/**
927906
* The scale of the game's delta time (dt).
928907
* Values higher than 1 increase the speed of time, while values smaller than 1 decrease it.
@@ -980,7 +959,7 @@
980959
loadPlugin(callback, config);
981960
}
982961
if (settings.autoscale) {
983-
on(root, "resize", onResize);
962+
on(root, "resize", resizeCanvas);
984963
}
985964
if (settings.tapEvents) {
986965
const _getXY = (pageX, pageY) => [
@@ -1180,47 +1159,47 @@
11801159
_canvas && _canvas.tagName === "CANVAS",
11811160
"Invalid canvas element"
11821161
);
1183-
DEV: assert(
1184-
null == instance.WIDTH || instance.WIDTH > 0,
1185-
`Litecanvas' "width" option should be null or a positive number`
1186-
);
1187-
DEV: assert(
1188-
null == instance.HEIGHT || instance.HEIGHT > 0,
1189-
`Litecanvas' "width" option should be null or a positive number`
1190-
);
1191-
DEV: assert(
1192-
null == instance.HEIGHT || instance.WIDTH > 0 && instance.HEIGHT > 0,
1193-
`Litecanvas' "width" is required when "heigth" is passed`
1194-
);
11951162
instance.setvar("CANVAS", _canvas);
11961163
_ctx = _canvas.getContext("2d");
11971164
on(_canvas, "click", () => root.focus());
11981165
_canvas.style = "";
1199-
if (!instance.WIDTH) {
1200-
instance.WIDTH = root.innerWidth;
1201-
instance.HEIGHT = root.innerHeight;
1202-
}
1203-
instance.resize(instance.WIDTH, instance.HEIGHT, false);
1166+
resizeCanvas();
12041167
if (!_canvas.parentNode) document.body.appendChild(_canvas);
12051168
}
1206-
function onResize() {
1207-
const styles = _canvas.style;
1169+
function resizeCanvas() {
1170+
DEV: assert(
1171+
null == settings.width || isFinite(settings.width) && settings.width > 0,
1172+
`Litecanvas' option "width" should be a positive number when defined`
1173+
);
1174+
DEV: assert(
1175+
null == settings.height || isFinite(settings.height) && settings.height > 0,
1176+
`Litecanvas' option "height" should be a positive number when defined`
1177+
);
1178+
DEV: assert(
1179+
null == settings.height || settings.width > 0 && settings.height > 0,
1180+
`Litecanvas' option "width" is required when the option "height" is defined`
1181+
);
1182+
const width = settings.width || root.innerWidth, height = settings.height || settings.width || root.innerHeight;
1183+
instance.setvar("WIDTH", _canvas.width = width);
1184+
instance.setvar("HEIGHT", _canvas.height = height);
1185+
instance.setvar("CENTERX", instance.WIDTH / 2);
1186+
instance.setvar("CENTERY", instance.HEIGHT / 2);
12081187
if (settings.autoscale) {
1209-
if (!styles.display) {
1210-
styles.display = "block";
1211-
styles.margin = "auto";
1188+
if (!_canvas.style.display) {
1189+
_canvas.style.display = "block";
1190+
_canvas.style.margin = "auto";
12121191
}
12131192
_scale = math.min(
12141193
root.innerWidth / instance.WIDTH,
12151194
root.innerHeight / instance.HEIGHT
12161195
);
12171196
_scale = (settings.pixelart ? ~~_scale : _scale) || 1;
1218-
styles.width = instance.WIDTH * _scale + "px";
1219-
styles.height = instance.HEIGHT * _scale + "px";
1197+
_canvas.style.width = instance.WIDTH * _scale + "px";
1198+
_canvas.style.height = instance.HEIGHT * _scale + "px";
12201199
}
12211200
if (!settings.antialias || settings.pixelart) {
12221201
_ctx.imageSmoothingEnabled = false;
1223-
styles.imageRendering = "pixelated";
1202+
_canvas.style.imageRendering = "pixelated";
12241203
}
12251204
instance.emit("resized", _scale);
12261205
if (!_animated) {

public/sw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "2.78.1";
2+
const version = "2.79.0";
33

44
const precacheResources = [
55
"/",

0 commit comments

Comments
 (0)