Skip to content

Commit 1112501

Browse files
authored
feat: 选择音擎时更易读,显示稀有度和专武对应代理人 (#87)
选择音擎时更易读,显示稀有度和专武对应代理人
1 parent 4159247 commit 1112501

File tree

2 files changed

+124
-30
lines changed

2 files changed

+124
-30
lines changed

zsim/lib_webui/constants.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,52 @@ def _init_char_mapping() -> dict[str, str]:
104104
"丽娜",
105105
"零号·安比",
106106
] # 这个值其实没啥意义,但是必须是三个角色,否则可能会报错
107-
__lf = pl.scan_csv("./zsim/data/character.csv")
108-
char_options = __lf.select("name").unique().collect().to_series().to_list()
107+
__lf_character = pl.scan_csv("./zsim/data/character.csv")
108+
char_options = __lf_character.select("name").unique().collect().to_series().to_list()
109109
# 角色名称->职业特性
110110
char_profession_map = {
111-
row["name"]: row["角色特性"] for row in __lf.collect().iter_rows(named=True)
111+
row["name"]: row["角色特性"] for row in __lf_character.collect().iter_rows(named=True)
112112
}
113113

114+
# 职业特性->角色名称列表
115+
profession_chars_map = {}
116+
for char_name, profession in char_profession_map.items():
117+
if profession not in profession_chars_map:
118+
profession_chars_map[profession] = []
119+
profession_chars_map[profession].append(char_name)
120+
121+
profession_chars_map["不限特性"] = char_options
122+
114123
# 武器选项
115-
__lf = pl.scan_csv("./zsim/data/weapon.csv")
116-
weapon_options = __lf.select("名称").unique().collect().to_series().to_list()
124+
__lf_weapon = pl.scan_csv("./zsim/data/weapon.csv")
125+
weapon_options = __lf_weapon.select("名称").unique().collect().to_series().to_list()
117126
# 音擎名称->职业
118127
weapon_profession_map = {
119-
row["名称"]: row["职业"] for row in __lf.collect().iter_rows(named=True)
128+
row["名称"]: row["职业"] for row in __lf_weapon.collect().iter_rows(named=True)
120129
}
130+
# 音擎名称->稀有度
131+
weapon_rarity_map = {
132+
row["名称"]: row["稀有度"] for row in __lf_weapon.collect().iter_rows(named=True)
133+
}
134+
# 音擎名称->角色名称 (仅限部分 S 级和 A 级)
135+
weapon_char_map: dict[str, str] = {}
136+
for row in __lf_weapon.collect().iter_rows(named=True):
137+
cid = row["ID"] % 1000 * 10 + 1
138+
names = (
139+
__lf_character
140+
.filter(pl.col("CID") == cid)
141+
.select("name")
142+
.collect()
143+
.to_series()
144+
.to_list()
145+
)
146+
# 如果没有对应角色,默认用空字符串
147+
weapon_char_map[row["名称"]] = names[0] if names else ""
121148

122149
# 驱动盘套装选项
123-
__lf = pl.scan_csv("./zsim/data/equip_set_2pc.csv")
150+
__lf_equip = pl.scan_csv("./zsim/data/equip_set_2pc.csv")
124151
equip_set_ids = (
125-
__lf.select("set_ID")
152+
__lf_equip.select("set_ID")
126153
.filter(pl.col("set_ID").is_not_null())
127154
.unique()
128155
.collect()
@@ -222,5 +249,7 @@ class IDDuplicateError(Exception):
222249

223250
pass
224251

225-
226-
del __lf # 确保在文件末尾删除临时变量
252+
# 确保在文件末尾删除临时变量
253+
del __lf_character
254+
del __lf_weapon
255+
del __lf_equip

zsim/page_character_config.py

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,63 @@ def page_character_config():
1515
equip_set4_options,
1616
weapon_options,
1717
weapon_profession_map,
18+
weapon_rarity_map,
19+
weapon_char_map,
1820
char_profession_map,
21+
profession_chars_map,
1922
)
2023

