diff --git a/data/src/floor.ts b/data/src/floor.ts index b4631b8..b870f75 100644 --- a/data/src/floor.ts +++ b/data/src/floor.ts @@ -90,7 +90,7 @@ function convertApeiriaEnemy( for (let ny = 0; ny < height; ny++) { for (let nx = 0; nx < width; nx++) { const tile = map[ny][nx]; - if (tile > 200 && tile <= 280) { + if (tile > 200 && tile <= 280 && tile !== 224) { // 这些是怪物 if (enemyMap[tile]) enemy.add(enemyMap[tile]); } @@ -103,7 +103,7 @@ function convertApeiriaEnemy( for (let ny = 0; ny < height; ny++) { for (let nx = 0; nx < width; nx++) { const tile = map[ny][nx]; - if (tile > 200 && tile <= 280) { + if (tile > 200 && tile <= 280 && tile !== 224) { // 这些是怪物 if (enemyMap[tile]) { // 替换为弱怪/中怪/强怪 diff --git a/data/src/ginka.ts b/data/src/ginka.ts index b150304..d2472a8 100644 --- a/data/src/ginka.ts +++ b/data/src/ginka.ts @@ -1,8 +1,5 @@ -import { exists, writeFile } from 'fs-extra'; -import { readFile } from 'node:fs/promises'; -import { join } from 'node:path'; -import { convertFloor } from './floor'; -import { mergeDataset } from './utils'; +import { writeFile } from 'fs-extra'; +import { FloorData, getAllFloors, parseTowerInfo } from './utils'; interface GinkaConfig { clip: { @@ -25,58 +22,34 @@ interface GinkaDataset { const [output, ...list] = process.argv.slice(2); -async function parseOneFloor( - path: string, - name: string, - floorId: string, - config: GinkaConfig -): Promise { - const floorFile = await readFile(path, 'utf-8'); - const floor: any = JSON.parse(floorFile.split('\n').slice(1).join('\n')); - const map = floor.map as number[][]; - const clip = config.clip.special[floorId] ?? config.clip.defaults; +function parseAllData(data: Map) { + const resolved: Record = {}; - const clipped = convertFloor(map, clip, name, floorId); - - if (!config.data[floorId]) { - console.log(`⚠️ 魔塔 ${name} 的楼层 ${floorId} 不存在描述文本!`); - } - - const data: GinkaTrainData = { - text: config.data[floorId], - map: clipped, - size: [clipped[0].length, clipped.length] - }; - - return data; -} - -async function parseOne(path: string): Promise { - const dataFile = await readFile(join(path, 'data.js'), 'utf-8'); - const configFile = await readFile(join(path, 'ginka-config.json'), 'utf-8'); - const data: any = JSON.parse(dataFile.split('\n').slice(1).join('\n')); - const config = JSON.parse(configFile) as GinkaConfig; - const floorIds = data.main.floorIds as string[]; - const name = data.firstData.name as string; - - const datas = await Promise.all( - floorIds.map(v => - parseOneFloor(join(path, 'floors', `${v}.js`), name, v, config) - ) - ); + data.forEach((floor, key) => { + const config = floor.config as GinkaConfig; + const text = config.data[floor.id] ?? []; + resolved[key] = { + map: floor.map, + size: [floor.map[0].length, floor.map.length], + text: text + }; + }); const dataset: GinkaDataset = { datasetId: Math.floor(Math.random() * 1e12), - data: Object.fromEntries(datas.map((v, i) => [floorIds[i], v])) + data: resolved }; return dataset; } (async () => { - const results = await Promise.all(list.map(v => parseOne(v))); - const dataset = mergeDataset(...results); - await writeFile(output, JSON.stringify(dataset, void 0), 'utf-8'); - const size = Object.keys(dataset.data).length; + const towers = await Promise.all( + list.map(v => parseTowerInfo(v, 'ginka-config.json')) + ); + const floors = await getAllFloors(...towers); + const results = parseAllData(floors); + await writeFile(output, JSON.stringify(results, void 0), 'utf-8'); + const size = Object.keys(results.data).length; console.log(`✅ 已处理 ${list.length} 个塔,共 ${size} 个地图`); })(); diff --git a/data/src/utils.ts b/data/src/utils.ts index 593de54..78e1d44 100644 --- a/data/src/utils.ts +++ b/data/src/utils.ts @@ -10,6 +10,7 @@ interface DatasetMergable { export interface FloorData { map: number[][]; + id: string; config: BaseConfig; } @@ -126,7 +127,11 @@ export async function getAllFloors(...info: TowerInfo[]) { const name = info[tid].name; tower.forEach((map, mid) => { const floorId = info[tid].floorIds[mid]; - maps.set(`${name}::${floorId}`, { map, config: info[tid].config }); + maps.set(`${name}::${floorId}`, { + map, + id: floorId, + config: info[tid].config + }); }); }); return maps;