2021-08-19 21:25:10 +02:00
|
|
|
import yaml
|
2023-08-13 20:56:43 +02:00
|
|
|
from flask import Flask
|
2023-08-13 21:08:31 +02:00
|
|
|
from typing import Optional, Set
|
2021-08-19 21:25:10 +02:00
|
|
|
|
|
|
|
from bemani.backend.iidx import IIDXFactory
|
|
|
|
from bemani.backend.popn import PopnMusicFactory
|
|
|
|
from bemani.backend.jubeat import JubeatFactory
|
|
|
|
from bemani.backend.bishi import BishiBashiFactory
|
|
|
|
from bemani.backend.ddr import DDRFactory
|
|
|
|
from bemani.backend.sdvx import SoundVoltexFactory
|
|
|
|
from bemani.backend.reflec import ReflecBeatFactory
|
|
|
|
from bemani.backend.museca import MusecaFactory
|
2021-09-04 17:17:22 +02:00
|
|
|
from bemani.backend.mga import MetalGearArcadeFactory
|
2023-08-13 20:56:43 +02:00
|
|
|
from bemani.common import GameConstants, cache
|
2021-08-20 06:43:59 +02:00
|
|
|
from bemani.data import Config, Data
|
2021-08-19 21:25:10 +02:00
|
|
|
|
|
|
|
|
2021-08-20 06:43:59 +02:00
|
|
|
def load_config(filename: str, config: Config) -> None:
|
2021-08-19 21:25:10 +02:00
|
|
|
config.update(yaml.safe_load(open(filename)))
|
2022-10-15 20:56:30 +02:00
|
|
|
config["database"]["engine"] = Data.create_engine(config)
|
|
|
|
config["filename"] = filename
|
2021-08-19 21:25:10 +02:00
|
|
|
|
|
|
|
supported_series: Set[GameConstants] = set()
|
|
|
|
for series in GameConstants:
|
2022-10-15 20:56:30 +02:00
|
|
|
if config.get("support", {}).get(series.value, False):
|
2021-08-19 21:25:10 +02:00
|
|
|
supported_series.add(series)
|
2022-10-15 20:56:30 +02:00
|
|
|
config["support"] = supported_series
|
2021-08-19 21:25:10 +02:00
|
|
|
|
|
|
|
|
2023-08-13 21:08:31 +02:00
|
|
|
def instantiate_cache(config: Config, app: Optional[Flask] = None) -> None:
|
|
|
|
# Possibly set up a dummy app context because flask-caching needs it.
|
|
|
|
if app is None:
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2023-08-13 20:56:43 +02:00
|
|
|
# This could easily be extended to add support for any other backend that flask-caching
|
|
|
|
# supports but right now the only demand is for in-memory, filesystem and memcached.
|
|
|
|
if config.memcached_server is not None:
|
|
|
|
cache.init_app(
|
|
|
|
app,
|
|
|
|
config={
|
|
|
|
"CACHE_TYPE": "MemcachedCache",
|
|
|
|
"CACHE_MEMCACHED_SERVERS": [config.memcached_server],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
elif config.cache_dir is not None:
|
|
|
|
cache.init_app(
|
|
|
|
app,
|
|
|
|
config={
|
|
|
|
"CACHE_TYPE": "FileSystemCache",
|
|
|
|
"CACHE_DIR": config.cache_dir,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
cache.init_app(
|
|
|
|
app,
|
|
|
|
config={
|
|
|
|
"CACHE_TYPE": "SimpleCache",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-20 06:43:59 +02:00
|
|
|
def register_games(config: Config) -> None:
|
|
|
|
if GameConstants.POPN_MUSIC in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
PopnMusicFactory.register_all()
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.JUBEAT in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
JubeatFactory.register_all()
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.IIDX in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
IIDXFactory.register_all()
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.BISHI_BASHI in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
BishiBashiFactory.register_all()
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.DDR in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
DDRFactory.register_all()
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.SDVX in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
SoundVoltexFactory.register_all()
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.REFLEC_BEAT in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
ReflecBeatFactory.register_all()
|
2021-08-20 06:43:59 +02:00
|
|
|
if GameConstants.MUSECA in config.support:
|
2021-08-19 21:25:10 +02:00
|
|
|
MusecaFactory.register_all()
|
2021-09-04 17:17:22 +02:00
|
|
|
if GameConstants.MGA in config.support:
|
|
|
|
MetalGearArcadeFactory.register_all()
|