Skip to content

Commit 6a1b3e5

Browse files
committed
#52 Fennec: Top Bar section
1 parent 628c4b5 commit 6a1b3e5

40 files changed

+1356
-29
lines changed

src/server/gsi.js

+16
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,25 @@ const updateGsiState = (body) => {
2929
}
3030

3131
const updateAdditionalState = (body) => {
32+
updateLastKnownBombPlantedCountdown(body)
3233
updateRoundDamages(body)
3334
}
3435

36+
const updateLastKnownBombPlantedCountdown = (body) => {
37+
const bomb = body.bomb
38+
if (bomb?.state === 'defusing') return
39+
40+
if (! bomb || bomb.state !== 'planted') {
41+
additionalState.lastKnownBombPlantedCountdown = {}
42+
return
43+
}
44+
45+
additionalState.lastKnownBombPlantedCountdown = {
46+
unixTimestamp: +new Date(),
47+
value: bomb.countdown,
48+
}
49+
}
50+
3551
const updateRoundDamages = (body) => {
3652
const roundNumber = body.map?.round
3753
if (! roundNumber) return

src/server/helpers/paths.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ export const themesDirectory = `${rootDirectory}/src/themes`
99
export const userspaceDirectory = `${themesDirectory}/userspace`
1010

1111
// files
12+
export const userspaceBombsitesPath = `${userspaceDirectory}/bombsites.json`
13+
export const userspaceRadarsPath = `${userspaceDirectory}/radars.json`
1214
export const userspaceSettingsPath = `${userspaceDirectory}/theme.json`

src/server/settings.js

+27-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mkdir, readFile, writeFile } from 'fs/promises'
22

33
import { merge } from 'lodash-es'
44

5-
import { themesDirectory, userspaceDirectory, userspaceSettingsPath } from './helpers/paths.js'
5+
import { themesDirectory, userspaceBombsitesPath, userspaceDirectory, userspaceRadarsPath, userspaceSettingsPath } from './helpers/paths.js'
66
import { fileExists } from './helpers/file-exists.js'
77

88
export const initSettings = async () => {
@@ -16,18 +16,33 @@ export const initSettings = async () => {
1616
}
1717

1818
export const getSettings = async () => {
19-
const settingsObjects = [await readJson(userspaceSettingsPath)]
2019
const themeTree = ['userspace']
2120

21+
const bombsiteObjects = [await readJsonIfExists(userspaceBombsitesPath)]
22+
const radarObjects = [await readJsonIfExists(userspaceRadarsPath)]
23+
const settingsObjects = [await readJson(userspaceSettingsPath)]
24+
2225
while (settingsObjects[settingsObjects.length - 1].parent) {
2326
themeTree.push(settingsObjects[settingsObjects.length - 1].parent)
27+
2428
settingsObjects.push(
25-
await readJson(`${themesDirectory}/${settingsObjects[settingsObjects.length - 1].parent}/theme.json`)
29+
await readJson(`${themesDirectory}/${settingsObjects[settingsObjects.length - 1].parent}/theme.json`),
30+
)
31+
32+
bombsiteObjects.push(
33+
await readJsonIfExists(`${themesDirectory}/${settingsObjects[settingsObjects.length - 1].parent}/bombsites.json`),
34+
)
35+
36+
radarObjects.push(
37+
await readJsonIfExists(`${themesDirectory}/${settingsObjects[settingsObjects.length - 1].parent}/radars.json`),
2638
)
2739
}
2840

2941
return {
3042
themeTree,
43+
44+
bombsites: merge({}, ...bombsiteObjects.reverse()),
45+
radars: merge({}, ...radarObjects.reverse()),
3146
settings: merge({}, ...settingsObjects.reverse()),
3247
}
3348
}
@@ -38,3 +53,12 @@ const readJson = async (path) => {
3853
const str = await readFile(path, 'utf-8')
3954
return JSON.parse(str)
4055
}
56+
57+
const readJsonIfExists = async (path) => {
58+
try {
59+
return await readJson(path)
60+
} catch (err) {
61+
if (err.code === 'ENOENT') return {}
62+
throw err
63+
}
64+
}

src/server/state.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const gsiState = {}
22

33
export const additionalState = {
4+
lastKnownBombPlantedCountdown: {},
45
roundDamages: {},
56
}

src/server/websocket.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ export class Websocket {
1111
this.sendState(client)
1212
})
1313

14+
this.bombsitesCache = {}
1415
this.optionsCache = {}
16+
this.radarsCache = {}
1517

1618
setInterval(() => {
17-
this.broadcastState() // TODO just completely remove this (probably)
18-
1919
// TODO run this when a value is changed on the config page instead (and maybe on a rare interval or something)
20-
getSettings().then(({ settings }) => {
20+
getSettings().then(({ bombsites, radars, settings }) => {
21+
this.bombsitesCache = bombsites
2122
this.optionsCache = Object.fromEntries(Object.entries(settings.options).map(([key, { value }]) => [key, value]))
23+
this.radarsCache = radars
2224
})
25+
26+
this.broadcastState() // TODO just completely remove this (probably)
2327
}, 5000)
2428
}
2529

@@ -28,8 +32,10 @@ export class Websocket {
2832
additionalState,
2933
gsiState,
3034

35+
bombsites: this.bombsitesCache,
3136
options: this.optionsCache,
32-
timestamp: new Date(),
37+
radars: this.radarsCache,
38+
unixTimestamp: +new Date(),
3339
}
3440
}
3541

