From 2852e0c0ede465a6451b28bce12ad1e69a56f52c Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 23 Oct 2024 20:52:57 +0100 Subject: [PATCH] track difficulty and characteristic for scoresaber scores --- projects/backend/src/service/score.service.ts | 15 +++++++++------ .../src/model/score/impl/scoresaber-score.ts | 5 +++-- projects/common/src/model/score/score.ts | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/projects/backend/src/service/score.service.ts b/projects/backend/src/service/score.service.ts index f6d46c2..e42d2f8 100644 --- a/projects/backend/src/service/score.service.ts +++ b/projects/backend/src/service/score.service.ts @@ -52,8 +52,8 @@ export class ScoreService { } const { score: scoreToken, leaderboard: leaderboardToken } = playerScore; - const score = getScoreSaberScoreFromToken(scoreToken, leaderboardToken, scoreToken.leaderboardPlayerInfo.id); const leaderboard = getScoreSaberLeaderboardFromToken(leaderboardToken); + const score = getScoreSaberScoreFromToken(scoreToken, leaderboard, scoreToken.leaderboardPlayerInfo.id); const playerInfo = score.playerInfo; // Not ranked @@ -124,7 +124,8 @@ export class ScoreService { * @param score the score to track * @param leaderboard the leaderboard to track */ - public static async trackScoreSaberScore({ score, leaderboard }: ScoreSaberPlayerScoreToken) { + public static async trackScoreSaberScore({ score, leaderboard: leaderboardToken }: ScoreSaberPlayerScoreToken) { + const leaderboard = getScoreSaberLeaderboardFromToken(leaderboardToken); const playerId = score.leaderboardPlayerInfo.id; const playerName = score.leaderboardPlayerInfo.name; const player: PlayerDocument | null = await PlayerModel.findById(playerId); @@ -164,6 +165,8 @@ export class ScoreService { playerId: playerId, leaderboardId: leaderboard.id, score: scoreToken.score, + difficulty: leaderboard.difficulty.difficulty, + characteristic: leaderboard.difficulty.characteristic, }) ) { console.log( @@ -328,13 +331,13 @@ export class ScoreService { ); for (const token of leaderboardScores.playerScores) { - const score = getScoreSaberScoreFromToken(token.score, token.leaderboard, playerId); - if (score == undefined) { + const leaderboard = getScoreSaberLeaderboardFromToken(token.leaderboard); + if (leaderboard == undefined) { continue; } - const leaderboard = getScoreSaberLeaderboardFromToken(token.leaderboard); - if (leaderboard == undefined) { + const score = getScoreSaberScoreFromToken(token.score, leaderboard, playerId); + if (score == undefined) { continue; } diff --git a/projects/common/src/model/score/impl/scoresaber-score.ts b/projects/common/src/model/score/impl/scoresaber-score.ts index a1cac85..7e4fbd8 100644 --- a/projects/common/src/model/score/impl/scoresaber-score.ts +++ b/projects/common/src/model/score/impl/scoresaber-score.ts @@ -2,7 +2,6 @@ import { getModelForClass, modelOptions, plugin, Prop, ReturnModelType, Severity import Score from "../score"; import { Modifier } from "../../../score/modifier"; import ScoreSaberScoreToken from "../../../types/token/scoresaber/score-saber-score-token"; -import ScoreSaberLeaderboardToken from "../../../types/token/scoresaber/score-saber-leaderboard-token"; import ScoreSaberLeaderboard from "../../../leaderboard/impl/scoresaber-leaderboard"; import { type ScoreSaberLeaderboardPlayerInfoToken } from "../../../types/token/scoresaber/score-saber-leaderboard-player-info-token"; import { Document } from "mongoose"; @@ -82,7 +81,7 @@ export type ScoreSaberScore = InstanceType; */ export function getScoreSaberScoreFromToken( token: ScoreSaberScoreToken, - leaderboard: ScoreSaberLeaderboardToken | ScoreSaberLeaderboard, + leaderboard: ScoreSaberLeaderboard, playerId?: string ): ScoreSaberScore { const modifiers: Modifier[] = @@ -100,6 +99,8 @@ export function getScoreSaberScoreFromToken( return { playerId: playerId || token.leaderboardPlayerInfo.id, leaderboardId: leaderboard.id, + difficulty: leaderboard.difficulty.difficulty, + characteristic: leaderboard.difficulty.characteristic, score: token.baseScore, accuracy: (token.baseScore / leaderboard.maxScore) * 100, rank: token.rank, diff --git a/projects/common/src/model/score/score.ts b/projects/common/src/model/score/score.ts index 89a13fe..5770b97 100644 --- a/projects/common/src/model/score/score.ts +++ b/projects/common/src/model/score/score.ts @@ -1,7 +1,8 @@ import { Modifier } from "../../score/modifier"; import { AdditionalScoreData } from "../additional-score-data/additional-score-data"; -import { type Leaderboards } from "../../leaderboard"; import { prop } from "@typegoose/typegoose"; +import { type MapDifficulty } from "@ssr/score/map-difficulty"; +import { type MapCharacteristic } from "@ssr/types/map-characteristic"; /** * The model for a score. @@ -15,11 +16,22 @@ export default class Score { /** * The id of the player who set the score. - * @private */ @prop({ required: true, index: true }) public readonly playerId!: string; + /** + * The map difficulty played in the score. + */ + @prop({ required: true }) + public readonly difficulty!: MapDifficulty; + + /** + * The characteristic of the map. + */ + @prop({ required: true }) + public readonly characteristic!: MapCharacteristic; + /** * The base score for the score. * @private