Files
romm/backend/utils/platform_aliases.py
Spinnich 60703be09c chore(platforms): split arcade aliases into per-emulator-family slugs (#5273)
* feat(platforms): split arcade aliases into per-emulator-family slugs

Give MAME, AdvanceMAME, FBNeo, FBA, Daphne, Singe and the arcade boards
that need their own emulator (NAOMI/NAOMI 2/NAOMI GD-ROM, Model 2/3,
Hikaru, Triforce, Lindbergh, Namco System 246/3xx, Gaelco, ...) their own
slugs with verified provider IDs. Providers without a dedicated entry fall
back to their Arcade platform via arcade_fallbacks(). MAME-only boards
(CPS1-3, System 16/32, Model 1, Namco 22) stay aliases of arcade.

Refs #5272

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): code-review pass on arcade slugs

- Retry IGDB on unmatched scans for every platform IGDB resolves, not
  just slugs in IGDB_PLATFORM_LIST.
- Resolve config binding/version values through the alias table, so a
  binding to a retired slug (cps2, model1, ...) still lands on a platform.
- Alias the Batocera `typex` folder to type-x.
- Build provider id->slug reverse maps before merging Arcade fallbacks.
- Share one MAME title lookup between base_handler and libretro.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(platforms): simplify pass on arcade slugs

- Alias the three RomM-keyed IGDB versions inside IGDB_PLATFORM_VERSIONS,
  dropping IGDB_VERSION_SLUGS and _version_slug.
- Derive EmulatorJS arcade entries from ARCADE_SET_PLATFORMS.
- Remove the unused provider id->slug reverse maps, so the Arcade
  fallback merge no longer has an ordering constraint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(platforms): humanizer pass on arcade slug comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): settle arcade slug review decisions

- Migration 0154 moves platforms still on a retired MAME-only board slug
  (cps1-3, model1, system16, system32, system-32) to arcade, so no row
  carries a slug the enum no longer has.
- MAME shortname expansion keys off the RomM slug via
  MAME_SHORTNAME_PLATFORMS instead of per-provider arcade ids, so Daphne,
  Singe, Type X and Lindbergh sets are no longer read as MAME sets. Neo Geo
  now expands at ScreenScraper too, as it already did at IGDB and Moby.
- fba offers fbneo before the FinalBurn Alpha CPS cores.
- AdvanceMAME leaves the WebRcade feed; EmulatorJS and WebRcade share
  PLAYABLE_ARCADE_SET_PLATFORMS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): code-review pass (xhigh) on arcade slugs

Verify arcade-board BIOS files against the known list's arcade entries,
and make migration 0154 match retired slugs case-insensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(platforms): simplify pass on arcade slugs

Apply IGDB family overrides once in get_platform instead of on each
return path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(platforms): use a slug with no shipped icon

singe now ships an icon, so the no-icon prefetch test needs a slug that never will.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(platforms): add a teknoparrot arcade slug

TeknoParrot runs PC-based arcade boards outside the MAME/FinalBurn family,
so its folder gets its own platform (RetroBat and ES-DE both use
`teknoparrot`). Providers fall back to their Arcade entry, MAME shortname
expansion skips it, and it gets a placeholder icon copied from `arcade`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(platforms): give each arcade-family icon its own marquee title

Redraws the ARCADE marquee on the copied cabinet icons with each
platform's name, in the Bungee typeface with the original inline and
extrusion styling. Sega boards use Sega blue, Namco systems Namco red,
and Type X Taito blue; the rest keep the original amber.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(platforms): code-review pass (xhigh) on arcade slugs

Neo Geo BIOS lives under arcade in the known BIOS list, so map
neogeoaes and neogeomvs there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(platforms): simplify pass on arcade slug tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-10-28 19:53:06 -04:00

218 lines
6.6 KiB
Python

