forked from Hay1tsme/artemis
Merge pull request 'add support for GetGameMusicScoreApi' (#220) from SoulGateKey/artemis:mai2_MusicScoreApi_support into develop
Reviewed-on: Hay1tsme/artemis#220
This commit is contained in:
@ -8,6 +8,10 @@ deliver:
|
||||
udbdl_enable: False
|
||||
content_folder: ""
|
||||
|
||||
chart_deliver: #for Prism and later
|
||||
enable: False
|
||||
chart_folder: ""
|
||||
|
||||
uploads:
|
||||
photos: False
|
||||
photos_dir: ""
|
||||
|
@ -77,6 +77,22 @@ class Mai2UploadsConfig:
|
||||
self.__config, "mai2", "uploads", "movies_dir", default=""
|
||||
)
|
||||
|
||||
class Mai2OnlineChartsConfig:
|
||||
def __init__(self, parent: "Mai2Config") -> None:
|
||||
self.__config = parent
|
||||
|
||||
@property
|
||||
def enable(self) -> bool:
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "mai2", "chart_deliver", "enable", default=False
|
||||
)
|
||||
|
||||
@property
|
||||
def chart_folder(self) -> int:
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "mai2", "chart_deliver", "chart_folder", default=""
|
||||
)
|
||||
|
||||
|
||||
class Mai2CryptoConfig:
|
||||
def __init__(self, parent_config: "Mai2Config") -> None:
|
||||
@ -106,4 +122,5 @@ class Mai2Config(dict):
|
||||
self.server = Mai2ServerConfig(self)
|
||||
self.deliver = Mai2DeliverConfig(self)
|
||||
self.uploads = Mai2UploadsConfig(self)
|
||||
self.crypto = Mai2CryptoConfig(self)
|
||||
self.crypto = Mai2CryptoConfig(self)
|
||||
self.charts = Mai2OnlineChartsConfig(self)
|
@ -1,3 +1,5 @@
|
||||
import base64
|
||||
import os
|
||||
from typing import Dict
|
||||
|
||||
from core.config import CoreConfig
|
||||
@ -25,16 +27,42 @@ class Mai2Prism(Mai2BuddiesPlus):
|
||||
"userItemList": []
|
||||
}
|
||||
|
||||
#seems to be used for downloading music scores online
|
||||
#used for downloading music scores online
|
||||
async def handle_get_game_music_score_api_request(self, data: Dict) -> Dict:
|
||||
return {
|
||||
"gameMusicScore": {
|
||||
"musicId": data["musicId"],
|
||||
"level": data["level"],
|
||||
"type": data["type"],
|
||||
"scoreData": ""
|
||||
}
|
||||
}
|
||||
if not self.game_config.charts.enable or not self.game_config.charts.chart_folder:
|
||||
return {"gameMusicScore": {"musicId": data["musicId"], "level": data["level"], "type": data["type"], "scoreData": ""}}
|
||||
|
||||
padded_music_id = str(data["musicId"]).zfill(6)
|
||||
padded_level_id = str(data["level"]).zfill(2)
|
||||
|
||||
if data["type"] == 0:
|
||||
target_filename = f"{padded_music_id}_{padded_level_id}.ma2"
|
||||
elif data["type"] == 1:
|
||||
target_filename = f"{padded_music_id}_{padded_level_id}_L.ma2"
|
||||
elif data["type"] == 2:
|
||||
target_filename = f"{padded_music_id}_{padded_level_id}_R.ma2"
|
||||
else:
|
||||
self.logger.error("Valid MusicScore type!")
|
||||
return {"gameMusicScore": {"musicId": data["musicId"], "level": data["level"], "type": data["type"], "scoreData": ""}}
|
||||
|
||||
|
||||
chart_path = os.path.join(self.game_config.charts.chart_folder, target_filename)
|
||||
if os.path.isfile(chart_path):
|
||||
with open(chart_path, 'rb') as file:
|
||||
file_content = file.read()
|
||||
base64_content = base64.b64encode(file_content).decode('ascii')
|
||||
return {
|
||||
"gameMusicScore": {
|
||||
"musicId": data["musicId"],
|
||||
"level": data["level"],
|
||||
"type": data["type"],
|
||||
"scoreData": base64_content
|
||||
}
|
||||
}
|
||||
else:
|
||||
self.logger.warning(f"Chart {target_filename} not found!")
|
||||
return {"gameMusicScore": {"musicId": data["musicId"], "level": data["level"], "type": data["type"], "scoreData": ""}}
|
||||
|
||||
|
||||
async def handle_get_game_kaleidx_scope_api_request(self, data: Dict) -> Dict:
|
||||
return {
|
||||
|
Reference in New Issue
Block a user