👽️ 适配深渊新字段

This commit is contained in:
目棃
2024-10-16 18:59:05 +08:00
parent f8121d504c
commit 1794df2b8a
5 changed files with 39 additions and 12 deletions

View File

@@ -139,6 +139,24 @@ class Sqlite {
for (const item of sqlD) { for (const item of sqlD) {
await db.execute(item); await db.execute(item);
} }
// 检测是否存在字段
await this.updateAbyss();
}
/**
* @description 更新 SpiralAbyss 表
* @since Beta v0.6.1
* @returns {Promise<void>}
*/
public async updateAbyss(): Promise<void> {
const db = await this.getDB();
try {
await db.select("SELECT skippedFloor FROM SpiralAbyss;");
} catch (e) {
await TGLogger.Error(JSON.stringify(e));
const sql = "ALTER TABLE SpiralAbyss ADD skippedFloor TEXT DEFAULT ''";
await db.execute(sql);
}
} }
/** /**

View File

@@ -1,7 +1,7 @@
/** /**
* @file plugins/Sqlite/modules/userAbyss.ts * @file plugins/Sqlite/modules/userAbyss.ts
* @description Sqlite-用户深渊模块 * @description Sqlite-用户深渊模块
* @since Beta v0.6.0 * @since Beta v0.6.1
*/ */
import { path } from "@tauri-apps/api"; import { path } from "@tauri-apps/api";
@@ -50,7 +50,7 @@ function getRestoreSql(data: TGApp.Sqlite.Abyss.SingleTable): string {
/** /**
* @description 获取深渊数据的插入更新Sql * @description 获取深渊数据的插入更新Sql
* @since Beta v0.6.0 * @since Beta v0.6.1
* @param {string} uid - 用户UID * @param {string} uid - 用户UID
* @param {TGApp.Game.Abyss.FullData} data -深渊数据 * @param {TGApp.Game.Abyss.FullData} data -深渊数据
* @returns {string} * @returns {string}
@@ -66,15 +66,16 @@ function getInsertSql(uid: string, data: TGApp.Game.Abyss.FullData): string {
const normalSkillRank = transCharacterData(data.normal_skill_rank); const normalSkillRank = transCharacterData(data.normal_skill_rank);
const energySkillRank = transCharacterData(data.energy_skill_rank); const energySkillRank = transCharacterData(data.energy_skill_rank);
const floors = transFloorData(data.floors); const floors = transFloorData(data.floors);
const skippedFloor = data.is_just_skipped_floor ? data.skipped_floor : "";
const timeNow = timestampToDate(new Date().getTime()); const timeNow = timestampToDate(new Date().getTime());
return ` return `
INSERT INTO SpiralAbyss (uid, id, startTime, endTime, totalBattleTimes, totalWinTimes, INSERT INTO SpiralAbyss (uid, id, startTime, endTime, totalBattleTimes, totalWinTimes, maxFloor,
maxFloor, totalStar, isUnlock, revealRank, defeatRank, damageRank, totalStar, isUnlock, revealRank, defeatRank, damageRank, takeDamageRank,
takeDamageRank, normalSkillRank, energySkillRank, floors, updated) normalSkillRank, energySkillRank, floors, skippedFloor, updated)
VALUES ('${uid}', ${data.schedule_id}, '${startTime}', '${endTime}', ${data.total_battle_times}, VALUES ('${uid}', ${data.schedule_id}, '${startTime}', '${endTime}', ${data.total_battle_times},
${data.total_win_times}, '${data.max_floor}', ${data.total_star}, ${data.total_win_times}, '${data.max_floor}', ${data.total_star}, ${isUnlock},
${isUnlock}, '${revealRank}', '${defeatRank}', '${damageRank}', '${takeDamageRank}', '${revealRank}', '${defeatRank}', '${damageRank}', '${takeDamageRank}', '${normalSkillRank}',
'${normalSkillRank}', '${energySkillRank}', '${floors}', '${timeNow}') '${energySkillRank}', '${floors}', '${skippedFloor}', '${timeNow}')
ON CONFLICT(uid, id) DO UPDATE ON CONFLICT(uid, id) DO UPDATE
SET startTime = '${startTime}', SET startTime = '${startTime}',
endTime = '${endTime}', endTime = '${endTime}',
@@ -90,6 +91,7 @@ function getInsertSql(uid: string, data: TGApp.Game.Abyss.FullData): string {
normalSkillRank = '${normalSkillRank}', normalSkillRank = '${normalSkillRank}',
energySkillRank = '${energySkillRank}', energySkillRank = '${energySkillRank}',
floors = '${floors}', floors = '${floors}',
skippedFloor = '${skippedFloor}',
updated = '${timeNow}'; updated = '${timeNow}';
`; `;
} }

View File

@@ -66,6 +66,7 @@ create table if not exists SpiralAbyss
normalSkillRank text, normalSkillRank text,
energySkillRank text, energySkillRank text,
floors text, floors text,
skippedFloor text,
updated text, updated text,
primary key (uid, id) primary key (uid, id)
); );

View File

@@ -26,7 +26,7 @@ declare namespace TGApp.Game.Abyss {
/** /**
* @description 深渊数据类型 * @description 深渊数据类型
* @interface FullData * @interface FullData
* @since Alpha v0.2.0 * @since Beta v0.6.1
* @property {number} schedule_id - 深渊周期 ID * @property {number} schedule_id - 深渊周期 ID
* @property {string} start_time - 深渊开始时间,单位:秒 * @property {string} start_time - 深渊开始时间,单位:秒
* @property {string} end_time - 深渊结束时间,单位:秒 * @property {string} end_time - 深渊结束时间,单位:秒
@@ -42,6 +42,8 @@ declare namespace TGApp.Game.Abyss {
* @property {Floor[]} floors - 深渊各层数据 * @property {Floor[]} floors - 深渊各层数据
* @property {number} total_star - 总星数 * @property {number} total_star - 总星数
* @property {boolean} is_unlock - 是否解锁 * @property {boolean} is_unlock - 是否解锁
* @property {boolean} is_just_skipped_floor - 是否跳过楼层
* @property {boolean} skipped_floor - 跳过楼层
* @return FullData * @return FullData
*/ */
interface FullData { interface FullData {
@@ -60,6 +62,8 @@ declare namespace TGApp.Game.Abyss {
floors: Floor[]; floors: Floor[];
total_star: number; total_star: number;
is_unlock: boolean; is_unlock: boolean;
is_just_skipped_floor: boolean;
skipped_floor: string;
} }
/** /**

View File

@@ -1,19 +1,19 @@
/** /**
* @file types/Sqlite/Abyss.d.ts * @file types/Sqlite/Abyss.d.ts
* @description 数据库深境螺旋相关类型定义文件 * @description 数据库深境螺旋相关类型定义文件
* @since Beta v0.3.9 * @since Beta v0.6.1
*/ */
/** /**
* @description 数据库深渊类型命名 * @description 数据库深渊类型命名
* @since Beta v0.3.9 * @since Beta v0.6.1
* @namespace TGApp.Sqlite.Abyss * @namespace TGApp.Sqlite.Abyss
* @memberof TGApp.Sqlite * @memberof TGApp.Sqlite
*/ */
declare namespace TGApp.Sqlite.Abyss { declare namespace TGApp.Sqlite.Abyss {
/** /**
* @description 数据库-深境螺旋表 * @description 数据库-深境螺旋表
* @since Alpha v0.2.0 * @since Beta v0.6.1
* @interface SingleTable * @interface SingleTable
* @property {string} uid - 用户 UID * @property {string} uid - 用户 UID
* @property {number} id - 深境螺旋 ID * @property {number} id - 深境螺旋 ID
@@ -32,6 +32,7 @@ declare namespace TGApp.Sqlite.Abyss {
* @property {Character[]} normalSkillRank - 元素战技释放数 * @property {Character[]} normalSkillRank - 元素战技释放数
* @property {Character[]} energySkillRank - 元素爆发次数 * @property {Character[]} energySkillRank - 元素爆发次数
* @property {Floor[]} floors - 深境螺旋各层数据 * @property {Floor[]} floors - 深境螺旋各层数据
* @property {string} skippedFloor - 跳过楼层
* @property {string} updated - 更新时间 * @property {string} updated - 更新时间
* @return SingleTable * @return SingleTable
*/ */
@@ -52,6 +53,7 @@ declare namespace TGApp.Sqlite.Abyss {
normalSkillRank: string; // Character[] normalSkillRank: string; // Character[]
energySkillRank: string; // Character[] energySkillRank: string; // Character[]
floors: string; // Floor[] floors: string; // Floor[]
skippedFloor: string;
updated: string; updated: string;
} }