code wiki / _hdl_build / nx_games_portal.nx

nx_games_portal.nx source

↩ module page · 64 lines · 6296 B

1// nx_games_portal.nx -- sovereign UNIFIED games-portal emitter. Reads the ONE games registry 2// (nx_native_config games-reg-, no tsv) and emits knowledge/sovereign-games.html = the /games portal that 3// lists ALL our games in one place (operator: "consolidate all games under /games, get them unified and 4// working"). deployed=1 -> a live Play card linking the game (href=path); deployed=0 -> a "coming soon" 5// card showing engine + location. Data-driven: edit the registry -> re-run -> the portal reflects it. 6// Replaces the hand-authored board-games portal so /games is the single games space. license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_native_config.nx" 9const K_MAGIC_262144: i64 = 262144 10 11func gp_puts(buf: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){buf[o]=s[i];o=o+1;i=i+1} return o } 12func gp_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13 14func main() -> i64 { 15 let h: *i64 = ncfg_open("knowledge/store/games-reg-\x00" as *u8) 16 if (h as i64) == 0 { gp_w("nx_games_portal: games-reg missing -- run nx_games_reg_seed first\n\x00" as *u8); return 5 } 17 let cnt: i64 = ncfg_count(h, "game\x00" as *u8) 18 let out: *u8 = sys_mmap(K_MAGIC_262144) 19 var o: i64 = 0 20 o = gp_puts(out, o, "<!doctype html><html lang='en'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>Nishi Games</title>\n" as *u8) 21 o = gp_puts(out, o, "<style>body{margin:0;background:#0d1018;color:#e8ecf4;font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif}header{padding:30px 20px;text-align:center;border-bottom:1px solid #1d2433}h1{margin:0 0 6px;font-size:30px;letter-spacing:.3px}header p{color:#8b95a7;margin:0;font-size:14px;max-width:74ch;margin:0 auto}.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:16px;padding:22px;max-width:1000px;margin:0 auto}.card{display:block;background:#151b27;border:1px solid #232c3d;border-radius:12px;overflow:hidden;text-decoration:none;color:inherit;transition:transform .12s,border-color .12s}.card:hover{transform:translateY(-3px);border-color:#3a4760}.soon{opacity:.55}.thumb{height:96px;background:linear-gradient(135deg,#1d3a5e,#5aa0d2)}.tg{background:linear-gradient(135deg,#1b5e3a,#5ad27a)}.tt{background:linear-gradient(135deg,#5e1d4f,#d25ab0)}.meta{padding:12px 14px}.meta h3{margin:0 0 4px;font-size:16px;display:flex;justify-content:space-between;align-items:center}.meta p{margin:0;color:#8b95a7;font-size:12px}.badge{font-size:11px;border:1px solid #2f3a4f;border-radius:20px;padding:1px 9px;color:#8b95a7}.play{color:#5ad27a;border-color:#2c5e3f}footer{text-align:center;color:#5c667a;font-size:12px;padding:26px}</style></head>\n" as *u8) 22 o = gp_puts(out, o, "<body><header><h1>Nishi Games</h1><p>Every Nishi game in one place &mdash; sovereign WebAssembly, integer raster, no 3rd-party engine. Live games play right now; the rest are on the way.</p></header><div class='grid'>\n" as *u8) 23 let rk: *i64 = sys_mmap(8*8) as *i64 24 let rv: *i64 = sys_mmap(8*8) as *i64 25 var i: i64 = 0 26 var nlive: i64 = 0 27 while i < cnt { 28 let nf: i64 = ncfg_row(h, "game\x00" as *u8, i, rk, rv, 8) 29 if nf > 0 { 30 let title: *u8 = ncfg_field(rk, rv, nf, "title\x00" as *u8) 31 let engine: *u8 = ncfg_field(rk, rv, nf, "engine\x00" as *u8) 32 let path: *u8 = ncfg_field(rk, rv, nf, "path\x00" as *u8) 33 let dep: *u8 = ncfg_field(rk, rv, nf, "deployed\x00" as *u8) 34 if (dep[0] as i64) == 49 { 35 o = gp_puts(out, o, "<a class='card' href='" as *u8); o = gp_puts(out, o, path) 36 o = gp_puts(out, o, "'><div class='thumb tg'></div><div class='meta'><h3>" as *u8); o = gp_puts(out, o, title) 37 o = gp_puts(out, o, "<span class='badge play'>Play</span></h3><p>" as *u8); o = gp_puts(out, o, engine) 38 o = gp_puts(out, o, " &middot; live</p></div></a>\n" as *u8) 39 nlive = nlive + 1 40 } else { 41 o = gp_puts(out, o, "<div class='card soon'><div class='thumb tt'></div><div class='meta'><h3>" as *u8); o = gp_puts(out, o, title) 42 o = gp_puts(out, o, "<span class='badge'>soon</span></h3><p>" as *u8); o = gp_puts(out, o, engine) 43 o = gp_puts(out, o, " &middot; " as *u8); o = gp_puts(out, o, path) 44 o = gp_puts(out, o, "</p></div></div>\n" as *u8) 45 } 46 } 47 i = i + 1 48 } 49 o = gp_puts(out, o, "</div><footer>Nishi ecosystem &middot; one games space, data-driven from the sovereign registry &middot; nishifamily.com</footer></body></html>\n" as *u8) 50 let fd: i64 = sys_openat_wr("knowledge/sovereign-games.html\x00" as *u8, 420) 51 if fd < 0 { gp_w("nx_games_portal: cannot write knowledge/sovereign-games.html\n\x00" as *u8); return 6 } 52 sys_write(fd, out, o) 53 sys_close(fd) 54 // stage the nx_aw_push deploy inputs SOVEREIGNLY (syscall file writes, no bash printf) -> deploy is just 55 // `nx_sov_build_run nx_aw_push`. src = this portal; dst = atomic cat+mv into the hub docroot (served /games). 56 let sfd: i64 = sys_openat_wr("/mnt/c/Users/elder/AppData/Local/Temp/awpush.src\x00" as *u8, 420) 57 if sfd >= 0 { let sp: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/knowledge/sovereign-games.html\n\x00" as *u8; var sn: i64=0; while sp[sn]!=(0 as u8){sn=sn+1} sys_write(sfd, sp, sn); sys_close(sfd) } 58 let dfd: i64 = sys_openat_wr("/mnt/c/Users/elder/AppData/Local/Temp/awpush.dst\x00" as *u8, 420) 59 if dfd >= 0 { let dp: *u8 = "mkdir -p /volume1/ai/hub/pages; cat > /volume1/ai/hub/pages/games.html.tmp; mv -f /volume1/ai/hub/pages/games.html.tmp /volume1/ai/hub/pages/games.html\n\x00" as *u8; var dn: i64=0; while dp[dn]!=(0 as u8){dn=dn+1} sys_write(dfd, dp, dn); sys_close(dfd) } 60 gp_w("nx_games_portal: wrote knowledge/sovereign-games.html + staged nx_aw_push inputs (deploy = run nx_aw_push); live games=" as *u8) 61 var m: i64=nlive; let bb: *u8=sys_mmap(8); if m==0{bb[0]=48 as u8;sys_write(1,bb,1)} else { let t:*u8=sys_mmap(8); var k:i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var j:i64=0; while j<k{bb[j]=t[k-1-j];j=j+1} sys_write(1,bb,k) } 62 gp_w(")\n\x00" as *u8) 63 return 0 64}