Files
MatchMaster_level/scripts/calibrate-level-glyphs.mjs

13 lines
1.1 KiB
JavaScript

// Developer-only, manually labelled glyphs. No level answers enter runtime code.
import {readFileSync as read,writeFileSync as write} from 'node:fs';
import {gunzipSync} from 'node:zlib';
const root=new URL('../colorBlock-level-editor/',import.meta.url);
const records=JSON.parse(read(new URL('test/fixtures/local-vision/level-glyph-calibration.json',root)));
const templates=records.map(({source,digit,box:b})=>{
const base=new URL(`test/fixtures/local-vision/${source}`,root),f=JSON.parse(read(new URL(base+'.json'))),data=gunzipSync(read(new URL(base+'.rgba.gz')));
const rows=Array.from({length:32},(_,y)=>Array.from({length:24},(_,x)=>{const p=((b.y+Math.floor((y+.5)*b.h/32))*f.width+b.x+Math.floor((x+.5)*b.w/24))*4;return data[p]>215&&data[p+1]>215&&data[p+2]>210?'1':'0';}).join(''));
return {digit,family:'level',aspect:b.w/b.h,rows};
});
write(new URL('src/vision/level-digit-templates.js',root),'// Manually labeled single glyphs from Level HUD; no full number/level answers.\nexport const LEVEL_DIGIT_TEMPLATES='+JSON.stringify(templates)+';\n');
console.log(`${templates.length} labelled level glyphs`);