🐛 修正深渊验证Schema&转换逻辑

This commit is contained in:
BTMuli
2026-04-21 10:41:54 +08:00
parent d63604a43e
commit 7fc6d6b11a
4 changed files with 94 additions and 36 deletions

View File

@@ -19,12 +19,12 @@
"title": "周期 ID"
},
"start_time": {
"type": "string",
"type": ["string", "integer"],
"title": "开始时间戳",
"description": "秒级时间戳"
},
"end_time": {
"type": "string",
"type": ["string", "integer"],
"title": "结束时间戳",
"description": "秒级时间戳"
},
@@ -139,25 +139,63 @@
"items": {
"type": "object",
"properties": {
"index": { "type": "number" },
"icon": { "type": "string" },
"is_unlock": { "type": "boolean" },
"settle_time": { "type": "string" },
"star": { "type": "number" },
"max_star": { "type": "number" },
"index": {
"type": "number"
},
"icon": {
"type": "string"
},
"is_unlock": {
"type": "boolean"
},
"settle_time": {
"type": ["string", "integer"]
},
"star": {
"type": "number"
},
"max_star": {
"type": "number"
},
"ley_line_disorder": {
"type": "array",
"items": { "type": "string" }
"items": {
"type": "string"
}
},
"ley_line_disorder_upper": {
"type": "array",
"items": {
"type": "string"
}
},
"ley_line_disorder_lower": {
"type": "array",
"items": {
"type": "string"
}
},
"settle_date_time": {
"type": ["object", "null"],
"properties": {
"year": { "type": "number" },
"month": { "type": "number" },
"day": { "type": "number" },
"hour": { "type": "number" },
"minute": { "type": "number" },
"second": { "type": "number" }
"year": {
"type": "number"
},
"month": {
"type": "number"
},
"day": {
"type": "number"
},
"hour": {
"type": "number"
},
"minute": {
"type": "number"
},
"second": {
"type": "number"
}
}
},
"levels": {
@@ -173,8 +211,12 @@
"items": {
"type": "object",
"properties": {
"index": { "type": "number" },
"timestamp": { "type": "string" },
"index": {
"type": "number"
},
"timestamp": {
"type": ["string", "integer"]
},
"settle_date_time": {
"type": "object",
"properties": {
@@ -200,7 +242,7 @@
}
}
},
"required": ["index", "timestamp", "avatars", "settle_date_time"]
"required": ["index", "timestamp", "avatars"]
}
},
"top_half_floor_monster": {
@@ -220,9 +262,15 @@
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"icon": { "type": "string" },
"level": { "type": "number" }
"name": {
"type": "string"
},
"icon": {
"type": "string"
},
"level": {
"type": "number"
}
},
"required": ["name", "level"]
}

View File

@@ -18,14 +18,15 @@ const CombatValidate = ajv.compile(CombatJson);
/**
* 验证深渊单条数据
* @since Beta v0.9.9
* @since Beta v0.10.1
* @param data - 待验证的数据
* @returns 验证是否通过(类型收束)
*/
function validateAbyss(data: unknown): data is TGApp.Plugins.Hutao.Abyss.ImportData {
if (!AbyssValidate(data)) {
const error = AbyssValidate.errors?.[0];
if (error) {
if (AbyssValidate.errors) {
const error = AbyssValidate.errors[0];
console.error(AbyssValidate.errors);
showSnackbar.error(
`深渊数据验证失败:${error.instancePath || error.schemaPath} ${error.message}`,
);

View File

@@ -44,15 +44,17 @@ export function transFloorData(data: Array<TGApp.Game.Abyss.Floor>): string {
* @param data - 接口获取楼层数据
* @returns 增益字符串
*/
function transFloorBuff(data: TGApp.Game.Abyss.Floor): Array<string> {
function transFloorBuff(data: TGApp.Game.Abyss.Floor): Array<string> | undefined {
const res: Array<string> = [];
if (data.ley_line_disorder_upper.length > 0) {
if (data.ley_line_disorder_upper && data.ley_line_disorder_upper.length > 0) {
res.push(`【上半】${data.ley_line_disorder_upper.join(";")}`);
}
if (data.ley_line_disorder_lower.length > 0) {
if (data.ley_line_disorder_lower && data.ley_line_disorder_lower.length > 0) {
res.push(`【下半】${data.ley_line_disorder_lower.join(";")}`);
}
if (data.ley_line_disorder.length > 0) res.push(...data.ley_line_disorder);
if (data.ley_line_disorder && data.ley_line_disorder.length > 0) {
res.push(...data.ley_line_disorder);
}
return res;
}
@@ -69,8 +71,15 @@ function transLevelData(data: TGApp.Game.Abyss.Level): TGApp.Sqlite.Abyss.Level
maxStar: data.max_star,
};
for (const battle of data.battles) {
if (battle.index === 1) res.upBattle = transBattleData(battle, data.top_half_floor_monster);
else res.downBattle = transBattleData(battle, data.bottom_half_floor_monster);
if (battle.index === 1) {
if (data.top_half_floor_monster) {
res.upBattle = transBattleData(battle, data.top_half_floor_monster);
}
} else {
if (data.bottom_half_floor_monster) {
res.downBattle = transBattleData(battle, data.bottom_half_floor_monster);
}
}
}
return res;
}

View File

@@ -95,16 +95,16 @@ declare namespace TGApp.Game.Abyss {
*/
settle_date_time: TGApp.Game.Base.DateTime | null;
/** 地脉异常 */
ley_line_disorder: Array<string>;
ley_line_disorder?: Array<string>;
/** 地脉异常:上半 */
ley_line_disorder_upper: Array<string>;
ley_line_disorder_upper?: Array<string>;
/** 地脉异常:下半 */
ley_line_disorder_lower: Array<string>;
ley_line_disorder_lower?: Array<string>;
};
/**
* 关卡数据
* @since Beta v0.9.0
* @since Beta v0.10.1
*/
type Level = {
/** 关卡索引 */
@@ -116,9 +116,9 @@ declare namespace TGApp.Game.Abyss {
/** 战斗数据 */
battles: Array<Battle>;
/** 上半场怪物数据 */
top_half_floor_monster: Array<MonsterInfo>;
top_half_floor_monster?: Array<MonsterInfo>;
/** 下半场怪物数据 */
bottom_half_floor_monster: Array<MonsterInfo>;
bottom_half_floor_monster?: Array<MonsterInfo>;
};
/**