mirror of https://github.com/dirtbags/moth.git
Compare commits
No commits in common. "6ff379e0f405f72e3001f218066897b6c58677ed" and "3d8c47d3167d0f6cecdd82d98f0c4ef16d65e77c" have entirely different histories.
6ff379e0f4
...
3d8c47d316
|
@ -1,13 +1,6 @@
|
|||
{
|
||||
"TrackSolved": true,
|
||||
"Scoreboard": {
|
||||
"DisplayServerURL": true,
|
||||
"ShowCategoryLeaders": true,
|
||||
"ReplayHistory": true,
|
||||
"ReplayFPS": 30,
|
||||
"ReplayDurationMS": 2000,
|
||||
"": ""
|
||||
},
|
||||
"URLInScoreboard": true,
|
||||
"Messages": "<!-- Messages can go here (HTML) -->",
|
||||
"": "this is here so you don't have to remember to take the comma off the last item"
|
||||
"__sentry__": "this is here so you don't have to remember to take the comma off the last item"
|
||||
}
|
|
@ -2,16 +2,14 @@ import * as moth from "./moth.mjs"
|
|||
import * as common from "./common.mjs"
|
||||
|
||||
const server = new moth.Server(".")
|
||||
const ReplayDuration = 0.3 * common.Second
|
||||
const MaxFrameRate = 60
|
||||
/** Don't let any team's score exceed this percentage width */
|
||||
const MaxScoreWidth = 90
|
||||
const MaxScoreWidth = 95
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves after timeout.
|
||||
*
|
||||
* This uses setTimeout instead of some other fancy thing like
|
||||
* requestAnimationFrame, because who actually cares about scoreboard update
|
||||
* framerate?
|
||||
*
|
||||
* @param {Number} timeout How long to sleep (milliseconds)
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
@ -25,26 +23,10 @@ function sleep(timeout) {
|
|||
* The update is animated, because I think that looks cool.
|
||||
*/
|
||||
async function update() {
|
||||
let config = {}
|
||||
try {
|
||||
config = await common.Config()
|
||||
}
|
||||
catch (err) {
|
||||
console.warn("Parsing config.json:", err)
|
||||
}
|
||||
|
||||
// Pull configuration settings
|
||||
let ScoreboardConfig = config.Scoreboard ?? {}
|
||||
let ReplayHistory = ScoreboardConfig.ReplayHistory ?? false
|
||||
let ReplayDurationMS = ScoreboardConfig.ReplayDurationMS ?? 300
|
||||
let ReplayFPS = ScoreboardConfig.ReplayFPS ?? 24
|
||||
if (!config.Scoreboard) {
|
||||
console.warn("config.json has empty Scoreboard section")
|
||||
}
|
||||
|
||||
let config = await common.Config()
|
||||
for (let e of document.querySelectorAll(".location")) {
|
||||
e.textContent = common.BaseURL
|
||||
e.classList.toggle("hidden", !ScoreboardConfig.DisplayServerURL)
|
||||
e.classList.toggle("hidden", !config.URLInScoreboard)
|
||||
}
|
||||
|
||||
let state = await server.GetState()
|
||||
|
@ -52,21 +34,19 @@ async function update() {
|
|||
let logSize = state.PointsLog.length
|
||||
|
||||
// Figure out the timing so that we can replay the scoreboard in about
|
||||
// ReplayDurationMS, but no more than 24 frames per second.
|
||||
// ReplayDuration, but no more than 24 frames per second.
|
||||
let frameModulo = 1
|
||||
let delay = 0
|
||||
while (delay < (common.Second / ReplayFPS)) {
|
||||
while (delay < (common.Second / MaxFrameRate)) {
|
||||
frameModulo += 1
|
||||
delay = ReplayDurationMS / (logSize / frameModulo)
|
||||
delay = ReplayDuration / (logSize / frameModulo)
|
||||
}
|
||||
|
||||
let frame = 0
|
||||
for (let scores of state.ScoresHistory()) {
|
||||
frame += 1
|
||||
if (frame < state.PointsLog.length) { // Always render the last frame
|
||||
if (!ReplayHistory || (frame % frameModulo)) { // Skip if we're not animating, or if we need to drop frames
|
||||
continue
|
||||
}
|
||||
if ((frame < state.PointsLog.length) && (frame % frameModulo)) {
|
||||
continue
|
||||
}
|
||||
|
||||
while (rankingsElement.firstChild) rankingsElement.firstChild.remove()
|
||||
|
@ -103,7 +83,7 @@ async function update() {
|
|||
block.title = `${points} points`
|
||||
block.style.width = `${width}%`
|
||||
block.classList.add("category", `cat${categoryNumber}`)
|
||||
block.classList.toggle("topscore", (score == 1) && ScoreboardConfig.ShowCategoryLeaders)
|
||||
block.classList.toggle("topscore", score == 1)
|
||||
|
||||
categoryNumber += 1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue