mirror of
https://github.com/DragonMinded/bemaniutils.git
synced 2026-08-28 05:14:11 -05:00
Switch to using an enum for GameConstants.
This commit is contained in:
@@ -107,7 +107,7 @@ class APIClient:
|
||||
raise UnsupportedVersionAPIException('The server does not support this version of the API!')
|
||||
raise APIException('The server returned an invalid status code {}!', format(r.status_code))
|
||||
|
||||
def __translate(self, game: str, version: int) -> Tuple[str, str]:
|
||||
def __translate(self, game: GameConstants, version: int) -> Tuple[str, str]:
|
||||
servergame = {
|
||||
GameConstants.DDR: 'ddr',
|
||||
GameConstants.IIDX: 'iidx',
|
||||
@@ -194,7 +194,7 @@ class APIClient:
|
||||
'versions': resp['versions'],
|
||||
})
|
||||
|
||||
def get_profiles(self, game: str, version: int, idtype: str, ids: List[str]) -> List[Dict[str, Any]]:
|
||||
def get_profiles(self, game: GameConstants, version: int, idtype: str, ids: List[str]) -> List[Dict[str, Any]]:
|
||||
# Allow remote servers to be disabled
|
||||
if not self.allow_scores:
|
||||
return []
|
||||
@@ -216,7 +216,7 @@ class APIClient:
|
||||
|
||||
def get_records(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: int,
|
||||
idtype: str,
|
||||
ids: List[str],
|
||||
@@ -247,7 +247,7 @@ class APIClient:
|
||||
# Couldn't talk to server, assume empty records
|
||||
return []
|
||||
|
||||
def get_statistics(self, game: str, version: int, idtype: str, ids: List[str]) -> List[Dict[str, Any]]:
|
||||
def get_statistics(self, game: GameConstants, version: int, idtype: str, ids: List[str]) -> List[Dict[str, Any]]:
|
||||
# Allow remote servers to be disabled
|
||||
if not self.allow_stats:
|
||||
return []
|
||||
@@ -267,7 +267,7 @@ class APIClient:
|
||||
# Couldn't talk to server, assume empty statistics
|
||||
return []
|
||||
|
||||
def get_catalog(self, game: str, version: int) -> Dict[str, List[Dict[str, Any]]]:
|
||||
def get_catalog(self, game: GameConstants, version: int) -> Dict[str, List[Dict[str, Any]]]:
|
||||
# No point disallowing this, since its only ever used for bootstrapping.
|
||||
|
||||
try:
|
||||
|
||||
@@ -49,12 +49,12 @@ class GlobalGameData(BaseGlobalData):
|
||||
}
|
||||
)
|
||||
|
||||
def get_items(self, game: str, version: int) -> List[Item]:
|
||||
def get_items(self, game: GameConstants, version: int) -> List[Item]:
|
||||
"""
|
||||
Given a game/userid, find all items in the catalog.
|
||||
|
||||
Parameters:
|
||||
game - String identifier of the game looking up the catalog.
|
||||
game - Enum value identifier of the game looking up the catalog.
|
||||
version - Integer identifier of the version looking up this catalog.
|
||||
|
||||
Returns:
|
||||
@@ -103,7 +103,7 @@ class GlobalGameData(BaseGlobalData):
|
||||
seen.add(key)
|
||||
return retval
|
||||
|
||||
def get_item(self, game: str, version: int, catid: int, cattype: str) -> Optional[ValidatedDict]:
|
||||
def get_item(self, game: GameConstants, version: int, catid: int, cattype: str) -> Optional[ValidatedDict]:
|
||||
"""
|
||||
Given a game/userid and catalog id/type, find that catalog entry.
|
||||
|
||||
@@ -111,7 +111,7 @@ class GlobalGameData(BaseGlobalData):
|
||||
as long as each one is a different type. Essentially, cattype namespaces catalog entry.
|
||||
|
||||
Parameters:
|
||||
game - String identifier of the game looking up this entry.
|
||||
game - Enum value identifier of the game looking up this entry.
|
||||
version - Integer identifier of the version looking up this entry.
|
||||
catid - Integer ID, as provided by a game.
|
||||
cattype - The type of catalog entry.
|
||||
|
||||
@@ -289,7 +289,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
},
|
||||
)
|
||||
|
||||
def __format_score(self, game: str, version: int, songid: int, songchart: int, data: Dict[str, Any]) -> Optional[Score]:
|
||||
def __format_score(self, game: GameConstants, version: int, songid: int, songchart: int, data: Dict[str, Any]) -> Optional[Score]:
|
||||
if game == GameConstants.DDR:
|
||||
return self.__format_ddr_score(version, songid, songchart, data)
|
||||
if game == GameConstants.IIDX:
|
||||
@@ -432,7 +432,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
},
|
||||
)
|
||||
|
||||
def __merge_score(self, game: str, version: int, oldscore: Score, newscore: Score) -> Score:
|
||||
def __merge_score(self, game: GameConstants, version: int, oldscore: Score, newscore: Score) -> Score:
|
||||
if oldscore.id != newscore.id or oldscore.chart != newscore.chart:
|
||||
raise Exception('Logic error! Tried to merge scores from different song/charts!')
|
||||
|
||||
@@ -453,7 +453,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
return oldscore
|
||||
|
||||
def get_score(self, game: str, version: int, userid: UserID, songid: int, songchart: int) -> Optional[Score]:
|
||||
def get_score(self, game: GameConstants, version: int, userid: UserID, songid: int, songchart: int) -> Optional[Score]:
|
||||
# Helper function so we can iterate over all servers for a single card
|
||||
def get_scores_for_card(cardid: str) -> List[Score]:
|
||||
return Parallel.flatten(Parallel.call(
|
||||
@@ -502,7 +502,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def get_scores(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: int,
|
||||
userid: UserID,
|
||||
since: Optional[int]=None,
|
||||
@@ -571,7 +571,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def __merge_global_scores(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: int,
|
||||
localcards: List[Tuple[str, UserID]],
|
||||
localscores: List[Tuple[UserID, Score]],
|
||||
@@ -629,7 +629,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def get_all_scores(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: Optional[int]=None,
|
||||
userid: Optional[UserID]=None,
|
||||
songid: Optional[int]=None,
|
||||
@@ -670,7 +670,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def __merge_global_records(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: int,
|
||||
localcards: List[Tuple[str, UserID]],
|
||||
localscores: List[Tuple[UserID, Score]],
|
||||
@@ -731,7 +731,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def get_all_records(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: Optional[int]=None,
|
||||
userlist: Optional[List[UserID]]=None,
|
||||
locationlist: Optional[List[int]]=None,
|
||||
@@ -761,7 +761,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def get_clear_rates(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: int,
|
||||
songid: Optional[int]=None,
|
||||
songchart: Optional[int]=None,
|
||||
@@ -1029,7 +1029,7 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def __format_song(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: int,
|
||||
songid: int,
|
||||
songchart: int,
|
||||
@@ -1056,14 +1056,14 @@ class GlobalMusicData(BaseGlobalData):
|
||||
|
||||
def get_all_songs(
|
||||
self,
|
||||
game: str,
|
||||
game: GameConstants,
|
||||
version: Optional[int]=None,
|
||||
) -> List[Song]:
|
||||
"""
|
||||
Given a game and a version, look up all song/chart combos associated with that game.
|
||||
|
||||
Parameters:
|
||||
game - String representing a game series.
|
||||
game - Enum value representing a game series.
|
||||
version - Integer representing which version of the game.
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -88,24 +88,25 @@ class GlobalUserData(BaseGlobalData):
|
||||
'extid': profile['extid'],
|
||||
}
|
||||
|
||||
if profile.get('game') == GameConstants.DDR:
|
||||
profilegame = GameConstants(profile['game'])
|
||||
if profilegame == GameConstants.DDR:
|
||||
base.update(self.__format_ddr_profile(profile))
|
||||
if profile.get('game') == GameConstants.IIDX:
|
||||
if profilegame == GameConstants.IIDX:
|
||||
base.update(self.__format_iidx_profile(profile))
|
||||
if profile.get('game') == GameConstants.JUBEAT:
|
||||
if profilegame == GameConstants.JUBEAT:
|
||||
base.update(self.__format_jubeat_profile(profile))
|
||||
if profile.get('game') == GameConstants.MUSECA:
|
||||
if profilegame == GameConstants.MUSECA:
|
||||
base.update(self.__format_museca_profile(profile))
|
||||
if profile.get('game') == GameConstants.POPN_MUSIC:
|
||||
if profilegame == GameConstants.POPN_MUSIC:
|
||||
base.update(self.__format_popn_profile(profile))
|
||||
if profile.get('game') == GameConstants.REFLEC_BEAT:
|
||||
if profilegame == GameConstants.REFLEC_BEAT:
|
||||
base.update(self.__format_reflec_profile(profile))
|
||||
if profile.get('game') == GameConstants.SDVX:
|
||||
if profilegame == GameConstants.SDVX:
|
||||
base.update(self.__format_sdvx_profile(profile))
|
||||
|
||||
return ValidatedDict(base)
|
||||
|
||||
def __profile_request(self, game: str, version: int, userid: UserID, exact: bool) -> Optional[ValidatedDict]:
|
||||
def __profile_request(self, game: GameConstants, version: int, userid: UserID, exact: bool) -> Optional[ValidatedDict]:
|
||||
# First, get or create the extid/refid for this virtual user
|
||||
cardid = RemoteUser.userid_to_card(userid)
|
||||
refid = self.user.get_refid(game, version, userid)
|
||||
@@ -134,7 +135,7 @@ class GlobalUserData(BaseGlobalData):
|
||||
del profile['match']
|
||||
|
||||
# Add in our defaults we always provide
|
||||
profile['game'] = game
|
||||
profile['game'] = game.value
|
||||
profile['version'] = version if exact_match else 0
|
||||
profile['refid'] = refid
|
||||
profile['extid'] = extid
|
||||
@@ -149,25 +150,25 @@ class GlobalUserData(BaseGlobalData):
|
||||
userid = RemoteUser.card_to_userid(cardid)
|
||||
return userid
|
||||
|
||||
def from_refid(self, game: str, version: int, refid: str) -> Optional[UserID]:
|
||||
def from_refid(self, game: GameConstants, version: int, refid: str) -> Optional[UserID]:
|
||||
return self.user.from_refid(game, version, refid)
|
||||
|
||||
def from_extid(self, game: str, version: int, extid: int) -> Optional[UserID]:
|
||||
def from_extid(self, game: GameConstants, version: int, extid: int) -> Optional[UserID]:
|
||||
return self.user.from_extid(game, version, extid)
|
||||
|
||||
def get_profile(self, game: str, version: int, userid: UserID) -> Optional[ValidatedDict]:
|
||||
def get_profile(self, game: GameConstants, version: int, userid: UserID) -> Optional[ValidatedDict]:
|
||||
if RemoteUser.is_remote(userid):
|
||||
return self.__profile_request(game, version, userid, exact=True)
|
||||
else:
|
||||
return self.user.get_profile(game, version, userid)
|
||||
|
||||
def get_any_profile(self, game: str, version: int, userid: UserID) -> Optional[ValidatedDict]:
|
||||
def get_any_profile(self, game: GameConstants, version: int, userid: UserID) -> Optional[ValidatedDict]:
|
||||
if RemoteUser.is_remote(userid):
|
||||
return self.__profile_request(game, version, userid, exact=False)
|
||||
else:
|
||||
return self.user.get_any_profile(game, version, userid)
|
||||
|
||||
def get_any_profiles(self, game: str, version: int, userids: List[UserID]) -> List[Tuple[UserID, Optional[ValidatedDict]]]:
|
||||
def get_any_profiles(self, game: GameConstants, version: int, userids: List[UserID]) -> List[Tuple[UserID, Optional[ValidatedDict]]]:
|
||||
if len(userids) == 0:
|
||||
return []
|
||||
|
||||
@@ -223,7 +224,7 @@ class GlobalUserData(BaseGlobalData):
|
||||
extid = self.user.get_extid(game, version, userid)
|
||||
|
||||
# Add in our defaults we always provide
|
||||
profile['game'] = game
|
||||
profile['game'] = game.value
|
||||
profile['version'] = version if exact_match else 0
|
||||
profile['refid'] = refid
|
||||
profile['extid'] = extid
|
||||
@@ -241,7 +242,7 @@ class GlobalUserData(BaseGlobalData):
|
||||
|
||||
return local_profiles
|
||||
|
||||
def get_all_profiles(self, game: str, version: int) -> List[Tuple[UserID, ValidatedDict]]:
|
||||
def get_all_profiles(self, game: GameConstants, version: int) -> List[Tuple[UserID, ValidatedDict]]:
|
||||
# Fetch local and remote profiles, and then merge by adding remote profiles to local
|
||||
# profiles when we don't have a profile for that user ID yet.
|
||||
local_cards, local_profiles, remote_profiles = Parallel.execute([
|
||||
@@ -282,7 +283,7 @@ class GlobalUserData(BaseGlobalData):
|
||||
extid = self.user.get_extid(game, version, userid)
|
||||
|
||||
# Add in our defaults we always provide
|
||||
profile['game'] = game
|
||||
profile['game'] = game.value
|
||||
profile['version'] = version
|
||||
profile['refid'] = refid
|
||||
profile['extid'] = extid
|
||||
|
||||
Reference in New Issue
Block a user