Skip to content

Commit

Permalink
Merge pull request #718 from LmeSzinc/dev
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
LmeSzinc authored Jan 15, 2025
2 parents 0a36ce7 + 4bb6899 commit b39286a
Show file tree
Hide file tree
Showing 37 changed files with 800 additions and 874 deletions.
1 change: 1 addition & 0 deletions config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"Item_Heaven_Incinerator": {},
"Item_Heavenly_Melody": {},
"Item_Myriad_Fruit": {},
"Item_Flower_of_Alaya": {},
"Item_Tracks_of_Destiny": {},
"Item_Destroyer_Final_Road": {},
"Item_Guardian_Lament": {},
Expand Down
2 changes: 1 addition & 1 deletion dev_tools/keyword_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,5 @@ def generate(self):


if __name__ == '__main__':
TextMap.DATA_FOLDER = '../DanhengServer-Resources'
TextMap.DATA_FOLDER = '../turnbasedgamedata'
KeywordExtract().generate()
20 changes: 17 additions & 3 deletions dev_tools/keywords/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def data(self) -> dict[int, str]:
if not os.path.exists(TextMap.DATA_FOLDER):
logger.critical('`TextMap.DATA_FOLDER` does not exist, please set it to your path to StarRailData')
exit(1)
file = os.path.join(TextMap.DATA_FOLDER, 'TextMap', f'TextMap{self.lang.upper()}.json')

if self.lang == 'cn':
lang = 'chs'
else:
lang = self.lang
file = os.path.join(TextMap.DATA_FOLDER, 'TextMap', f'TextMap{lang.upper()}.json')
data = {}
for id_, text in read_file(file).items():
text = text.replace('\u00A0', '')
Expand Down Expand Up @@ -69,7 +74,7 @@ def text_to_variable(text):
# text = re.sub(r'[#_]?\d+(_times?)?', '', text)
text = re.sub(r'<color=#?\w+>', '', text)
text = re.sub(r'^\d+', '', text)
text = text.replace('é', 'e')
text = replace_non_ascii(text)
return text.strip('_')


Expand All @@ -88,6 +93,13 @@ def replace_templates(text: str) -> str:
return text


def replace_non_ascii(text: str) -> str:
text = text.replace('ī', 'i')
text = text.replace('é', 'e')
text = text.replace('Ā', 'A')
return text


class GenerateKeyword:
text_map: dict[str, TextMap] = {lang: TextMap(lang) for lang in UI_LANGUAGES}

Expand Down Expand Up @@ -160,7 +172,9 @@ def convert_name(self, text: str, keyword: dict) -> str:
return text_to_variable(replace_templates(text))

def convert_keyword(self, text: str, lang: str) -> str:
return replace_templates(text)
text = replace_templates(text)
text = replace_non_ascii(text)
return text

def iter_rows(self) -> t.Iterable[dict]:
for keyword in self.iter_keywords():
Expand Down
1 change: 1 addition & 0 deletions dev_tools/keywords/dungeon_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def iter_rows(self) -> t.Iterable[dict]:
'Calyx_Crimson_Erudition',
'Calyx_Crimson_Harmony',
'Calyx_Crimson_Nihility',
'Calyx_Crimson_Remembrance',
]
for keyword in order:
condition = lambda x: x['name'].startswith(keyword)
Expand Down
17 changes: 15 additions & 2 deletions dev_tools/keywords/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class GenerateItemCalyx(GenerateItemBase):
output_file = './tasks/planner/keywords/item_calyx.py'
purpose_type = [7]

# Not available at 3.0
# TODO: Delete this at next game patch
blacklist = [115001, 115002, 115003]

def iter_keywords(self) -> t.Iterable[dict]:
items = list(super().iter_keywords())

Expand All @@ -136,10 +140,19 @@ class GenerateItemValuable(GenerateItemBase):
purpose_type = [10]

def iter_keywords(self) -> t.Iterable[dict]:
data = {}
for row in super().iter_keywords():
# 自塑尘脂
if row['item_id'] not in [236]:
# 自塑尘脂, 遂愿尘脂, 变量骰子
if row['item_id'] not in [236, 237, 238]:
continue
data[row['item_id']] = row

# 遂愿尘脂 first
try:
yield data.pop(237)
except KeyError:
pass
for row in data.values():
yield row


Expand Down
108 changes: 102 additions & 6 deletions dev_tools/keywords/map_plane.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing as t

