fix dashboard skill save index drift

This commit is contained in:
daixiawu 2026-06-26 15:34:24 +08:00
parent 4e62cbe301
commit edf0c64fb0

View File

@ -2083,13 +2083,13 @@ class DashboardHandler(http.server.SimpleHTTPRequestHandler):
raw_list = data.get('SkillInfoList', [])
if not isinstance(raw_list, list):
raw_list = []
if asset_index < 0 or asset_index >= len(raw_list):
raise ValueError('assetIndex out of range')
asset_index = self._resolve_form_helper_skill_index(
exporter,
raw_list,
asset_index,
expected_skill_type,
)
current_item = raw_list[asset_index]
current_skill_type = exporter.safe_int(current_item.get('SkillType'))
if expected_skill_type is not None and current_skill_type != expected_skill_type:
raise ValueError(f'skillType mismatch: expected {expected_skill_type}, current {current_skill_type}')
with open(SKILL_DATA_ASSET, 'r', encoding='utf-8', newline='') as f:
lines = f.readlines()
@ -2149,6 +2149,39 @@ class DashboardHandler(http.server.SimpleHTTPRequestHandler):
'source': self._project_relpath(SKILL_DATA_ASSET),
}
def _resolve_form_helper_skill_index(self, exporter, raw_list, asset_index, expected_skill_type):
if asset_index < 0:
raise ValueError('assetIndex out of range')
if asset_index < len(raw_list):
current_item = raw_list[asset_index]
current_skill_type = exporter.safe_int(current_item.get('SkillType'))
if expected_skill_type is None or current_skill_type == expected_skill_type:
return asset_index
matches = [
index
for index, item in enumerate(raw_list)
if exporter.safe_int(item.get('SkillType')) == expected_skill_type
]
if len(matches) == 1:
return matches[0]
if len(matches) > 1:
raise ValueError(f'duplicate SkillType rows: {expected_skill_type}')
raise ValueError(f'skillType mismatch: expected {expected_skill_type}, current {current_skill_type}')
if expected_skill_type is not None:
matches = [
index
for index, item in enumerate(raw_list)
if exporter.safe_int(item.get('SkillType')) == expected_skill_type
]
if len(matches) == 1:
return matches[0]
if len(matches) > 1:
raise ValueError(f'duplicate SkillType rows: {expected_skill_type}')
raise ValueError('assetIndex out of range')
def _current_skill_top_value(self, exporter, item, key, kind):
if key == 'SkillName':
return self._decode_skill_string(exporter, item.get('SkillName', ''))