Răsfoiți Sursa

Prevent complete failure if browser denies localStorage rudely.
Set up with current typescript version.

Reddo 5 ani în urmă
părinte
comite
df7b753688

+ 13 - 3
app/Controls/Modules/Memory.ts

@@ -7,12 +7,22 @@ module Controls.Memory {
     let memories : {[id : string] : StoredMemory<any>} = {};
 
     export function getValue (id : string, defValue : any) {
-        let storage = localStorage.getItem(memoryPrefix + id);
-        return storage == undefined ? defValue : JSON.parse(storage);
+        try {
+            let storage = localStorage.getItem(memoryPrefix + id);
+            return storage == undefined ? defValue : JSON.parse(storage);
+        } catch (e) {
+            // no localStorage
+            console.error("[MEMORY] Can't use localStorage!");
+            return defValue;
+        }
     }
 
     export function setValue (id : string, value : any) {
-        localStorage.setItem(memoryPrefix + id, JSON.stringify(value));
+        try {
+            localStorage.setItem(memoryPrefix + id, JSON.stringify(value));
+        } catch (e) {
+            console.error("[MEMORY] Can't use localStorage!");
+        }
 
         if (!versionSet) {
             versionSet = true;

+ 1 - 1
app/SaveHandler.ts

@@ -50,7 +50,7 @@ module SaveHandler {
                     var fr = new FileReader();
 
                     fr.onload = (ev) => {
-                        resolve(ev.target['result']);
+                        resolve((<any> ev.target)['result']);
                     }
 
                     fr.readAsText(element.files[0]);

+ 31 - 31
content/ContentPicker/MinotaurGuard.ts

@@ -1,32 +1,32 @@
 ///<reference path="../Rooms/Forest/Maze/People/MinotaurGuard.ts"/>
-(new CombatDescription("Minotaur Attacks"))
-    .setDescriptionFunction((actor, target, weapons, markers) => {
-        let say = new Say();
-
-        if (markers.includes(CombatHit.MISS)) {
-            say.add("The minotaur heaves his heavy punches at you, but you narrowly avoid it.");
-        } else if (markers.includes(CombatHit.HIT)) {
-            say.add("The minotaur punches you with ease.");
-        } else if (markers.includes(CombatHit.CRITICAL)) {
-            say.add("The minotaur punches you in the gut. Ouch, you felt that HARD.");
-        }
-
-        say.add(" ");
-
-        if (markers.includes(CombatResult.KILLED)) {
-            say.add("YOU ARE DEAD.");
-        } else if (markers.includes(CombatResult.KNOCKED_OFF)) {
-            say.add("You lose consciousness.");
-        } else if (markers.includes(CombatResult.KNOCKED)) {
-            say.add("You are knocked to the ground!");
-        }
-
-        return say;
-    })
-    .addUnit()
-    .setActor(MinotaurGuard)
-    .setTarget(WorldState.player)
-    .setWeapon(Thing)
-    .addMarker(AdaptiveDifferential.FULLYADAPTIVE(CombatHit.MISS, CombatHit.HIT, CombatHit.CRITICAL))
-    .addMarker(AdaptiveDifferential.FULLYADAPTIVE(CombatResult.KNOCKED, CombatResult.KILLED, CombatResult.KNOCKED_OFF))
-;
+// (new CombatDescription("Minotaur Attacks"))
+//     .setDescriptionFunction((actor, target, weapons, markers) => {
+//         let say = new Say();
+//
+//         if (markers.includes(CombatHit.MISS)) {
+//             say.add("The minotaur heaves his heavy punches at you, but you narrowly avoid it.");
+//         } else if (markers.includes(CombatHit.HIT)) {
+//             say.add("The minotaur punches you with ease.");
+//         } else if (markers.includes(CombatHit.CRITICAL)) {
+//             say.add("The minotaur punches you in the gut. Ouch, you felt that HARD.");
+//         }
+//
+//         say.add(" ");
+//
+//         if (markers.includes(CombatResult.KILLED)) {
+//             say.add("YOU ARE DEAD.");
+//         } else if (markers.includes(CombatResult.KNOCKED_OFF)) {
+//             say.add("You lose consciousness.");
+//         } else if (markers.includes(CombatResult.KNOCKED)) {
+//             say.add("You are knocked to the ground!");
+//         }
+//
+//         return say;
+//     })
+//     .addUnit()
+//     .setActor(MinotaurGuard)
+//     .setTarget(WorldState.player)
+//     .setWeapon(Thing)
+//     .addMarker(AdaptiveDifferential.FULLYADAPTIVE(CombatHit.MISS, CombatHit.HIT, CombatHit.CRITICAL))
+//     .addMarker(AdaptiveDifferential.FULLYADAPTIVE(CombatResult.KNOCKED, CombatResult.KILLED, CombatResult.KNOCKED_OFF))
+// ;

+ 12 - 0
package-lock.json

@@ -0,0 +1,12 @@
+{
+  "name": "The Obelisk",
+  "requires": true,
+  "lockfileVersion": 1,
+  "dependencies": {
+    "typescript": {
+      "version": "3.7.2",
+      "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.2.tgz",
+      "integrity": "sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ=="
+    }
+  }
+}

+ 4 - 1
package.json

@@ -1,4 +1,7 @@
 {
   "name": "The Obelisk",
-  "main": "dist/The Obelisk.html"
+  "main": "dist/The Obelisk.html",
+  "dependencies": {
+    "typescript": "^3.7.2"
+  }
 }