支持手动更新背包记录

This commit is contained in:
BTMuli
2025-12-18 01:34:45 +08:00
parent 66006bb0f9
commit 8879dfd912
6 changed files with 185 additions and 23 deletions

View File

@@ -43,6 +43,7 @@ function getInsertSql(tb: TGApp.Sqlite.UserBag.TableMaterialRaw): string {
* @param {number} itemId - 材料ID
* @param {number} count - 材料数量
* @param {Array<TGApp.Sqlite.UserBag.MaterialRecord>} [records] - 更新记录
* @param {boolean} manual - 是否手动
* @returns {Promise<void>}
*/
async function insertMaterial(
@@ -50,12 +51,14 @@ async function insertMaterial(
itemId: number,
count: number,
records: Array<TGApp.Sqlite.UserBag.MaterialRecord> = [],
manual: boolean = false,
): Promise<void> {
const now = Date.now();
const newRecord: TGApp.Sqlite.UserBag.MaterialRecord = {
count: count,
time: Math.floor(now / 1000),
};
if (manual) newRecord.manual = true;
const newRecords = [...records, newRecord];
const newTable: TGApp.Sqlite.UserBag.TableMaterialRaw = {
uid: uid,
@@ -100,7 +103,9 @@ function parseMaterial(
): TGApp.Sqlite.UserBag.TableMaterial {
return {
...raw,
records: JSON.parse(raw.records),
records: (<Array<TGApp.Sqlite.UserBag.MaterialRecord>>JSON.parse(raw.records)).sort(
(a, b) => b.time - a.time,
),
};
}