Skip to content

Commit

Permalink
#52: add theme options
Browse files Browse the repository at this point in the history
  • Loading branch information
drweissbrot committed May 28, 2023
1 parent 858516a commit f6c96c5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
14 changes: 11 additions & 3 deletions src/server/websocket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WebSocketServer, WebSocket } from 'ws'

import { additionalState, gsiState } from './state.js'
import { getSettings } from './settings.js'

export class Websocket {
constructor(server) {
Expand All @@ -10,17 +11,24 @@ export class Websocket {
this.sendState(client)
})

// TODO
this.optionsCache = {}

setInterval(() => {
this.broadcastState()
}, 1000)
this.broadcastState() // TODO just completely remove this (probably)

// TODO run this when a value is changed on the config page instead (and maybe on a rare interval or something)
getSettings().then(({ settings }) => {
this.optionsCache = Object.fromEntries(Object.entries(settings.options).map(([key, { value }]) => [key, value]))
})
}, 5000)
}

getState() {
return {
additionalState,
gsiState,

options: this.optionsCache,
timestamp: new Date(),
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/themes/fennec/players-alive/players-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { teamColorClass } from '/hud/helpers/team-color-class.js'
export default {
computed: {
isActive() {
return !this.$round.isFreezetime
if (this.$opts['preferences.playersAlive.hideDuringFreezetime']) {
return !this.$round.isFreezetime
}

return true
},

leftTeamAlive() {
Expand Down
14 changes: 8 additions & 6 deletions src/themes/fennec/shell/shell.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<!-- <Radar /> -->
<!-- <TopBar /> -->
<PlayersAlive />
<template v-if="$map.name">
<!-- <Radar /> -->
<!-- <TopBar /> -->
<PlayersAlive />

<!-- <PlayerSidebars /> -->
<!-- <FocusedPlayer /> -->
<!-- <PlayerSidebars /> -->
<!-- <FocusedPlayer /> -->

<!-- <SeriesGraph /> -->
<!-- <SeriesGraph /> -->
</template>
11 changes: 10 additions & 1 deletion src/themes/fennec/theme.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"parent": "raw"
"parent": "raw",

"options": {
"preferences.playersAlive.hideDuringFreezetime": {
"type": "boolean",
"value": true,
"section": "Preferences",
"label": "Hide \"Players Alive\" during freezetime"
}
}
}
3 changes: 2 additions & 1 deletion src/themes/raw/core/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Vue from '/dependencies/vue.js'
import { bomb, grenades, gsiState, map, misc, players, round, rounds, teams } from '/hud/core/state.js'
import { bomb, grenades, gsiState, map, misc, options, players, round, rounds, teams } from '/hud/core/state.js'
import { connectToWebsocket } from '/hud/core/websocket.js'
import { loadModule } from '/dependencies/vue3-sfc-loader.js'
import { sfcLoaderOptions } from '/hud/core/sfc-loader-options.js'
Expand All @@ -15,6 +15,7 @@ app.config.globalProperties.$grenades = grenades
app.config.globalProperties.$gsiState = gsiState
app.config.globalProperties.$map = map
app.config.globalProperties.$misc = misc
app.config.globalProperties.$opts = options
app.config.globalProperties.$players = players
app.config.globalProperties.$round = round
app.config.globalProperties.$rounds = rounds
Expand Down
1 change: 1 addition & 0 deletions src/themes/raw/core/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { reactive } from '/dependencies/vue.js'

export const additionalState = reactive({})
export const gsiState = reactive({})
export const options = reactive({})

export const bomb = reactive({})
export const grenades = reactive([])
Expand Down
5 changes: 3 additions & 2 deletions src/themes/raw/core/websocket-on-message.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { additionalState, gsiState } from '/hud/core/state.js'
import { additionalState, gsiState, options } from '/hud/core/state.js'
import { parseGsiState } from '/hud/core/parse-gsi-state.js'

export const onMessage = (msg) => {
const data = JSON.parse(msg.data)
console.debug(data)

Object.assign(gsiState, data.gsiState)
Object.assign(additionalState, data.additionalState)
Object.assign(gsiState, data.gsiState)
Object.assign(options, data.options)

parseGsiState()
}

0 comments on commit f6c96c5

Please sign in to comment.