Skip to content

Commit e5956c2

Browse files
committed
Debugging
1 parent 892e9d1 commit e5956c2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

app/source/library/game/GamePage.svelte

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
);
213213
214214
unsubscribers.push(
215-
gameRound.subscribe(async (value) => {
215+
gameRound.subscribe((value) => {
216216
if (!value) {
217217
return;
218218
}
@@ -230,33 +230,37 @@
230230
let lastSeenRoundStatus: GameRound["status"] | null = null;
231231
unsubscribers.push(
232232
gameRoundStatus.subscribe(async (value) => {
233-
if (Boolean(value) !== Boolean($gameRound)) {
233+
const previousValue = lastSeenRoundStatus;
234+
lastSeenRoundStatus = value;
235+
const gameRoundValue = svelteStore.get(gameRound);
236+
if (Boolean(value) !== Boolean(gameRoundValue)) {
234237
throw new Error("gameRoundStatus and $gameRound out of sync");
235238
}
236239
237240
/**
238241
* Handle when the round ends in any way. PATCH the round in the backend (if applicable.)
239242
* The `ongoing` / new round creation case (POST) is not handled here, see loadRound.
240243
*/
241-
if (value !== "ongoing" && lastSeenRoundStatus === "ongoing") {
244+
if (value !== "ongoing" && previousValue === "ongoing") {
242245
const roundAttributeUpdates: Partial<Round["attributes"]> = {};
243-
if (!$gameRound) {
246+
if (!gameRoundValue) {
244247
throw new Error("round is falsy");
245248
}
246249
247250
if (value === "completed") {
248-
if ($totalScore === null) {
251+
const totalScoreValue = svelteStore.get(totalScore);
252+
if (totalScoreValue === null) {
249253
throw new Error("totalScore is undefined");
250254
}
251255
252256
roundAttributeUpdates.score = computeTotalScore(
253-
$totalScore,
254-
$gameRound,
257+
totalScoreValue,
258+
gameRoundValue,
255259
);
256260
roundAttributeUpdates.status = "completed";
257261
258262
// New device best score?
259-
if (roundAttributeUpdates.score > ($deviceBestScore ?? 0)) {
263+
if (roundAttributeUpdates.score > (svelteStore.get(deviceBestScore) ?? 0)) {
260264
deviceBestScore.set(roundAttributeUpdates.score);
261265
gameRound.update((value) => {
262266
if (!value) {
@@ -276,19 +280,17 @@
276280
roundAttributeUpdates.status = "abandoned";
277281
}
278282
279-
if ($isOrganizationUrl) {
280-
if ($gameRound.id === "local-only") {
283+
if (svelteStore.get(isOrganizationUrl)) {
284+
if (gameRoundValue.id === "local-only") {
281285
throw new Error("Round ID is 'local-only'");
282286
}
283287
await api.patchResource<Round>({
284288
attributes: roundAttributeUpdates,
285-
id: $gameRound.id,
289+
id: gameRoundValue.id,
286290
type: "round",
287291
});
288292
}
289293
}
290-
291-
lastSeenRoundStatus = value;
292294
}),
293295
);
294296

0 commit comments

Comments
 (0)