Skip to content

Commit

Permalink
Fix: ignore status:nodump ROMs when merging & splitting (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Oct 1, 2023
1 parent add9ec9 commit 6e5b4e9
Show file tree
Hide file tree
Showing 6 changed files with 450 additions and 160 deletions.
2 changes: 2 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { JestConfigWithTsJest } from 'ts-jest';
const jestConfig: JestConfigWithTsJest = {
testEnvironment: 'node',

setupFilesAfterEnv: ['jest-extended/all'],

// Most tests are I/O-bound, increase the test timeout globally
testTimeout: 20_000,

Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"eslint-plugin-unicorn": "48.0.1",
"husky": "8.0.3",
"jest": "29.7.0",
"jest-extended": "^4.0.1",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "5.2.2",
Expand Down
29 changes: 13 additions & 16 deletions src/modules/datMergerSplitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,16 @@ export default class DATMergerSplitter extends Module {
private mergeParent(parent: Parent, gameNamesToGames: Map<string, Game>): Game[] {
let games = parent.getGames();

const romNameFunc = (rom: ROM): string => rom.getName()
// Numeric sort will sort underscore before hyphens? ASCII says don't do that
.replace('-', '__');
const romSortFunc = (a: ROM, b: ROM): number => romNameFunc(a)
.localeCompare(romNameFunc(b), undefined, { numeric: true });

// Sanitization
games = games.map((game) => {
const romNames = game.getRoms().map((rom) => rom.getName());
return game.withProps({
rom: game.getRoms()
// Get rid of ROMs that haven't been dumped yet
.filter((rom) => rom.getStatus() !== 'nodump')
// Get rid of duplicate ROMs. MAME will sometimes duplicate a file with the exact same
// name, size, and checksum but with a different "region" (e.g. neogeo).
.filter((rom, idx) => romNames.indexOf(rom.getName()) === idx)
// Sort for easier debugging and testing
.sort(romSortFunc),
.filter((rom, idx) => romNames.indexOf(rom.getName()) === idx),
});
});

Expand All @@ -92,11 +86,16 @@ export default class DATMergerSplitter extends Module {
return game.withProps({
rom: [
...game.getDeviceRefs()
.map((deviceRef) => gameNamesToGames.get(deviceRef.getName()))
// De-duplicate DeviceRef names
.map((deviceRef) => deviceRef.getName())
.reduce(ArrayPoly.reduceUnique(), [])
// Get ROMs from the DeviceRef
.map((deviceRefName) => gameNamesToGames.get(deviceRefName))
.filter(ArrayPoly.filterNotNullish)
.flatMap((deviceGame) => deviceGame.getRoms()),
.flatMap((deviceGame) => deviceGame.getRoms()
.filter((rom) => rom.getStatus() !== 'nodump')),
...game.getRoms(),
].sort(romSortFunc),
],
});
});
}
Expand All @@ -122,8 +121,7 @@ export default class DATMergerSplitter extends Module {
});

return game.withProps({
rom: DATMergerSplitter.diffGameRoms(biosGame, game)
.sort(romSortFunc),
rom: DATMergerSplitter.diffGameRoms(biosGame, game),
});
});
}
Expand All @@ -146,8 +144,7 @@ export default class DATMergerSplitter extends Module {
}

return game.withProps({
rom: DATMergerSplitter.diffGameRoms(parentGame, game)
.sort(romSortFunc),
rom: DATMergerSplitter.diffGameRoms(parentGame, game),
});
});
}
Expand Down
10 changes: 8 additions & 2 deletions src/types/dats/rom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import Archive from '../files/archives/archive.js';
import ArchiveEntry from '../files/archives/archiveEntry.js';
import File from '../files/file.js';

type ROMStatus = 'baddump' | 'nodump' | 'good';

export interface ROMProps {
readonly name: string,
readonly size: number,
readonly crc?: string,
readonly md5?: string,
readonly sha1?: string,
readonly status?: string,
readonly status?: ROMStatus,
readonly merge?: string,
readonly bios?: string,
}
Expand All @@ -35,7 +37,7 @@ export default class ROM implements ROMProps {
readonly sha1?: string;

@Expose()
readonly status?: string;
readonly status?: ROMStatus;

@Expose()
readonly merge?: string;
Expand Down Expand Up @@ -84,6 +86,10 @@ export default class ROM implements ROMProps {
return this.crc ? this.crc.replace(/^0x/, '').padStart(8, '0') : '';
}

getStatus(): ROMStatus | undefined {
return this.status;
}

getMerge(): string | undefined {
return this.merge;
}
Expand Down
Loading

0 comments on commit 6e5b4e9

Please sign in to comment.