Skip to content

Commit

Permalink
Feature: add {genre} token (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Jun 16, 2024
1 parent f2b546c commit aa13e5e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/modules/datScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export default class DATScanner extends Scanner {
cloneOf: game.cloneof,
romOf: game.romof,
sampleOf: undefined,
genre: game.genre?.toString(),
release: undefined,
rom: roms,
});
Expand Down
10 changes: 10 additions & 0 deletions src/types/dats/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface GameProps {
readonly cloneOf?: string,
readonly romOf?: string,
readonly sampleOf?: string,
readonly genre?: string,
// readonly board?: string,
// readonly rebuildTo?: string,
// readonly year?: string,
Expand Down Expand Up @@ -104,6 +105,10 @@ export default class Game implements GameProps {
@Expose({ name: 'sampleof' })
readonly sampleOf?: string;

// This is non-standard, but libretro uses it
@Expose({ name: 'genre' })
readonly genre?: string;

// readonly board?: string;
// readonly rebuildto?: string;
// readonly year?: string;
Expand All @@ -128,6 +133,7 @@ export default class Game implements GameProps {
this.cloneOf = props?.cloneOf;
this.romOf = props?.romOf;
this.sampleOf = props?.sampleOf;
this.genre = props?.genre;
this.release = props?.release ?? [];
this.rom = props?.rom ?? [];
}
Expand Down Expand Up @@ -184,6 +190,10 @@ export default class Game implements GameProps {
return this.device === 'yes';
}

getGenre(): string | undefined {
return this.genre;
}

getReleases(): Release[] {
if (Array.isArray(this.release)) {
return this.release;
Expand Down
5 changes: 5 additions & 0 deletions src/types/outputFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export default class OutputFactory {

output = output.replace('{gameType}', game.getGameType());

const gameGenre = game.getGenre();
if (gameGenre) {
output = output.replace('{genre}', gameGenre);
}

return output;
}

Expand Down
21 changes: 21 additions & 0 deletions test/outputFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ describe('token replacement', () => {
expect(outputPath.format()).toEqual(expectedPath);
});

test.each([
['root/{genre}', 'Platform', path.join('root', 'Platform', 'Dummy.rom')],
['root/{genre}', 'Sports', path.join('root', 'Sports', 'Dummy.rom')],
])('should replace {genre}: %s', async (output, genre, expectedPath) => {
const options = new Options({ commands: ['copy'], output });
const dat = new LogiqxDAT(new Header(), []);
const game = new Game({
genre,
});

const outputPath = OutputFactory.getPath(
options,
dat,
game,
game.getReleases().find(() => true),
dummyRom,
await dummyRom.toFile(),
);
expect(outputPath.format()).toEqual(expectedPath);
});

test.each([
// Highest priority
['Game [BIOS]', 'BIOS'],
Expand Down

0 comments on commit aa13e5e

Please sign in to comment.