Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per-beatmap team ranking #11989

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
private static function assertSupporterOnlyOptions(?User $currentUser, string $type, array $mods): void
{
$isSupporter = $currentUser !== null && $currentUser->isSupporter();
if ($type !== 'global' && !$isSupporter) {
if (!in_array($type, ScoreSearchParams::FREE_TYPES, true) && !$isSupporter) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if it makes more sense to make it SUPPORTER_TYPES now if the condition is no longer simply !== 'global'

throw new InvariantException(osu_trans('errors.supporter_only'));
}
if (!empty($mods) && !is_api_request() && !$isSupporter) {
Expand Down
3 changes: 3 additions & 0 deletions app/Libraries/Search/ScoreSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public function getQuery(): BoolQuery
case 'friend':
$query->filter(['terms' => ['user_id' => $this->params->getFriendIds()]]);
break;
case 'team':
$query->filter(['terms' => ['user_id' => $this->params->getTeamMemberIds()]]);
break;
}

$beforeTotalScore = $this->params->beforeTotalScore;
Expand Down
8 changes: 7 additions & 1 deletion app/Libraries/Search/ScoreSearchParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

class ScoreSearchParams extends SearchParams
{
const VALID_TYPES = ['global', 'country', 'friend'];
const DEFAULT_TYPE = 'global';
const FREE_TYPES = ['global', 'team'];
const VALID_TYPES = ['global', 'country', 'friend', 'team'];

public ?array $beatmapIds = null;
public ?Score $beforeScore = null;
Expand Down Expand Up @@ -103,6 +104,11 @@ public function getFriendIds(): array
return [...$this->user->friends()->allRelatedIds(), $this->user->getKey()];
}

public function getTeamMemberIds(): array
{
return $this->user?->team?->members()->pluck('user_id')->all() ?? [];
}

public function getType(): string
{
return $this->type;
Expand Down
6 changes: 5 additions & 1 deletion resources/js/beatmapsets-show/scoreboard/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ export default class Controller {
return 'unranked';
}

if (!core.currentUser?.is_supporter && (this.currentType !== 'global' || this.enabledMods.size > 0)) {
if (!core.currentUser?.is_supporter && this.requiresSupporter) {
return 'supporter_only';
}

return this.xhrState;
}

get requiresSupporter() {
return !['global', 'team'].includes(this.currentType) || this.enabledMods.size > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be a const Set<ScoreboardType> (also maybe make it match against supporter required instead of not free)

}

constructor(private readonly container: HTMLElement, private readonly getBeatmap: () => BeatmapExtendedJson) {
let storedState: StoredState | null = null;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

export const scoreboardTypes = ['global', 'country', 'friend'] as const;
export const scoreboardTypes = ['global', 'country', 'friend', 'team'] as const;

type ScoreboardType = typeof scoreboardTypes[number];
export default ScoreboardType;
13 changes: 12 additions & 1 deletion resources/js/beatmapsets-show/scoreboard/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

import { observer } from 'mobx-react';
import core from 'osu-core-singleton';
import * as React from 'react';
import { classWithModifiers } from 'utils/css';
import { trans } from 'utils/lang';
Expand All @@ -15,15 +16,25 @@ interface Props {

@observer
export default class ScoreboardTab extends React.Component<Props> {
private get isVisible() {
return this.props.type !== 'team' || core.currentUser?.team != null;
}

render() {
if (!this.isVisible) return null;

const label = trans(`beatmapsets.show.scoreboard.${this.props.type}`);

return (
<div
className={classWithModifiers('page-tabs__tab', {
active: this.props.controller.currentType === this.props.type,
})}
onClick={this.onClick}
>
{trans(`beatmapsets.show.scoreboard.${this.props.type}`)}
<span className='fake-bold' data-content={label}>
{label}
</span>
</div>
);
}
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/beatmapsets.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
'global' => 'Global Ranking',
'supporter-link' => 'Click <a href=":link">here</a> to see all the fancy features that you get!',
'supporter-only' => 'You need to be an osu!supporter to access the friend, country, or mod-specific rankings!',
'team' => 'Team Ranking',
'title' => 'Scoreboard',

'headers' => [
Expand All @@ -192,6 +193,7 @@
'friend' => 'None of your friends have set a score on this map yet!',
'global' => 'No scores yet. Maybe you should try setting some?',
'loading' => 'Loading scores...',
'team' => 'No one from your team has set a score on this map yet!',
'unranked' => 'Unranked beatmap.',
],
'score' => [
Expand Down