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 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]) {
// 替换为弱怪/中怪/强怪

View File

@ -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<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;
function parseAllData(data: Map<string, FloorData>) {
const resolved: Record<string, GinkaTrainData> = {};
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<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)
)
);
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} 个地图`);
})();

View File

@ -10,6 +10,7 @@ interface DatasetMergable<T> {
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;