diff --git a/app/Http/Controllers/ScoresController.php b/app/Http/Controllers/ScoresController.php index c1ea826a339..6d45fc44415 100644 --- a/app/Http/Controllers/ScoresController.php +++ b/app/Http/Controllers/ScoresController.php @@ -73,6 +73,7 @@ public function show($mode, $id) $scoreJson = json_item($score, 'Score', array_merge([ 'beatmap.max_combo', 'beatmapset', + 'difficulty_rating', 'rank_global', ], $userIncludes)); diff --git a/app/Models/Score/Model.php b/app/Models/Score/Model.php index 70c816d71ad..c84f5285aee 100644 --- a/app/Models/Score/Model.php +++ b/app/Models/Score/Model.php @@ -54,6 +54,18 @@ public static function getMode(): string return snake_case(get_class_basename(static::class)); } + public function difficultyRating(): ?float + { + $value = $this->beatmap + ->difficulty() + ->where('mode', Beatmap::modeInt(static::getMode())) + ->where('mods', ModsHelper::toBitset($this->enabled_mods)) + ->first() + ?->diff_unified; + + return $value === null ? null : round($value, 2); + } + public function scopeDefault($query) { return $query diff --git a/app/Transformers/ScoreTransformer.php b/app/Transformers/ScoreTransformer.php index 99a0fdbe69f..67c0bddfb74 100644 --- a/app/Transformers/ScoreTransformer.php +++ b/app/Transformers/ScoreTransformer.php @@ -27,6 +27,7 @@ class ScoreTransformer extends TransformerAbstract 'beatmap', 'beatmapset', 'current_user_attributes', + 'difficulty_rating', 'rank_country', 'rank_global', 'weight', @@ -125,6 +126,11 @@ public function includeBeatmapset($score) return $this->item($score->beatmap->beatmapset, new BeatmapsetCompactTransformer()); } + public function includeDifficultyRating($score) + { + return $this->primitive($score->difficultyRating()); + } + public function includeWeight($score) { if ($score instanceof ScoreBest && $score->weight !== null) { diff --git a/resources/assets/lib/interfaces/score-json.ts b/resources/assets/lib/interfaces/score-json.ts index d69c30f6fc5..4d84cfad280 100644 --- a/resources/assets/lib/interfaces/score-json.ts +++ b/resources/assets/lib/interfaces/score-json.ts @@ -24,6 +24,7 @@ export default interface ScoreJson { current_user_attributes: { pin?: ScoreCurrentUserPinJson; }; + difficulty_rating?: number | null; id: number; max_combo: number; mode?: GameMode; diff --git a/resources/assets/lib/scores-show/main.tsx b/resources/assets/lib/scores-show/main.tsx index 721c49ccd49..e354f834ff8 100644 --- a/resources/assets/lib/scores-show/main.tsx +++ b/resources/assets/lib/scores-show/main.tsx @@ -20,6 +20,10 @@ export default function Main(props: Props) { throw new Error('score json is missing beatmap or beatmapset details'); } + if (props.score.difficulty_rating != null) { + beatmap.difficulty_rating = props.score.difficulty_rating; + } + return ( <>