Files
syskiller 63fe0c8d41
Paramix Studio / build (push) Canceled after 0s
Paramix Studio / pages (push) Canceled after 0s
다마고치 변경할 때 본체 색상도 선택하도록 추가
2026-11-11 21:34:16 +09:00

66 lines
5.9 KiB
JavaScript

const fs=require('fs'),assert=require('assert/strict'),path=require('path');
const C=require('../src/core.js'),F=require('../src/feld.js'),E=require('../src/emu.js'),S=require('../src/saves.js');require('../src/menu-font-ko.js');
const read=p=>new Uint8Array(fs.readFileSync(p)),rom=read(process.argv[2]),ctx=C.openRom(rom),defs=C.charTable(ctx.files[0]);
const u32=(b,o)=>new DataView(b.buffer,b.byteOffset,b.byteLength).getUint32(o,true);
const ghost=0xDEE000, original=rom.slice(), petId=new DataView(rom.buffer).getUint16(ghost+0x10a,true),def=defs.find(c=>c.id===petId);
assert.equal(C.textGet(rom,1,'ko'),'정보');assert.equal(C.textGet(rom,14,'ko'),'육지');
assert.equal(C.KO_CHARS.length,2350);
assert.throws(()=>C.textClean('힣','ko'),/지원/);
const edits=new Map([[14,'한글나라'],[def.name,'한글이']]),out=C.textApply(rom,edits,'ko');
assert.equal(C.textGet(out,14,'ko'),'한글나라');assert.equal(C.textGet(out,def.name,'ko'),'한글이');
assert.equal(C.textGet(out,14,'en'),C.textGet(rom,14,'en'));
assert.deepEqual(rom,original);
assert.equal((u32(out,ghost)+u32(out,ghost+4))>>>0,0);
let delta=0;for(let i=8;i<0x180;i+=4)delta=(delta+u32(out,ghost+i)-u32(rom,ghost+i))>>>0;
assert.equal(u32(out,ghost),(u32(rom,ghost)+delta)>>>0);
const decodeName=b=>{let s='';for(let i=0;i<26;i+=2){const k=b[i]|b[i+1]<<8;if(!k)break;s+=C.KO_CHARS[k-481]||'?';}return s;};
assert.equal(decodeName(out.subarray(ghost+226,ghost+252)),'한글이');
const save={pages:S.paraFromImage(rom,ctx.editionId),edition:ctx.editionId};
const newer=S.paraPetSet(save,ctx.editionId,{happy:20,hunger:6});
assert.equal(S.paraPet(newer,ctx.editionId).happy,20);
assert.throws(()=>S.paraPetSet(save,ctx.editionId,{happy:21}),/범위/);
const live=rom.slice();for(const[a,d]of newer.pages)live.set(d,a);
async function main(){
const changed=new Set([ghost]),base=async()=>({image:live,notes:[],kept:1,protectedSectors:[ghost]});
const merged=await S.keepEdits(base,ctx.editionId,new Map([[petId,'한글이']]),{hunger:5},petId)(null,out,changed);
const p=S.paraPet({pages:S.paraFromImage(merged.image,ctx.editionId)},ctx.editionId);
assert.equal(p.happy,20);assert.equal(p.hunger,5);assert.equal(decodeName(merged.image.subarray(ghost+226,ghost+252)),'한글이');
assert(!merged.protectedSectors.includes(ghost));assert(changed.has(ghost));
await assert.rejects(()=>S.keepEdits(base,ctx.editionId,null,{hunger:5},9999)(null,out,changed),/다릅니다/);
const chars=F.characters(out,'ko'),items=F.itemCatalog(out,'ko');
assert(chars.length>60);assert(chars.every(c=>/[가-힣]/.test(c.name)));
assert(items.filter(c=>/[가-힣]/.test(c.name)).length>=264);
assert.equal(items.find(c=>c.id===7059).name,'GASHAPON'); // Official Korean table uses the brand in Latin letters.
const emb={feld:read(path.join(__dirname,'../feld/feld-ko.bin')),stub:read(path.join(__dirname,'../feld/stub_feld_tpl.bin'))};
const built=F.feldApply(out,{fields:true,bag:true,tama:true,saves:true},null,emb,E);
const image=built.rom||built,info=F.feldFind(image,emb.stub);assert(info);assert(Buffer.from(image.subarray(info.off,info.off+0x8000)).includes(Buffer.from('ITOSM_KO_MENU_V1')));
const cat=info.catOff,n=u32(image,cat+4),font=cat+12+40*n;assert.equal(u32(image,font),0x31464f4b);
const glyphCount=globalThis.ParamixKoreanMenu.fixed.length+C.KO_CHARS.length;
assert.equal(u32(image,font+4),glyphCount);
const names=font+8+13*glyphCount;let portraits=0;
const nativeFont=C.spriteDecode(ctx.entries[15]).subs;
for(const [i,ch]of [...globalThis.ParamixKoreanMenu.fixed,...C.KO_CHARS].entries()){
if(ch==='·')continue;const glyph=nativeFont[C.KO_ENC[ch]-1];
for(let y=0;y<10;y++)for(let x=0;x<10;x++){const bit=y*10+x;assert.equal(!!(image[font+8+i*13+(bit>>3)]&(128>>(bit&7))),!!glyph.data[((y+3)*16+x+3)*4+3],`Native font changed: ${ch} ${x},${y}`);}
}
const all=defs.filter(c=>c.id>1000&&c.id<9000);
for(let i=0;i<n;i++){
const off=u32(image,names+26*n+4*i);if(!off)continue;portraits++;
const at=cat+off;assert.equal(u32(image,at),0x3154504b);const w=image[at+4],h=image[at+6];assert.equal(w,64);assert.equal(h,64);
const id=image[cat+8+28*i]|image[cat+9+28*i]<<8,g=ctx.groups[all.findIndex(c=>c.id===id)+1],pose=C.faceFirst(ctx.files[0],g,g+1,g+2);
const body=C.spriteDecode(ctx.entries[g]).subs[pose.bs],pixels=body.data.slice();
for(const [j,v]of [[1,pose.eye],[2,pose.mouth]]){if(!v)continue;const p=C.spriteDecode(ctx.entries[g+j]).subs[v.sub],dx=(w-p.w)/2+v.dx,dy=(h-p.h)/2+v.dy;for(let y=0;y<p.h;y++)for(let x=0;x<p.w;x++){const sx=x+dx,sy=y+dy,k=(y*p.w+x)*4;if(sx>=0&&sy>=0&&sx<w&&sy<h&&p.data[k+3])pixels.set(p.data.subarray(k,k+4),(sy*w+sx)*4);}}
for(let p=0;p<w*h;p++){const k=4*p,expected=pixels[k+3]?((pixels[k]>>3)<<11)|((pixels[k+1]>>2)<<5)|(pixels[k+2]>>3):0xf81f;assert.equal(image[at+8+2*p]|image[at+9+2*p]<<8,expected,`Portrait pixel changed: ${id} ${p}`);}
}
assert(portraits>=60,'Character pictures missing: '+portraits);
const stripped=F.feldStrip(image,emb,E);assert(stripped.subarray(cat,cat+4096).every(b=>b===255));
assert.deepEqual(stripped.subarray(0xD49000),out.subarray(0xD49000),'Menu removal changed device saves');
const rebuilt=F.feldApply(stripped,{fields:true,bag:true,tama:true,saves:true},null,emb,E);assert.deepEqual(rebuilt,image,'Menu rebuild round trip');
const fieldsOnly=F.feldApply(out,{fields:true},null,emb,E),fo=F.feldFind(fieldsOnly,emb.stub);
assert(F.feldStrip(fieldsOnly,emb,E).subarray(fo.catOff,fo.catOff+4096).every(b=>b===255),'Font-only catalog removal');
assert.deepEqual(F.feldApply(F.feldStrip(fieldsOnly,emb,E),{fields:true},null,emb,E),fieldsOnly,'Empty color catalog strip/rebuild');
if(process.argv[3]){fs.writeFileSync(process.argv[3],image);fs.writeFileSync(process.argv[3]+'.json',JSON.stringify(info));}
console.log(JSON.stringify({passed:true,characters:chars.length,items:items.length,portraits,menuBytes:emb.feld.length,keptLatestHappiness:p.happy,physicalDevice:false}));
}
main().catch(e=>{console.error(e);process.exit(1);});