public start() {
this.oldEventListenerWindow = window.addEventListener;
this.oldEventListenerDocument = document.addEventListener;
const _this = this;
window.addEventListener = function (...args: any[]) {
_this.eventsAddedOnWindow.push({type: args[0], callback: args[1]});
_this.oldEventListenerWindow.apply(this, args);
};
document.addEventListener = function (...args: any[]) {
_this.eventsAddedOnDocument.push({type: args[0], callback: args[1]});
_this.oldEventListenerDocument.apply(this, args);
};
this.game.start();
}
public stop(): void {
this.game.stop();
window.addEventListener = this.oldEventListenerWindow;
document.addEventListener = this.oldEventListenerDocument;
this.eventsAddedOnWindow.forEach((e) => {
window.removeEventListener(e.type, e.callback);
});
this.eventsAddedOnDocument.forEach((e) => {
document.removeEventListener(e.type, e.callback);
});
const elementButton = document.getElementById('excalibur-play');
if (elementButton) {
elementButton.parentElement.remove();
}
}