Auroriax / PuzzleScriptPlus

Puzzlescript Plus: Open Source HTML5 Puzzle Game Engine (with lots of extra functionality)
https://auroriax.github.io/PuzzleScript/
34 stars 4 forks source link

Expand event system #48

Open Auroriax opened 1 year ago

Auroriax commented 1 year ago

This is an undocumented feature for in the latest release (so this may change, use with care!), but PS+ will now throw some events on the document so it becomes easier to listen to those events from native JS code. You can listen to psplusGameStarted, psplusLevelLoaded, and psplusLevelRestarted, with the latter two passing the level number as detail. Ideally I want to expand on this a bit more, by adding more events, deciding from which component to fire the events (probably the canvas instead of the document, and document it properly (also explaining the use cases).

For example, this would fire a console message each time a level was started:

document.addEventListener("psplusLevelLoaded", LevelStartFunction);

function LevelStartFunction(e) {
    var level = e.detail;
    console.log("Wow! You're already at level " + level + "!");
}
Auroriax commented 1 year ago

Probably allow developers to fire events using commands e.g. javascriptevent [eventname]. So that you can catch & react on any arbitrary choice inside of the game state.