Coverage for src/romfarmer/config/console_generations.py: 47%
38 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-05 02:19 -0700
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-05 02:19 -0700
1"""Console generation definitions (platform → generation vocabulary).
3Moved from ``romfarmer.ai.generation`` (2026-09-03) so that ``config`` — and
4therefore the compiler driver — never imports from ``ai``. ``ai.generation``
5re-exports these names for existing callers.
7Used for 1R1G cross-platform deduplication and for the optimizer's
8per-generation rating thresholds.
10Each generation defines:
11- The platforms in that generation
12- Priority order (first = keep, rest = exclusives only)
13- Platform capability mappings for the target system
15Priority is based on: library quality, emulation accuracy, and community
16consensus for "definitive version" of cross-platform games.
17"""
19from __future__ import annotations
21from dataclasses import dataclass, field
24@dataclass
25class GenerationDefinition:
26 """A console generation for cross-platform deduplication.
28 Attributes:
29 name: Generation identifier (gen3, gen4, gen5, etc.)
30 label: Human-readable label
31 era: Approximate year range
32 platforms: Platform names in priority order (first = highest priority).
33 These must match ROM Farmer platform directory names.
34 notes: Per-platform notes explaining priority decisions
35 """
37 name: str
38 label: str
39 era: str
40 platforms: list[str]
41 notes: dict[str, str] = field(default_factory=dict)
43 @property
44 def primary(self) -> str:
45 """The highest priority platform (keeper for duplicates)."""
46 return self.platforms[0]
48 @property
49 def secondary(self) -> list[str]:
50 """Lower priority platforms (become exclusives-only)."""
51 return self.platforms[1:]
53 def platform_rank(self, platform: str) -> int | None:
54 """Get priority rank (0=highest). None if not in this generation."""
55 try:
56 return self.platforms.index(platform)
57 except ValueError:
58 return None
61# ---------------------------------------------------------------------------
62# Console generation definitions
63# ---------------------------------------------------------------------------
64# Priority rationale for each generation:
65# - "Definitive version" community consensus
66# - Emulation maturity and accuracy on x86_64 Batocera
67# - Library size (larger library = more exclusives to preserve)
68#
69# For 1R1G: the PRIMARY platform keeps ALL its games.
70# Secondary platforms keep only exclusives (games not on primary).
71# This saves enormous space on cross-platform generations.
72# ---------------------------------------------------------------------------
74CONSOLE_GENERATIONS: list[GenerationDefinition] = [
75 GenerationDefinition(
76 name="gen3",
77 label="8-bit Era",
78 era="1983-1992",
79 platforms=["nes", "mastersystem", "atari7800", "sg1000"],
80 notes={
81 "nes": "Largest library, best emulation, definitive 8-bit platform",
82 "mastersystem": "Strong European library, good exclusives",
83 "atari7800": "Small library, unique backward compat titles",
84 "sg1000": "Niche, mostly Japan-only",
85 },
86 ),
87 GenerationDefinition(
88 name="gen4",
89 label="16-bit Era",
90 era="1988-1996",
91 platforms=["snes", "megadrive", "pcengine", "supergrafx"],
92 notes={
93 "snes": "Strongest RPG/platformer library, definitive 16-bit",
94 "megadrive": "Strong action/sports library, excellent exclusives",
95 "pcengine": "Best shmup library, strong Japan exclusives",
96 "supergrafx": "Tiny library (7 games), all exclusive to platform",
97 },
98 ),
99 GenerationDefinition(
100 name="gen5",
101 label="32/64-bit Era",
102 era="1993-2000",
103 platforms=["psx", "saturn"],
104 notes={
105 "psx": "Largest library in history, definitive gen5 platform",
106 "saturn": "Best 2D library, strong Japan exclusives, arcade ports",
107 # N64 deliberately excluded: tiny cart-based library, no meaningful
108 # cross-platform overlap worth deduplicating.
109 # 3DO excluded: tiny library, minimal overlap.
110 },
111 ),
112 GenerationDefinition(
113 name="gen5_handheld",
114 label="Gen 5 Handhelds",
115 era="1989-2003",
116 platforms=["gbc", "gba", "gamegear", "ngpc", "wswan", "wswanc"],
117 notes={
118 "gbc": "Largest handheld library of era, backward compat with GB",
119 "gba": "32-bit handheld, many SNES-quality exclusives",
120 "gamegear": "Sega's handheld, strong Sonic/Sega exclusives",
121 "ngpc": "Tiny gem library — fighting games masterclass",
122 "wswan": "Japan-only, some unique RPGs",
123 "wswanc": "WonderSwan Color — enhanced Japan-only titles",
124 },
125 ),
126 GenerationDefinition(
127 name="gen6",
128 label="128-bit Era",
129 era="2000-2005",
130 platforms=["ps2", "dreamcast", "xbox"],
131 notes={
132 "ps2": "Largest console library ever. Best RPG/action catalog",
133 "dreamcast": "Died young but legendary library. Best arcade ports (Naomi)",
134 "xbox": "Strongest Western exclusives (Halo, Knights of the Old Republic)",
135 },
136 ),
137 GenerationDefinition(
138 name="gen7",
139 label="HD Era",
140 era="2005-2013",
141 platforms=["ps3", "xbox360", "wii"],
142 notes={
143 "ps3": "Definitive multiplatform library, best exclusives (Uncharted, "
144 "God of War III, The Last of Us). Blu-ray = more content on disc.",
145 "xbox360": "Strong Western exclusives, best multiplatform performance "
146 "in early gen7. Halo 3/ODST/Reach, Gears series, Forza.",
147 "wii": "Motion controls = largely exclusive library. Very little "
148 "cross-platform overlap with PS3/360 that isn't already inferior.",
149 # GameCube excluded: gen6 platform, not gen7.
150 # Wii dedup against PS3/360 is minimal — most Wii games are exclusives.
151 # Wii is lowest priority: multiplatform ports were consistently inferior.
152 },
153 ),
154 GenerationDefinition(
155 name="gen7_handheld",
156 label="Gen 7 Handhelds",
157 era="2004-2014",
158 platforms=["psp", "nds", "3ds"],
159 notes={
160 "psp": "Console-quality handheld, strong RPG/action library",
161 "nds": "Massive library, touch-screen exclusives, backward compat GBA",
162 "3ds": "Successor to NDS — many NDS ports enhanced for 3DS",
163 },
164 ),
165 GenerationDefinition(
166 name="gen6_handheld",
167 label="Gen 6 Handhelds",
168 era="2001-2010",
169 platforms=["nds", "psp"],
170 notes={
171 "nds": "Massive library, touch-screen exclusives, backward compat GBA",
172 "psp": "Console-quality handheld, strong RPG/action library",
173 },
174 ),
175 GenerationDefinition(
176 name="portable",
177 label="Dedicated Portables",
178 era="1989-2017",
179 platforms=["gb", "gbc", "gba", "nds", "3ds"],
180 notes={
181 "gb": "The original Game Boy — foundational handheld titles",
182 "gbc": "Enhanced GB with color",
183 "gba": "32-bit handheld golden age",
184 "nds": "Dual-screen innovation, huge library",
185 "3ds": "Most recent dedicated Nintendo handheld",
186 },
187 ),
188 # Arcade generations aren't cross-platform in the same way —
189 # arcade ports to consoles are different enough to both merit inclusion.
190 # But MAME vs FBNeo IS a dedup target.
191 GenerationDefinition(
192 name="arcade",
193 label="Arcade",
194 era="1970-2010",
195 platforms=[
196 "mame",
197 "fbneo",
198 "naomi",
199 "naomi2",
200 "atomiswave",
201 "model2",
202 "model3",
203 "namco246",
204 "triforce",
205 ],
206 notes={
207 "mame": "Most comprehensive, definitive arcade platform",
208 "fbneo": "Alternative emulator, some games better here",
209 "naomi": "Sega arcade board — Dreamcast sibling",
210 "naomi2": "Enhanced Naomi — Virtua Fighter 4, etc.",
211 "atomiswave": "Later Sega arcade board",
212 "model2": "Sega Model 2 — Daytona USA, Virtua Fighter 2",
213 "model3": "Sega Model 3 — Virtua Fighter 3, Daytona 2",
214 "namco246": "Namco System 246 — PS2-based arcade",
215 "triforce": "Nintendo/Sega/Namco GameCube-based arcade",
216 },
217 ),
218]
221def get_generation(name: str) -> GenerationDefinition | None:
222 """Look up a generation by name."""
223 for gen in CONSOLE_GENERATIONS:
224 if gen.name == name:
225 return gen
226 return None
229def find_platform_generation(platform: str) -> GenerationDefinition | None:
230 """Find which generation a platform belongs to (first match)."""
231 for gen in CONSOLE_GENERATIONS:
232 if platform in gen.platforms:
233 return gen
234 return None
237def get_all_platforms_with_generation() -> dict[str, GenerationDefinition]:
238 """Map every platform to its generation."""
239 result = {}
240 for gen in CONSOLE_GENERATIONS:
241 for platform in gen.platforms:
242 if platform not in result: # First match wins
243 result[platform] = gen
244 return result