21-
col1, col2, col3 = st.columns(3)
24+
col0, col1, col2, col3, col4, col5, col6, col7 = st.columns([1, 1, 1, 1, 1, 1, 1, 1])
25+
with col0:
26+
profession_0 = st.selectbox(
27+
"角色1特性",
28+
list(profession_chars_map.keys()),
29+
index=list(profession_chars_map.keys()).index("不限特性"),
30+
key="profession_select_0",
31+
)
2232
with col1:
2333
name_box_0 = [
2434
st.selectbox(
2535
"角色1",
26-
char_options,
27-
index=char_options.index(default_chars[0])
28-
if len(default_chars) > 0
36+
profession_chars_map[profession_0],
37+
index=profession_chars_map[profession_0].index(default_chars[0])
38+
if len(default_chars) > 0 and default_chars[0] in profession_chars_map[profession_0]
2939
else 0,
3040
key="char_select_0",
3141
)
3242
]
33-
with col2:
43+
with col3:
44+
profession_1 = st.selectbox(
45+
"角色2特性",
46+
list(profession_chars_map.keys()),
47+
index=list(profession_chars_map.keys()).index("不限特性"),
48+
key="profession_select_1",
49+
)
50+
with col4:
3451
name_box_1 = [
3552
st.selectbox(
3653
"角色2",
37-
char_options,
38-
index=char_options.index(default_chars[1])
39-
if len(default_chars) > 1
54+
profession_chars_map[profession_1],
55+
index=profession_chars_map[profession_1].index(default_chars[1])
56+
if len(default_chars) > 1 and default_chars[1] in profession_chars_map[profession_1]
4057
else 0,
4158
key="char_select_1",
4259
)
4360
]
44-
with col3:
61+
with col6:
62+
profession_2 = st.selectbox(
63+
"角色3特性",
64+
list(profession_chars_map.keys()),
65+
index=list(profession_chars_map.keys()).index("不限特性"),
66+
key="profession_select_2",
67+
)
68+
with col7:
4569
name_box_2 = [
4670
st.selectbox(
4771
"角色3",
48-
char_options,
49-
index=char_options.index(default_chars[2])
50-
if len(default_chars) > 2
72+
profession_chars_map[profession_2],
73+
index=profession_chars_map[profession_2].index(default_chars[2])
74+
if len(default_chars) > 2 and default_chars[2] in profession_chars_map[profession_2]
5175
else 0,
5276
key="char_select_2",
5377
)
@@ -62,9 +86,11 @@ def page_character_config():
6286
with st.expander(f"{name}的配置"):
6387
col_weapon, col_level, col_cinema = st.columns(3)
6488
with col_weapon:
65-
show_adapted_weapon = st.session_state.get(
66-
f"{name}_show_adapted_weapon", True
67-
)
89+
show_adapted_weapon = st.session_state.get(f"{name}_show_adapted_weapon", True)
90+
show_rarity_s = st.session_state.get(f"{name}_show_rarity_s", True)
91+
show_rarity_a = st.session_state.get(f"{name}_show_rarity_a", True)
92+
show_rarity_b = st.session_state.get(f"{name}_show_rarity_b", False)
93+
6894
char_profession = char_profession_map.get(name)
6995
if show_adapted_weapon and char_profession:
7096
filtered_weapon_options = [
@@ -74,6 +100,20 @@ def page_character_config():
74100
]
75101
else:
76102
filtered_weapon_options = list(weapon_options)
103+
104+
# 根据稀有度筛选
105+
filtered_weapon_options = [
106+
w for w in filtered_weapon_options
107+
if (show_rarity_s and weapon_rarity_map.get(w) == "S") or
108+
(show_rarity_a and weapon_rarity_map.get(w) == "A") or
109+
(show_rarity_b and weapon_rarity_map.get(w) == "B")
110+
]
111+
rarity_order = {"S": 0, "A": 1, "B": 2}
112+
filtered_weapon_options = sorted(
113+
filtered_weapon_options,
114+
key=lambda w: (rarity_order.get(weapon_rarity_map.get(w), 3), w)
115+
)
116+
77117
if name in saved_char_config:
78118
current_weapon = saved_char_config[name].get("weapon")
79119
else:
@@ -93,12 +133,37 @@ def page_character_config():
93133
filtered_weapon_options,
94134
index=filtered_weapon_options.index(current_weapon),
95135
key=f"{name}_weapon",
136+
format_func=lambda x: (
137+
f"({weapon_rarity_map.get(x, '未知')}"
138+
f"{' ' + weapon_char_map.get(x) if weapon_char_map.get(x) else ''}) {x}"
139+
),
140+
)
141+
142+
col_rarity = st.columns(4)
143+
with col_rarity[0]:
144+
show_adapted_weapon = st.checkbox(
145+
"只显示适配音擎",
146+
value=show_adapted_weapon,
147+
key=f"{name}_show_adapted_weapon",
148+
)
149+
with col_rarity[1]:
150+
show_rarity_s = st.checkbox(
151+
"S",
152+
value=show_rarity_s,
153+
key=f"{name}_show_rarity_s",
154+
)
155+
with col_rarity[2]:
156+
show_rarity_a = st.checkbox(
157+
"A",
158+
value=show_rarity_a,
159+
key=f"{name}_show_rarity_a",
160+
)
161+
with col_rarity[3]:
162+
show_rarity_b = st.checkbox(
163+
"B",
164+
value=show_rarity_b,
165+
key=f"{name}_show_rarity_b",
96166
)
97-
show_adapted_weapon = st.checkbox(
98-
"只显示适配音擎",
99-
value=show_adapted_weapon,
100-
key=f"{name}_show_adapted_weapon",
101-
)
102167
with col_level:
103168
st.number_input(
104169
"音擎精炼等级",

0 commit comments

Comments
 (0)