diff --git a/src/main.js b/src/main.js index 8565b3f..aea9c02 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,6 @@ import App from './App.svelte'; +import { shared } from './game/gameScene'; +import { sharedErrorData } from './stores/error'; const app = new App({ target: document.body @@ -8,4 +10,57 @@ if ('serviceWorker' in navigator) { navigator.serviceWorker.register('./service-worker.js'); } +var lastUpdate; +var lastError; +window.addEventListener("error", (error) => { + lastError = error; + lastUpdate = shared.lastUpdate; + + setTimeout(() => { + if(lastUpdate === shared.lastUpdate) { // if no updates in 50ms (60fps means an update each 16ms), game likely crashed from that error + if(!sharedErrorData.gameCrashed) { // svelte crashed, or something similarly horrible happened. Bare minimum error will now show + error = lastError.error; + console.error("GAME CRASH!", error); + console.error("Normal crash handler couldn't handle it, using the backup non-svelte one."); + console.warn("Screenshot the above messages, and report them to the devs. If you can, open the first error (red box) you see (simply clicking should do the job), and send it's contents as well."); + console.warn("This site does not track it's users, nor does it send any data about them - the dev won't know about this error until you report it. So please do it."); + + document.body.innerHTML = ` +
+

Heaventaker horribly crashed.

+

Here's the error (the most important part when sharing this with devs!):

+
${error.stack}
+
+ Please report this to the devs: + +

Please, include the error above (or the whole screen) in the report. If you're on desktop, open Dev Tools (f12), switch to Console tab in there and send a screenshot of them as well. Every report improves the game!

+

You should never see this page, as there's another page for normal errors. If you see this page, it means something went horribly to the point not even the normal error page can handle it.

+ +
+ +`; + } + } + }, 100); +}); + export default app; \ No newline at end of file diff --git a/src/pages/crashHandler.svelte b/src/pages/crashHandler.svelte new file mode 100644 index 0000000..c21f8c1 --- /dev/null +++ b/src/pages/crashHandler.svelte @@ -0,0 +1,65 @@ + + + + +{#if error} +
+

Game crashed {error.message === "Debug crash" ? ":>" : ":("}

+

Here's the error (the most important part when sharing this with devs!):

+
{error.stack}
+
+ {#if error.message === "Debug crash"} + Please do NOT report this error. This error was triggered using debug key (f3) and C pressed at once. + {:else} + Please report this to the devs: + {/if} + +

Please, include the error above (or the whole screen) in the report. If you're on desktop, open Dev Tools (f12), switch to Console tab in there and send a screenshot of them as well. Every report improves the game!

+

Refresh this page (or close and reopen the application) to continue playing. Progress is auto saved (not inside levels though).

+
+{/if} + + \ No newline at end of file diff --git a/src/stores/error.js b/src/stores/error.js new file mode 100644 index 0000000..28e3ac7 --- /dev/null +++ b/src/stores/error.js @@ -0,0 +1,8 @@ +import { writable } from "svelte/store"; + +export const gameCrashed = writable(false); +export const sharedErrorData = { gameCrashed: false }; + +gameCrashed.subscribe(t => { + sharedErrorData.gameCrashed = t; +}); \ No newline at end of file diff --git a/src/stores/keypress.svelte b/src/stores/keypress.svelte index 25ed888..bb2890e 100644 --- a/src/stores/keypress.svelte +++ b/src/stores/keypress.svelte @@ -6,7 +6,6 @@ function keydown(e) { if(!keys.has(e.key)) { dispatch("keypress", e); - console.log("keypress"); keys.add(e.key); } }