본체 언어에 맞춰 A+C 메뉴와 이름이 바뀌도록 추가
This commit is contained in:
1 parent
14db4fc70d
commit
80d332a79c
51 files changed
+6649
-14
No files matched your search
@@ -0,0 +1,37 @@
|
||||
/* Native names and font pixels are extracted from the owner's ROM at build time. */
|
||||
(function(root){
|
||||
function build(rom,cat){
|
||||
const C=root.ParamixCore,D=root.ParamixAutoMenuData,ctx=C.openRom(rom),tabs=C.textTablesOf(rom).tabs;
|
||||
if(tabs.length!==9)throw Error('This ROM does not contain all nine language tables.');
|
||||
const glyphs=[],ids=new Map(),small=C.spriteDecode(ctx.entries[15]).subs,large=C.spriteDecode(ctx.entries[16]).subs;
|
||||
const pair=i=>String.fromCharCode(128+(i>>7),128+(i&127));
|
||||
function add(key,make){if(!ids.has(key)){if(glyphs.length>=16384)throw Error('Too many menu glyphs');ids.set(key,glyphs.length);glyphs.push(make());}return pair(ids.get(key));}
|
||||
function native(id){
|
||||
if(id>=318&&id<=343)return String.fromCharCode(65+id-318);
|
||||
if(id>=344&&id<=369)return String.fromCharCode(97+id-344);
|
||||
if(id>=306&&id<=315)return String(id-306);
|
||||
const plain={305:' ',317:' ',370:'!',375:'&',376:"'",381:'.',382:'/',388:'?',61440:' '};if(id in plain)return plain[id];
|
||||
return add('n'+id,()=>{
|
||||
const s=(id>=2831?large:small)[id-1];if(!s||s.w!==16||s.h!==16)throw Error('Missing native glyph: '+id);
|
||||
let x0=16,y0=16,x1=-1,y1=-1;for(let y=0;y<16;y++)for(let x=0;x<16;x++)if(s.data[(y*16+x)*4+3]){x0=Math.min(x0,x);y0=Math.min(y0,y);x1=Math.max(x1,x);y1=Math.max(y1,y);}
|
||||
const w=Math.max(id>=2831?12:10,x1-x0+1),h=Math.max(id>=2831?12:10,y1-y0+1);if(w>14||h>14)throw Error('Native glyph exceeds menu cell: '+id);
|
||||
const b=new Uint8Array(28);b[0]=w;b[1]=h;
|
||||
const ox=id<2831&&x0>=3&&x1<=12?3:x0-Math.floor((w-(x1-x0+1))/2),oy=id<2831&&y0>=3&&y1<=12?3:y0-Math.floor((h-(y1-y0+1))/2);
|
||||
for(let y=y0;y<=y1;y++)for(let x=x0;x<=x1;x++)if(s.data[(y*16+x)*4+3]){const p=(y-oy)*14+x-ox;b[2+(p>>3)]|=128>>(p&7);}return b;
|
||||
});
|
||||
}
|
||||
function encode(s){let out='';for(let ch of s){if(ch.charCodeAt(0)<128){out+=ch;continue;}if(ch in C.KO_ENC)out+=native(C.KO_ENC[ch]);else if(ch in D.native)out+=native(D.native[ch]);else if(ch in D.glyphs)out+=add('u'+ch,()=>Uint8Array.from(D.glyphs[ch]));else throw Error('Missing translated menu glyph: '+ch);}return out;}
|
||||
function words(t,i){if(!Number.isInteger(i)||i>=t.n)throw Error('Missing native name index '+i);let s='';for(let o=t.offs[i]*2;o+1<t.b.length;o+=2){const v=t.b[o]|t.b[o+1]<<8;if(!v)break;s+=native(v);}return s;}
|
||||
const labels=Array.from({length:9},(_,l)=>D.locales.map(row=>encode(row[l]))),names=tabs.map(t=>cat.map(c=>words(t,c.text)));
|
||||
let pos=32+9*8+9*4*(D.keys.length+cat.length);const strings=[],stringsByText=new Map();
|
||||
const ptr=s=>{if(!stringsByText.has(s)){stringsByText.set(s,pos);strings.push([pos,s]);pos+=s.length+1;}return stringsByText.get(s);};
|
||||
const lp=labels.map(row=>row.map(ptr)),np=names.map(row=>row.map(ptr));pos=(pos+3)&~3;const font=pos;pos+=glyphs.length*28;
|
||||
const b=new Uint8Array(pos),w=(o,v)=>{for(let i=0;i<4;i++)b[o+i]=(v>>>(8*i))&255;};
|
||||
w(0,0x324c5041);w(4,D.keys.length);w(8,cat.length);w(12,font);w(16,glyphs.length);let at=104;
|
||||
for(let l=0;l<9;l++){w(32+l*8,at);for(let v of lp[l]){w(at,v);at+=4;}w(36+l*8,at);for(let v of np[l]){w(at,v);at+=4;}}
|
||||
for(let[o,s]of strings)for(let i=0;i<s.length;i++)b[o+i]=s.charCodeAt(i);
|
||||
glyphs.forEach((g,i)=>b.set(g,font+i*28));
|
||||
return b;
|
||||
}
|
||||
root.ParamixAutoMenu={build};if(typeof module!=='undefined')module.exports=root.ParamixAutoMenu;
|
||||
})(typeof window!=='undefined'?window:globalThis);
|
||||
Reference in new issue
Block a user