|
27 | 27 | var assert = (condition, message = "Assertion failed") => { |
28 | 28 | if (!condition) throw new Error(message); |
29 | 29 | }; |
30 | | - var version = "0.89.2"; |
| 30 | + var version = "0.90.0"; |
31 | 31 | function litecanvas(settings = {}) { |
32 | 32 | const root = window, math = Math, TWO_PI = math.PI * 2, raf = requestAnimationFrame, _browserEventListeners = [], on = (elem, evt, callback) => { |
33 | 33 | elem.addEventListener(evt, callback, false); |
|
1341 | 1341 | _canvas.width = width; |
1342 | 1342 | _canvas.height = height; |
1343 | 1343 | if (settings.autoscale) { |
| 1344 | + let maxScale = +settings.autoscale; |
1344 | 1345 | if (!_canvas.style.display) { |
1345 | 1346 | _canvas.style.display = "block"; |
1346 | 1347 | _canvas.style.margin = "auto"; |
1347 | 1348 | } |
1348 | 1349 | _scale = math.min(root.innerWidth / width, root.innerHeight / height); |
| 1350 | + _scale = maxScale > 1 && _scale > maxScale ? maxScale : _scale; |
1349 | 1351 | _scale = (settings.pixelart ? ~~_scale : _scale) || 1; |
1350 | 1352 | _canvas.style.width = width * _scale + "px"; |
1351 | 1353 | _canvas.style.height = height * _scale + "px"; |
|
1995 | 1997 | if (c = Object.assign({}, j, c), a.stat(1)) throw 'Plugin Migrate should be loaded before the "init" event'; |
1996 | 1998 | let l = a.stat(0); |
1997 | 1999 | function s(t, e, r = "") { |
1998 | | - c.warnings && console.warn(`[Migrate] warning: ${t} is removed. ` + (e ? `Use ${e} instead. ` : "") + r); |
| 2000 | + c.warnings && console.warn(`[migrate] ${t} is removed. ` + (e ? `Use ${e} instead. ` : "") + r); |
1999 | 2001 | } |
2000 | 2002 | function h(t) { |
2001 | 2003 | return s("seed()", "rseed()"), t && a.rseed(t), a.stat(9); |
|
2086 | 2088 | break; |
2087 | 2089 | } |
2088 | 2090 | } |
2089 | | - function R(t, e) { |
| 2091 | + function L(t, e) { |
2090 | 2092 | s("setvar()", "def()"), u(t, e); |
2091 | 2093 | } |
2092 | 2094 | a.listen("resized", v); |
2093 | 2095 | function v() { |
2094 | 2096 | u("CX", a.W / 2), u("CY", a.H / 2); |
2095 | 2097 | } |
2096 | 2098 | v(), u("CANVAS", a.canvas()); |
2097 | | - function F(t, e) { |
| 2099 | + function R(t, e) { |
2098 | 2100 | if (l.autoscale) throw "resize() don't works with autoscale enabled"; |
2099 | 2101 | s("resize()", null, "Avoid changing the canvas dimensions at runtime."), a.CANVAS.width = t, u("W", t), u("CX", t / 2), a.CANVAS.height = e, u("H", e), u("CY", e / 2), a.emit("resized", 1); |
2100 | 2102 | } |
2101 | 2103 | for (let t of ["W", "H", "T", "CX", "CY", "MX", "MY"]) a[t] != null && u(t, a[t]); |
2102 | | - if (s("FPS", "some library to measure the FPS", "Recommendation: https://github.com/mrdoob/stats.js/"), n("FPS", ""), l.fps && a.framerate(l.fps), l.background >= 0) { |
| 2104 | + if (s("FPS", "", "but you can use our plugin to measure the fps: https://github.com/litecanvas/plugin-frame-rate-meter"), n("FPS", ""), l.fps && a.framerate(l.fps), l.background >= 0) { |
2103 | 2105 | let t = stat(5); |
2104 | 2106 | a.CANVAS.style.backgroundColor = t[~~l.background % t.length]; |
2105 | 2107 | } |
2106 | | - function L(t) { |
| 2108 | + function F(t) { |
2107 | 2109 | return s("path()", "`new Path2D`", "See https://developer.mozilla.org/en-US/docs/Web/API/Path2D"), new Path2D(t); |
2108 | 2110 | } |
2109 | | - let Y = a.fill; |
2110 | | - function z(t, e) { |
| 2111 | + let z = a.fill; |
| 2112 | + function N(t, e) { |
2111 | 2113 | if (e instanceof Path2D) { |
2112 | 2114 | s("fill(color, path)"); |
2113 | 2115 | let r = a.stat(5), i = a.ctx(); |
2114 | 2116 | i.fillStyle = r[~~t % r.length], a.ctx().fill(e); |
2115 | | - } else Y(t); |
| 2117 | + } else z(t); |
2116 | 2118 | } |
2117 | | - let N = a.stroke; |
2118 | | - function X(t, e) { |
| 2119 | + let Y = a.stroke; |
| 2120 | + function H(t, e) { |
2119 | 2121 | if (e instanceof Path2D) { |
2120 | 2122 | s("stroke(color, path)"); |
2121 | 2123 | let r = a.stat(5), i = a.ctx(); |
2122 | 2124 | i.strokeStyle = r[~~t % r.length], a.ctx().stroke(e); |
2123 | | - } else N(t); |
| 2125 | + } else Y(t); |
2124 | 2126 | } |
2125 | | - let H = a.clip; |
| 2127 | + let X = a.clip; |
2126 | 2128 | function D(t) { |
2127 | | - s("clip(path)", "clip(callback)", "E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"), t instanceof Path2D ? a.ctx().clip(t) : H(t); |
| 2129 | + s("clip(path)", "clip(callback)", "E.g: `clip((ctx) => ctx.rect(0, 0, 200, 200))`"), t instanceof Path2D ? a.ctx().clip(t) : X(t); |
2128 | 2130 | } |
2129 | | - return { def: u, seed: h, print: M, clear: I, setfps: O, setvar: R, textstyle: b, textmetrics: E, text: y, cliprect: T, clipcirc: A, blendmode: k, transform: S, getcolor: C, mousepos: P, resize: F, path: L, fill: z, stroke: X, clip: D, colrect: _, colcirc: x }; |
| 2131 | + return { def: u, seed: h, print: M, clear: I, setfps: O, setvar: L, textstyle: b, textmetrics: E, text: y, cliprect: T, clipcirc: A, blendmode: k, transform: S, getcolor: C, mousepos: P, resize: R, path: F, fill: N, stroke: H, clip: D, colrect: _, colcirc: x }; |
2130 | 2132 | } |
2131 | 2133 | window.pluginMigrate = g; |
2132 | 2134 | })(); |
|
2213 | 2215 | function o(e, y = {}) { |
2214 | 2216 | let p = e.text, f = e.textsize, b = e.textalign, d = { chars: u, first: 33, size: 8 }, n = 1, t = null, v = (a) => { |
2215 | 2217 | n = Math.round(a / t.size); |
2216 | | - }, h = () => console.warn("textalign() xxx has not yet been implemented for pixel font"), g = (a, c, x, l = 3) => { |
| 2218 | + }, h = () => console.warn("textalign() has not yet been implemented for pixel font"), g = (a, c, x, l = 3) => { |
2217 | 2219 | let m = x.charCodeAt(0), r = t.chars[m - t.first]; |
2218 | 2220 | if (r) for (let s = 0; s < t.size; s++) for (let i = 0; i < t.size; i++) (r[s] | 0) & 1 << i && e.rectfill(a + i * n, c + s * n, n, n, l); |
2219 | 2221 | }, w = (a, c, x, l = 3) => { |
|
0 commit comments