2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
import copy
|
|
|
|
from typing import Any, Dict, Iterator, Tuple
|
|
|
|
|
2022-08-13 19:17:51 +02:00
|
|
|
from flask_caching import Cache
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.backend.bishi import BishiBashiFactory
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import Profile, ValidatedDict, ID, GameConstants
|
2021-09-07 04:48:33 +02:00
|
|
|
from bemani.data import Data, Config
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.frontend.base import FrontendBase
|
|
|
|
|
|
|
|
|
|
|
|
class BishiBashiFrontend(FrontendBase):
|
|
|
|
|
2021-09-07 19:57:31 +02:00
|
|
|
game: GameConstants = GameConstants.BISHI_BASHI
|
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)
|
|
|
|
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:
|
2022-10-15 20:56:30 +02:00
|
|
|
newstr = newvalue.decode("shift-jis")
|
2019-12-08 22:43:49 +01:00
|
|
|
except Exception:
|
2022-10-15 20:56:30 +02:00
|
|
|
newstr = ""
|
2019-12-08 22:43:49 +01:00
|
|
|
if len(newstr) == 0:
|
|
|
|
return oldvalue
|
|
|
|
else:
|
|
|
|
return newstr
|
|
|
|
|
|
|
|
def sanitize_name(self, name: str) -> str:
|
|
|
|
if len(name) == 0:
|
2022-10-15 20:56:30 +02:00
|
|
|
return "なし"
|
2019-12-08 22:43:49 +01:00
|
|
|
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)
|
2022-10-15 20:56:30 +02:00
|
|
|
for i in range(len(newprofile["strdatas"])):
|
|
|
|
strdata = newprofile["strdatas"][i]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Figure out the profile type
|
2022-10-15 20:56:30 +02:00
|
|
|
csvs = strdata.split(b",")
|
2019-12-08 22:43:49 +01:00
|
|
|
if len(csvs) < 2:
|
|
|
|
# Not long enough to care about
|
|
|
|
continue
|
2022-10-15 20:56:30 +02:00
|
|
|
datatype = csvs[1].decode("ascii")
|
|
|
|
if datatype != "IBBDAT00":
|
2019-12-08 22:43:49 +01:00
|
|
|
# Not the right profile type requested
|
|
|
|
continue
|
2022-10-15 20:56:30 +02:00
|
|
|
csvs[27] = name.encode("shift-jis")
|
|
|
|
newprofile["strdatas"][i] = b",".join(csvs)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return newprofile
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def format_profile(
|
|
|
|
self, profile: Profile, playstats: ValidatedDict
|
|
|
|
) -> Dict[str, Any]:
|
|
|
|
name = "なし" # Nothing
|
|
|
|
shop = "未設定" # Not set
|
|
|
|
shop_area = "未設定" # Not set
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
for i in range(len(profile["strdatas"])):
|
|
|
|
strdata = profile["strdatas"][i]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Figure out the profile type
|
2022-10-15 20:56:30 +02:00
|
|
|
csvs = strdata.split(b",")
|
2019-12-08 22:43:49 +01:00
|
|
|
if len(csvs) < 2:
|
|
|
|
# Not long enough to care about
|
|
|
|
continue
|
2022-10-15 20:56:30 +02:00
|
|
|
datatype = csvs[1].decode("ascii")
|
|
|
|
if datatype != "IBBDAT00":
|
2019-12-08 22:43:49 +01:00
|
|
|
# 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 {
|
2022-10-15 20:56:30 +02:00
|
|
|
"name": name,
|
|
|
|
"extid": ID.format_extid(profile.extid),
|
|
|
|
"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"),
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|