from __future__ import annotations
from collections.abc import Iterable
from typing import TYPE_CHECKING, Final
from utils.platform_slugs import UniversalPlatformSlug as UPS
if TYPE_CHECKING:
from config.config_manager import Config
# Folder names used by Batocera, RetroBat and ES-DE that differ from RomM slugs.
PLATFORM_FS_ALIASES: Final[dict[str, UPS]] = {
"adam": UPS.COLECOADAM,
"advision": UPS.ADVENTURE_VISION,
"amiga1200": UPS.AMIGA,
"amiga4000": UPS.AMIGA,
"amiga500": UPS.AMIGA,
"amiga600": UPS.AMIGA,
"amigacd32": UPS.AMIGA_CD32,
"amigacdtv": UPS.AMIGA_CD32,
"amstradcpc": UPS.ACPC,
"apfm1000": UPS.APF,
"apple2": UPS.APPLEII,
"apple2gs": UPS.APPLE_IIGS,
"arcadia": UPS.ARCADIA_2001,
"archimedes": UPS.ACORN_ARCHIMEDES,
"astrocde": UPS.ASTROCADE,
"atarijaguar": UPS.JAGUAR,
"atarijaguarcd": UPS.ATARI_JAGUAR_CD,
"atarilynx": UPS.LYNX,
"atarist": UPS.ATARI_ST,
"atarixe": UPS.ATARI_XEGS,
"bbc": UPS.BBCMICRO,
"c20": UPS.VIC_20,
"camplynx": UPS.CAMPUTERS_LYNX,
"cdi": UPS.PHILIPS_CD_I,
"cdimono1": UPS.PHILIPS_CD_I,
"cdtv": UPS.COMMODORE_CDTV,
"channelf": UPS.FAIRCHILD_CHANNEL_F,
"coco": UPS.TRS_80_COLOR_COMPUTER,
"consolearcade": UPS.ARCADE,
"cplus4": UPS.C_PLUS_4,
"cps": UPS.ARCADE,
"cps1": UPS.ARCADE,
"cps2": UPS.ARCADE,
"cps3": UPS.ARCADE,
"crvision": UPS.CREATIVISION,
"dragon32": UPS.DRAGON_32_SLASH_64,
"dreamcast": UPS.DC,
"easyrpg": UPS.RPG_MAKER,
"electron": UPS.ACORN_ELECTRON,
"flash": UPS.BROWSER,
"fm7": UPS.FM_7,
"fmtowns": UPS.FM_TOWNS,
"gameandwatch": UPS.G_AND_W,
"gamecom": UPS.GAME_DOT_COM,
"gamecube": UPS.NGC,
"gamepock": UPS.EPOCH_GAME_POCKET_COMPUTER,
"gb2players": UPS.GB,
"gba2players": UPS.GBA,
"gbc2players": UPS.GBC,
"gc": UPS.NGC,
"gmaster": UPS.HARTUNG,
"gx4000": UPS.AMSTRAD_GX4000,
"gzdoom": UPS.DOOM,
"jaguarcd": UPS.ATARI_JAGUAR_CD,
"laserdisc": UPS.DAPHNE,
"lcdgames": UPS.HANDHELD_ELECTRONIC_LCD,
"macintosh": UPS.MAC,
"mark3": UPS.SMS,
"mastersystem": UPS.SMS,
"megacd": UPS.SEGACD,
"megacdjp": UPS.SEGACD,
"megadrive": UPS.GENESIS,
"megadrive-msu": UPS.GENESIS,
"megadrivejp": UPS.GENESIS,
"megaduck": UPS.MEGA_DUCK_SLASH_COUGAR_BOY,
"model1": UPS.ARCADE,
"msu-md": UPS.GENESIS,
"msx1": UPS.MSX,
"msx2+": UPS.MSX2PLUS,
"msxturbor": UPS.MSX_TURBO,
"mz2500": UPS.SHARP_MZ_80B20002500,
"mz700": UPS.SHARP_MZ_80K7008001500,
"mz800": UPS.SHARP_MZ_80K7008001500,
"mz80k": UPS.SHARP_MZ_80K7008001500,
"n3ds": UPS.N3DS,
"n64dd": UPS.N64DD,
"namco22": UPS.ARCADE,
"neogeo": UPS.NEOGEOAES,
"neogeocd": UPS.NEO_GEO_CD,
"ngp": UPS.NEO_GEO_POCKET,
"ngpc": UPS.NEO_GEO_POCKET_COLOR,
"odyssey2": UPS.ODYSSEY_2,
"oricatmos": UPS.ATMOS,
"palm": UPS.PALM_OS,
"pc": UPS.WIN,
"pc88": UPS.PC_8800_SERIES,
"pc98": UPS.PC_9800_SERIES,
"pcengine": UPS.TG16,
"pcenginecd": UPS.TURBOGRAFX_CD,
"pcfx": UPS.PC_FX,
"pcw": UPS.AMSTRAD_PCW,
"pet": UPS.CPET,
"plugnplay": UPS.PLUG_AND_PLAY,
"pokemini": UPS.POKEMON_MINI,
"prboom": UPS.DOOM,
"ps": UPS.PSX,
"ps3-psn": UPS.PS3,
"pspminis": UPS.PSP_MINIS,
"pv1000": UPS.CASIO_PV_1000,
"samcoupe": UPS.SAM_COUPE,
"scv": UPS.EPOCH_SUPER_CASSETTE_VISION,
"sega32x": UPS.SEGA32,
"segastv": UPS.STV,
"sfc": UPS.SFAM,
"sg-1000": UPS.SG1000,
"sgb": UPS.GBC,
"sgb-msu1": UPS.GBC,
"snes-msu1": UPS.SNES,
"sufami": UPS.SUFAMI_TURBO,
"supracan": UPS.SUPER_ACAN,
"system-32": UPS.ARCADE,
"system16": UPS.ARCADE,
"system32": UPS.ARCADE,
"tg-cd": UPS.TURBOGRAFX_CD,
"thomson": UPS.THOMSON_MO5,
"ti99": UPS.TI_99,
"tic80": UPS.TIC_80,
"tutor": UPS.TOMY_TUTOR,
"typex": UPS.TYPE_X,
"vc4000": UPS.VC_4000,
"vic20": UPS.VIC_20,
"videopac": UPS.VIDEOPAC_G7400,
"videopacplus": UPS.VIDEOPAC_G7400,
"vpinball": UPS.PINBALL,
"wasm4": UPS.WASM_4,
"wiiware": UPS.WII,
"windows": UPS.WIN,
"windows3x": UPS.WIN3X,
"windows9x": UPS.WIN9X,
"wonderswancolor": UPS.WONDERSWAN_COLOR,
"wswan": UPS.WONDERSWAN,
"wswanc": UPS.WONDERSWAN_COLOR,
"x68000": UPS.SHARP_X68000,
"xegs": UPS.ATARI_XEGS,
"zc210": UPS.ZELDA_CLASSIC,
"zc250": UPS.ZELDA_CLASSIC,
"zmachine": UPS.Z_MACHINE,
"zxspectrum": UPS.ZXS,
}
def _unambiguous_folders() -> dict[str, str]:
folders_by_slug: dict[UPS, list[str]] = {}
for fs_slug, slug in PLATFORM_FS_ALIASES.items():
folders_by_slug.setdefault(slug, []).append(fs_slug)
return {
slug.value: folders[0]
for slug, folders in folders_by_slug.items()
if len(folders) == 1
}
# Only a slug reached by exactly one folder name can be resolved back to it.
PLATFORM_SLUG_FOLDERS: Final[dict[str, str]] = _unambiguous_folders()
def _to_slug(name: str) -> str:
key = name.lower()
if key in UPS:
return key
alias = PLATFORM_FS_ALIASES.get(key)
return alias.value if alias else name
def resolve_platform_slug(fs_slug: str, config: Config) -> str:
"""Resolve a platform folder name to a RomM platform slug."""
key = fs_slug.lower()
bound = config.PLATFORMS_BINDING.get(key) or config.PLATFORMS_VERSIONS.get(key)
# A bound name resolves like a folder name, so it may be an alias too.
return _to_slug(bound or fs_slug)
def resolve_fs_slug(slug: str, config: Config) -> str | None:
"""Resolve a RomM platform slug back to the folder name it came from.
Returns:
The folder name, or None when no folder maps to the slug or several
alias folders collapse onto it.
"""
for mapping in (config.PLATFORMS_BINDING, config.PLATFORMS_VERSIONS):
for fs_slug, bound in mapping.items():
if _to_slug(bound) == slug:
return fs_slug
return PLATFORM_SLUG_FOLDERS.get(slug)
def resolve_fs_folder(fs_slug: str, fs_platforms: Iterable[str]) -> str | None:
"""Resolve a folder name to the one on disk it names, ignoring case.
Config keys are lowercased, but paths are built from the folder's own
casing. An exact match wins, so on a case-sensitive filesystem two folders
differing only by case each still resolve to themselves.
Returns:
The folder as it is spelled on disk, or None when none matches.
"""
folded = fs_slug.lower()
fallback: str | None = None
for folder in fs_platforms:
if folder == fs_slug:
return folder
if fallback is None and folder.lower() == folded:
fallback = folder
return fallback