@tmustier/pi-nes 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/extensions/nes/config.ts +32 -12
- package/extensions/nes/index.ts +24 -8
- package/package.json +1 -1
- package/spec.md +2 -4
package/README.md
CHANGED
|
@@ -58,8 +58,8 @@ Config is stored at `~/.pi/nes/config.json`. Use `/nes config` for guided setup.
|
|
|
58
58
|
|
|
59
59
|
```json
|
|
60
60
|
{
|
|
61
|
-
"romDir": "
|
|
62
|
-
"saveDir": "
|
|
61
|
+
"romDir": "/roms/nes",
|
|
62
|
+
"saveDir": "/roms/nes/saves",
|
|
63
63
|
"renderer": "image",
|
|
64
64
|
"pixelScale": 1.2,
|
|
65
65
|
"keybindings": {
|
|
@@ -79,16 +79,16 @@ Config is stored at `~/.pi/nes/config.json`. Use `/nes config` for guided setup.
|
|
|
79
79
|
|
|
80
80
|
| Option | Default | Description |
|
|
81
81
|
|--------|---------|-------------|
|
|
82
|
-
| `romDir` |
|
|
83
|
-
| `saveDir` |
|
|
82
|
+
| `romDir` | `/roms/nes` | Where to look for ROM files |
|
|
83
|
+
| `saveDir` | `/roms/nes/saves` | Where to store battery saves (defaults to `<romDir>/saves`) |
|
|
84
84
|
| `renderer` | `"image"` | `"image"` (Kitty graphics) or `"text"` (ANSI) |
|
|
85
85
|
| `pixelScale` | `1.2` | Display scale (0.5–4.0) |
|
|
86
86
|
|
|
87
87
|
## Terminal Support
|
|
88
88
|
|
|
89
|
-
**Best experience:**
|
|
89
|
+
**Best experience:** a Kitty-protocol terminal like Ghostty, Kitty, or WezTerm (image protocol + key-up events).
|
|
90
90
|
|
|
91
|
-
- **Kitty** — Full graphics via image protocol (shared memory or file transport)
|
|
91
|
+
- **Kitty-protocol terminals** — Full graphics via image protocol (shared memory or file transport)
|
|
92
92
|
- **Other terminals** — Falls back to ANSI half-block characters (`▀▄`)
|
|
93
93
|
|
|
94
94
|
Set `"renderer": "text"` if you prefer the ANSI renderer or have display issues.
|
package/extensions/nes/config.ts
CHANGED
|
@@ -15,9 +15,15 @@ export interface NesConfig {
|
|
|
15
15
|
keybindings: InputMapping;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const DEFAULT_ROM_DIR = path.join(path.sep, "roms", "nes");
|
|
19
|
+
|
|
20
|
+
export function getDefaultSaveDir(romDir: string): string {
|
|
21
|
+
return path.join(romDir, "saves");
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
export const DEFAULT_CONFIG: NesConfig = {
|
|
19
|
-
romDir:
|
|
20
|
-
saveDir:
|
|
25
|
+
romDir: DEFAULT_ROM_DIR,
|
|
26
|
+
saveDir: getDefaultSaveDir(DEFAULT_ROM_DIR),
|
|
21
27
|
enableAudio: false,
|
|
22
28
|
renderer: "image",
|
|
23
29
|
pixelScale: 1.2,
|
|
@@ -39,15 +45,18 @@ export function getConfigPath(): string {
|
|
|
39
45
|
|
|
40
46
|
export function normalizeConfig(raw: unknown): NesConfig {
|
|
41
47
|
const parsed = typeof raw === "object" && raw !== null ? (raw as RawConfig) : {};
|
|
48
|
+
const romDir =
|
|
49
|
+
typeof parsed.romDir === "string" && parsed.romDir.length > 0
|
|
50
|
+
? normalizePath(parsed.romDir, DEFAULT_CONFIG.romDir)
|
|
51
|
+
: DEFAULT_CONFIG.romDir;
|
|
52
|
+
const saveDirFallback = getDefaultSaveDir(romDir);
|
|
53
|
+
const saveDir =
|
|
54
|
+
typeof parsed.saveDir === "string" && parsed.saveDir.length > 0
|
|
55
|
+
? normalizePath(parsed.saveDir, saveDirFallback)
|
|
56
|
+
: saveDirFallback;
|
|
42
57
|
return {
|
|
43
|
-
romDir
|
|
44
|
-
|
|
45
|
-
? normalizePath(parsed.romDir, DEFAULT_CONFIG.romDir)
|
|
46
|
-
: DEFAULT_CONFIG.romDir,
|
|
47
|
-
saveDir:
|
|
48
|
-
typeof parsed.saveDir === "string" && parsed.saveDir.length > 0
|
|
49
|
-
? normalizePath(parsed.saveDir, DEFAULT_CONFIG.saveDir)
|
|
50
|
-
: DEFAULT_CONFIG.saveDir,
|
|
58
|
+
romDir,
|
|
59
|
+
saveDir,
|
|
51
60
|
enableAudio: typeof parsed.enableAudio === "boolean" ? parsed.enableAudio : DEFAULT_CONFIG.enableAudio,
|
|
52
61
|
renderer: parsed.renderer === "text" ? "text" : DEFAULT_CONFIG.renderer,
|
|
53
62
|
pixelScale: normalizePixelScale(parsed.pixelScale),
|
|
@@ -61,12 +70,15 @@ export function formatConfig(config: NesConfig): string {
|
|
|
61
70
|
|
|
62
71
|
export async function loadConfig(): Promise<NesConfig> {
|
|
63
72
|
const configPath = getConfigPath();
|
|
73
|
+
let config: NesConfig;
|
|
64
74
|
try {
|
|
65
75
|
const raw = await fs.readFile(configPath, "utf8");
|
|
66
|
-
|
|
76
|
+
config = normalizeConfig(JSON.parse(raw));
|
|
67
77
|
} catch {
|
|
68
|
-
|
|
78
|
+
config = DEFAULT_CONFIG;
|
|
69
79
|
}
|
|
80
|
+
await ensureDirectory(config.saveDir);
|
|
81
|
+
return config;
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
export async function configExists(): Promise<boolean> {
|
|
@@ -84,6 +96,14 @@ export async function saveConfig(config: NesConfig): Promise<void> {
|
|
|
84
96
|
await fs.writeFile(configPath, formatConfig(config));
|
|
85
97
|
}
|
|
86
98
|
|
|
99
|
+
async function ensureDirectory(dirPath: string): Promise<void> {
|
|
100
|
+
try {
|
|
101
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
102
|
+
} catch {
|
|
103
|
+
// ignore
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
87
107
|
function normalizePixelScale(raw: unknown): number {
|
|
88
108
|
if (typeof raw !== "number" || Number.isNaN(raw)) {
|
|
89
109
|
return DEFAULT_CONFIG.pixelScale;
|
package/extensions/nes/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
configExists,
|
|
9
9
|
formatConfig,
|
|
10
10
|
getConfigPath,
|
|
11
|
+
getDefaultSaveDir,
|
|
11
12
|
loadConfig,
|
|
12
13
|
normalizeConfig,
|
|
13
14
|
saveConfig,
|
|
@@ -139,17 +140,28 @@ async function configureWithWizard(
|
|
|
139
140
|
ctx: ExtensionCommandContext,
|
|
140
141
|
config: Awaited<ReturnType<typeof loadConfig>>,
|
|
141
142
|
): Promise<boolean> {
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
const romDirDisplay = displayPath(config.romDir);
|
|
144
|
+
const romDirDefaultLabel = config.romDir === DEFAULT_CONFIG.romDir ? "Use default" : "Use current";
|
|
145
|
+
const romDirOptions = [
|
|
146
|
+
`${romDirDefaultLabel} (${romDirDisplay})`,
|
|
147
|
+
"Enter a custom path",
|
|
148
|
+
];
|
|
149
|
+
const romDirChoice = await ctx.ui.select("ROM directory", romDirOptions);
|
|
150
|
+
if (!romDirChoice) {
|
|
148
151
|
return false;
|
|
149
152
|
}
|
|
150
|
-
|
|
153
|
+
|
|
151
154
|
let romDir = config.romDir;
|
|
152
|
-
if (
|
|
155
|
+
if (romDirChoice === romDirOptions[1]) {
|
|
156
|
+
const romDirInput = await ctx.ui.input("ROM directory", romDirDisplay);
|
|
157
|
+
if (romDirInput === undefined) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const trimmedRomDir = romDirInput.trim();
|
|
161
|
+
if (!trimmedRomDir) {
|
|
162
|
+
ctx.ui.notify("ROM directory cannot be empty.", "error");
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
153
165
|
romDir = resolvePathInput(trimmedRomDir, ctx.cwd);
|
|
154
166
|
const valid = await validateRomDir(romDir, ctx);
|
|
155
167
|
if (!valid) {
|
|
@@ -192,9 +204,13 @@ async function configureWithWizard(
|
|
|
192
204
|
pixelScale = parsed;
|
|
193
205
|
}
|
|
194
206
|
|
|
207
|
+
const defaultSaveDir = getDefaultSaveDir(config.romDir);
|
|
208
|
+
const shouldSyncSaveDir = config.saveDir === defaultSaveDir;
|
|
209
|
+
const saveDir = shouldSyncSaveDir ? getDefaultSaveDir(romDir) : config.saveDir;
|
|
195
210
|
const normalized = normalizeConfig({
|
|
196
211
|
...config,
|
|
197
212
|
romDir,
|
|
213
|
+
saveDir,
|
|
198
214
|
pixelScale,
|
|
199
215
|
});
|
|
200
216
|
await saveConfig(normalized);
|
package/package.json
CHANGED
package/spec.md
CHANGED
|
@@ -60,12 +60,10 @@ pi-nes/
|
|
|
60
60
|
- Use `isKeyRelease()` for clean key‑up events.
|
|
61
61
|
|
|
62
62
|
## Saves
|
|
63
|
-
- Store SRAM at
|
|
63
|
+
- Store SRAM at `<saveDir>/<rom-name>.sav` (default `/roms/nes/saves`).
|
|
64
64
|
- Load SRAM on ROM start.
|
|
65
65
|
- Persist on exit and periodically (e.g., every 5–10 seconds).
|
|
66
66
|
|
|
67
|
-
Note: the native core does not currently expose SRAM for persistence.
|
|
68
|
-
|
|
69
67
|
## Configuration
|
|
70
68
|
- `~/.pi/nes/config.json` with:
|
|
71
69
|
- `romDir`
|
|
@@ -91,4 +89,4 @@ Note: audio output is currently disabled; setting `enableAudio` will show a warn
|
|
|
91
89
|
- Default ROM dir: `/roms/nes` (configurable).
|
|
92
90
|
- Default core: `native`.
|
|
93
91
|
- Default pixel scale: `1.2`.
|
|
94
|
-
- Default save dir:
|
|
92
|
+
- Default save dir: `/roms/nes/saves` (configurable).
|