Skip to content

Commit 5cf75c7

Browse files
feat: closable modal when desynced (openfrontio#214)
![Capture d'écran 2025-03-11 215857](https://github.com/user-attachments/assets/9aec98d9-dd3c-4a00-a257-aa0acb67633c)
1 parent c4b8d6b commit 5cf75c7

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

src/client/ClientGameRunner.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ export class ClientGameRunner {
243243
"",
244244
this.lobby.gameID,
245245
this.lobby.clientID,
246+
true,
247+
"You are desynced from other players. What you see might differ from other players.",
246248
);
247-
this.stop();
248-
return;
249249
}
250250
if (message.type == "turn") {
251251
if (!this.hasJoined) {
@@ -320,12 +320,17 @@ function showErrorModal(
320320
stack: string,
321321
gameID: GameID,
322322
clientID: ClientID,
323+
closable = false,
324+
heading = "Game crashed!",
323325
) {
324326
const errorText = `Error: ${errMsg}\nStack: ${stack}`;
325-
consolex.error(errorText);
327+
328+
if (document.querySelector("#error-modal")) {
329+
return;
330+
}
326331

327332
const modal = document.createElement("div");
328-
const content = `Game crashed! game id: ${gameID}, client id: ${clientID}\nPlease paste the following in your bug report in Discord:\n${errorText}`;
333+
const content = `${heading}\n game id: ${gameID}, client id: ${clientID}\nPlease paste the following in your bug report in Discord:\n${errorText}`;
329334

330335
// Create elements
331336
const pre = document.createElement("pre");
@@ -342,11 +347,23 @@ function showErrorModal(
342347
.catch(() => (button.textContent = "Failed to copy"));
343348
});
344349

350+
const closeButton = document.createElement("button");
351+
closeButton.textContent = "X";
352+
closeButton.style.cssText =
353+
"color: white;top: 0px;right: 0px;cursor: pointer;background: red;margin-right: 0px;position: fixed;width: 40px;";
354+
closeButton.addEventListener("click", () => {
355+
modal.style.display = "none";
356+
});
357+
345358
// Add to modal
346359
modal.style.cssText =
347360
"position:fixed; padding:20px; background:white; border:1px solid black; top:50%; left:50%; transform:translate(-50%,-50%); z-index:9999;";
348361
modal.appendChild(pre);
349362
modal.appendChild(button);
363+
modal.id = "error-modal";
364+
if (closable) {
365+
modal.appendChild(closeButton);
366+
}
350367

351368
document.body.appendChild(modal);
352369
}

0 commit comments

Comments
 (0)