2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
2021-09-07 19:57:31 +02:00
|
|
|
from typing import Any, Dict, Iterator, List, Tuple
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-08-13 19:17:51 +02:00
|
|
|
from flask_caching import Cache
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.backend.museca import MusecaFactory, MusecaBase
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import GameConstants, VersionConstants, DBConstants, Profile, ValidatedDict
|
2021-09-07 04:48:33 +02:00
|
|
|
from bemani.data import Attempt, Data, Config, Score, Song, UserID
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.frontend.base import FrontendBase
|
|
|
|
|
|
|
|
|
|
|
|
class MusecaFrontend(FrontendBase):
|
|
|
|
|
2021-09-07 19:57:31 +02:00
|
|
|
game: GameConstants = GameConstants.MUSECA
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-07 19:57:31 +02:00
|
|
|
valid_charts: List[int] = [
|
2019-12-08 22:43:49 +01:00
|
|
|
MusecaBase.CHART_TYPE_GREEN,
|
|
|
|
MusecaBase.CHART_TYPE_ORANGE,
|
|
|
|
MusecaBase.CHART_TYPE_RED,
|
|
|
|
]
|
|
|
|
|
2021-09-07 04:48:33 +02:00
|
|
|
def __init__(self, data: Data, config: Config, cache: Cache) -> None:
|
2019-12-08 22:43:49 +01:00
|
|
|
super().__init__(data, config, cache)
|
|
|
|
|
2021-08-19 21:21:22 +02:00
|
|
|
def all_games(self) -> Iterator[Tuple[GameConstants, int, str]]:
|
2019-12-08 22:43:49 +01:00
|
|
|
yield from MusecaFactory.all_games()
|
2020-12-17 21:16:30 +01:00
|
|
|
yield (
|
|
|
|
GameConstants.MUSECA,
|
|
|
|
VersionConstants.MUSECA_1_PLUS + DBConstants.OMNIMIX_VERSION_BUMP,
|
|
|
|
'MÚSECA PLUS',
|
|
|
|
) # Hard code entry for MÚSECA PLUS since entries will go in blank category otherwise
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def format_score(self, userid: UserID, score: Score) -> Dict[str, Any]:
|
|
|
|
formatted_score = super().format_score(userid, score)
|
|
|
|
formatted_score['combo'] = score.data.get_int('combo', -1)
|
|
|
|
formatted_score['grade'] = {
|
|
|
|
MusecaBase.GRADE_DEATH: 'Death (没)',
|
|
|
|
MusecaBase.GRADE_POOR: 'Poor (拙)',
|
|
|
|
MusecaBase.GRADE_MEDIOCRE: 'Mediocre (凡)',
|
|
|
|
MusecaBase.GRADE_GOOD: 'Good (佳)',
|
|
|
|
MusecaBase.GRADE_GREAT: 'Great (良)',
|
|
|
|
MusecaBase.GRADE_EXCELLENT: 'Excellent (優)',
|
|
|
|
MusecaBase.GRADE_SUPERB: 'Superb (秀)',
|
|
|
|
MusecaBase.GRADE_MASTERPIECE: 'Masterpiece (傑)',
|
|
|
|
MusecaBase.GRADE_PERFECT: 'Perfect (傑)',
|
|
|
|
}.get(score.data.get_int('grade'), 'No Play')
|
|
|
|
formatted_score['clear_type'] = {
|
2022-10-08 19:22:37 +02:00
|
|
|
MusecaBase.CLEAR_TYPE_FAILED: 'FAILED',
|
|
|
|
MusecaBase.CLEAR_TYPE_CLEARED: 'CLEARED',
|
|
|
|
MusecaBase.CLEAR_TYPE_FULL_COMBO: 'FULL COMBO',
|
|
|
|
}.get(score.data.get_int('clear_type'), 'FAILED')
|
2019-12-08 22:43:49 +01:00
|
|
|
formatted_score['medal'] = score.data.get_int('clear_type')
|
2022-10-08 04:25:03 +02:00
|
|
|
formatted_score['stats'] = score.data.get_dict('stats')
|
2019-12-08 22:43:49 +01:00
|
|
|
return formatted_score
|
|
|
|
|
|
|
|
def format_attempt(self, userid: UserID, attempt: Attempt) -> Dict[str, Any]:
|
|
|
|
formatted_attempt = super().format_attempt(userid, attempt)
|
|
|
|
formatted_attempt['combo'] = attempt.data.get_int('combo', -1)
|
|
|
|
formatted_attempt['grade'] = {
|
|
|
|
MusecaBase.GRADE_DEATH: 'Death (没)',
|
|
|
|
MusecaBase.GRADE_POOR: 'Poor (拙)',
|
|
|
|
MusecaBase.GRADE_MEDIOCRE: 'Mediocre (凡)',
|
|
|
|
MusecaBase.GRADE_GOOD: 'Good (佳)',
|
|
|
|
MusecaBase.GRADE_GREAT: 'Great (良)',
|
|
|
|
MusecaBase.GRADE_EXCELLENT: 'Excellent (優)',
|
|
|
|
MusecaBase.GRADE_SUPERB: 'Superb (秀)',
|
|
|
|
MusecaBase.GRADE_MASTERPIECE: 'Masterpiece (傑)',
|
|
|
|
MusecaBase.GRADE_PERFECT: 'Perfect (傑)',
|
|
|
|
}.get(attempt.data.get_int('grade'), 'No Play')
|
|
|
|
formatted_attempt['clear_type'] = {
|
2022-10-08 19:22:37 +02:00
|
|
|
MusecaBase.CLEAR_TYPE_FAILED: 'FAILED',
|
|
|
|
MusecaBase.CLEAR_TYPE_CLEARED: 'CLEARED',
|
|
|
|
MusecaBase.CLEAR_TYPE_FULL_COMBO: 'FULL COMBO',
|
|
|
|
}.get(attempt.data.get_int('clear_type'), 'FAILED')
|
2019-12-08 22:43:49 +01:00
|
|
|
formatted_attempt['medal'] = attempt.data.get_int('clear_type')
|
2022-10-08 04:25:03 +02:00
|
|
|
formatted_attempt['stats'] = attempt.data.get_dict('stats')
|
2019-12-08 22:43:49 +01:00
|
|
|
return formatted_attempt
|
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
def format_profile(self, profile: Profile, playstats: ValidatedDict) -> Dict[str, Any]:
|
2019-12-08 22:43:49 +01:00
|
|
|
formatted_profile = super().format_profile(profile, playstats)
|
|
|
|
formatted_profile['plays'] = playstats.get_int('total_plays')
|
|
|
|
return formatted_profile
|
|
|
|
|
|
|
|
def format_song(self, song: Song) -> Dict[str, Any]:
|
|
|
|
difficulties = [0, 0, 0]
|
|
|
|
difficulties[song.chart] = song.data.get_int('difficulty', 21)
|
|
|
|
|
|
|
|
formatted_song = super().format_song(song)
|
|
|
|
formatted_song['difficulties'] = difficulties
|
|
|
|
formatted_song['category'] = song.version
|
|
|
|
return formatted_song
|
|
|
|
|
|
|
|
def merge_song(self, existing: Dict[str, Any], new: Song) -> Dict[str, Any]:
|
|
|
|
new_song = super().merge_song(existing, new)
|
|
|
|
if existing['difficulties'][new.chart] == 0:
|
|
|
|
new_song['difficulties'][new.chart] = new.data.get_int('difficulty', 21)
|
|
|
|
# Set the category to the earliest seen version of this song
|
|
|
|
if existing['category'] > new.version:
|
|
|
|
new_song['category'] = new.version
|
|
|
|
return new_song
|