diff --git a/src/components/PlayerList.vue b/src/components/PlayerList.vue
index 721812f..ba16aee 100644
--- a/src/components/PlayerList.vue
+++ b/src/components/PlayerList.vue
@@ -2,26 +2,26 @@
-
+
{{ index+1 }}
-
{{ players[playerId].username }}
-
{{ players[playerId].kills }}
-
{{ players[playerId].deaths }}
-
{{ Math.round(players[playerId].kills / Math.max(1, players[playerId].deaths) * 100) / 100 }}
-
{{ players[playerId].max_distance }}
-
{{ Math.round(((players[playerId].total_distance / players[playerId].kills) || 0) * 100) / 100 }}
+
{{ player.username }}
+
{{ player.kills }}
+
{{ player.deaths }}
+
{{ Math.round(player.kills / Math.max(1, player.deaths) * 100) / 100 }}
+
{{ player.max_distance }}
+
{{ Math.round(((player.total_distance / player.kills) || 0) * 100) / 100 }}
@@ -49,17 +49,44 @@ export default defineComponent({
const data = this.store.getPlayerList(withoutPlayer)?.value.data
if (!data) return this.store.fetchPlayers(withoutPlayer).value.data
return data
+ },
+ playerList ():(Player & {id:string})[] {
+ if (!this.players) return []
+ let players = Object.entries(this.players).map(e => ({ id: e[0], ...e[1] }))
+
+ if (this.sortingData.argument === 'username') {
+ const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' })
+ players.sort((a: Player, b: Player) => {
+ return collator.compare(a.username, b.username)
+ })
+ } else if (this.sortingData.argument === 'k/d') {
+ players.sort((a: Player, b: Player) => {
+ return a.kills / Math.max(1, a.deaths) - b.kills / Math.max(1, b.deaths)
+ })
+ } else if (this.sortingData.argument === 'avg_distance') {
+ players.sort((a: Player, b: Player) => {
+ return ((a.total_distance / a.kills) || 0) - ((b.total_distance / b.kills) || 0)
+ })
+ } else {
+ const argument = this.sortingData.argument
+ players.sort((a: Player, b: Player) => {
+ return a[argument] - b[argument]
+ })
+ }
+
+ if (this.sortingData.direction < 0) {
+ players.reverse()
+ }
+
+ players = players.slice(0, 500)
+ return players
}
},
watch: {
players: {
handler (newval: { [key: string]: Player }): void {
if (!newval) return
- this.playerIdList = []
this.sortingData.direction *= -1
- this.playerIdList = Object.keys(newval)
- this.sortPlayerList(this.sortingData.argument)
- this.playerIdList = this.playerIdList.slice(0, 500)
},
immediate: true
},
@@ -74,41 +101,6 @@ export default defineComponent({
element[0].scrollIntoView({ behavior: 'smooth', block: 'center' })
},
methods: {
- sortPlayerList (arg: ((keyof Player) | 'k/d' | 'avg_distance')) {
- if (arg === this.sortingData.argument) {
- this.sortingData.direction *= -1
- } else {
- if (arg === 'username') {
- this.sortingData.direction = 1
- }
- }
- this.sortingData.argument = arg
-
- this.playerIdList.sort((a: string, b: string) => {
- if (!this.players) {
- return 0
- }
- let varA, varB
- if (arg === 'k/d') {
- varA = this.players[a].kills / Math.max(1, this.players[a].deaths)
- varB = this.players[b].kills / Math.max(1, this.players[b].deaths)
- } else if (arg === 'avg_distance') {
- varA = (this.players[a].total_distance / this.players[a].kills) || 0
- varB = (this.players[b].total_distance / this.players[b].kills) || 0
- } else {
- varA = this.players[a][arg]
- varB = this.players[b][arg]
- }
- if (varA === undefined || varB === undefined) return 0
- if (varA < varB) {
- return -1 * this.sortingData.direction
- }
- if (varA > varB) {
- return 1 * this.sortingData.direction
- }
- return 0
- })
- },
selectNextPlayer (e: KeyboardEvent) {
const values = {
Home: -Infinity,
@@ -128,6 +120,14 @@ export default defineComponent({
if (nextIndex >= this.playerIdList.length) nextIndex = this.playerIdList.length - 1
if (nextIndex < 0) nextIndex = 0
this.$emit('highlightPlayer', this.playerIdList[nextIndex])
+ },
+ updateSort (argument:string) {
+ if (this.sortingData.argument === argument) {
+ this.sortingData.direction *= -1
+ } else {
+ this.sortingData.direction = -1
+ }
+ this.sortingData.argument = argument as typeof this.sortingData.argument
}
}
diff --git a/src/components/WeaponChart.vue b/src/components/WeaponChart.vue
index de89df3..46da9cd 100644
--- a/src/components/WeaponChart.vue
+++ b/src/components/WeaponChart.vue
@@ -103,7 +103,7 @@ export default defineComponent({
datalabels: {
formatter: (value: any, context: any) => {
const weaponId = this.sortedWeaponList[context.dataIndex]
- if (!(weapons as {[key:string]:string})[weaponId]) console.log(weaponId)
+ // if (!(weapons as {[key:string]:string})[weaponId]) console.log(weaponId)
return (weapons as {[key:string]:string})[weaponId] || weaponId
},
backgroundColor: (context: any) => {
diff --git a/src/stores/kill.ts b/src/stores/kill.ts
index 0c0243b..af04a22 100644
--- a/src/stores/kill.ts
+++ b/src/stores/kill.ts
@@ -43,7 +43,7 @@ export interface KillData
{
export interface Player extends Kill {
username: string;
// eslint-disable-next-line camelcase
- deaths_while_equipped?: number;
+ // deaths_while_equipped?: number;
}
export interface Weapon extends Kill {
diff --git a/src/views/PlayerView.vue b/src/views/PlayerView.vue
index 343b9d3..cc265c2 100644
--- a/src/views/PlayerView.vue
+++ b/src/views/PlayerView.vue
@@ -21,15 +21,15 @@
>
+ :options="sortedPlayerList" :allow-empty="true" :custom-label="((e:Player) => e?.username)">