-
Notifications
You must be signed in to change notification settings - Fork 9
Add support for Onion (OnionOS) artwork format #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ | |
| "minui", | ||
| "nextui", | ||
| "muos", | ||
| "anbernic", | ||
| "onion", | ||
| "scraper", | ||
| "boxart", | ||
| "ai" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ export enum Format { | |
| MinUI = 'minui', | ||
| NextUI = 'nextui', | ||
| MuOS = 'muos', | ||
| Anbernic = 'anbernic' | ||
| Anbernic = 'anbernic', | ||
| Onion = 'onion' | ||
| } | ||
|
|
||
| export type SeparateArtworksFunction = (options: Options) => Promise<boolean>; | ||
|
|
@@ -53,6 +54,11 @@ export async function getOutputFormat(options: Options): Promise<OutputFormat> { | |
| return anbernic.default; | ||
| } | ||
|
|
||
| case Format.Onion: { | ||
| const onion = await import('./onion.js'); | ||
| return onion.default; | ||
| } | ||
|
Comment on lines
+57
to
+60
|
||
|
|
||
| // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check | ||
| default: { | ||
| throw new Error(`Unknown format: ${options.output}`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import path from 'node:path'; | ||
| import fs from 'node:fs/promises'; | ||
| import createDebug from 'debug'; | ||
| import glob from 'fast-glob'; | ||
| import { getArtTypes } from '../libretro.js'; | ||
| import { type Options } from '../options.js'; | ||
| import { composeImageTo, resizeImageTo } from '../image.js'; | ||
| import { type ArtType } from '../art.js'; | ||
|
|
||
| const debug = createDebug('onion'); | ||
| const boxartFolder = 'boxart'; | ||
|
|
||
| export async function useSeparateArtworks(_options: Options) { | ||
| return false; | ||
| } | ||
|
|
||
| export async function getArtPath(filePath: string, _machine: string, _type?: ArtType) { | ||
| const fileName = path.basename(filePath, path.extname(filePath)); | ||
| return path.join(path.dirname(filePath), boxartFolder, `${fileName}.png`); | ||
| } | ||
|
|
||
| export async function exportArtwork( | ||
| art1Url: string | undefined, | ||
| art2Url: string | undefined, | ||
| artPath: string, | ||
| options: Options | ||
| ) { | ||
| const artTypes = getArtTypes(options); | ||
| if (artTypes.art2 && (art1Url ?? art2Url)) { | ||
| debug(`Found art URL(s): "${art1Url}" / "${art2Url}"`); | ||
| await composeImageTo(art1Url, art2Url, artPath, { width: options.width, height: options.height }); | ||
| } else if (art1Url) { | ||
| debug(`Found art URL: "${art1Url}"`); | ||
| await resizeImageTo(art1Url, artPath, { width: options.width, height: options.height }); | ||
| } else { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| export async function cleanupArtwork(targetPath: string, _romFolders: string[], _options: Options) { | ||
| const boxartFolders = await glob([`**/${boxartFolder}`], { onlyDirectories: true, cwd: targetPath }); | ||
| await Promise.all(boxartFolders.map(async (boxartFolder) => fs.rm(boxartFolder, { recursive: true }))); | ||
| console.info(`Removed ${boxartFolders.length} ${boxartFolder} folders`); | ||
| } | ||
|
|
||
| const onion = { | ||
| useSeparateArtworks, | ||
| getArtPath, | ||
| exportArtwork, | ||
| cleanupArtwork | ||
| }; | ||
|
|
||
| export default onion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README option description has mismatched parentheses: it says "(can be (" but never closes that parenthetical. Please fix the formatting so the supported formats list is clearly delimited (e.g., remove the extra parenthesis or add the missing closing one).