Skip to content

Commit

Permalink
Merge branch 'PhlexPlexico:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xe1os authored Apr 22, 2024
2 parents 4587ced + 7e5df69 commit e14de9d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "g5v",
"version": "1.7.0",
"version": "1.7.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
100 changes: 63 additions & 37 deletions src/components/PlayerStatTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,48 @@
<v-container class="mapinfo" fluid>
<div
class="text-subtitle-2 mapInfo"
v-if="arrMapString[index] != null"
v-if="mapStats[index] != null"
align="center"
>
{{ arrMapString[index].score }} - {{ arrMapString[index].map }}
{{ mapStats[index].score }} - {{ mapStats[index].map }}
</div>
<div
class="text-subtitle-2 mapInfo"
v-if="
arrMapString[index] != null && arrMapString[index].start != null
mapStats[index] != null && mapStats[index].start != null
"
align="center"
>
{{ arrMapString[index].start }}
{{ mapStats[index].start }}
</div>
<div
class="text-subtitle-2 mapInfo"
v-if="
arrMapString[index] != null && arrMapString[index].end != null
mapStats[index] != null && mapStats[index].end != null
"
align="center"
>
{{ arrMapString[index].end }}
{{ mapStats[index].end }}
</div>
<div
class="text-subtitle-2 mapInfo"
v-if="
arrMapString[index] != null && arrMapString[index].demo != null
mapStats[index] != null && mapStats[index].demo != null
"
align="center"
>
<v-btn
small
color="secondary"
:href="apiUrl + '/demo/' + arrMapString[index].demo"
:href="apiUrl + '/demo/' + mapStats[index].demo"
>
{{ $t("PlayerStats.Download") }}
</v-btn>
</div>
<div
class="text-subtitle-2 mapInfo"
v-if="
arrMapString[index] != null && arrMapString[index].end == null
mapStats[index] != null && mapStats[index].end == null
"
align="left"
></div>
Expand Down Expand Up @@ -113,7 +113,7 @@ export default {
return {
playerstats: [],
isLoading: true,
arrMapString: [{}],
mapStats: [],
allowRefresh: false,
timeoutId: -1,
isFinished: false,
Expand All @@ -122,7 +122,6 @@ export default {
},
created() {
this.useStreamOrStaticData();
this.getMapString();
},
computed: {
headers() {
Expand Down Expand Up @@ -239,8 +238,14 @@ export default {
async useStreamOrStaticData() {
// Template will contain v-rows/etc like on main Team page.
let matchData = await this.GetMatchData(this.match_id);
if (matchData.end_time == null) this.GetMapPlayerStatsStream(matchData);
else this.GetMapPlayerStats(matchData);
if (matchData.end_time == null) {
this.GetMapStatsStream(matchData);
this.GetMapPlayerStatsStream(matchData);
}
else {
this.getMapString(matchData);
this.GetMapPlayerStats(matchData);
}
},
async retrieveStatsHelper(serverResponse, matchData) {
if (typeof serverResponse == "string") return;
Expand Down Expand Up @@ -324,34 +329,55 @@ export default {
}
return;
},
async getMapString() {
async GetMapStatsStream(matchData) {
try {
let mapStats = await this.GetMapStats(this.match_id);
if (typeof mapStats == "string") return;
mapStats.forEach((singleMapStat, index) => {
this.arrMapString[index] = {};
this.arrMapString[index].score =
"Score: " +
singleMapStat.team1_score +
" " +
this.GetScoreSymbol(
singleMapStat.team1_score,
singleMapStat.team2_score
) +
" " +
singleMapStat.team2_score;
this.arrMapString[index].start =
"Map Start: " + new Date(singleMapStat.start_time).toLocaleString();
this.arrMapString[index].end =
singleMapStat.end_time == null
? null
: "Map End: " + new Date(singleMapStat.end_time).toLocaleString();
this.arrMapString[index].map = "Map: " + singleMapStat.map_name;
this.arrMapString[index].demo = singleMapStat.demoFile;
let sseClient = await this.GetEventMapStats(this.match_id);
await sseClient.connect();
await sseClient.on("mapstats", async message => {
await this.retrieveMapStatsHelper(message,matchData);
});
} catch (error) {
console.log("String error " + error);
console.log("Our error: " + error);
} finally {
this.isLoading = false;
}
return;
},
async getMapString(matchData) {
try {
let res = await this.GetMapStats(this.match_id);
await this.retrieveMapStatsHelper(res, matchData);
} catch (error) {
console.log("Our error: " + error);
} finally {
this.isLoading = false;
}
return;
},
async retrieveMapStatsHelper(serverResponse, matchData) {
if (typeof serverResponse == "string") return;
await serverResponse.forEach((singleMapStat, index) => {
if (!this.mapStats[index]) {
this.$set(this.mapStats, index, {});
}
this.$set(this.mapStats[index], 'score', "Score: " +
singleMapStat.team1_score +
" " +
this.GetScoreSymbol(
singleMapStat.team1_score,
singleMapStat.team2_score
) +
" " +
singleMapStat.team2_score);
this.$set(this.mapStats[index], 'start', "Map Start: " + new Date(singleMapStat.start_time).toLocaleString());
this.$set(this.mapStats[index], 'end', singleMapStat.end_time == null ?
null :
"Map End: " + new Date(singleMapStat.end_time).toLocaleString());
this.$set(this.mapStats[index], 'map', "Map: " + singleMapStat.map_name);
this.$set(this.mapStats[index], 'demo', singleMapStat.demoFile);
});
if (matchData.end_time != null) this.isFinished = true;
}
}
};
Expand Down
13 changes: 13 additions & 0 deletions src/utils/api.vue
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,19 @@ export default {
}
return message;
},
async GetEventMapStats(matchid) {
return this.$sse
.create({
url: `${process.env?.VUE_APP_G5V_API_URL ||
"/api"}/mapstats/${matchid}/stream`,
format: "json",
withCredentials: true,
polyfill: true
})
.on("error", err =>
console.error("Failed to parse or lost connection:", err)
);
},
// END MAP STATS
// BEGIN MATCH ADMIN CALLS
async PauseMatch(matchid) {
Expand Down

0 comments on commit e14de9d

Please sign in to comment.