Skip to content

Commit

Permalink
update engine
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbills committed May 8, 2024
1 parent def446c commit 87bbac2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 33 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions public/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,7 @@ <h2><a id="plugin-api">Plugin API</a></h2>

// add a game loop listener
// returns a function that removes the listener
listen(event: string, callback: function, highPriority = false): function

// call all listeners of a specific game loop event
emit(event, ...args): void</code></pre>
listen(event: string, callback: function, highPriority = false): function</code></pre>

<h2><a id="advanced">Advanced Features</a></h2>

Expand Down
2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions public/litecanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,19 +707,6 @@
_loop[event] = _loop[event].filter((f) => f !== callback);
};
},
/**
* Call all listeners attached to a game loop
*
* @param {string} event The game loop event
* @param {...any} args Arguments passed to all functions
*/
emit(event, ...args) {
if (!_loop[event])
return;
for (let i = 0; i < _loop[event].length; ++i) {
_loop[event][i](...args);
}
},
/**
* Get the color value
*
Expand Down Expand Up @@ -829,7 +816,7 @@
on(root, "resize", pageResized);
}
pageResized();
instance.emit("init");
emit("init");
_lastFrame = time();
_rafid = requestAnimationFrame(frame);
}
Expand All @@ -838,15 +825,15 @@
_lastFrame = now;
_accumulated += t;
while (_accumulated >= _stepMs) {
instance.emit("update", _step);
emit("update", _step);
instance.setvar("ELAPSED", instance.ELAPSED + _step);
_accumulated -= _stepMs;
ticks++;
instance.setvar("TAPPED", false);
}
if (ticks) {
_drawCount++;
instance.emit("draw");
emit("draw");
_drawTime += _stepMs * ticks;
if (_drawTime + _accumulated >= 1e3) {
instance.setvar("FPS", _drawCount);
Expand Down Expand Up @@ -901,7 +888,7 @@
_offsetTop = _canvas.offsetTop;
_offsetLeft = _canvas.offsetLeft;
instance.textalign(_textAlign, _textBaseline);
instance.emit("resized");
emit("resized");
}
function updateTapped(tapped, x, y) {
instance.setvar("TAPPED", tapped);
Expand All @@ -921,6 +908,13 @@
}
}
}
function emit(event, ...args) {
if (!_loop[event])
return;
for (let i = 0; i < _loop[event].length; ++i) {
_loop[event][i](...args);
}
}
if (settings.global) {
if (root.__litecanvas) {
throw new Error("Cannot instantiate litecanvas globally twice");
Expand All @@ -937,7 +931,7 @@
}
window.litecanvas = litecanvas;
})();
/*! litecanvas v0.28.0 | https://github.com/litecanvas/game-engine */
/*! litecanvas v0.29.0 | https://github.com/litecanvas/game-engine */

(()=>{var s=getScriptLoader=t=>(o,r)=>{t.setvar("LOADING",t.LOADING+1),script=document.createElement("script"),script.onload=()=>{r&&r(script),t.setvar("LOADING",t.LOADING-1)},script.onerror=()=>{r&&r(null)},script.src=o,document.head.appendChild(script)};var L=getImageLoader=t=>(o,r)=>{t.setvar("LOADING",t.LOADING+1);let d=new Image;d.onload=()=>{r&&r(d),t.setvar("LOADING",t.LOADING-1)},d.onerror=function(){r&&r(null)},d.src=o};var p=getFontLoader=t=>async(o,r,d)=>{let e=new FontFace(o,`url(${r})`);t.setvar("LOADING",t.LOADING+1),document.fonts.add(e),e.load().then(a=>{d&&d(a),t.setvar("LOADING",t.LOADING-1)}).catch(()=>{d&&d(null)})};window.pluginAssetLoader=u;function u(t,o){return t.setvar("LOADING",0),{loadScript:s(t,o),loadImage:L(t,o),loadFont:p(t,o)}}})();
/*! Asset Loader plugin for litecanvas v0.4.2 by Luiz Bills | MIT Licensed */
2 changes: 1 addition & 1 deletion public/sw.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cacheName = "luizbills.litecanvas-editor-v1";
const version = "1.44.1";
const version = "1.45.0";

const precacheResources = [
"/",
Expand Down
6 changes: 0 additions & 6 deletions src/completions.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,6 @@ export default function customCompletions(context) {
apply: "listen(",
detail: "(event,callback,[highPriority])",
},
{
label: "emit",
type: "function",
apply: "emit(",
detail: "(event,...args)",
},

// asset loader plugin
{
Expand Down

0 comments on commit 87bbac2

Please sign in to comment.