Skip to content

Commit 16486f9

Browse files
feat(core): Unload existing KS instances on load
Fixes #812 Relates to #801
1 parent 35b24ed commit 16486f9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/kitten-scientists/source/KittenScientists.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export class KittenScientists {
4747
gameLanguage: GameLanguage = "en",
4848
engineState?: EngineState,
4949
) {
50-
cinfo(`Kitten Scientists ${ksVersion("v")} constructed.`);
50+
cinfo(`Kitten Scientists ${ksVersion("v")} constructed. Checking for previous instances...`);
51+
if ("kittenScientists" in UserScriptLoader.window) {
52+
cwarn("Detected existing KS instance. Trying to unload it...");
53+
UserScriptLoader.window.kittenScientists?.unload();
54+
}
5155
cinfo(`You are on the '${String(KS_RELEASE_CHANNEL)}' release channel.`);
5256

5357
this.game = game;
@@ -92,6 +96,7 @@ export class KittenScientists {
9296
* Removes Kitten Scientists from the browser.
9397
*/
9498
unload(): void {
99+
cwarn("Unloading Kitten Scientists...");
95100
this.engine.stop();
96101
this._userInterface.destroy();
97102
if (this._gameBeforeSaveHandle !== undefined) {
@@ -107,6 +112,7 @@ export class KittenScientists {
107112
this.game.managers.splice(managerIndex, 1);
108113
}
109114
delete window.kittenScientists;
115+
cwarn("Kitten Scientists have been unloaded!");
110116
}
111117

112118
/**

0 commit comments

Comments
 (0)