본체 한글 목록과 아이템 수량 선택
Paramix Studio / build (push) Canceled after 0s
Paramix Studio / pages (push) Canceled after 0s

This commit is contained in:
syskiller committed 2026-11-10 21:46:45 +09:00
1 parent b1f7f64142
commit 7d6381f4a4
14 files changed
+2864 -2814

No files matched your search

+85 -85
View File
@@ -1,85 +1,85 @@
// Generate compact two-byte menu strings; storage/config structures stay upstream-compatible.
const fs=require('fs'),path=require('path');const root=path.resolve(__dirname,'..'),dir=path.join(root,'feld/src/feld');
const tr={};for(const row of fs.readFileSync(dir+'/ko.tsv','utf8').split(/\r?\n/)){if(!row)continue;const p=row.indexOf('\t');tr[row.slice(0,p)]=row.slice(p+1);}
const fields={LAND:'랜드',WATER:'워터',SKY:'스카이',FOREST:'포레스트',TROPICAL:'트로피컬',GLACIER:'글레이셔'};
const chars=[...new Set((Object.values({...tr,...fields}).join('')+'다마고치 편집지역과 저장다마포인트아이템프로그램A 이동 B 선택 C 뒤로'))].filter(x=>x.charCodeAt(0)>127).sort();
const native=require('../src/core.js').KO_CHARS;
const wanted=new Set([...chars,...native]);
const glyphs=new Map();const bdf=fs.readFileSync(root+'/third-party/Galmuri9.bdf','utf8');
for(const block of bdf.split('STARTCHAR ').slice(1)){
const cp=Number(block.match(/ENCODING (\d+)/)?.[1]);if(!wanted.has(String.fromCodePoint(cp||0)))continue;
const [w,h,x,y]=block.match(/BBX (-?\d+) (-?\d+) (-?\d+) (-?\d+)/).slice(1).map(Number);
const rows=block.split(/BITMAP\r?\n/)[1].split(/\r?\n/).slice(0,h).map(x=>parseInt(x,16));
// 10x10 canvas with the baseline at y=9; Galmuri9's Hangul is nine pixels tall.
const bits=new Uint8Array(13);for(let r=0;r<h;r++)for(let c=0;c<w;c++)if(rows[r]&(2**(Math.ceil(w/8)*8-1-c))){
const xx=x+c,yy=9-y-h+r;if(xx<0||xx>=10||yy<0||yy>=10)throw Error('Glyph crop: '+String.fromCodePoint(cp));
const n=yy*10+xx;bits[n>>3]|=128>>(n&7);
}
glyphs.set(cp,[...bits]);
}
for(const c of chars)if(!glyphs.has(c.codePointAt(0)))throw Error('Missing glyph '+c);
for(const c of native)if(!glyphs.has(c.codePointAt(0)))throw Error('Missing native glyph '+c);
const allGlyphs=[...chars,...native];
const font=Buffer.alloc(8+allGlyphs.length*13);font.writeUInt32LE(0x31464f4b,0);font.writeUInt32LE(allGlyphs.length,4);
allGlyphs.forEach((c,i)=>font.set(glyphs.get(c.codePointAt(0)),8+i*13));
fs.writeFileSync(root+'/src/menu-font-ko.js',`// Generated Galmuri9 native Korean font. See third-party/Galmuri-OFL.txt.
(function(root){
const fixed=${JSON.stringify(chars.join(''))}, native=${JSON.stringify(native)}, data=${JSON.stringify(font.toString('base64'))};
function encode(s,max=255){let out='';for(const c of s){let v=c;if(c.charCodeAt(0)>127){let n=fixed.indexOf(c);if(n<0){let k=native.indexOf(c);if(k<0)throw Error('본체 메뉴에서 지원하지 않는 문자: '+c);n=fixed.length+k;}v=String.fromCharCode(128+(n>>7),128+(n&127));}if(out.length+v.length>max)break;out+=v;}return out;}
function font(){return typeof Buffer!=='undefined'?new Uint8Array(Buffer.from(data,'base64')):Uint8Array.from(atob(data),c=>c.charCodeAt(0));}
root.ParamixKoreanMenu={encode,font,fixed,native};
if(typeof module!=='undefined')module.exports=root.ParamixKoreanMenu;
})(typeof window!=='undefined'?window:globalThis);
`);
const enc=s=>[...s].map(c=>c.charCodeAt(0)<128?c.replace(/\\/g,'\\\\').replace(/"/g,'\\"'):[128+(chars.indexOf(c)>>7),128+(chars.indexOf(c)&127)].map(x=>'\\'+x.toString(8).padStart(3,'0')).join('')).join('');
fs.writeFileSync(dir+'/font_ko.h','/* ITOSM Korean menu subset of Galmuri9, quiple, SIL OFL 1.1.\n * See third-party/Galmuri-OFL.txt. Generated by scripts/build-menu-ko.cjs. */\n#define KO_GLYPHS '+chars.length+'\nstatic const unsigned char ko_font[KO_GLYPHS][13]={\n'+chars.map(c=>'{'+glyphs.get(c.codePointAt(0)).join(',')+'}, /* '+c+' */').join('\n')+'\n};\n');
let s=fs.readFileSync(dir+'/main.c','utf8').replace(/\r\n/g,'\n');const counts={};
s=s.replace(/"((?:[^"\\]|\\.)*)"/g,(whole,k)=>{if(!(k in tr))return whole;counts[k]=(counts[k]||0)+1;return '"'+enc(tr[k])+'"';});
for(const k of Object.keys(tr))if(!counts[k])throw Error('Unused menu translation '+k);
s=s.replace('#include "font.h"','#include "font.h"\n#include "font_ko.h"');
const from=s.indexOf('static int text_w('),to=s.indexOf('static void text(int',from);
s=s.slice(0,from)+`/* Korean pairs have both bytes >= 128. Never interpret truncated input as an index. */
static int ko_pair(const char *s){ return (u8)s[0]>=128 && (u8)s[1]>=128; }
static int ko_scale(const char *s,int sc){ for(int i=0;s[i];i++) if((u8)s[i]>=128) return 1; return sc; }
static int text_w(const char *s,int sc){ sc=ko_scale(s,sc); int w=0; for(int i=0;s[i];i++){if(ko_pair(s+i)){w+=10*sc;i++;}else w+=6*sc;}return w?w-sc:0; }
static void textn(int x,int y,const char *s,int n,u16 c,int sc){
sc=ko_scale(s,sc); const int limit=x+n*6*sc;
for(int i=0;i<n && s[i];i++){
if(ko_pair(s+i)){
unsigned k=(((u8)s[i]&127)<<7)|((u8)s[i+1]&127);i++;
if(x+10*sc>limit || x+10*sc>128)break;
const volatile u8 *g=0;
if(k<KO_GLYPHS+2350u && g_cfg.cat_off){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;if(rd32(a)==0x31464f4bu)g=fl(a+8u+13u*k);}
#ifdef FELD_CLEAN
if(!g && k<KO_GLYPHS)g=ko_font[k];
#endif
if(g)for(int r=0;r<10;r++)for(int q=0;q<10;q++){int p=r*10+q;if(g[p>>3]&(128>>(p&7)))rect(x+q*sc,y+r*sc,x+(q+1)*sc,y+(r+1)*sc,c);}
x+=10*sc;
}else{
if(x+5*sc>limit || x+5*sc>128)break;
int ch=(u8)s[i];if(ch>=128)ch='?';if(ch>=0x60 && ch!='x')ch-=32;
int k=glyph(ch);if(k<0||k>=96)k='?'-32;
const u8 *g=g_font[k];
for(int r=0;r<7;r++)for(int q=0;q<5;q++)if(g[r]&(16>>q))rect(x+q*sc,y+r*sc,x+(q+1)*sc,y+(r+1)*sc,c);
x+=6*sc;
}
}
}
`+s.slice(to);
// Bottom help rows used to be seven pixels tall. Keep the ten-pixel Hangul inside 128px.
s=s.replace(/ctext\(119,/g,'ctext(117,').replace(/text\(5,119,/g,'text(5,117,');
// In the tall tile the status is below a Korean title (10px vs the original 14px).
s=s.replace('text(9,y+19,st,stc,1);','text(9,y+17,st,stc,1);');
s=s.replace('text(9,y+4,name,c,2);\n int w=text_w(st,1), x=121-w, nx=9+text_w(name,2)+4; if(x<nx) x=nx;\n textn(x,y+8,st,(121-x)/6,stc,1);', 'text(9,y+2,name,c,1);\n textn(9,y+12,st,19,stc,1);');
s=s.replace('rect(5,y+2,123,y+20,BG);','rect(4,y+1,124,y+21,BG);');
s=s.replace('char nm[12], st[24];','char nm[12], st[48];');
const nameFunc='static const char *ko_field(const char *s){\n'+Object.entries(fields).map(([a,b])=>' {const char *a="'+a+'";int i=0;while(a[i]&&s[i]&&a[i]==s[i])i++;if(!a[i]&&!s[i])return "'+enc(b)+'";}').join('\n')+'\nreturn s;}\n';
s=s.replace('static const char *fname(u32 i){ return i<4u ? (const char*)g_cfg.field_name[i] : (const char*)g_cfg.field_name2[i-4u]; }',nameFunc+'static const char *fname(u32 i){ return ko_field(i<4u ? (const char*)g_cfg.field_name[i] : (const char*)g_cfg.field_name2[i-4u]); }');
s=require('./native-menu-layout.cjs')(s,enc);
fs.writeFileSync(dir+'/main-ko.c',s);
let sh=fs.readFileSync(dir+'/build.sh','utf8').replace('main.c hw.c','main-ko.c hw.c').replace('[ "$n" = main ]','[ "$n" = main-ko ]').replace('N=${OUT:-feld}','N=${OUT:-feld-ko}').replace('OUT=feldc','OUT=feldc-ko').replace('-ffreestanding','-flto -ffreestanding').replace('sh "$0" --inner','sh ./build-ko.sh --inner');
sh=sh.replace(' -Os ', ' -Oz ');
sh=sh.replace('llvm-size $N.elf; ls -l $N.bin', 'python3 -c \'import pathlib,sys; p=pathlib.Path(sys.argv[1]); p.write_bytes(p.read_bytes()+b"ITOSM_KO_MENU_V1\\x00")\' "$N.bin"\nllvm-size $N.elf; ls -l $N.bin');
fs.writeFileSync(dir+'/build-ko.sh',sh.replace(/\r\n/g,'\n'));
fs.writeFileSync(dir+'/ko-encoding.json',JSON.stringify({chars,translations:tr,fields},null,2));
console.log('Menu:',Object.keys(counts).length,'strings,',chars.length,'glyphs,',chars.length*13,'font bytes');
// Generate compact two-byte menu strings; storage/config structures stay upstream-compatible.
const fs=require('fs'),path=require('path');const root=path.resolve(__dirname,'..'),dir=path.join(root,'feld/src/feld');
const tr={};for(const row of fs.readFileSync(dir+'/ko.tsv','utf8').split(/\r?\n/)){if(!row)continue;const p=row.indexOf('\t');tr[row.slice(0,p)]=row.slice(p+1);}
const fields={LAND:'랜드',WATER:'워터',SKY:'스카이',FOREST:'포레스트',TROPICAL:'트로피컬',GLACIER:'글레이셔'};
const chars=[...new Set((Object.values({...tr,...fields}).join('')+'다마고치 편집지역과 저장다마포인트아이템프로그램A 이동 B 선택 C 뒤로B 변경 C 목록추가수량개휠 수량 조절B 확인 C 목록최대 15개 보유더 추가할 수 없습니다'))].filter(x=>x.charCodeAt(0)>127).sort();
const native=require('../src/core.js').KO_CHARS;
const wanted=new Set([...chars,...native]);
const glyphs=new Map();const bdf=fs.readFileSync(root+'/third-party/Galmuri9.bdf','utf8');
for(const block of bdf.split('STARTCHAR ').slice(1)){
const cp=Number(block.match(/ENCODING (\d+)/)?.[1]);if(!wanted.has(String.fromCodePoint(cp||0)))continue;
const [w,h,x,y]=block.match(/BBX (-?\d+) (-?\d+) (-?\d+) (-?\d+)/).slice(1).map(Number);
const rows=block.split(/BITMAP\r?\n/)[1].split(/\r?\n/).slice(0,h).map(x=>parseInt(x,16));
// 10x10 canvas with the baseline at y=9; Galmuri9's Hangul is nine pixels tall.
const bits=new Uint8Array(13);for(let r=0;r<h;r++)for(let c=0;c<w;c++)if(rows[r]&(2**(Math.ceil(w/8)*8-1-c))){
const xx=x+c,yy=9-y-h+r;if(xx<0||xx>=10||yy<0||yy>=10)throw Error('Glyph crop: '+String.fromCodePoint(cp));
const n=yy*10+xx;bits[n>>3]|=128>>(n&7);
}
glyphs.set(cp,[...bits]);
}
for(const c of chars)if(!glyphs.has(c.codePointAt(0)))throw Error('Missing glyph '+c);
for(const c of native)if(!glyphs.has(c.codePointAt(0)))throw Error('Missing native glyph '+c);
const allGlyphs=[...chars,...native];
const font=Buffer.alloc(8+allGlyphs.length*13);font.writeUInt32LE(0x31464f4b,0);font.writeUInt32LE(allGlyphs.length,4);
allGlyphs.forEach((c,i)=>font.set(glyphs.get(c.codePointAt(0)),8+i*13));
fs.writeFileSync(root+'/src/menu-font-ko.js',`// Generated Galmuri9 native Korean font. See third-party/Galmuri-OFL.txt.
(function(root){
const fixed=${JSON.stringify(chars.join(''))}, native=${JSON.stringify(native)}, data=${JSON.stringify(font.toString('base64'))};
function encode(s,max=255){let out='';for(const c of s){let v=c;if(c.charCodeAt(0)>127){let n=fixed.indexOf(c);if(n<0){let k=native.indexOf(c);if(k<0)throw Error('본체 메뉴에서 지원하지 않는 문자: '+c);n=fixed.length+k;}v=String.fromCharCode(128+(n>>7),128+(n&127));}if(out.length+v.length>max)break;out+=v;}return out;}
function font(){return typeof Buffer!=='undefined'?new Uint8Array(Buffer.from(data,'base64')):Uint8Array.from(atob(data),c=>c.charCodeAt(0));}
root.ParamixKoreanMenu={encode,font,fixed,native};
if(typeof module!=='undefined')module.exports=root.ParamixKoreanMenu;
})(typeof window!=='undefined'?window:globalThis);
`);
const enc=s=>[...s].map(c=>c.charCodeAt(0)<128?c.replace(/\\/g,'\\\\').replace(/"/g,'\\"'):[128+(chars.indexOf(c)>>7),128+(chars.indexOf(c)&127)].map(x=>'\\'+x.toString(8).padStart(3,'0')).join('')).join('');
fs.writeFileSync(dir+'/font_ko.h','/* ITOSM Korean menu subset of Galmuri9, quiple, SIL OFL 1.1.\n * See third-party/Galmuri-OFL.txt. Generated by scripts/build-menu-ko.cjs. */\n#define KO_GLYPHS '+chars.length+'\nstatic const unsigned char ko_font[KO_GLYPHS][13]={\n'+chars.map(c=>'{'+glyphs.get(c.codePointAt(0)).join(',')+'}, /* '+c+' */').join('\n')+'\n};\n');
let s=fs.readFileSync(dir+'/main.c','utf8').replace(/\r\n/g,'\n');const counts={};
s=s.replace(/"((?:[^"\\]|\\.)*)"/g,(whole,k)=>{if(!(k in tr))return whole;counts[k]=(counts[k]||0)+1;return '"'+enc(tr[k])+'"';});
for(const k of Object.keys(tr))if(!counts[k])throw Error('Unused menu translation '+k);
s=s.replace('#include "font.h"','#include "font.h"\n#include "font_ko.h"');
const from=s.indexOf('static int text_w('),to=s.indexOf('static void text(int',from);
s=s.slice(0,from)+`/* Korean pairs have both bytes >= 128. Never interpret truncated input as an index. */
static int ko_pair(const char *s){ return (u8)s[0]>=128 && (u8)s[1]>=128; }
static int ko_scale(const char *s,int sc){ for(int i=0;s[i];i++) if((u8)s[i]>=128) return 1; return sc; }
static int text_w(const char *s,int sc){ sc=ko_scale(s,sc); int w=0; for(int i=0;s[i];i++){if(ko_pair(s+i)){w+=10*sc;i++;}else w+=6*sc;}return w?w-sc:0; }
static void textn(int x,int y,const char *s,int n,u16 c,int sc){
sc=ko_scale(s,sc); const int limit=x+n*6*sc;
for(int i=0;i<n && s[i];i++){
if(ko_pair(s+i)){
unsigned k=(((u8)s[i]&127)<<7)|((u8)s[i+1]&127);i++;
if(x+10*sc>limit || x+10*sc>128)break;
const volatile u8 *g=0;
if(k<KO_GLYPHS+2350u && g_cfg.cat_off){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;if(rd32(a)==0x31464f4bu)g=fl(a+8u+13u*k);}
#ifdef FELD_CLEAN
if(!g && k<KO_GLYPHS)g=ko_font[k];
#endif
if(g)for(int r=0;r<10;r++)for(int q=0;q<10;q++){int p=r*10+q;if(g[p>>3]&(128>>(p&7)))rect(x+q*sc,y+r*sc,x+(q+1)*sc,y+(r+1)*sc,c);}
x+=10*sc;
}else{
if(x+5*sc>limit || x+5*sc>128)break;
int ch=(u8)s[i];if(ch>=128)ch='?';if(ch>=0x60 && ch!='x')ch-=32;
int k=glyph(ch);if(k<0||k>=96)k='?'-32;
const u8 *g=g_font[k];
for(int r=0;r<7;r++)for(int q=0;q<5;q++)if(g[r]&(16>>q))rect(x+q*sc,y+r*sc,x+(q+1)*sc,y+(r+1)*sc,c);
x+=6*sc;
}
}
}
`+s.slice(to);
// Bottom help rows used to be seven pixels tall. Keep the ten-pixel Hangul inside 128px.
s=s.replace(/ctext\(119,/g,'ctext(117,').replace(/text\(5,119,/g,'text(5,117,');
// In the tall tile the status is below a Korean title (10px vs the original 14px).
s=s.replace('text(9,y+19,st,stc,1);','text(9,y+17,st,stc,1);');
s=s.replace('text(9,y+4,name,c,2);\n int w=text_w(st,1), x=121-w, nx=9+text_w(name,2)+4; if(x<nx) x=nx;\n textn(x,y+8,st,(121-x)/6,stc,1);', 'text(9,y+2,name,c,1);\n textn(9,y+12,st,19,stc,1);');
s=s.replace('rect(5,y+2,123,y+20,BG);','rect(4,y+1,124,y+21,BG);');
s=s.replace('char nm[12], st[24];','char nm[12], st[48];');
const nameFunc='static const char *ko_field(const char *s){\n'+Object.entries(fields).map(([a,b])=>' {const char *a="'+a+'";int i=0;while(a[i]&&s[i]&&a[i]==s[i])i++;if(!a[i]&&!s[i])return "'+enc(b)+'";}').join('\n')+'\nreturn s;}\n';
s=s.replace('static const char *fname(u32 i){ return i<4u ? (const char*)g_cfg.field_name[i] : (const char*)g_cfg.field_name2[i-4u]; }',nameFunc+'static const char *fname(u32 i){ return ko_field(i<4u ? (const char*)g_cfg.field_name[i] : (const char*)g_cfg.field_name2[i-4u]); }');
s=require('./native-menu-layout.cjs')(s,enc);
fs.writeFileSync(dir+'/main-ko.c',s);
let sh=fs.readFileSync(dir+'/build.sh','utf8').replace('main.c hw.c','main-ko.c hw.c').replace('[ "$n" = main ]','[ "$n" = main-ko ]').replace('N=${OUT:-feld}','N=${OUT:-feld-ko}').replace('OUT=feldc','OUT=feldc-ko').replace('-ffreestanding','-flto -ffreestanding').replace('sh "$0" --inner','sh ./build-ko.sh --inner');
sh=sh.replace(' -Os ', ' -Oz ');
sh=sh.replace('llvm-size $N.elf; ls -l $N.bin', 'python3 -c \'import pathlib,sys; p=pathlib.Path(sys.argv[1]); p.write_bytes(p.read_bytes()+b"ITOSM_KO_MENU_V1\\x00")\' "$N.bin"\nllvm-size $N.elf; ls -l $N.bin');
fs.writeFileSync(dir+'/build-ko.sh',sh.replace(/\r\n/g,'\n'));
fs.writeFileSync(dir+'/ko-encoding.json',JSON.stringify({chars,translations:tr,fields},null,2));
console.log('Menu:',Object.keys(counts).length,'strings,',chars.length,'glyphs,',chars.length*13,'font bytes');
+23 -21
View File
@@ -1,21 +1,23 @@
#!/bin/sh
set -eu
cd /home/syskiller/docker/tamagotchi
mkdir -p site
cp source/dist/index.html source/dist/ParamixStudio.html source/dist/restore.html source/guide.html site/
cp source/admin.html source/admin.js source/about.html source/site.css source/robots.txt source/sitemap.xml site/
cp source/account.html source/account.js site/
cp source/share.js site/
cp source/member-nav.js site/
cp source/feld/src/feld/qa/001.png site/menu-main.png
cp source/feld/src/feld/qa/020.png site/menu-points.png
cp source/feld/src/feld/qa/009.png site/menu-character.png
cp source/feld/src/feld/qa/018.png site/menu-item.png
cp source/LICENSE site/LICENSE.txt
cp source/NOTICE.md site/NOTICE.txt
cp source/third-party/Galmuri-OFL.txt site/Galmuri-OFL.txt
cp source/docker-compose.yaml source/nginx-static.conf .
printf 'ok\n' > site/health.txt
sha256sum site/index.html > deploy-sha256.txt
chmod -R a+rX site
docker compose -f docker-compose.yaml config --quiet
#!/bin/sh
set -eu
cd /home/syskiller/docker/tamagotchi
mkdir -p site
cp source/dist/index.html source/dist/ParamixStudio.html source/dist/restore.html source/guide.html site/
cp source/admin.html source/admin.js source/about.html source/site.css source/robots.txt source/sitemap.xml site/
cp source/account.html source/account.js site/
cp source/share.js site/
cp source/member-nav.js site/
cp source/feld/src/feld/qa/menu-main.png site/menu-main.png
cp source/feld/src/feld/qa/menu-character-list.png site/menu-character-list.png
cp source/feld/src/feld/qa/menu-character.png site/menu-character.png
cp source/feld/src/feld/qa/menu-item-list.png site/menu-item-list.png
cp source/feld/src/feld/qa/menu-item.png site/menu-item.png
cp source/feld/src/feld/qa/menu-points.png site/menu-points.png
cp source/LICENSE site/LICENSE.txt
cp source/NOTICE.md site/NOTICE.txt
cp source/third-party/Galmuri-OFL.txt site/Galmuri-OFL.txt
cp source/docker-compose.yaml source/nginx-static.conf .
printf 'ok\n' > site/health.txt
sha256sum site/index.html > deploy-sha256.txt
chmod -R a+rX site
docker compose -f docker-compose.yaml config --quiet
+88 -57
View File
@@ -1,57 +1,88 @@
// Applied to the generated Korean variant only. Core input and write logic stay intact.
module.exports=function(s,enc){
const start=s.indexOf('static void main_menu(void){'), end=s.indexOf('\nstatic void run(void)',start);
let menu=s.slice(start,end);
const a=menu.indexOf(' rect(0,0,128,128,BG);'),b=menu.indexOf(' show(); wait_release();',a);
menu=menu.slice(0,a)+` rect(0,0,128,128,BG);
ctext(3,"${enc('다마고치 편집')}",WHITE,1);
for(u32 i=0;i<n;i++){
int x=9+(int)(i%3u)*39,y=21+(int)(i/3u)*39;
u16 col=i==sel?GOLD:GREY;
rect(x-3,y-3,x+34,y+34,col);rect(x-1,y-1,x+32,y+32,BG);
/* Compact pixel icons: planet, bag, points, Tama and programs. */
if(kinds[i]==0){rect(x+7,y+3,x+24,y+27,RGB(60,180,235));rect(x+2,y+9,x+29,y+21,RGB(60,180,235));rect(x+7,y+10,x+18,y+15,RGB(110,220,100));rect(x+16,y+17,x+24,y+22,RGB(110,220,100));}
else if(kinds[i]==1){rect(x+6,y+10,x+26,y+27,PINK);rect(x+10,y+4,x+22,y+14,PINK);rect(x+13,y+7,x+19,y+11,BG);}
else if(kinds[i]==2){rect(x+7,y+4,x+25,y+27,GOLD);rect(x+3,y+9,x+29,y+22,GOLD);text(x+12,y+11,"P",BG,1);}
else if(kinds[i]==4){rect(x+5,y+9,x+27,y+25,RGB(120,220,120));rect(x+7,y+3,x+11,y+12,RGB(120,220,120));rect(x+21,y+3,x+25,y+12,RGB(120,220,120));rect(x+10,y+14,x+13,y+17,BG);rect(x+20,y+14,x+23,y+17,BG);rect(x+14,y+21,x+20,y+23,BG);}
else {rect(x+3,y+6,x+29,y+25,ORANGE);text(x+9,y+11,"AB",BG,1);}
}
const char *label;
switch(kinds[sel]){case 0:label="${enc('지역과 저장')}";break;case 1:label="${enc('아이템')}";break;case 2:label="${enc('다마포인트')}";break;case 4:label="${enc('다마고치')}";break;default:label="${enc('프로그램')}";}
ctext(102,label,WHITE,1);ctext(117,"${enc('A 이동 B 선택 C 뒤로')}",GREY,1);
`+menu.slice(b);
s=s.slice(0,start)+menu+s.slice(end);
// Original Paradise uses a light menu surface and a colored selection frame.
s=s.replace(/#define BG\s+[^\n]+/,'#define BG RGB(246,247,221)');
s=s.replace(/#define WHITE\s+[^\n]+/,'#define WHITE RGB(33,48,72)');
s=s.replace(/#define GREY\s+[^\n]+/,'#define GREY RGB(75,96,108)');
s=s.replace(/#define GOLD\s+[^\n]+/,'#define GOLD RGB(157,95,8)').replace(/#define ORANGE\s+[^\n]+/,'#define ORANGE RGB(160,80,12)').replace(/#define PINK\s+[^\n]+/,'#define PINK RGB(176,45,100)');
// Korean native names are also stored as the firmware's u16 glyph codes after the font.
const pos=s.indexOf('static void chr_pick(void){');
const helpers=`static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31464f4bu?a+8u+13u*rd32(a+4u):0;}
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=rd32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;for(u32 y=0;y<32;y++)for(u32 x=0;x<32;x++){u32 c=rd16(g_cfg.cat_off+o+2u*(y*32u+x));if(c!=0xf81fu)rect(32+x*2,27+y*2,34+x*2,29+y*2,(u16)c);}}
`;
s=s.slice(0,pos)+helpers+s.slice(pos);
s=s.replace(/ list_draw\(t, g_chrn, sel, top, chr_row, [^\n]+/,` rect(0,0,128,128,BG);ctext(3,t,WHITE,1);ko_portrait(g_chr[sel]);char name[24];chr_name(g_chr[sel],name);ctext(98,name,WHITE,1);ctext(117,"${enc('A 단계 B 선택 C 뒤로')}",GREY,1);show();`);
s=s.replace('static char g_nm[24];','static char g_nm[64];');
s=s.replace('u32 n=fl(o+3)[0]; if(n>20u) n=20u;', 'u32 n=fl(o+3)[0]; if(n==255u){u32 a=g_cfg.cat_off+rd32(o+8);u32 i=0;while(i<60u&&fl(a+i)[0]){g_nm[i]=(char)fl(a+i)[0];i++;}g_nm[i]=0;return g_nm;} if(n>20u) n=20u;');
s=s.replace(/static void chr_name\(u32 k, char \*out\)\{[^\n]+/, 'static void chr_name(u32 k, char *out){const char *n=item_name(rd16(g_cfg.cat_off+8u+28u*k));int i=0;while(n[i]&&i<60){out[i]=n[i];i++;}out[i]=0;}');
s=s.replace(/\b(nm|name|st|t)\[24\]/g,'$1[64]');
// Wrap by glyph boundaries rather than splitting a two-byte Korean character.
const split=s.indexOf('static const char *item_name');
s=s.slice(0,split)+`static void ko_title(const char *s,int y){int n=0,w=0;while(s[n]){int z=ko_pair(s+n)?2:1,px=z==2?10:6;if(w+px>116)break;w+=px;n+=z;}textn((128-w)/2,y,s,n,WHITE,1);if(s[n])ctext(y+11,s+n,WHITE,1);}\n`+s.slice(split);
s=s.replace('if(L<=20) ctext(4,nm,WHITE,1); else { textn(4,2,nm,20,WHITE,1); textn(4,11,nm+20,20,WHITE,1); }','ko_title(nm,2);');
s=s.replace('ctext(98,name,WHITE,1);','ko_title(name,94);');
s=s.replace(/ list_draw\(t, g_catn, sel, top, cat_row, [^\n]+/,` rect(0,0,128,128,BG);ctext(3,t,WHITE,1);draw_item_pic(g_cat[sel],64,54,64);ko_title(item_name(g_cat[sel]),94);ctext(117,"${enc('A 분류 B 선택 C 뒤로')}",GREY,1);show();`);
s=s.replace('static u32 tama_files(u32 old, u32 nw){','static u32 ko_names(void);\nstatic u32 tama_files(u32 old, u32 nw){');
s=s.replace(' flash_read(a, g_page, PAGE);\n#ifdef FELD_TAMA_ANY',' flash_read(a, g_page, PAGE);\n u32 before=0;for(u32 z=8;z<0x180;z+=4)before+=*(u32*)(g_page+z);\n#ifdef FELD_TAMA_ANY');
s=s.replace(' flash_prog4k(a, g_page); n++;',` if(rd32(a)+rd32(a+4u)==0u){
int k=cat_find(nw);u32 names=ko_names();if(k>=0&&names){for(u32 j=0;j<26;j++)g_page[226u+j]=fl(names+26u*(u32)k+j)[0];g_page[0xfcu]=fl(g_cfg.cat_off+8u+28u*(u32)k+6u)[0];g_page[0xfdu]=0;}
u32 sum=rd32(a)-before;for(u32 z=8;z<0x180;z+=4)sum+=*(u32*)(g_page+z);*(u32*)g_page=sum;*(u32*)(g_page+4u)=0u-sum;
}
flash_prog4k(a, g_page); n++;`);
s=s.replace('RGB(60,60,110)','RGB(205,225,169)').replace('RGB(40,40,70)','BG');
s=s.replace('if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); t[15]=0;', 'if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); int z=0;while(t[z]&&z+(ko_pair(t+z)?2:1)<=14)z+=ko_pair(t+z)?2:1;t[z]=0;');
// Keep the current item on a picture screen before confirming a change.
return s;
};
// Korean text lists with picture confirmation and bounded batch item additions.
module.exports=function(s,enc){
const start=s.indexOf('static void main_menu(void){'), end=s.indexOf('\nstatic void run(void)',start);
let menu=s.slice(start,end);
const a=menu.indexOf(' rect(0,0,128,128,BG);'),b=menu.indexOf(' show(); wait_release();',a);
menu=menu.slice(0,a)+` rect(0,0,128,128,BG);
ctext(3,"${enc('다마고치 편집')}",WHITE,1);
for(u32 i=0;i<n;i++){
const char *label;
switch(kinds[i]){case 0:label="${enc('지역과 저장')}";break;case 1:label="${enc('아이템')}";break;case 2:label="${enc('다마포인트')}";break;case 4:label="${enc('다마고치')}";break;default:label="${enc('프로그램')}";}
int y=22+(int)i*18;
if(i==sel){rect(5,y-3,123,y+13,GOLD);rect(7,y-1,121,y+11,RGB(205,225,169));}
text(14,y,label,WHITE,1);
}
ctext(117,"${enc('A 이동 B 선택 C 뒤로')}",GREY,1);
`+menu.slice(b);
menu=menu.replace('int ok=set_load()==0;','set_load();');
s=s.slice(0,start)+menu+s.slice(end);
// Original Paradise uses a light menu surface and a colored selection frame.
s=s.replace(/#define BG\s+[^\n]+/,'#define BG RGB(246,247,221)');
s=s.replace(/#define WHITE\s+[^\n]+/,'#define WHITE RGB(33,48,72)');
s=s.replace(/#define GREY\s+[^\n]+/,'#define GREY RGB(75,96,108)');
s=s.replace(/#define GOLD\s+[^\n]+/,'#define GOLD RGB(157,95,8)').replace(/#define ORANGE\s+[^\n]+/,'#define ORANGE RGB(160,80,12)').replace(/#define PINK\s+[^\n]+/,'#define PINK RGB(176,45,100)');
// Korean native names are also stored as the firmware's u16 glyph codes after the font.
const pos=s.indexOf('static void chr_pick(void){');
const helpers=`static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31464f4bu?a+8u+13u*rd32(a+4u):0;}
static u32 ko_le32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=ko_le32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;for(u32 y=0;y<32;y++)for(u32 x=0;x<32;x++){const volatile u8 *p=fl(g_cfg.cat_off+o+2u*(y*32u+x));u32 c=p[0]|((u32)p[1]<<8);if(c!=0xf81fu)rect(32+x*2,27+y*2,34+x*2,29+y*2,(u16)c);}}
`;
s=s.slice(0,pos)+helpers+s.slice(pos);
s=s.replace('static char g_nm[24];','static char g_nm[64];');
s=s.replace('u32 n=fl(o+3)[0]; if(n>20u) n=20u;', 'u32 n=fl(o+3)[0]; if(n==255u){u32 a=g_cfg.cat_off+rd32(o+8);u32 i=0;while(i<60u&&fl(a+i)[0]){g_nm[i]=(char)fl(a+i)[0];i++;}g_nm[i]=0;return g_nm;} if(n>20u) n=20u;');
s=s.replace(/static void chr_name\(u32 k, char \*out\)\{[^\n]+/, 'static void chr_name(u32 k, char *out){const char *n=item_name(rd16(g_cfg.cat_off+8u+28u*k));int i=0;while(n[i]&&i<60){out[i]=n[i];i++;}out[i]=0;}');
s=s.replace(/\b(nm|name|st|t)\[24\]/g,'$1[64]');
// Wrap by glyph boundaries rather than splitting a two-byte Korean character.
const split=s.indexOf('static const char *item_name');
s=s.slice(0,split)+`static void ko_title(const char *s,int y){int n=0,w=0;while(s[n]){int z=ko_pair(s+n)?2:1,px=z==2?10:6;if(w+px>116)break;w+=px;n+=z;}textn((128-w)/2,y,s,n,WHITE,1);if(s[n])ctext(y+11,s+n,WHITE,1);}\n`+s.slice(split);
s=s.replace('if(L<=20) ctext(4,nm,WHITE,1); else { textn(4,2,nm,20,WHITE,1); textn(4,11,nm+20,20,WHITE,1); }','ko_title(nm,2);');
// Eight legible Korean rows. Keep scrolling and scrollbar geometry in agreement.
s=s.replace('r<10u && top+r<n','r<8u && top+r<n').replace('int y=12+(int)r*10','int y=16+(int)r*12');
s=s.replace('128,y+8,RGB','128,y+10,RGB');
s=s.replace('if(n>10u){ int h=100*10/(int)n; if(h<6) h=6; int y=12+(int)(100-h)*(int)top/(int)(n-10u);','if(n>8u){ int h=96*8/(int)n; if(h<6) h=6; int y=16+(int)(96-h)*(int)top/(int)(n-8u);');
s=s.replaceAll('if(sel>=top+10u) top=sel-9u;','if(sel>=top+8u) top=sel-7u;');
s=s.replace('q<3){ right[q]=fn[q];','q<4){ right[q]=fn[q];');
s=s.replace('fn=fname(f-1u); *col=fcol(f-1u);','fn=fname(f-1u); *col=WHITE;');
s=s.replace(/ rect\(0,0,128,128,BG\); ctext\(24,[^\n]+\n ctext\(76,[^\n]+/,` rect(0,0,128,128,BG);ko_title(nm,2);ko_portrait(kk);
ctext(95,stage_name(st),GREY,1);ctext(117,"${enc('B 변경 C 목록')}",GREY,1);show();`);
// A newly selected item adds the requested amount to the existing stack. The
// native save stores each quantity in four bits, so the total cannot exceed 15.
const countStart=s.indexOf('#ifdef BAG_DEL\nstatic u32 count_edit('), countEnd=s.indexOf('static int g_dirty;',countStart);
if(countStart<0||countEnd<0)throw Error('Item quantity editor not found');
s=s.slice(0,countStart)+`static u32 count_choose(u32 id,u32 v,u32 lo,u32 hi,int adding){
if(v<lo)v=lo;if(v>hi)v=hi;
for(;;){
rect(0,0,128,128,BG);ko_title(item_name(id),2);draw_item_pic(id,64,54,60);
char num[8];utoa_(v,num);
text(20,87,adding?"${enc('추가')}":"${enc('수량')}",WHITE,1);text(65,85,num,GOLD,2);text(103,87,"${enc('개')}",WHITE,1);
ctext(105,"${enc('휠 수량 조절')}",GREY,1);ctext(117,"${enc('B 확인 C 목록')}",GREY,1);show();wait_release();
for(;;){int k=input();
if(k==1){int nv=(int)v+g_step;if(nv<(int)lo)nv=(int)lo;if(nv>(int)hi)nv=(int)hi;v=(u32)nv;break;}
if(k==K_A){if(v<hi)v++;break;}
if(k==K_OK)return v;if(k==K_BACK)return 16u;
}
}
}
#ifdef BAG_DEL
static u32 count_edit(u32 id,u32 v,u32 lo){return count_choose(id,v,lo,15u,0);}
#else
static u32 count_edit(u32 id,u32 v){u32 n=count_choose(id,v,1u,15u,0);return n==16u?0u:n;}
#endif
static u32 count_add(u32 id,u32 owned){
if(owned>=15u){message("${enc('최대 15개 보유')}","${enc('더 추가할 수 없습니다')}","");return 16u;}
u32 n=count_choose(id,1u,1u,15u-owned,1);return n==16u?16u:owned+n;
}
`+s.slice(countEnd);
s=s.replace('count_edit(id, slot<n ? count_get(slot) : 1u, 1u)','count_add(id, slot<n ? count_get(slot) : 0u)');
s=s.replace('u32 v=count_edit(id, slot<n ? count_get(slot) : 1u);\n if(v){','u32 v=count_add(id, slot<n ? count_get(slot) : 0u);\n if(v<16u){');
s=s.replace('static u32 tama_files(u32 old, u32 nw){','static u32 ko_names(void);\nstatic u32 tama_files(u32 old, u32 nw){');
s=s.replace(' flash_read(a, g_page, PAGE);\n#ifdef FELD_TAMA_ANY',' flash_read(a, g_page, PAGE);\n u32 before=0;for(u32 z=8;z<0x180;z+=4)before+=*(u32*)(g_page+z);\n#ifdef FELD_TAMA_ANY');
s=s.replace(' flash_prog4k(a, g_page); n++;',` if(rd32(a)+rd32(a+4u)==0u){
int k=cat_find(nw);u32 names=ko_names();if(k>=0&&names){for(u32 j=0;j<26;j++)g_page[226u+j]=fl(names+26u*(u32)k+j)[0];g_page[0xfcu]=fl(g_cfg.cat_off+8u+28u*(u32)k+6u)[0];g_page[0xfdu]=0;}
u32 sum=rd32(a)-before;for(u32 z=8;z<0x180;z+=4)sum+=*(u32*)(g_page+z);*(u32*)g_page=sum;*(u32*)(g_page+4u)=0u-sum;
}
flash_prog4k(a, g_page); n++;`);
s=s.replace('RGB(60,60,110)','RGB(205,225,169)').replace('RGB(40,40,70)','BG');
s=s.replace('if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); t[15]=0;', 'if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); int z=0;while(t[z]&&z+(ko_pair(t+z)?2:1)<=14)z+=ko_pair(t+z)?2:1;t[z]=0;');
return s;
};