mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
🌱 深渊数据支持多用户,暂时不做用户切换
This commit is contained in:
@@ -192,12 +192,12 @@ class Sqlite {
|
||||
* @param {number} seriesId 系列 ID
|
||||
* @returns {Promise<TGApp.Sqlite.NameCard.Item>}
|
||||
*/
|
||||
public async getNameCard (seriesId: number): Promise<TGApp.Sqlite.NameCard.Item> {
|
||||
public async getNameCard (seriesId: number): Promise<TGApp.Sqlite.NameCard.SingleTable> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = `SELECT *
|
||||
FROM NameCard
|
||||
WHERE name = (SELECT nameCard FROM AchievementSeries WHERE id = ${seriesId});`;
|
||||
const res: TGApp.Sqlite.NameCard.Item[] = await db.select(sql);
|
||||
const res: TGApp.Sqlite.NameCard.SingleTable[] = await db.select(sql);
|
||||
await db.close();
|
||||
return res[0];
|
||||
}
|
||||
@@ -319,12 +319,13 @@ class Sqlite {
|
||||
/**
|
||||
* @description 保存深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} uid 游戏 UID
|
||||
* @param {TGApp.Game.Abyss.FullData} data 深渊数据
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async saveAbyss (data: TGApp.Game.Abyss.FullData): Promise<void> {
|
||||
public async saveAbyss (uid: string, data: TGApp.Game.Abyss.FullData): Promise<void> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = insertAbyssData(data);
|
||||
const sql = insertAbyssData(uid, data);
|
||||
await db.execute(sql);
|
||||
await db.close();
|
||||
}
|
||||
@@ -332,11 +333,12 @@ class Sqlite {
|
||||
/**
|
||||
* @description 获取深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} uid 游戏 UID
|
||||
* @returns {Promise<TGApp.Game.Abyss.FullData>}
|
||||
*/
|
||||
public async getAbyss (): Promise<TGApp.Sqlite.Abyss.SingleTable[]> {
|
||||
public async getAbyss (uid: string): Promise<TGApp.Sqlite.Abyss.SingleTable[]> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = "SELECT * FROM SpiralAbyss order by id desc";
|
||||
const sql = `SELECT * FROM SpiralAbyss WHERE uid = '${uid}' order by id desc`;
|
||||
const res: TGApp.Sqlite.Abyss.SingleTable[] = await db.select(sql);
|
||||
await db.close();
|
||||
return res;
|
||||
|
||||
@@ -83,7 +83,8 @@ create table if not exists NameCard
|
||||
-- @brief 创建深渊数据表
|
||||
create table if not exists SpiralAbyss
|
||||
(
|
||||
id integer primary key,
|
||||
uid text,
|
||||
id integer,
|
||||
startTime text,
|
||||
endTime text,
|
||||
totalBattleTimes integer,
|
||||
@@ -98,7 +99,8 @@ create table if not exists SpiralAbyss
|
||||
normalSkillRank text,
|
||||
energySkillRank text,
|
||||
floors text,
|
||||
updated text
|
||||
updated text,
|
||||
primary key (uid, id)
|
||||
);
|
||||
|
||||
-- @brief 创建战绩数据表
|
||||
|
||||
@@ -133,10 +133,11 @@ export function insertCharacterData (data: TGApp.App.Character.WikiBriefInfo): s
|
||||
/**
|
||||
* @description 插入深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} uid 用户 uid
|
||||
* @param {TGApp.User.Abyss} data 深渊数据
|
||||
* @returns {string} sql
|
||||
*/
|
||||
export function insertAbyssData (data: TGApp.Game.Abyss.FullData): string {
|
||||
export function insertAbyssData (uid: string, data: TGApp.Game.Abyss.FullData): string {
|
||||
const startTime = timeToSecond(data.start_time);
|
||||
const endTime = timeToSecond(data.end_time);
|
||||
const isUnlock = data.is_unlock ? 1 : 0;
|
||||
@@ -148,14 +149,14 @@ export function insertAbyssData (data: TGApp.Game.Abyss.FullData): string {
|
||||
const energySkillRank = transCharacterData(data.energy_skill_rank);
|
||||
const floors = transFloorData(data.floors);
|
||||
return `
|
||||
INSERT INTO SpiralAbyss (id, startTime, endTime, totalBattleTimes, totalWinTimes, maxFloor, totalStar, isUnlock,
|
||||
revealRank, defeatRank, damageRank, takeDamageRank, normalSkillRank, energySkillRank,
|
||||
floors, updated)
|
||||
VALUES (${data.schedule_id}, '${startTime}', '${endTime}', ${data.total_battle_times}, ${data.total_win_times},
|
||||
'${data.max_floor}', ${data.total_star},
|
||||
${isUnlock}, '${revealRank}', '${defeatRank}', '${damageRank}', '${takeDamageRank}', '${normalSkillRank}',
|
||||
'${energySkillRank}', '${floors}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(id) DO UPDATE
|
||||
INSERT INTO SpiralAbyss (uid, id, startTime, endTime, totalBattleTimes, totalWinTimes,
|
||||
maxFloor, totalStar, isUnlock, revealRank, defeatRank, damageRank,
|
||||
takeDamageRank, normalSkillRank, energySkillRank, floors, updated)
|
||||
VALUES ('${uid}', ${data.schedule_id}, '${startTime}', '${endTime}', ${data.total_battle_times},
|
||||
${data.total_win_times}, '${data.max_floor}', ${data.total_star},
|
||||
${isUnlock}, '${revealRank}', '${defeatRank}', '${damageRank}', '${takeDamageRank}',
|
||||
'${normalSkillRank}', '${energySkillRank}', '${floors}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(uid, id) DO UPDATE
|
||||
SET startTime = '${startTime}',
|
||||
endTime = '${endTime}',
|
||||
totalBattleTimes = ${data.total_battle_times},
|
||||
|
||||
Reference in New Issue
Block a user