Skip to content

Commit

Permalink
Refactor: remove the "game" suffix from {gameRegion} and {gameLanguag…
Browse files Browse the repository at this point in the history
…e} (#1166)
  • Loading branch information
emmercm authored Jun 16, 2024
1 parent 3b715d6 commit f2b546c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
10 changes: 5 additions & 5 deletions docs/output/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For example, if you want to group all ROMs based on their region, you would spec
igir copy extract ^
--dat *.dat ^
--input ROMs\ ^
--output "ROMs-Sorted\{gameRegion}\"
--output "ROMs-Sorted\{region}\"
```

=== ":simple-apple: macOS"
Expand All @@ -21,7 +21,7 @@ For example, if you want to group all ROMs based on their region, you would spec
igir copy extract \
--dat *.dat \
--input ROMs/ \
--output "ROMs-Sorted/{gameRegion}/"
--output "ROMs-Sorted/{region}/"
```

=== ":simple-linux: Linux"
Expand All @@ -30,7 +30,7 @@ For example, if you want to group all ROMs based on their region, you would spec
igir copy extract \
--dat *.dat \
--input ROMs/ \
--output "ROMs-Sorted/{gameRegion}/"
--output "ROMs-Sorted/{region}/"
```

This might result in an output structure such as:
Expand Down Expand Up @@ -60,8 +60,8 @@ When using [DATs](../dats/introduction.md), you can make use of console & game i

- `{datName}` the matching DAT's name, similar to how the [`--dir-dat-name` option](./path-options.md) works
- `{datDescription}` the matching DAT's description, similar to how the [`--dir-dat-description` option](./path-options.md) works
- `{gameRegion}` each of the ROM's region(s) (e.g. `USA`, `EUR`, `JPN`, `WORLD`)
- `{gameLanguage}` each of the ROM's language(s) (e.g. `EN`, `ES`, `JA`)
- `{region}` each of the ROM's region(s) (e.g. `USA`, `EUR`, `JPN`, `WORLD`)
- `{language}` each of the ROM's language(s) (e.g. `EN`, `ES`, `JA`)

## Game information

Expand Down
5 changes: 3 additions & 2 deletions src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,10 @@ Advanced usage:
Tokens that are replaced when generating the output (--output) path of a ROM:
{datName} The name of the DAT that contains the ROM (e.g. "Nintendo - Game Boy")
{datDescription} The description of the DAT that contains the ROM
{gameRegion} The region of the ROM release (e.g. "USA"), each ROM can have multiple
{gameLanguage} The language of the ROM release (e.g. "En"), each ROM can have multiple
{region} The region of the ROM release (e.g. "USA"), each ROM can have multiple
{language} The language of the ROM release (e.g. "En"), each ROM can have multiple
{gameType} The type of the game (e.g. "Retail", "Demo", "Prototype")
{genre} The DAT-defined genre of the game
{inputDirname} The input file's dirname
{outputBasename} Equivalent to "{outputName}.{outputExt}"
Expand Down
25 changes: 17 additions & 8 deletions src/types/outputFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,17 @@ export default class OutputFactory {
}

let output = input;
output = output.replace('{gameRegion}', release.getRegion());
output = output.replace('{datReleaseRegion}', release.getRegion()); // deprecated
output = output
.replace('{region}', release.getRegion())
.replace('{gameRegion}', release.getRegion()) // deprecated
.replace('{datReleaseRegion}', release.getRegion()); // deprecated

const releaseLanguage = release.getLanguage();
if (releaseLanguage) {
output = output.replace('{gameLanguage}', releaseLanguage);
output = output.replace('{datReleaseLanguage}', releaseLanguage); // deprecated
output = output
.replace('{language}', releaseLanguage)
.replace('{gameLanguage}', releaseLanguage) // deprecated
.replace('{datReleaseLanguage}', releaseLanguage); // deprecated
}

return output;
Expand All @@ -200,20 +204,25 @@ export default class OutputFactory {
if (!game) {
return input;
}

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

const gameRegion = game.getRegions().find(() => true);
if (gameRegion) {
output = output.replace('{gameRegion}', gameRegion);
// TODO(cemmer): drop the game* prefixed tokens
output = output
.replace('{region}', gameRegion)
.replace('{gameRegion}', gameRegion);
}

const gameLanguage = game.getLanguages().find(() => true);
if (gameLanguage) {
output = output.replace('{gameLanguage}', gameLanguage);
output = output
.replace('{gameLanguage}', gameLanguage)
.replace('{language}', gameLanguage);
}

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

return output;
}

Expand Down
16 changes: 8 additions & 8 deletions test/outputFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ describe('token replacement', () => {
});

test.each([
['root/{gameRegion}', 'Game (E)', [], path.join('root', 'EUR', 'Dummy.rom')],
['root/{gameRegion}', 'Game (Europe)', [], path.join('root', 'EUR', 'Dummy.rom')],
['root/{gameRegion}', 'Game', ['EUR'], path.join('root', 'EUR', 'Dummy.rom')],
['root/{region}', 'Game (E)', [], path.join('root', 'EUR', 'Dummy.rom')],
['root/{region}', 'Game (Europe)', [], path.join('root', 'EUR', 'Dummy.rom')],
['root/{region}', 'Game', ['EUR'], path.join('root', 'EUR', 'Dummy.rom')],
['root/{gameRegion}', 'Game', ['EUR', 'JPN'], path.join('root', 'EUR', 'Dummy.rom')],
['root/{gameRegion}', 'Game', ['JPN'], path.join('root', 'JPN', 'Dummy.rom')],
['root/{gameRegion}', 'Game', ['JPN', 'EUR'], path.join('root', 'JPN', 'Dummy.rom')],
])('should replace {gameRegion}: %s', async (output, gameName, regions, expectedPath) => {
])('should replace {region}: %s', async (output, gameName, regions, expectedPath) => {
const options = new Options({ commands: ['copy'], output });
const dat = new LogiqxDAT(new Header(), []);
const game = new Game({
Expand All @@ -107,13 +107,13 @@ describe('token replacement', () => {
});

test.each([
['root/{gameLanguage}', 'Game (E)', [], path.join('root', 'EN', 'Dummy.rom')],
['root/{gameLanguage}', 'Game (Europe)', [], path.join('root', 'EN', 'Dummy.rom')],
['root/{gameLanguage}', 'Game', ['EUR'], path.join('root', 'EN', 'Dummy.rom')],
['root/{language}', 'Game (E)', [], path.join('root', 'EN', 'Dummy.rom')],
['root/{language}', 'Game (Europe)', [], path.join('root', 'EN', 'Dummy.rom')],
['root/{language}', 'Game', ['EUR'], path.join('root', 'EN', 'Dummy.rom')],
['root/{gameLanguage}', 'Game', ['EUR', 'JPN'], path.join('root', 'EN', 'Dummy.rom')],
['root/{gameLanguage}', 'Game', ['JPN'], path.join('root', 'JA', 'Dummy.rom')],
['root/{gameLanguage}', 'Game', ['JPN', 'EUR'], path.join('root', 'JA', 'Dummy.rom')],
])('should replace {gameLanguage}: %s', async (output, gameName, regions, expectedPath) => {
])('should replace {language}: %s', async (output, gameName, regions, expectedPath) => {
const options = new Options({ commands: ['copy'], output });
const dat = new LogiqxDAT(new Header(), []);
const game = new Game({
Expand Down

0 comments on commit f2b546c

Please sign in to comment.