@@ -135,13 +135,55 @@ function findConfigDir() {
135135 process . exit ( 1 ) ;
136136}
137137
138+ // Parse arena registry index.yaml to build ARENA_REGISTRY
139+ function parseArenaRegistry ( registryDir ) {
140+ const indexFile = path . join ( registryDir , 'index.yaml' ) ;
141+ if ( ! fs . existsSync ( indexFile ) ) {
142+ console . warn ( 'Warning: arena_registry/index.yaml not found, using empty registry' ) ;
143+ return { } ;
144+ }
145+
146+ const content = fs . readFileSync ( indexFile , 'utf8' ) ;
147+ const registry = { } ;
148+ let currentGen = null ;
149+
150+ for ( const line of content . split ( '\n' ) ) {
151+ if ( line . trim ( ) . startsWith ( '#' ) || line . trim ( ) === '' ) continue ;
152+ if ( line . match ( / ^ v e r s i o n : / ) ) continue ;
153+
154+ // Generation section header (e.g., "G41:" or "G6:")
155+ const sectionMatch = line . match ( / ^ ( \w + ) : $ / ) ;
156+ if ( sectionMatch ) {
157+ // Map YAML keys to generation names: G41 -> G4.1, G4 -> G4, G6 -> G6
158+ const key = sectionMatch [ 1 ] ;
159+ if ( key === 'G41' ) currentGen = 'G4.1' ;
160+ else currentGen = key ;
161+ registry [ currentGen ] = { } ;
162+ continue ;
163+ }
164+
165+ // Arena ID entry (e.g., " 1: G41_2x12_cw")
166+ const entryMatch = line . match ( / ^ \s + ( \d + ) : \s * ( \S + ) / ) ;
167+ if ( entryMatch && currentGen ) {
168+ registry [ currentGen ] [ parseInt ( entryMatch [ 1 ] ) ] = entryMatch [ 2 ] ;
169+ }
170+ }
171+
172+ return registry ;
173+ }
174+
138175// Main
139176function main ( ) {
140177 const configDir = findConfigDir ( ) ;
141178 const outputFile = path . join ( process . cwd ( ) , 'js' , 'arena-configs.js' ) ;
142179
143180 console . log ( `Reading configs from: ${ configDir } ` ) ;
144181
182+ // Also find registry directory (sibling of arenas/)
183+ const registryDir = path . join ( path . dirname ( configDir ) , 'arena_registry' ) ;
184+ const arenaRegistry = parseArenaRegistry ( registryDir ) ;
185+ console . log ( ` Arena registry: ${ JSON . stringify ( arenaRegistry ) } ` ) ;
186+
145187 const configs = { } ;
146188 const files = fs . readdirSync ( configDir ) . filter ( f => f . endsWith ( '.yaml' ) || f . endsWith ( '.yml' ) ) ;
147189
@@ -181,17 +223,88 @@ function main() {
181223 sortedConfigs [ key ] = configs [ key ] ;
182224 } ) ;
183225
226+ // Format ARENA_REGISTRY as readable JS
227+ const registryLines = [ ] ;
228+ for ( const [ gen , entries ] of Object . entries ( arenaRegistry ) ) {
229+ const items = Object . entries ( entries ) . map ( ( [ id , name ] ) => `${ id } : '${ name } '` ) . join ( ', ' ) ;
230+ registryLines . push ( ` '${ gen } ': { ${ items } }` ) ;
231+ }
232+ const registryStr = registryLines . join ( ',\n' ) ;
233+
184234 // Generate output
185235 const output = `/**
186236 * Arena Configurations
187- * Auto-generated from maDisplayTools/configs/arenas/
237+ * Auto-generated from maDisplayTools/configs/arenas/ and arena_registry/
188238 * Last updated: ${ new Date ( ) . toISOString ( ) }
189239 *
190240 * DO NOT EDIT MANUALLY - regenerate with: node scripts/generate-arena-configs.js
191241 */
192242
193243const STANDARD_CONFIGS = ${ JSON . stringify ( sortedConfigs , null , 2 ) } ;
194244
245+ // Generation ID registry (from maDisplayTools/configs/arena_registry/generations.yaml)
246+ const GENERATIONS = {
247+ 0: { name: 'unspecified', panel_size: null },
248+ 1: { name: 'G3', panel_size: 8 },
249+ 2: { name: 'G4', panel_size: 16 },
250+ 3: { name: 'G4.1', panel_size: 16 },
251+ 4: { name: 'G6', panel_size: 20 },
252+ 5: { name: 'G5', panel_size: null, deprecated: true }
253+ };
254+
255+ // Arena ID registry — per-generation namespaces (from maDisplayTools/configs/arena_registry/index.yaml)
256+ const ARENA_REGISTRY = {
257+ ${ registryStr }
258+ };
259+
260+ /**
261+ * Get generation name from ID
262+ * @param {number} id - Generation ID (0-7)
263+ * @returns {string} Generation name or 'unknown'
264+ */
265+ function getGenerationName(id) {
266+ return GENERATIONS[id] ? GENERATIONS[id].name : 'unknown';
267+ }
268+
269+ /**
270+ * Get generation ID from name
271+ * @param {string} name - Generation name (e.g., 'G6', 'G4.1')
272+ * @returns {number} Generation ID or 0
273+ */
274+ function getGenerationId(name) {
275+ for (const [id, gen] of Object.entries(GENERATIONS)) {
276+ if (gen.name === name) return parseInt(id);
277+ }
278+ return 0;
279+ }
280+
281+ /**
282+ * Get arena config name from generation and arena ID
283+ * @param {string} generation - Generation name (e.g., 'G6', 'G4')
284+ * @param {number} arenaId - Arena ID
285+ * @returns {string|null} Arena config name or null
286+ */
287+ function getArenaName(generation, arenaId) {
288+ const genRegistry = ARENA_REGISTRY[generation];
289+ if (!genRegistry) return null;
290+ return genRegistry[arenaId] || null;
291+ }
292+
293+ /**
294+ * Get arena ID from generation and config name
295+ * @param {string} generation - Generation name (e.g., 'G6', 'G4')
296+ * @param {string} arenaName - Arena config name (e.g., 'G6_2x10')
297+ * @returns {number} Arena ID or 0
298+ */
299+ function getArenaId(generation, arenaName) {
300+ const genRegistry = ARENA_REGISTRY[generation];
301+ if (!genRegistry) return 0;
302+ for (const [id, name] of Object.entries(genRegistry)) {
303+ if (name === arenaName) return parseInt(id);
304+ }
305+ return 0;
306+ }
307+
195308// Panel specifications by generation
196309const PANEL_SPECS = {
197310 'G3': {
@@ -251,8 +364,33 @@ function getConfigsByGeneration() {
251364
252365// Export for both browser and Node.js
253366if (typeof module !== 'undefined' && module.exports) {
254- module.exports = { STANDARD_CONFIGS, PANEL_SPECS, getConfig, getConfigsByGeneration };
367+ module.exports = {
368+ STANDARD_CONFIGS, PANEL_SPECS, GENERATIONS, ARENA_REGISTRY,
369+ getConfig, getConfigsByGeneration,
370+ getGenerationName, getGenerationId, getArenaName, getArenaId
371+ };
372+ }
373+
374+ // Browser global export (for non-module scripts)
375+ if (typeof window !== 'undefined') {
376+ window.STANDARD_CONFIGS = STANDARD_CONFIGS;
377+ window.PANEL_SPECS = PANEL_SPECS;
378+ window.GENERATIONS = GENERATIONS;
379+ window.ARENA_REGISTRY = ARENA_REGISTRY;
380+ window.getConfig = getConfig;
381+ window.getConfigsByGeneration = getConfigsByGeneration;
382+ window.getGenerationName = getGenerationName;
383+ window.getGenerationId = getGenerationId;
384+ window.getArenaName = getArenaName;
385+ window.getArenaId = getArenaId;
255386}
387+
388+ // ES6 module export
389+ export {
390+ STANDARD_CONFIGS, PANEL_SPECS, GENERATIONS, ARENA_REGISTRY,
391+ getConfig, getConfigsByGeneration,
392+ getGenerationName, getGenerationId, getArenaName, getArenaId
393+ };
256394` ;
257395
258396 // Ensure js/ directory exists
0 commit comments