From 6f32223d780a030984e4839f15f3b9740675f32b Mon Sep 17 00:00:00 2001 From: Damnae Date: Fri, 12 Jul 2024 15:53:40 +0200 Subject: [PATCH] Ensure excel entries are indexed. --- src/common/common.ts | 22 ++++++++++++++ src/common/datasource.ts | 64 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/common/common.ts b/src/common/common.ts index fd1a679..223984e 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -112,4 +112,26 @@ export function deepEquals(first:any, second:any) : boolean } return false +} + +export function mapByKeys(data:any, keys:string[]) : any +{ + if (!Array.isArray(data)) + return data + + const result = {} + for (const element of data) + { + var container:any = result + for (const key of keys.slice(0, -1)) + { + const elementKey = element[key] + if (!container.hasOwnProperty(elementKey)) + container[elementKey] = {} + container = container[elementKey] + } + const lastElementKey = element[keys[keys.length - 1]] + container[lastElementKey] = element + } + return result } \ No newline at end of file diff --git a/src/common/datasource.ts b/src/common/datasource.ts index efe844f..c5f70a7 100644 --- a/src/common/datasource.ts +++ b/src/common/datasource.ts @@ -2,6 +2,7 @@ import { openDB, DBSchema } from 'idb' import { Mutex, MutexGroup } from './mutex' import useSettings from './settings' import { ref } from 'vue' +import { mapByKeys } from './common' const [settings, _sessionSettings] = useSettings() @@ -76,7 +77,7 @@ export async function retrieveJson(request:string, commit:string, useApi:boolean { const existing = await (await configDB).get('data', IDBKeyRange.only([sha])); if (existing?.content) - return JSON.parse(existing.content) + return postProcessJson(request, JSON.parse(existing.content)) const result = await fetchJson(request, commit, useApi) if (result) @@ -84,14 +85,14 @@ export async function retrieveJson(request:string, commit:string, useApi:boolean await (await configDB).put('data', { sha:sha, content:JSON.stringify(result) }) console.log(`dataDB stored ${request} @${commit}`) } - return result + return postProcessJson(request, result) } else console.warn(`file map miss for ${request}@${commit}`) } const existing = await (await configDB).get('files', IDBKeyRange.only([commit, request])); if (existing?.hash) - return JSON.parse(existing.content) + return postProcessJson(request, JSON.parse(existing.content)) const result = await fetchJson(request, commit, useApi) if (result) @@ -99,15 +100,66 @@ export async function retrieveJson(request:string, commit:string, useApi:boolean await (await configDB).put('files', { hash:commit, path:request, content:JSON.stringify(result) }) console.log(`fileDB stored ${request} @${commit}`) } - return result + return postProcessJson(request, result) }) } -export interface DataSourceFileMap +const excelDataIndexes:{[request: string]: string[]} = +{ + // Used by sources + 'ExcelOutput/AvatarRankConfig.json': ['RankID'], + 'ExcelOutput/AvatarConfig.json': ['AvatarID'], + 'ExcelOutput/AvatarSkillTreeConfig.json': ['PointID', 'Level'], + 'ExcelOutput/AvatarSkillConfig.json': ['SkillID', 'Level'], + 'ExcelOutput/BattleEventData.json': ['BattleEventID'], + 'ExcelOutput/BattleEventConfig.json': ['BattleEventID'], + 'ExcelOutput/BattleEventSkillConfig.json': ['SkillID'], + 'ExcelOutput/EquipmentSkillConfig.json': ['SkillID', 'Level'], + 'ExcelOutput/EquipmentConfig.json': ['EquipmentID'], + 'ExcelOutput/MazeSkill.json': ['MazeSkillId'], + 'ExcelOutput/MonsterCamp.json': ['ID'], + 'ExcelOutput/MonsterTemplateConfig.json': ['MonsterTemplateID'], + 'ExcelOutput/MonsterConfig.json': ['MonsterID'], + 'ExcelOutput/MonsterSkillConfig.json': ['SkillID'], + 'ExcelOutput/AvatarRelicRecommend.json': ['AvatarID'], + 'ExcelOutput/RelicSetSkillConfig.json': ['SetID', 'RequireNum'], + 'ExcelOutput/RelicSetConfig.json': ['SetID'], + 'ExcelOutput/RogueBuffType.json': ['RogueBuffType'], + 'ExcelOutput/RogueMazeBuff.json': ['ID', 'Lv'], + 'ExcelOutput/RogueBuff.json': ['MazeBuffID', 'MazeBuffLevel'], + 'ExcelOutput/StatusConfig.json': ['StatusID'], + 'ExcelOutput/AvatarStatusConfig.json': ['StatusID'], + 'ExcelOutput/MonsterStatusConfig.json': ['StatusID'], + // Helps with diff + 'ExcelOutput/AvatarAtlas.json': ['AvatarID'], + 'ExcelOutput/AvatarBaseType.json': ['ID'], + 'ExcelOutput/DamageType.json': ['ID'], + 'ExcelOutput/EliteGroup.json': ['EliteGroup'], + 'ExcelOutput/HardLevelGroup.json': ['HardLevelGroup'], + 'ExcelOutput/ConstValueRogue.json': ['ConstRogueName'], + 'ExcelOutput/MazeBuff.json': ['ID'], + 'ExcelOutput/UIRedDot.json': ['RedDot'], +} + +function postProcessJson(request:string, data:any) : any +{ + var result = data + + var indexes = excelDataIndexes[request] + if (!indexes && request.startsWith('ExcelOutput/') && request.includes('Const')) + indexes = ['ConstValueName'] + + if (indexes) + result = mapByKeys(result, indexes) + + return result +} + +interface DataSourceFileMap { [Path:string]: string } -export const fileMapPaths = +const fileMapPaths = [ 'Config/ConfigCharacter/Avatar', 'Config/ConfigCharacter/Monster', //'Config/ConfigCharacter/BattleEvent', missing 'Config/ConfigAdventureAbility/LocalPlayer', 'Config/ConfigAdventureAbility/WhiteBox/LocalPlayer', 'Config/ConfigAdventureModifier',