Skip to content

Commit

Permalink
#52 Cleanup: series map numbers helper
Browse files Browse the repository at this point in the history
  • Loading branch information
drweissbrot committed Jun 18, 2023
1 parent c926b56 commit 16ae047
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 54 deletions.
13 changes: 13 additions & 0 deletions src/themes/fennec/helpers/series-map-numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// needs to be a `function` so `this` is the Vue component
export function seriesMapNumbers() {
const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) {
const mapNumber = Number(key.substring(12).split('.', 2)[0])
mapNumbers.add(mapNumber)
}
}

return [...mapNumbers].sort((a, b) => a - b)
}
13 changes: 5 additions & 8 deletions src/themes/fennec/series-graph/series-graph.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { formatMapName } from '/hud/helpers/format-map-name.js'
import { seriesMapNumbers } from '/hud/helpers/series-map-numbers.js'
import Match from '/hud/series-graph/match/match.vue'

export default {
Expand All @@ -7,21 +8,17 @@ export default {
},

computed: {
matches() {
const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) mapNumbers.add(key.substring(12).split('.', 2)[0])
}
seriesMapNumbers,

matches() {
const maps = []

for (const mapNumber of [...mapNumbers].sort((a, b) => Number(a) - Number(b))) {
for (const mapNumber of this.seriesMapNumbers) {
const mapName = this.$opts[`series.maps.${mapNumber}.name`]
const scoreA = this.$opts[`series.maps.${mapNumber}.pickTeamScore`]
const scoreB = this.$opts[`series.maps.${mapNumber}.enemyTeamScore`]

const isOnlyMatch = mapNumbers.size === 1
const isOnlyMatch = this.seriesMapNumbers.length === 1
const isFirstMapWithoutScores = ! scoreA && ! scoreB && (mapNumber === 1 || maps[maps.length - 1]?.scores)

maps.push({
Expand Down
16 changes: 7 additions & 9 deletions src/themes/fennec/sidebars/sidebar/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { seriesMapNumbers } from '/hud/helpers/series-map-numbers.js'
import Player from '/hud/sidebars/sidebar/player/player.vue'
import TeamEquipment from '/hud/sidebars/sidebar/team-equipment/team-equipment.vue'
import TeamGrenades from '/hud/sidebars/sidebar/team-grenades/team-grenades.vue'
Expand All @@ -21,14 +22,11 @@ export default {

hasSeriesGraph() {
if (this.$opts['preferences.seriesGraph.showMapForOnlyMatch']) return true

const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) mapNumbers.add(key.substring(12).split('.', 2)[0])
}

return mapNumbers.size > 1
return this.seriesMapNumbers().length > 1
},
}
},

methods: {
seriesMapNumbers,
},
}
13 changes: 6 additions & 7 deletions src/themes/fennec/top-bar/center/center.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { seriesMapNumbers } from '/hud/helpers/series-map-numbers.js'
import CurrentMap from '/hud/top-bar/center/current-map/current-map.vue'
import CurrentRound from '/hud/top-bar/center/current-round/current-round.vue'
import Digits from '/hud/digits/digits.vue'
Expand All @@ -17,13 +18,11 @@ export default {

computed: {
isMultipleMapSeries() {
const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) mapNumbers.add(key.substring(12).split('.', 2)[0])
}

return mapNumbers.size > 1
return this.seriesMapNumbers().length > 1
},
},

methods: {
seriesMapNumbers,
},
}
24 changes: 8 additions & 16 deletions src/themes/fennec/top-bar/center/current-map/current-map.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
import { seriesMapNumbers } from '/hud/helpers/series-map-numbers.js'

export default {
computed: {
currentMapNumber() {
const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) mapNumbers.add(key.substring(12).split('.', 2)[0])
}
seriesMapNumbers,

if (mapNumbers.size === 1) return 1
currentMapNumber() {
if (this.seriesMapNumbers.length < 2) return 1

for (const mapNumber of [...mapNumbers].sort((a, b) => Number(a) - Number(b))) {
for (const mapNumber of this.seriesMapNumbers) {
const scoreA = this.$opts[`series.maps.${mapNumber}.pickTeamScore`]
const scoreB = this.$opts[`series.maps.${mapNumber}.enemyTeamScore`]

const isFirstMapWithoutScores = !scoreA && !scoreB
const isFirstMapWithoutScores = ! scoreA && ! scoreB
if (isFirstMapWithoutScores) return mapNumber
}

return 1
},

seriesLength() {
const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) mapNumbers.add(key.substring(12).split('.', 2)[0])
}

return mapNumbers.size
return this.seriesMapNumbers.length
},
},
}
14 changes: 7 additions & 7 deletions src/themes/fennec/top-bar/center/map-wins/map-wins.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { seriesMapNumbers } from '/hud/helpers/series-map-numbers.js'
import { teamColorClass } from '/hud/helpers/team-color-class.js'

export default {
Expand All @@ -16,12 +17,7 @@ export default {
},

pips() {
const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) mapNumbers.add(key.substring(12).split('.', 2)[0])
}

const mapNumbers = this.seriesMapNumbers()
const pips = []

for (const mapNumber of mapNumbers) {
Expand All @@ -34,8 +30,12 @@ export default {
} else if (scoreB > scoreA) pips.push(true)
}

const maxMapWins = Math.floor(mapNumbers.size / 2) + 1
const maxMapWins = Math.floor(mapNumbers.length / 2) + 1
return [...pips, ...new Array(maxMapWins - pips.length).fill(false)]
},
},

methods: {
seriesMapNumbers,
},
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { seriesMapNumbers } from '/hud/helpers/series-map-numbers.js'

export default {
computed: {
isMatchPointRoundsActive() {
Expand All @@ -6,13 +8,11 @@ export default {
},

isMultipleMapSeries() {
const mapNumbers = new Set()

for (const key of Object.keys(this.$opts)) {
if (key.startsWith('series.maps.')) mapNumbers.add(key.substring(12).split('.', 2)[0])
}

return mapNumbers.size > 1
return this.seriesMapNumbers().length > 1
},
},

methods: {
seriesMapNumbers,
},
}

0 comments on commit 16ae047

Please sign in to comment.