2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
import copy
|
|
|
|
from typing import Any, Dict, Iterator, Tuple
|
|
|
|
|
|
|
|
from flask_caching import Cache # type: ignore
|
|
|
|
|
|
|
|
from bemani.backend.bishi import BishiBashiFactory
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import Profile, ValidatedDict, ID, GameConstants
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import Data
|
|
|
|
from bemani.frontend.base import FrontendBase
|
|
|
|
|
|
|
|
|
|
|
|
class BishiBashiFrontend(FrontendBase):
|
|
|
|
|
|
|
|
game = GameConstants.BISHI_BASHI
|
|
|
|
|
|
|
|
def __init__(self, data: Data, config: Dict[str, Any], cache: Cache) -> None:
|
|
|
|
super().__init__(data, config, cache)
|
|
|
|
self.machines: Dict[int, str] = {}
|
|
|
|
|
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 BishiBashiFactory.all_games()
|
|
|
|
|
|
|
|
def __update_value(self, oldvalue: str, newvalue: bytes) -> str:
|
|
|
|
try:
|
|
|
|
newstr = newvalue.decode('shift-jis')
|
|
|
|
except Exception:
|
|
|
|
newstr = ''
|
|
|
|
if len(newstr) == 0:
|
|
|
|
return oldvalue
|
|
|
|
else:
|
|
|
|
return newstr
|
|
|
|
|
|
|
|
def sanitize_name(self, name: str) -> str:
|
|
|
|
if len(name) == 0:
|
|
|
|
return 'なし'
|
|
|
|
return name
|
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
def update_name(self, profile: Profile, name: str) -> Profile:
|
2019-12-08 22:43:49 +01:00
|
|
|
newprofile = copy.deepcopy(profile)
|
|
|
|
for i in range(len(newprofile['strdatas'])):
|
|
|
|
strdata = newprofile['strdatas'][i]
|
|
|
|
|
|
|
|
# Figure out the profile type
|
|
|
|
csvs = strdata.split(b',')
|
|
|
|
if len(csvs) < 2:
|
|
|
|
# Not long enough to care about
|
|
|
|
continue
|
|
|
|
datatype = csvs[1].decode('ascii')
|
|
|
|
if datatype != 'IBBDAT00':
|
|
|
|
# Not the right profile type requested
|
|
|
|
continue
|
|
|
|
csvs[27] = name.encode('shift-jis')
|
|
|
|
newprofile['strdatas'][i] = b','.join(csvs)
|
|
|
|
|
|
|
|
return newprofile
|
|
|
|
|
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
|
|
|
name = 'なし' # Nothing
|
|
|
|
shop = '未設定' # Not set
|
|
|
|
shop_area = '未設定' # Not set
|
|
|
|
|
|
|
|
for i in range(len(profile['strdatas'])):
|
|
|
|
strdata = profile['strdatas'][i]
|
|
|
|
|
|
|
|
# Figure out the profile type
|
|
|
|
csvs = strdata.split(b',')
|
|
|
|
if len(csvs) < 2:
|
|
|
|
# Not long enough to care about
|
|
|
|
continue
|
|
|
|
datatype = csvs[1].decode('ascii')
|
|
|
|
if datatype != 'IBBDAT00':
|
|
|
|
# Not the right profile type requested
|
|
|
|
continue
|
|
|
|
|
|
|
|
name = self.__update_value(name, csvs[27])
|
|
|
|
shop = self.__update_value(shop, csvs[30])
|
|
|
|
shop_area = self.__update_value(shop_area, csvs[31])
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': name,
|
2021-08-20 06:44:17 +02:00
|
|
|
'extid': ID.format_extid(profile.extid),
|
2019-12-08 22:43:49 +01:00
|
|
|
'shop': shop,
|
|
|
|
'shop_area': shop_area,
|
|
|
|
'first_play_time': playstats.get_int('first_play_timestamp'),
|
|
|
|
'last_play_time': playstats.get_int('last_play_timestamp'),
|
|
|
|
'plays': playstats.get_int('total_plays'),
|
|
|
|
}
|