Skip to content

Commit

Permalink
ROMProps
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm committed Sep 18, 2023
1 parent 4e693b6 commit b58a48b
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 166 deletions.
10 changes: 5 additions & 5 deletions src/modules/candidatePatchGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ export default class CandidatePatchGenerator extends Module {
romName,
);
}
rom = new ROM(
romName,
outputFile.getSize(),
outputFile.getCrc32(),
);
rom = new ROM({
name: romName,
size: outputFile.getSize(),
crc: outputFile.getCrc32(),
});

this.progressBar.logTrace(`${dat.getNameShort()}: ${inputFile.toString()}: patch candidate generated: ${outputFile.toString()}`);
}
Expand Down
10 changes: 5 additions & 5 deletions src/modules/datInferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export default class DATInferrer extends Module {
}, new Map<string, File[]>());

const games = [...gameNamesToRomFiles.entries()].map(([gameName, gameRomFiles]) => {
const roms = gameRomFiles.map((romFile) => new ROM(
path.basename(romFile.getExtractedFilePath()),
romFile.getSize(),
romFile.getCrc32(),
));
const roms = gameRomFiles.map((romFile) => new ROM({
name: path.basename(romFile.getExtractedFilePath()),
size: romFile.getSize(),
crc: romFile.getCrc32(),
}));
return new Game({
name: gameName,
rom: roms,
Expand Down
28 changes: 14 additions & 14 deletions src/modules/datScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ export default class DATScanner extends Scanner {
const game = obj as DatfileGame;
const roms = game.entries
.filter((rom) => rom.name) // we need ROM filenames
.map((entry) => new ROM(
entry.name ?? '',
parseInt(entry.size ?? '0', 10),
entry.crc ?? '',
entry.md5,
entry.sha1,
));
.map((entry) => new ROM({
name: entry.name ?? '',
size: parseInt(entry.size ?? '0', 10),
crc: entry.crc ?? '',
md5: entry.md5,
sha1: entry.sha1,
}));

return new Game({
...game,
Expand Down Expand Up @@ -271,13 +271,13 @@ export default class DATScanner extends Scanner {
this.progressBar.logTrace(`${datFile.toString()}: parsed SMDB, deserializing to DAT`);

const games = rows.map((row) => {
const rom = new ROM(
row.name,
parseInt(row.size ?? '', 10),
row.crc,
row.md5,
row.sha1,
);
const rom = new ROM({
name: row.name,
size: parseInt(row.size ?? '', 10),
crc: row.crc,
md5: row.md5,
sha1: row.sha1,
});
const gameName = row.name.replace(/\.[^\\/]+$/, '');
return new Game({
name: gameName,
Expand Down
6 changes: 3 additions & 3 deletions src/types/logiqx/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ export interface GameProps {
* {@link Release}s.
*/
export default class Game implements GameProps {
@Expose({ name: 'name' })
@Expose()
readonly name: string;

/**
* This is non-standard, but Redump uses it:
* @see http://wiki.redump.org/index.php?title=Redump_Search_Parameters#Category
*/
@Expose({ name: 'category' })
@Expose()
readonly category: string;

@Expose({ name: 'description' })
@Expose()
readonly description: string;

@Expose({ name: 'isbios' })
Expand Down
66 changes: 47 additions & 19 deletions src/types/logiqx/rom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,54 @@ import Archive from '../files/archives/archive.js';
import ArchiveEntry from '../files/archives/archiveEntry.js';
import File from '../files/file.js';

export interface ROMProps {
readonly name: string,
readonly size: number,
readonly crc?: string,
readonly md5?: string,
readonly sha1?: string,
readonly status?: string,
readonly merge?: string,
readonly bios?: string,
}

/**
* @see http://www.logiqx.com/DatFAQs/CMPro.php
*/
export default class ROM {
@Expose({ name: 'name' })
private readonly name: string;
export default class ROM implements ROMProps {
@Expose()
readonly name: string;

@Expose()
readonly size: number;

@Expose()
readonly crc?: string;

@Expose({ name: 'size' })
private readonly size: number;
@Expose()
readonly md5?: string;

@Expose({ name: 'crc' })
private readonly crc?: string;
@Expose()
readonly sha1?: string;

@Expose({ name: 'md5' })
private readonly md5?: string;
@Expose()
readonly status?: string;

@Expose({ name: 'sha1' })
private readonly sha1?: string;
@Expose()
readonly merge?: string;

@Expose({ name: 'status' })
private readonly status?: string;
@Expose()
readonly bios?: string;

constructor(name: string, size: number, crc: string, md5?: string, sha1?: string) {
this.name = name;
this.size = size;
this.crc = crc;
this.md5 = md5;
this.sha1 = sha1;
constructor(props?: ROMProps) {
this.name = props?.name ?? '';
this.size = props?.size ?? 0;
this.crc = props?.crc;
this.md5 = props?.md5;
this.sha1 = props?.sha1;
this.status = props?.status;
this.merge = props?.merge;
this.bios = props?.bios;
}

/**
Expand Down Expand Up @@ -64,6 +84,14 @@ export default class ROM {
return this.crc ? this.crc.replace(/^0x/, '').padStart(8, '0') : '';
}

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

getBios(): string | undefined {
return this.bios;
}

/**
* Turn this {@link ROM} into a non-existent {@link File}.
*/
Expand Down
20 changes: 10 additions & 10 deletions test/modules/candidateGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@ const gameWithOneRom = new Game({
new Release('game with one ROM and multiple releases', 'EUR', 'En'),
new Release('game with one ROM and multiple releases', 'JPN', 'Ja'),
],
rom: new ROM('one.rom', 1, '12345678'),
rom: new ROM({ name: 'one.rom', size: 1, crc: '12345678' }),
});
const gameWithTwoRomsParent = new Game({
name: 'game with two ROMs (parent)',
release: new Release('game with two ROMs (parent)', 'WORLD'),
rom: [
new ROM('two.a', 2, 'abcdef90'),
new ROM('two.b', 3, '09876543'),
new ROM({ name: 'two.a', size: 2, crc: 'abcdef90' }),
new ROM({ name: 'two.b', size: 3, crc: '09876543' }),
],
});
const gameWithTwoRomsClone = new Game({
name: 'game with two ROMs (clone)',
cloneOf: gameWithTwoRomsParent.getName(),
release: new Release('game with two ROMs (clone)', 'JPN'),
rom: [
new ROM('three.a', 4, 'abcd1234'),
new ROM('three.b', 5, '86753090'),
new ROM({ name: 'three.a', size: 4, crc: 'abcd1234' }),
new ROM({ name: 'three.b', size: 5, crc: '86753090' }),
],
});
const gameWithDuplicateRoms = new Game({
name: 'game with duplicate ROMs',
rom: [
new ROM('Disc.cue', 0, 'a8c5c66e'),
new ROM('Disc (Track 01).cue', 1, '22144d0f'),
new ROM('Disc (Track 02).cue', 2, '11bf5dbd'),
new ROM('Disc (Track 03).cue', 3, 'f9188f3a'),
new ROM('Disc (Track 04).cue', 4, '11bf5dbd'),
new ROM({ name: 'Disc.cue', size: 0, crc: 'a8c5c66e' }),
new ROM({ name: 'Disc (Track 01).cue', size: 1, crc: '22144d0f' }),
new ROM({ name: 'Disc (Track 02).cue', size: 2, crc: '11bf5dbd' }),
new ROM({ name: 'Disc (Track 03).cue', size: 3, crc: 'f9188f3a' }),
new ROM({ name: 'Disc (Track 04).cue', size: 4, crc: '11bf5dbd' }),
],
});
const datWithFourGames = new DAT(new Header(), [
Expand Down
8 changes: 4 additions & 4 deletions test/modules/candidatePostProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const singleRomGames = [
'Brilliant',
].map((name) => new Game({
name,
rom: new ROM(`${name}.rom`, 0, '00000000'),
rom: new ROM({ name: `${name}.rom`, size: 0, crc: '00000000' }),
}));
const subDirRomGames = [
'Cheerful',
'Confident',
'Cool',
].map((name) => new Game({
name,
rom: new ROM(`disk1\\${name}.rom`, 0, '00000000'),
rom: new ROM({ name: `disk1\\${name}.rom`, size: 0, crc: '00000000' }),
}));
const multiRomGames = [
'Dainty',
Expand All @@ -39,8 +39,8 @@ const multiRomGames = [
].map((name) => new Game({
name,
rom: [
new ROM(`${name}.cue`, 0, '00000000'),
new ROM(`${name} (Track 01).bin`, 0, '00000000'),
new ROM({ name: `${name}.cue`, size: 0, crc: '00000000' }),
new ROM({ name: `${name} (Track 01).bin`, size: 0, crc: '00000000' }),
],
}));
const games = [...singleRomGames, ...subDirRomGames, ...multiRomGames];
Expand Down
2 changes: 1 addition & 1 deletion test/modules/candidatePreferer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function buildReleaseCandidatesWithRegionLanguage(
releases.push(new Release(releaseName, region, language));
}

const rom = new ROM(`${romName}.rom`, 0, '00000000');
const rom = new ROM({ name: `${romName}.rom`, size: 0, crc: '00000000' });
const game = new Game({
name: romName, rom: [rom], release: releases, ...gameOptionsArr[i],
});
Expand Down
2 changes: 1 addition & 1 deletion test/modules/datFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function buildGameWithRegionLanguage(
releases.push(new Release(releaseName, region, language));
}

const rom = new ROM(`${romName}.rom`, 0, '00000000');
const rom = new ROM({ name: `${romName}.rom`, size: 0, crc: '00000000' });
const game = new Game({
name: romName, rom: [rom], release: releases, ...gameOptionsArr[i],
});
Expand Down
6 changes: 3 additions & 3 deletions test/modules/fixdatCreator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const gameWithNoRoms = new Game({
});
const gameWithOneRom = new Game({
name: 'game with one ROM',
rom: new ROM('one.rom', 1, '12345678'),
rom: new ROM({ name: 'one.rom', size: 1, crc: '12345678' }),
});
const gameWithTwoRoms = new Game({
name: 'game with two ROMs',
rom: [
new ROM('two.a', 2, 'abcdef90'),
new ROM('two.b', 3, '09876543'),
new ROM({ name: 'two.a', size: 2, crc: 'abcdef90' }),
new ROM({ name: 'two.b', size: 3, crc: '09876543' }),
],
});
const dat = new DAT(new Header(), [gameWithNoRoms, gameWithOneRom, gameWithTwoRoms]);
Expand Down
Loading

0 comments on commit b58a48b

Please sign in to comment.