diff --git a/theme/config.json b/theme/config.json index 1d5a0a1..d32b227 100644 --- a/theme/config.json +++ b/theme/config.json @@ -1,5 +1,6 @@ { "TrackSolved": true, "URLInScoreboard": true, + "Messages": "", "__sentry__": "this is here so you don't have to remember to take the comma off the last item" } \ No newline at end of file diff --git a/theme/index.mjs b/theme/index.mjs index 231c845..d30c013 100644 --- a/theme/index.mjs +++ b/theme/index.mjs @@ -68,6 +68,10 @@ class App { */ async UpdateConfig() { this.config = await common.Config() + + for (let e of document.querySelectorAll(".messages")) { + e.innerHTML = this.config.Messages || "" + } } /** @@ -79,9 +83,6 @@ class App { */ async UpdateState() { this.state = await this.server.GetState() - for (let e of document.querySelectorAll(".messages")) { - e.innerHTML = this.state.Messages - } // Update elements with data-track-solved for (let e of document.querySelectorAll("[data-track-solved]")) { @@ -133,7 +134,7 @@ class App { if (this.state.DevelopmentMode()) { let a = h.appendChild(document.createElement('a')) a.classList.add("mothball") - a.textContent = "📦" + a.textContent = "⬇️" a.href = this.server.URL(`mothballer/${cat}.mb`) a.title = "Download a compiled puzzle for this category" } diff --git a/theme/moth.mjs b/theme/moth.mjs index c1db74b..e59dfcb 100644 --- a/theme/moth.mjs +++ b/theme/moth.mjs @@ -352,7 +352,7 @@ class State { * @param {Object} obj Raw state data */ constructor(server, obj) { - for (let key of ["Config", "Messages", "TeamNames", "PointsLog"]) { + for (let key of ["Config", "TeamNames", "PointsLog"]) { if (!obj[key]) { throw(`Missing state property: ${key}`) } diff --git a/theme/puzzle.mjs b/theme/puzzle.mjs index 6f886d5..ef830a3 100644 --- a/theme/puzzle.mjs +++ b/theme/puzzle.mjs @@ -142,9 +142,24 @@ async function loadPuzzle(category, points) { } let puzzle = server.GetPuzzle(category, points) + console.time("Populate") - await puzzle.Populate() - console.timeEnd("Populate") + try { + await puzzle.Populate() + } + catch { + let error = puzzleElement().appendChild(document.createElement("pre")) + error.classList.add("notification", "error") + error.textContent = puzzle.Error.Body + return + } + finally { + console.timeEnd("Populate") + } + + console.info(`Setting base tag to ${contentBase}`) + let baseElement = document.head.appendChild(document.createElement("base")) + baseElement.href = contentBase console.info("Tweaking HTML...") let title = `${category} ${points}` @@ -183,9 +198,6 @@ async function loadPuzzle(category, points) { } } - let baseElement = document.head.appendChild(document.createElement("base")) - baseElement.href = contentBase - window.app.puzzle = puzzle console.info("window.app.puzzle =", window.app.puzzle)