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
|
|
|
|
|
|
|
from bemani.backend.popn import PopnMusicFactory, PopnMusicBase
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import Profile, ValidatedDict, GameConstants, VersionConstants
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import Attempt, Score, Song, UserID
|
|
|
|
from bemani.frontend.base import FrontendBase
|
|
|
|
|
|
|
|
|
|
|
|
class PopnMusicFrontend(FrontendBase):
|
|
|
|
|
2021-09-07 19:57:31 +02:00
|
|
|
game: GameConstants = GameConstants.POPN_MUSIC
|
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
|
|
|
PopnMusicBase.CHART_TYPE_EASY,
|
|
|
|
PopnMusicBase.CHART_TYPE_NORMAL,
|
|
|
|
PopnMusicBase.CHART_TYPE_HYPER,
|
|
|
|
PopnMusicBase.CHART_TYPE_EX,
|
|
|
|
]
|
|
|
|
|
2021-09-07 19:57:31 +02:00
|
|
|
valid_rival_types: List[str] = ['rival']
|
2020-05-12 23:00:26 +02:00
|
|
|
|
2021-09-07 19:57:31 +02:00
|
|
|
max_active_rivals: Dict[int, int] = {
|
2020-05-12 23:03:01 +02:00
|
|
|
# Technically there is support for Rivals in Tune Street but I
|
|
|
|
# couldn't get it booting anymore to test.
|
|
|
|
VersionConstants.POPN_MUSIC_TUNE_STREET: 0,
|
|
|
|
VersionConstants.POPN_MUSIC_FANTASIA: 2,
|
|
|
|
VersionConstants.POPN_MUSIC_SUNNY_PARK: 2,
|
2021-09-06 03:30:43 +02:00
|
|
|
VersionConstants.POPN_MUSIC_LAPISTORIA: 2,
|
2020-05-12 23:03:01 +02:00
|
|
|
VersionConstants.POPN_MUSIC_ECLALE: 4,
|
|
|
|
VersionConstants.POPN_MUSIC_USANEKO: 4,
|
|
|
|
}
|
|
|
|
|
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 PopnMusicFactory.all_games()
|
2020-12-17 21:16:30 +01:00
|
|
|
yield (GameConstants.POPN_MUSIC, 0, 'CS and Licenses') # Folder that doesn't belong to any specific game
|
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['medal'] = score.data.get_int('medal')
|
2022-10-08 19:22:37 +02:00
|
|
|
formatted_score['stats'] = score.data.get_dict('stats')
|
2019-12-08 22:43:49 +01:00
|
|
|
formatted_score['status'] = {
|
2022-10-08 19:22:37 +02:00
|
|
|
PopnMusicBase.PLAY_MEDAL_NO_PLAY: "NO PLAY",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_CIRCLE_FAILED: "○ FAILED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_DIAMOND_FAILED: "◇ FAILED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_STAR_FAILED: "☆ FAILED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_EASY_CLEAR: "EASY CLEAR",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_CIRCLE_CLEARED: "○ CLEARED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_DIAMOND_CLEARED: "◇ CLEARED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_STAR_CLEARED: "☆ CLEARED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_CIRCLE_FULL_COMBO: "○ FULL COMBO",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_DIAMOND_FULL_COMBO: "◇ FULL COMBO",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_STAR_FULL_COMBO: "☆ FULL COMBO",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_PERFECT: "PERFECT",
|
|
|
|
}.get(score.data.get_int('medal'), 'NO PLAY')
|
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['medal'] = attempt.data.get_int('medal')
|
2022-10-08 19:22:37 +02:00
|
|
|
formatted_attempt['stats'] = attempt.data.get_dict('stats')
|
2019-12-08 22:43:49 +01:00
|
|
|
formatted_attempt['status'] = {
|
2022-10-08 19:22:37 +02:00
|
|
|
PopnMusicBase.PLAY_MEDAL_CIRCLE_FAILED: "○ FAILED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_DIAMOND_FAILED: "◇ FAILED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_STAR_FAILED: "☆ FAILED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_EASY_CLEAR: "EASY CLEAR",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_CIRCLE_CLEARED: "○ CLEARED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_DIAMOND_CLEARED: "◇ CLEARED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_STAR_CLEARED: "☆ CLEARED",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_CIRCLE_FULL_COMBO: "○ FULL COMBO",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_DIAMOND_FULL_COMBO: "◇ FULL COMBO",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_STAR_FULL_COMBO: "☆ FULL COMBO",
|
|
|
|
PopnMusicBase.PLAY_MEDAL_PERFECT: "PERFECT",
|
|
|
|
}.get(attempt.data.get_int('medal'), 'NO PLAY')
|
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, 0]
|
|
|
|
difficulties[song.chart] = song.data.get_int('difficulty', 51)
|
|
|
|
|
|
|
|
formatted_song = super().format_song(song)
|
|
|
|
formatted_song['category'] = song.data.get_str('category')
|
|
|
|
formatted_song['difficulties'] = difficulties
|
|
|
|
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', 51)
|
|
|
|
return new_song
|