refactor: 修改 GINKA 数据集处理方式

This commit is contained in:
unanmed 2025-03-19 21:33:35 +08:00
parent a801d6e357
commit 7aa8939e4e
3 changed files with 29 additions and 51 deletions

View File

@ -90,7 +90,7 @@ function convertApeiriaEnemy(
for (let ny = 0; ny < height; ny++) { for (let ny = 0; ny < height; ny++) {
for (let nx = 0; nx < width; nx++) { for (let nx = 0; nx < width; nx++) {
const tile = map[ny][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]); if (enemyMap[tile]) enemy.add(enemyMap[tile]);
} }
@ -103,7 +103,7 @@ function convertApeiriaEnemy(
for (let ny = 0; ny < height; ny++) { for (let ny = 0; ny < height; ny++) {
for (let nx = 0; nx < width; nx++) { for (let nx = 0; nx < width; nx++) {
const tile = map[ny][nx]; const tile = map[ny][nx];
if (tile > 200 && tile <= 280) { if (tile > 200 && tile <= 280 && tile !== 224) {
// 这些是怪物 // 这些是怪物
if (enemyMap[tile]) { if (enemyMap[tile]) {
// 替换为弱怪/中怪/强怪 // 替换为弱怪/中怪/强怪

View File

@ -1,8 +1,5 @@
import { exists, writeFile } from 'fs-extra'; import { writeFile } from 'fs-extra';
import { readFile } from 'node:fs/promises'; import { FloorData, getAllFloors, parseTowerInfo } from './utils';
import { join } from 'node:path';
import { convertFloor } from './floor';
import { mergeDataset } from './utils';
interface GinkaConfig { interface GinkaConfig {
clip: { clip: {
@ -25,58 +22,34 @@ interface GinkaDataset {
const [output, ...list] = process.argv.slice(2); const [output, ...list] = process.argv.slice(2);
async function parseOneFloor( function parseAllData(data: Map<string, FloorData>) {
path: string, const resolved: Record<string, GinkaTrainData> = {};
name: string,
floorId: string,
config: GinkaConfig
): Promise<GinkaTrainData> {
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;
const clipped = convertFloor(map, clip, name, floorId); data.forEach((floor, key) => {
const config = floor.config as GinkaConfig;
if (!config.data[floorId]) { const text = config.data[floor.id] ?? [];
console.log(`⚠️ 魔塔 ${name} 的楼层 ${floorId} 不存在描述文本!`); resolved[key] = {
} map: floor.map,
size: [floor.map[0].length, floor.map.length],
const data: GinkaTrainData = { text: text
text: config.data[floorId], };
map: clipped, });
size: [clipped[0].length, clipped.length]
};
return data;
}
async function parseOne(path: string): Promise<GinkaDataset> {
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)
)
);
const dataset: GinkaDataset = { const dataset: GinkaDataset = {
datasetId: Math.floor(Math.random() * 1e12), datasetId: Math.floor(Math.random() * 1e12),
data: Object.fromEntries(datas.map((v, i) => [floorIds[i], v])) data: resolved
}; };
return dataset; return dataset;
} }
(async () => { (async () => {
const results = await Promise.all(list.map(v => parseOne(v))); const towers = await Promise.all(
const dataset = mergeDataset(...results); list.map(v => parseTowerInfo(v, 'ginka-config.json'))
await writeFile(output, JSON.stringify(dataset, void 0), 'utf-8'); );
const size = Object.keys(dataset.data).length; 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} 个地图`); console.log(`✅ 已处理 ${list.length} 个塔,共 ${size} 个地图`);
})(); })();

View File

@ -10,6 +10,7 @@ interface DatasetMergable<T> {
export interface FloorData { export interface FloorData {
map: number[][]; map: number[][];
id: string;
config: BaseConfig; config: BaseConfig;
} }
@ -126,7 +127,11 @@ export async function getAllFloors(...info: TowerInfo[]) {
const name = info[tid].name; const name = info[tid].name;
tower.forEach((map, mid) => { tower.forEach((map, mid) => {
const floorId = info[tid].floorIds[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; return maps;