다마고치 변경할 때 본체 색상도 선택하도록 추가
This commit is contained in:
1 parent
fda254aa35
commit
63fe0c8d41
35 files changed
+421
-188
No files matched your search
+27
-3
@@ -1171,7 +1171,30 @@ function charTable(dp) {
|
||||
// Native current-pet genes: nine names, two palettes, 54 five-layer frames and
|
||||
// large/small eye sprites. Header-only ID changes retain the previous pet's look.
|
||||
// Layout and checksum are checked against independent firmware-generated exports.
|
||||
function characterGhost(rom,id,ctx=null,texts=null){
|
||||
function characterColorTable(rom,ctx=null){
|
||||
ctx=ctx||openRom(rom);const e=ctx.entries[197],h=e&&spriteHeader(e);
|
||||
if(!h||h.numPal!==16||h.bpp!==2||h.palBpp!==17||h.palOffset+512>e.length)throw Error('Native character colors are unavailable');
|
||||
return Array.from({length:16},(_,i)=>e.slice(h.palOffset+32*i,h.palOffset+32*i+16));
|
||||
}
|
||||
function characterPortrait(rom,id,color=-1,ctx=null,genes=null){
|
||||
ctx=ctx||openRom(rom);if(!Number.isInteger(color)||color< -1||color>15)throw Error('Invalid character color');
|
||||
const all=charTable(ctx.files[0]).filter(c=>c.id>1000&&c.id<9000),g=ctx.groups[all.findIndex(c=>c.id===id)+1];
|
||||
if(g===undefined)throw Error('Character sprites are missing');
|
||||
const pose=faceFirst(ctx.files[0],g,g+1,g+2),dec=spriteDecode(ctx.entries[g]),base=dec.subs[pose.bs];
|
||||
const img={w:base.w,h:base.h,data:new Uint8ClampedArray(base.w*base.h*4),mask:new Uint8Array(base.w*base.h).fill(15)};
|
||||
const colors=color<0?null:characterColorTable(rom,ctx)[color];
|
||||
const paint=(d,sub,dx,dy,recolor)=>{const part=d.subs[sub],h=d.header,iw=Math.max(1,h.iw),ih=Math.max(1,h.ih);
|
||||
for(let y=0;y<part.h;y++)for(let x=0;x<part.w;x++){const xx=x+dx,yy=y+dy,k=(y*part.w+x)*4;if(xx<0||yy<0||xx>=img.w||yy>=img.h||!part.data[k+3])continue;
|
||||
const o=(yy*img.w+xx)*4,index=d.cells[sub*iw*ih+Math.floor(y/h.sh)*iw+Math.floor(x/h.sw)][(y%h.sh)*h.sw+x%h.sw];
|
||||
img.data.set(part.data.subarray(k,k+4),o);img.mask[o/4]=recolor&&d.palettes&&index<8?index:15;
|
||||
if(colors&&img.mask[o/4]<8)img.data.set(rgb565ToRgb(u16(colors,index*2)),o);
|
||||
}};
|
||||
// Eyes use their own palette. Only body and mouth indexes 0..7 are recolored.
|
||||
paint(dec,pose.bs,0,0,true);for(const[j,v]of[[1,pose.eye],[2,pose.mouth]])if(v){let entry=ctx.entries[g+j];if(j===1&&genes){const off=u32(genes,0x118),len=u32(genes,0x11c);if(off&&len&&off+len<=genes.length)entry=genes.subarray(off,off+len);}const d=spriteDecode(entry),p=d.subs[v.sub];if(!p)throw Error('Character eye frame is unavailable');paint(d,v.sub,(img.w-p.w)/2+v.dx,(img.h-p.h)/2+v.dy,j===2);}
|
||||
return img;
|
||||
}
|
||||
function characterGhost(rom,id,ctx=null,texts=null,color=-1){
|
||||
if(!Number.isInteger(color)||color< -1||color>15)throw Error('Invalid character color');
|
||||
ctx=ctx||openRom(rom);texts=texts||textTablesOf(rom);const dp=ctx.files[0],table=i=>u32(dp,i*4)*2;
|
||||
let rec=null;for(let o=table(11);o<table(12);o+=30)if(u16(dp,o)===id){rec=Array.from({length:15},(_,k)=>u16(dp,o+2*k));break;}
|
||||
if(!rec)throw Error('Character definition is missing');
|
||||
@@ -1180,10 +1203,11 @@ function characterGhost(rom,id,ctx=null,texts=null){
|
||||
const eye=ctx.entries[body+1],small=ctx.entries[body+4],align=n=>(n+3)&~3;
|
||||
const out=new Uint8Array(0x1d34+align(eye.length)+align(small.length));
|
||||
if(out.length>0x4000)throw Error('Character genes exceed the native slot');
|
||||
w32(out,8,1);w16(out,12,4017);w16(out,14,id);out[16]=Math.min(15,rec[14]);
|
||||
w32(out,8,1);w16(out,12,4017);w16(out,14,id);out[16]=color<0?Math.min(15,rec[14]):color;
|
||||
w16(out,0xfc,rec[3]);w16(out,0xfe,rec[5]);w16(out,0x100,rec[7]);w16(out,0x102,rec[8]);w16(out,0x10a,id);w32(out,0x10c,out.length);
|
||||
for(let lang=0;lang<9;lang++){const t=texts.tabs[lang],index=rec[2]+1;if(!t||index>=t.n)throw Error('Native name table is missing');const start=t.offs[index]*2,end=index+1<t.n?t.offs[index+1]*2:t.b.length;let n=0;for(let i=start;i+1<end&&n<12;i+=2){const c=u16(t.b,i);if(c===0||c===0xf000)break;w16(out,18+26*lang+2*n++,c);}}
|
||||
for(const[k,g]of[[0,body],[1,body+2]]){const e=ctx.entries[g],h=spriteHeader(e);out.set(e.subarray(h.palOffset,h.palOffset+32),0x140+32*k);}
|
||||
if(color>=0){const palette=characterColorTable(rom,ctx)[color];out.set(palette,0x140);out.set(palette,0x160);}
|
||||
const types=[0,1,15,16,17],map=[1,2,6,7,4,3,5,8,9,10,0];
|
||||
for(let f=0;f<54;f++){const row=table(18)+4*(rec[1]*54+f),first=u16(dp,row),count=u16(dp,row+2);if(first===65535)continue;if(count>32)throw Error('Invalid character frame');
|
||||
for(let j=0;j<count;j++){let pos=table(15)+u32(dp,table(16)+4*(first+j))*2,mask=u16(dp,pos);pos+=2;const v=[0,0,0,4096,0,64,0,0,0,0,0];for(let bit=0;bit<11;bit++)if(mask&(1<<bit)){v[map[bit]]=u16(dp,pos);pos+=2;}const ti=types.indexOf(v[10]);if(ti<0)continue;if(ti<3&&v[0])v[0]-=body;for(let k=0;k<11;k++)w16(out,0x600+(f*5+ti)*22+2*k,v[k]&65535);}
|
||||
@@ -1324,7 +1348,7 @@ function nativePetNames(out,edition,names,language){
|
||||
return out;
|
||||
}
|
||||
|
||||
root.ParamixCore = { characterGhost, koreanPetNames, paraLayers, faceFirst, facePoses, layersMove, EYE_V2, smaDetect, smaLoad, eyeFirst, eyeRelGet, shiftEyes, textClean, textGet, textApply, textTablesOf, TXT_ENC, DE_ENC, KO_CHARS, KO_ENC,
|
||||
root.ParamixCore = { characterColorTable, characterPortrait, characterGhost, koreanPetNames, paraLayers, faceFirst, facePoses, layersMove, EYE_V2, smaDetect, smaLoad, eyeFirst, eyeRelGet, shiftEyes, textClean, textGet, textApply, textTablesOf, TXT_ENC, DE_ENC, KO_CHARS, KO_ENC,
|
||||
fieldSets, charTable, FIELD_NAMES,
|
||||
ASSET_BASE, EDITIONS, GROUP_PARTS, GROUP_SHEET_W, GROUP_SHEET_H,
|
||||
arc2Parse, arc2Files, arc2Build, arc2Checksum, packSplit, packJoin, spriteHeader, spriteDecode, spriteEncode, spriteBlank, spriteTiny, spriteAlign, partOptions, launcherKeep, launcherChanges, isLauncher,
|
||||
|
||||
Reference in new issue
Block a user