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.sdvx import SoundVoltexFactory, SoundVoltexBase
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import GameConstants, 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 SoundVoltexFrontend(FrontendBase):
|
2021-09-07 19:57:31 +02:00
|
|
|
game: GameConstants = GameConstants.SDVX
|
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
|
|
|
SoundVoltexBase.CHART_TYPE_NOVICE,
|
|
|
|
SoundVoltexBase.CHART_TYPE_ADVANCED,
|
|
|
|
SoundVoltexBase.CHART_TYPE_EXHAUST,
|
|
|
|
SoundVoltexBase.CHART_TYPE_INFINITE,
|
|
|
|
SoundVoltexBase.CHART_TYPE_MAXIMUM,
|
|
|
|
]
|
|
|
|
|
2021-09-07 19:57:31 +02:00
|
|
|
valid_rival_types: List[str] = [
|
2022-10-15 20:56:30 +02:00
|
|
|
"rival",
|
2019-12-08 22:43:49 +01:00
|
|
|
]
|
|
|
|
|
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 SoundVoltexFactory.all_games()
|
|
|
|
|
|
|
|
def format_score(self, userid: UserID, score: Score) -> Dict[str, Any]:
|
|
|
|
formatted_score = super().format_score(userid, score)
|
2022-10-15 20:56:30 +02:00
|
|
|
formatted_score["combo"] = score.data.get_int("combo", -1)
|
|
|
|
formatted_score["grade"] = {
|
|
|
|
SoundVoltexBase.GRADE_NO_PLAY: "-",
|
|
|
|
SoundVoltexBase.GRADE_D: "D",
|
|
|
|
SoundVoltexBase.GRADE_C: "C",
|
|
|
|
SoundVoltexBase.GRADE_B: "B",
|
|
|
|
SoundVoltexBase.GRADE_A: "A",
|
|
|
|
SoundVoltexBase.GRADE_A_PLUS: "A+",
|
|
|
|
SoundVoltexBase.GRADE_AA: "AA",
|
|
|
|
SoundVoltexBase.GRADE_AA_PLUS: "AA+",
|
|
|
|
SoundVoltexBase.GRADE_AAA: "AAA",
|
|
|
|
SoundVoltexBase.GRADE_AAA_PLUS: "AAA+",
|
|
|
|
SoundVoltexBase.GRADE_S: "S",
|
|
|
|
}.get(score.data.get_int("grade"), "No Play")
|
|
|
|
formatted_score["clear_type"] = {
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_NO_PLAY: "NO PLAY",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_FAILED: "FAILED",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_CLEAR: "CLEARED",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_HARD_CLEAR: "HARD CLEARED",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_ULTIMATE_CHAIN: "ULTIMATE CHAIN",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN: "PERFECT ULTIMATE CHAIN",
|
|
|
|
}.get(score.data.get_int("clear_type"), "FAILED")
|
|
|
|
formatted_score["medal"] = score.data.get_int("clear_type")
|
|
|
|
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)
|
2022-10-15 20:56:30 +02:00
|
|
|
formatted_attempt["combo"] = attempt.data.get_int("combo", -1)
|
|
|
|
formatted_attempt["grade"] = {
|
|
|
|
SoundVoltexBase.GRADE_NO_PLAY: "-",
|
|
|
|
SoundVoltexBase.GRADE_D: "D",
|
|
|
|
SoundVoltexBase.GRADE_C: "C",
|
|
|
|
SoundVoltexBase.GRADE_B: "B",
|
|
|
|
SoundVoltexBase.GRADE_A: "A",
|
|
|
|
SoundVoltexBase.GRADE_A_PLUS: "A+",
|
|
|
|
SoundVoltexBase.GRADE_AA: "AA",
|
|
|
|
SoundVoltexBase.GRADE_AA_PLUS: "AA+",
|
|
|
|
SoundVoltexBase.GRADE_AAA: "AAA",
|
|
|
|
SoundVoltexBase.GRADE_AAA_PLUS: "AAA+",
|
|
|
|
SoundVoltexBase.GRADE_S: "S",
|
|
|
|
}.get(attempt.data.get_int("grade"), "No Play")
|
|
|
|
formatted_attempt["clear_type"] = {
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_NO_PLAY: "NO PLAY",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_FAILED: "FAILED",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_CLEAR: "CLEARED",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_HARD_CLEAR: "HARD CLEARED",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_ULTIMATE_CHAIN: "ULTIMATE CHAIN",
|
|
|
|
SoundVoltexBase.CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN: "PERFECT ULTIMATE CHAIN",
|
|
|
|
}.get(attempt.data.get_int("clear_type"), "FAILED")
|
|
|
|
formatted_attempt["medal"] = attempt.data.get_int("clear_type")
|
|
|
|
formatted_attempt["stats"] = attempt.data.get_dict("stats")
|
2019-12-08 22:43:49 +01:00
|
|
|
return formatted_attempt
|
|
|
|
|
2022-10-15 20:56:30 +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)
|
2022-10-15 20:56:30 +02:00
|
|
|
formatted_profile["plays"] = playstats.get_int("total_plays")
|
2019-12-08 22:43:49 +01:00
|
|
|
return formatted_profile
|
|
|
|
|
|
|
|
def format_song(self, song: Song) -> Dict[str, Any]:
|
|
|
|
difficulties = [0, 0, 0, 0, 0]
|
2022-10-15 20:56:30 +02:00
|
|
|
difficulties[song.chart] = song.data.get_int("difficulty", 21)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
formatted_song = super().format_song(song)
|
2022-10-15 20:56:30 +02:00
|
|
|
formatted_song["difficulties"] = difficulties
|
|
|
|
formatted_song["category"] = song.version
|
2019-12-08 22:43:49 +01:00
|
|
|
return formatted_song
|
|
|
|
|
|
|
|
def merge_song(self, existing: Dict[str, Any], new: Song) -> Dict[str, Any]:
|
|
|
|
new_song = super().merge_song(existing, new)
|
2022-10-15 20:56:30 +02:00
|
|
|
if existing["difficulties"][new.chart] == 0:
|
|
|
|
new_song["difficulties"][new.chart] = new.data.get_int("difficulty", 21)
|
2019-12-08 22:43:49 +01:00
|
|
|
# Set the category to the earliest seen version of this song
|
2022-10-15 20:56:30 +02:00
|
|
|
if existing["category"] > new.version:
|
|
|
|
new_song["category"] = new.version
|
2019-12-08 22:43:49 +01:00
|
|
|
return new_song
|