Skip to content

Commit

Permalink
chore: 更改遗器模块相关json数据的存储位置,并兼容旧版本
Browse files Browse the repository at this point in the history
  • Loading branch information
weiduhuo committed Nov 17, 2023
1 parent d0f9164 commit b89a0b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions data/char_weight_default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"说明": "此文件为预留文件,待后续开发 (内容物为角色的默认属性权重)"
}
28 changes: 19 additions & 9 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,36 @@
from .log import log

CONFIG_FILE_NAME = "config.json"
RELIC_FILE_NAME = "relics_set.json"
LOADOUT_FILE_NAME = "relics_loadout.json"
TEAM_FILE_NAME = "relics_team.json"
RELIC_FILE_NAME = "data/relics_set.json"
LOADOUT_FILE_NAME = "data/relics_loadout.json"
TEAM_FILE_NAME = "data/relics_team.json"


def normalize_file_path(filename):
# 尝试在当前目录下读取文件
current_dir = os.getcwd()
file_path = os.path.join(current_dir, filename)
if os.path.exists(file_path):
return file_path
pre_file_path = os.path.join(current_dir, filename)
if os.path.exists(pre_file_path):
return pre_file_path
else:
# 如果当前目录下没有该文件,则尝试在上一级目录中查找
parent_dir = os.path.dirname(current_dir)
file_path = os.path.join(parent_dir, filename)
if os.path.exists(file_path):
return file_path
else:
# 如果上一级目录中也没有该文件,则返回None
return None
# 如果仍然没有,则尝试减去文件名称的一个层级
pre_filename = str(filename).split('/', 1)[-1]
file_path = os.path.join(current_dir, pre_filename)
if os.path.exists(file_path):
if str(filename).split('/', 1)[0] == "data":
# 兼容旧版本 (<=1.8.7)
import shutil
shutil.move(file_path, pre_file_path)
log.info(_("文件位置更新,由'{}'更改至'{}'").format(pre_filename, filename))
return pre_file_path
return file_path
# 如果仍然没有,则返回None
return None


def read_json_file(filename: str, path=False, schema:dict=None) -> dict:
Expand Down

0 comments on commit b89a0b7

Please sign in to comment.