from dev_tools.keywords.base import GenerateKeyword
from dev_tools.keywords.base import GenerateKeyword, TextMap
from module.base.decorator import cached_property
from module.config.utils import deep_get

Expand All @@ -9,29 +9,117 @@ class GenerateMapPlane(GenerateKeyword):
output_file = './tasks/map/keywords/plane.py'

@cached_property
def data(self):
def AreaMapConfig(self):
return self.read_file('./ExcelOutput/AreaMapConfig.json')

def iter_planes(self) -> t.Iterable[dict]:
for data in self.data:
@cached_property
def NavMapTab(self):
rows = self.read_file('./ExcelOutput/NavMapTab.json')
data = {}
for row in rows:
plane_id = int(deep_get(row, 'ID', 0))
data[plane_id] = row
return data

@cached_property
def MazePlane(self):
rows = self.read_file('./ExcelOutput/MazePlane.json')
data = {}
for row in rows:
floors = deep_get(row, 'FloorIDList', [])
if floors and len(floors) == 1:
plane_id = floors[0]
else:
plane_id = int(deep_get(row, 'StartFloorID', 0))
data[plane_id] = row
return data

def iter_planes_v20(self) -> t.Iterable[dict]:
dic_hardcoded_text = {
# 观景车厢
1000001: 1731188599,
# 客房车厢
1000002: 2134473126,
# 派对车厢
1000003: 1905536184,
# 金人巷
1020204: 1146019185,
}
for data in self.AreaMapConfig:
plane_id = int(deep_get(data, 'ID', 0))
world_id = int(str(plane_id)[-5])
sort_id = int(deep_get(data, 'MenuSortID', 0))
text_id = deep_get(data, 'Name.Hash')

if plane_id <= 1000000:
continue

# Redirect to names in MapPlane
try:
p = plane_id // 10 * 100 + plane_id % 10
maze_data = self.MazePlane[p]
text_id = deep_get(maze_data, ['PlaneName', 'Hash'], default=0)
# text = self.find_keyword(text_id, lang='cn')[1]
# print(world_id, maze_data, plane_id, text_id, text)
except KeyError:
# print(world_id, plane_id, text_id)
text_id = dic_hardcoded_text.get(plane_id, text_id)
yield dict(
text_id=text_id,
world_id=world_id,
plane_id=plane_id,
sort_id=sort_id,
)

def iter_planes_v30(self) -> t.Iterable[dict]:
for data in self.MazePlane.values():
plane_type = deep_get(data, ['PlaneType'], default='')
if plane_type not in ['Town', 'Maze', 'Train']:
continue
plane_id = deep_get(data, ['StartFloorID'], default=0)
text_id = deep_get(data, ['PlaneName', 'Hash'], default=0)
text = self.find_keyword(text_id, lang='cn')[1]
# {TEXTJOIN#87}
if 'TEXTJOIN#' in text:
continue
if plane_id <= 10000000:
continue

world_id = deep_get(data, ['WorldID'], default=-1)
if world_id >= 100:
world_id = int(world_id // 100) - 1
try:
sort_id = self.NavMapTab[plane_id]['SortID']
except KeyError:
# print(world_id, plane_id, text_id, text)
continue

# 20331001 -> 2033101
plane_id = int(plane_id // 10 + plane_id % 10)
yield dict(
text_id=text_id,
world_id=world_id,
plane_id=plane_id,
sort_id=sort_id,
)

def iter_planes(self):
rows = {}
for data in self.iter_planes_v20():
rows[data['plane_id']] = data
for data in self.iter_planes_v30():
rows.setdefault(data['plane_id'], data)
for data in rows.values():
yield data

def iter_keywords(self) -> t.Iterable[dict]:
"""
1010201
^^ floor
20123001
^^^ floor
^^ plane
^ world
"""

def to_id(name):
return self.find_keyword(name, lang='cn')[0]

Expand Down Expand Up @@ -80,3 +168,11 @@ def convert_name(self, text: str, keyword: dict) -> str:
def convert_keyword(self, text: str, lang: str) -> str:
text = text.replace('™', '')
return super().convert_keyword(text, lang=lang)


if __name__ == '__main__':
import os

os.chdir(os.path.join(os.path.dirname(__file__), '../../'))
TextMap.DATA_FOLDER = '../turnbasedgamedata'
self = GenerateMapPlane()
Loading

0 comments on commit b39286a

Please sign in to comment.