Skip to content

Commit a664925

Browse files
swz-gitVirxEC
andcommitted
Fix loading botlist from localstorage
Closes #87 Co-authored-by: Eric Veilleux <virx@virxcase.dev>
1 parent c13297d commit a664925

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

frontend/src/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,40 @@ import {
1010
import App from "./App.svelte";
1111
import SuperJSON from "superjson";
1212

13+
SuperJSON.registerClass(BotInfo);
14+
SuperJSON.registerClass(PsyonixBotInfo);
15+
SuperJSON.registerClass(HumanInfo);
16+
SuperJSON.registerClass(LoadoutConfig);
17+
1318
const app: any = mount(App, {
1419
target: document.body,
1520
// props: {
1621
// name: "world",
1722
// },
1823
});
1924

20-
SuperJSON.registerClass(BotInfo);
21-
SuperJSON.registerClass(PsyonixBotInfo);
22-
SuperJSON.registerClass(HumanInfo);
23-
2425
export function parseJSON(item: string | null): any | null {
2526
if (item === null) {
26-
return null;
27+
return null
2728
}
2829

2930
try {
3031
return JSON.parse(item);
31-
} catch {
32+
} catch (e) {
33+
console.warn("JSON Parse error", e)
34+
return null;
35+
}
36+
}
37+
38+
export function parseSuperJSON(item: string | null): any | null {
39+
if (item === null) {
40+
return null
41+
}
42+
43+
try {
44+
return SuperJSON.parse(item);
45+
} catch (e) {
46+
console.warn("SuperJSON Parse error", e)
3247
return null;
3348
}
3449
}

frontend/src/pages/Home.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import {
2222
type ToggleableScript,
2323
draggablePlayerToPlayerJs,
2424
parseJSON,
25+
parseSuperJSON,
2526
} from "../index";
2627
import { mapStore } from "../settings";
2728
import {
2829
DebugRendering,
2930
ExistingMatchBehavior,
3031
} from "../../bindings/github.com/RLBot/go-interface/flat/models.js";
32+
import SuperJSON from "superjson";
3133
3234
let {
3335
paths = $bindable([]),
@@ -111,10 +113,10 @@ let loadingPlayers = $state(false);
111113
112114
let players: DraggablePlayer[] = $state(BASE_PLAYERS.slice(1));
113115
let bluePlayers: DraggablePlayer[] = $state(
114-
parseJSON(localStorage.getItem("BLUE_PLAYERS")) || [BASE_PLAYERS[0]],
116+
parseSuperJSON(localStorage.getItem("BLUE_PLAYERS")) || [BASE_PLAYERS[0]],
115117
);
116118
let orangePlayers: DraggablePlayer[] = $state(
117-
parseJSON(localStorage.getItem("ORANGE_PLAYERS")) || [],
119+
parseSuperJSON(localStorage.getItem("ORANGE_PLAYERS")) || [],
118120
);
119121
let showHuman = $derived(
120122
!(
@@ -124,10 +126,10 @@ let showHuman = $derived(
124126
);
125127
126128
$effect(() => {
127-
localStorage.setItem("BLUE_PLAYERS", JSON.stringify(bluePlayers));
129+
localStorage.setItem("BLUE_PLAYERS", SuperJSON.stringify(bluePlayers));
128130
});
129131
$effect(() => {
130-
localStorage.setItem("ORANGE_PLAYERS", JSON.stringify(orangePlayers));
132+
localStorage.setItem("ORANGE_PLAYERS", SuperJSON.stringify(orangePlayers));
131133
});
132134
133135
let latestScriptUpdateTime = null;

0 commit comments

Comments
 (0)