Skip to content

Commit 854120e

Browse files
committed
Fix
1 parent afe84f0 commit 854120e

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/modules/dats/datCombiner.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ export default class DATCombiner extends Module {
2121
combine(dats: DAT[]): DAT {
2222
this.prefixedLogger.trace(`combining ${dats.length} DAT${dats.length === 1 ? '' : 's'}`);
2323

24+
const games = dats
25+
.flatMap((dat) => dat.getGames())
26+
.filter(ArrayUtil.filterUniqueMapped((game) => game.hashCode()));
27+
28+
// Preserve MAME provenance so that consumers relying on {@link DAT.isMame} (e.g. raw archive
29+
// checksumming decisions) continue to treat the combined DAT as MAME-derived
30+
const isMame = dats.some((dat) => dat.isMame());
31+
2432
const newDat = new LogiqxDAT({
2533
header: DATCombiner.generateHeader(dats),
26-
games: dats
27-
.flatMap((dat) => dat.getGames())
28-
.filter(ArrayUtil.filterUniqueMapped((game) => game.hashCode())),
34+
...(isMame ? { machine: games } : { games }),
2935
});
3036

3137
this.prefixedLogger.trace(`done combining ${dats.length} DAT${dats.length === 1 ? '' : 's'}`);

test/modules/dats/datCombiner.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type DAT from '../../../src/models/dats/dat.js';
22
import Game from '../../../src/models/dats/game.js';
33
import Header from '../../../src/models/dats/logiqx/header.js';
44
import LogiqxDAT from '../../../src/models/dats/logiqx/logiqxDat.js';
5+
import MameDAT from '../../../src/models/dats/mame/mameDat.js';
56
import DATCombiner from '../../../src/modules/dats/datCombiner.js';
67
import ProgressBarFake from '../../console/progressBarFake.js';
78

@@ -41,3 +42,31 @@ test.each([[1], [10], [100]])('should combine with any number of DATs: %s', (dat
4142
.toSorted(),
4243
).toEqual([...expectedGameNames].toSorted());
4344
});
45+
46+
test('should not be MAME when no source DAT is MAME', () => {
47+
const dats = generateDummyDats(3);
48+
const combinedDat = new DATCombiner(new ProgressBarFake()).combine(dats);
49+
50+
expect(combinedDat.isMame()).toEqual(false);
51+
});
52+
53+
test('should be MAME when any source DAT is MAME', () => {
54+
const dats: DAT[] = [
55+
new LogiqxDAT({
56+
header: new Header({ name: 'Logiqx' }),
57+
games: [new Game({ name: 'Logiqx Game' })],
58+
}),
59+
new MameDAT({
60+
machine: [new Game({ name: 'MAME Machine' })],
61+
}),
62+
];
63+
const combinedDat = new DATCombiner(new ProgressBarFake()).combine(dats);
64+
65+
expect(combinedDat.isMame()).toEqual(true);
66+
expect(
67+
combinedDat
68+
.getGames()
69+
.map((game) => game.getName())
70+
.toSorted(),
71+
).toEqual(['Logiqx Game', 'MAME Machine']);
72+
});

0 commit comments

Comments
 (0)