src/themes/fennec/css/base.css

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*,
22
*::after,
33
*::before {
4-
box-sizing: border-box;
54
margin: 0;
65
padding: 0;
76
}

src/themes/fennec/css/vars.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
*/
55
--background-color: green;
66
--text-color: #fff;
7+
--red: #f00;
78

9+
--counter-terrorists-rgb: 29, 158, 222;
810
--counter-terrorists: #1d9ede;
11+
--terrorists-rgb: 193, 136, 3;
912
--terrorists: #c18803;
1013

11-
--counter-terrorists-rgb: 29, 158, 222;
12-
--terrorists-rgb: 193, 136, 3;
14+
--progress-bar-fill-color-bomb: var(--red);
1315

1416
/*
1517
* Spacing, Sizes
@@ -19,6 +21,12 @@
1921
--focused-player-width: 50%;
2022
--focused-player-icon-height: 2rem;
2123

24+
--top-bar-width: 50%;
25+
--top-bar-padding-x: 0.8rem;
26+
--top-bar-score-font-size: 3rem;
27+
--top-bar-row-height: calc(2 * var(--top-bar-padding-x) + var(--top-bar-score-font-size));
28+
--top-bar-half-row-height: calc(var(--top-bar-row-height) / 2);
29+
2230
/* Viewport Margin */
2331
--viewport-margin-x: 2rem;
2432
--viewport-margin-y: 1.5rem;

src/themes/fennec/digits/digits.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
export default {
22
props: [
3-
'value',
43
'digits',
4+
'pad',
5+
'value',
56
],
67

78
computed: {
89
elements() {
9-
return `${this.value}`.padStart(this.digits, ' ').split('')
10+
return `${this.value}`.padStart(this.digits, this.pad ?? ' ').split('')
1011
},
1112
},
1213
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/* TODO this ends up not scoped */
12
@import '/hud/focused-player/name-and-stats/data-row/data-row-item-shared.css';
Loading
Loading

src/themes/fennec/img/icons/pause.svg

+1
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.progress-bar-background {
2+
width: 100%;
3+
height: 0.6rem;
4+
background: rgba(255, 255, 255, 0.5);
5+
overflow: hidden;
6+
}
7+
8+
.progress-bar-fill {
9+
height: 100%;
10+
11+
&.--to-left,
12+
&.--left {
13+
transform-origin: left;
14+
}
15+
16+
&.--to-right,
17+
&.--right {
18+
transform-origin: right;
19+
}
20+
21+
&.--ct {
22+
background: var(--counter-terrorists);
23+
}
24+
25+
&.--t {
26+
background: var(--terrorists);
27+
}
28+
29+
&.--bomb {
30+
background: var(--progress-bar-fill-color-bomb);
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="progress-bar-background">
2+
<div :class="['progress-bar-fill', `--${direction}`, colorClass]" :style="styleAttr"></div>
3+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
props: [
3+
'colorClass',
4+
'direction',
5+
'max',
6+
'min',
7+
'value',
8+
],
9+
10+
computed: {
11+
styleAttr() {
12+
const min = this.min || 0
13+
const max = this.max ?? 1
14+
15+
const percent = (this.value - min) / (max - min)
16+
17+
return `transform: scaleX(${percent})`
18+
},
19+
},
20+
}

src/themes/fennec/shell/shell.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template v-if="$map.name">
22
<!-- <Radar /> -->
3-
<!-- <TopBar /> -->
3+
<TopBar />
44
<PlayersAlive />
55

66
<!-- <PlayerSidebars /> -->

src/themes/fennec/shell/shell.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import FocusedPlayer from '/hud/focused-player/focused-player.vue'
22
import PlayersAlive from '/hud/players-alive/players-alive.vue'
3+
import TopBar from '/hud/top-bar/top-bar.vue'
34

45
export default {
56
components: {
67
FocusedPlayer,
78
PlayersAlive,
9+
TopBar,
810
},
911
}

src/themes/fennec/theme.json

+35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22
"parent": "raw",
33

44
"options": {
5+
"cvars.mp_c4timer": {
6+
"type": "number",
7+
"value": 40,
8+
"section": "Cvars",
9+
"label": "Value of mp_c4timer, i.e. the number of seconds from when the bomb is planted until it explodes"
10+
},
11+
12+
"cvars.mp_maxrounds": {
13+
"type": "number",
14+
"value": 30,
15+
"section": "Cvars",
16+
"label": "Value of mp_maxrounds, i.e. the maximum number of rounds played in regulation"
17+
},
18+
19+
"cvars.mp_overtime_maxrounds": {
20+
"type": "number",
21+
"value": 6,
22+
"section": "Cvars",
23+
"label": "Value of mp_overtime_maxrounds, i.e. the maximum number of rounds played per overtime"
24+
},
25+
26+
"cvars.mp_team_timeout_max": {
27+
"type": "number",
28+
"value": 4,
29+
"section": "Cvars",
30+
"label": "Value of mp_team_timeout_max, i.e. the number of tactical timeouts available per team"
31+
},
32+
33+
"cvars.mp_team_timeout_time": {
34+
"type": "number",
35+
"value": 30,
36+
"section": "Cvars",
37+
"label": "Value of mp_team_timeout_time, i.e. the duration in seconds of each tactical timeout"
38+
},
39+
540
"preferences.playersAlive.hideDuringFreezetime": {
641
"type": "boolean",
742
"value": true,

0 commit comments

Comments
 (0)