@nilvn/core 0.16.3 → 0.17.0
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/dist/chunk-build.d.ts +10 -0
- package/dist/chunk-build.js +6 -4
- package/dist/ir.d.ts +20 -2
- package/dist/ir.js +6 -2
- package/dist/package.d.ts +18 -1
- package/dist/package.js +33 -4
- package/dist/versions.d.ts +1 -1
- package/package.json +1 -1
package/dist/chunk-build.d.ts
CHANGED
|
@@ -28,6 +28,16 @@ export interface BuildChunkedOptions {
|
|
|
28
28
|
/** Command schema registry for serialization (`commandRegistry(manifests)`);
|
|
29
29
|
* built-ins only when omitted — see SerializeOptions.commands. */
|
|
30
30
|
commands?: Record<string, CommandSchema>;
|
|
31
|
+
/** A scoped build (the studio's preview of one scene): only these scene ids, in
|
|
32
|
+
* project order, go into the package — as ONE chunk, which is also the entry —
|
|
33
|
+
* and a jump or choice that leaves the scope routes to the unset landing
|
|
34
|
+
* (serialize's non-`crossChunk` mode) instead of naming a label the package
|
|
35
|
+
* does not carry. `groups` is ignored when set. Omitted = the whole project. */
|
|
36
|
+
scenes?: string[];
|
|
37
|
+
/** Emit `[label anchorLabel]` right before this node (play-from-here). */
|
|
38
|
+
anchorNodeId?: string;
|
|
39
|
+
/** The label to inject at `anchorNodeId`; defaults to `__nilvn_here__`. */
|
|
40
|
+
anchorLabel?: string;
|
|
31
41
|
}
|
|
32
42
|
/** Catalog keys a scene's runtime body references (say/narrate text + choice
|
|
33
43
|
* option labels) — i.e. the text that belongs in this scene's locale slice.
|
package/dist/chunk-build.js
CHANGED
|
@@ -57,10 +57,12 @@ export function sceneTextKeys(nodes, into) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
export function buildChunkedExport(project, opts) {
|
|
60
|
-
const
|
|
60
|
+
const scoped = opts.scenes ? project.scenes.filter((s) => opts.scenes.includes(s.id)) : project.scenes;
|
|
61
|
+
const sceneOrder = scoped.map((s) => s.id);
|
|
61
62
|
const sceneIds = new Set(sceneOrder);
|
|
62
|
-
const byId = new Map(
|
|
63
|
-
const groups = opts.groups ?? sceneOrder.map((id) => [id]);
|
|
63
|
+
const byId = new Map(scoped.map((s) => [s.id, s]));
|
|
64
|
+
const groups = opts.scenes ? [sceneOrder] : (opts.groups ?? sceneOrder.map((id) => [id]));
|
|
65
|
+
const anchor = opts.anchorNodeId ? { anchorNodeId: opts.anchorNodeId, ...(opts.anchorLabel ? { anchorLabel: opts.anchorLabel } : {}) } : {};
|
|
64
66
|
// Each group → one chunk. Chunk id = its first scene id (stable, unique).
|
|
65
67
|
const chunks = [];
|
|
66
68
|
const files = [];
|
|
@@ -76,7 +78,7 @@ export function buildChunkedExport(project, opts) {
|
|
|
76
78
|
if (!ids.length)
|
|
77
79
|
continue;
|
|
78
80
|
const chunkId = ids[0];
|
|
79
|
-
const { body, labels, assetRefs } = serializeChunk(project, { scenes: ids, keepKeys: true, crossChunk:
|
|
81
|
+
const { body, labels, assetRefs } = serializeChunk(project, { scenes: ids, keepKeys: true, crossChunk: !opts.scenes, ...anchor, ...(opts.commands ? { commands: opts.commands } : {}) });
|
|
80
82
|
const scriptChunk = { id: chunkId, body, labels };
|
|
81
83
|
const text = JSON.stringify(scriptChunk);
|
|
82
84
|
const bytes = utf8Len(text);
|
package/dist/ir.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
export type Lang = string;
|
|
2
2
|
/** textKey -> localized string. Values may carry inline markup ({wave:..}, {w:0.5}, {br}). */
|
|
3
3
|
export type TextCatalog = Record<string, string>;
|
|
4
|
+
/** The work's engine configuration — the JSON form of `nilvn.config.toml`,
|
|
5
|
+
* section by section (`title`, `ending`, `theme`, `window`, `menu`, `settings`,
|
|
6
|
+
* `keys`, `saves`, `choices`, `input`, `preload`, `ui`, `persist`, `strings`,
|
|
7
|
+
* `plugins.<id>` …). Core keeps it opaque on purpose: the engine is the one
|
|
8
|
+
* source of its meaning (its `CONFIG_SCHEMA` / `checkConfig` validate it and the
|
|
9
|
+
* studio's settings forms are generated from that schema), so nothing here
|
|
10
|
+
* duplicates the engine's types. Sections the package model carries elsewhere
|
|
11
|
+
* (`game.entry` / `game.scripts` / `path` / `actors` / `plugins.use`) do not
|
|
12
|
+
* belong in it — the engine drops them with a diagnostic. */
|
|
13
|
+
export interface WorkConfig {
|
|
14
|
+
[section: string]: unknown;
|
|
15
|
+
}
|
|
4
16
|
export interface Project {
|
|
5
17
|
meta: ProjectMeta;
|
|
6
18
|
actors: Record<string, Actor>;
|
|
@@ -18,6 +30,10 @@ export interface Project {
|
|
|
18
30
|
* the engine unlocks a segment when normal play passes its end. Optional: older
|
|
19
31
|
* projects simply have none. */
|
|
20
32
|
replays?: ReplaySegment[];
|
|
33
|
+
/** The work's engine configuration (see {@link WorkConfig}); travels into the
|
|
34
|
+
* script package as `nilvn.json` `config`. Optional: a project without one
|
|
35
|
+
* plays with the engine's defaults. Added at schema v12. */
|
|
36
|
+
config?: WorkConfig;
|
|
21
37
|
}
|
|
22
38
|
/** A node position id: which scene, which node — the timeline's stable locator
|
|
23
39
|
* (`NodeBase.id` is minted once and survives edits around it). */
|
|
@@ -73,8 +89,10 @@ export interface ReplaySegment {
|
|
|
73
89
|
* v11: plugin platform v2 — `PluginRef`
|
|
74
90
|
* is `{ id, version?, config? }` keyed by the plugin's reverse-DNS id; the
|
|
75
91
|
* migration maps bundled short names (`textfx` → `app.nilvn.textfx`) and keeps
|
|
76
|
-
* unknown names verbatim (the editor reports them, nothing is dropped).
|
|
77
|
-
|
|
92
|
+
* unknown names verbatim (the editor reports them, nothing is dropped).
|
|
93
|
+
* v12: `Project.config` — the work's engine configuration (the JSON form of
|
|
94
|
+
* nilvn.config.toml), exported as the package's `config`. Pure addition. */
|
|
95
|
+
export declare const CURRENT_SCHEMA_VERSION = 12;
|
|
78
96
|
/** Bring a loaded project up to CURRENT_SCHEMA_VERSION in place (then return it).
|
|
79
97
|
* Call once on load, after reading from disk. Runs every table step the project
|
|
80
98
|
* predates, in order, then stamps the current version. */
|
package/dist/ir.js
CHANGED
|
@@ -40,8 +40,10 @@ import { resolvePluginId } from './plugins.js';
|
|
|
40
40
|
* v11: plugin platform v2 — `PluginRef`
|
|
41
41
|
* is `{ id, version?, config? }` keyed by the plugin's reverse-DNS id; the
|
|
42
42
|
* migration maps bundled short names (`textfx` → `app.nilvn.textfx`) and keeps
|
|
43
|
-
* unknown names verbatim (the editor reports them, nothing is dropped).
|
|
44
|
-
|
|
43
|
+
* unknown names verbatim (the editor reports them, nothing is dropped).
|
|
44
|
+
* v12: `Project.config` — the work's engine configuration (the JSON form of
|
|
45
|
+
* nilvn.config.toml), exported as the package's `config`. Pure addition. */
|
|
46
|
+
export const CURRENT_SCHEMA_VERSION = 12;
|
|
45
47
|
/** The stable id a ref (of either shape) points at. */
|
|
46
48
|
function refId(r) {
|
|
47
49
|
const raw = r.id ?? r.name;
|
|
@@ -152,6 +154,8 @@ const MIGRATIONS = [
|
|
|
152
154
|
p.plugins = next;
|
|
153
155
|
},
|
|
154
156
|
},
|
|
157
|
+
// v11 -> v12: `Project.config` (the work's engine configuration). Pure addition
|
|
158
|
+
// — a project without one plays with the engine's defaults.
|
|
155
159
|
];
|
|
156
160
|
/** Bring a loaded project up to CURRENT_SCHEMA_VERSION in place (then return it).
|
|
157
161
|
* Call once on load, after reading from disk. Runs every table step the project
|
package/dist/package.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Project } from './ir.js';
|
|
1
|
+
import type { Project, WorkConfig } from './ir.js';
|
|
2
2
|
import { type ChunkManifest, type ManifestAsset } from './chunk.js';
|
|
3
3
|
import { type BuildChunkedOptions, type ChunkFile } from './chunk-build.js';
|
|
4
4
|
/** Script-package format version. Bumped only when nilvn.json's shape changes
|
|
@@ -49,6 +49,14 @@ export interface PackageManifest {
|
|
|
49
49
|
textSpeed: number;
|
|
50
50
|
/** Per-work id the runtime namespaces saves / settings by. */
|
|
51
51
|
saveKey: string;
|
|
52
|
+
/** The work's engine configuration — the JSON form of `nilvn.config.toml`
|
|
53
|
+
* (`Project.config`). The engine applies it once the package is open, after
|
|
54
|
+
* the asset table is filled, so a skin, logo or background in it resolves by
|
|
55
|
+
* ref like any other asset. Optional (a package without one plays with the
|
|
56
|
+
* engine's defaults); the sections `nilvn.json` carries itself (`game.entry`
|
|
57
|
+
* / `game.scripts` / `path` / `actors` / `plugins.use`) are dropped with a
|
|
58
|
+
* diagnostic. Engines before 0.17 ignore the field. */
|
|
59
|
+
config?: WorkConfig;
|
|
52
60
|
/** The chunk manifest (chunk.ts), embedded as-is: chunk / locale-slice / asset
|
|
53
61
|
* index + entry label. Wire files (`chunks/**`, `assets/**`) are unchanged. */
|
|
54
62
|
chunks: ChunkManifest;
|
|
@@ -74,6 +82,8 @@ export interface BuildPackageOptions extends BuildChunkedOptions {
|
|
|
74
82
|
textSpeed?: number;
|
|
75
83
|
/** Defaults to the project id, else the title. */
|
|
76
84
|
saveKey?: string;
|
|
85
|
+
/** Defaults to `project.config`; left out of the manifest when empty. */
|
|
86
|
+
config?: WorkConfig;
|
|
77
87
|
}
|
|
78
88
|
export interface ScriptPackagePlan {
|
|
79
89
|
/** nilvn.json, with `chunks.assets` still EMPTY — the producer resolves the
|
|
@@ -96,5 +106,12 @@ export declare function packageActors(project: Project): Record<string, PackageA
|
|
|
96
106
|
* single-file / asset-ZIP shape) plus the manifest fields the shells used to bake
|
|
97
107
|
* into their bootstraps. Pure, zero-I/O. */
|
|
98
108
|
export declare function buildScriptPackage(project: Project, opts: BuildPackageOptions): ScriptPackagePlan;
|
|
109
|
+
/** Asset refs a work configuration names — a skin, logo, background, music,
|
|
110
|
+
* HUD icon or preload entry — found by walking every string in it with the
|
|
111
|
+
* same predicate the scene walk uses (`isAssetRef`), so a producer resolves
|
|
112
|
+
* them into the package's by-ref table alongside the scenes' assets. Strings
|
|
113
|
+
* holding a `{placeholder}` (a layered actor's `src` template) are templates,
|
|
114
|
+
* not refs, and are left to the actor table. */
|
|
115
|
+
export declare function configAssetRefs(config: WorkConfig | undefined): string[];
|
|
99
116
|
/** Fill the by-ref asset table (`chunks.assets`). Returns a new manifest. */
|
|
100
117
|
export declare function fillPackageAssets(manifest: PackageManifest, assets: Record<string, ManifestAsset>): PackageManifest;
|
package/dist/package.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// Pure types + a builder over buildChunkedExport, zero-dep. The editor's four
|
|
9
9
|
// exports (single-file HTML / asset ZIP / chunked ZIP / .nvpk) are this package
|
|
10
10
|
// plus a shell; the engine's `load()` is its one consumer.
|
|
11
|
+
import { isAssetRef } from './serialize.js';
|
|
11
12
|
import { isChunkManifest } from './chunk.js';
|
|
12
13
|
import { buildChunkedExport } from './chunk-build.js';
|
|
13
14
|
/** Script-package format version. Bumped only when nilvn.json's shape changes
|
|
@@ -57,12 +58,14 @@ export function packageActors(project) {
|
|
|
57
58
|
* single-file / asset-ZIP shape) plus the manifest fields the shells used to bake
|
|
58
59
|
* into their bootstraps. Pure, zero-I/O. */
|
|
59
60
|
export function buildScriptPackage(project, opts) {
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
61
|
+
// The chunk options ride through whole (registry, grouping, a preview's scene
|
|
62
|
+
// scope and anchor): without the command registry the chunks serialize plugin
|
|
63
|
+
// commands against the built-ins alone, and a positional argument
|
|
64
|
+
// (`[move yuki …]`) degrades to `id=yuki`, which the plugin never reads.
|
|
65
|
+
const plan = buildChunkedExport(project, opts);
|
|
64
66
|
const title = opts.title ?? (project.meta.title || 'NilVN');
|
|
65
67
|
const lang = (opts.lang ?? project.meta.defaultLang);
|
|
68
|
+
const config = opts.config ?? project.config;
|
|
66
69
|
const manifest = {
|
|
67
70
|
format: PACKAGE_FORMAT,
|
|
68
71
|
title,
|
|
@@ -73,10 +76,36 @@ export function buildScriptPackage(project, opts) {
|
|
|
73
76
|
plugins: opts.plugins ?? project.plugins.map((p) => ({ id: p.id })),
|
|
74
77
|
textSpeed: opts.textSpeed ?? (Number(project.meta.textSpeed) || 40),
|
|
75
78
|
saveKey: opts.saveKey ?? (project.meta.id || project.meta.title || 'nilvn'),
|
|
79
|
+
...(config && Object.keys(config).length ? { config } : {}),
|
|
76
80
|
chunks: plan.manifest,
|
|
77
81
|
};
|
|
78
82
|
return { manifest, files: plan.files, assetRefs: plan.assetRefs };
|
|
79
83
|
}
|
|
84
|
+
/** Asset refs a work configuration names — a skin, logo, background, music,
|
|
85
|
+
* HUD icon or preload entry — found by walking every string in it with the
|
|
86
|
+
* same predicate the scene walk uses (`isAssetRef`), so a producer resolves
|
|
87
|
+
* them into the package's by-ref table alongside the scenes' assets. Strings
|
|
88
|
+
* holding a `{placeholder}` (a layered actor's `src` template) are templates,
|
|
89
|
+
* not refs, and are left to the actor table. */
|
|
90
|
+
export function configAssetRefs(config) {
|
|
91
|
+
const out = new Set();
|
|
92
|
+
const walk = (v) => {
|
|
93
|
+
if (typeof v === 'string') {
|
|
94
|
+
if (isAssetRef(v) && !v.includes('{'))
|
|
95
|
+
out.add(v);
|
|
96
|
+
}
|
|
97
|
+
else if (Array.isArray(v)) {
|
|
98
|
+
for (const x of v)
|
|
99
|
+
walk(x);
|
|
100
|
+
}
|
|
101
|
+
else if (v && typeof v === 'object') {
|
|
102
|
+
for (const x of Object.values(v))
|
|
103
|
+
walk(x);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
walk(config);
|
|
107
|
+
return [...out];
|
|
108
|
+
}
|
|
80
109
|
/** Fill the by-ref asset table (`chunks.assets`). Returns a new manifest. */
|
|
81
110
|
export function fillPackageAssets(manifest, assets) {
|
|
82
111
|
return { ...manifest, chunks: { ...manifest.chunks, assets } };
|
package/dist/versions.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const FORMAT_VERSIONS: Readonly<{
|
|
2
2
|
/** Project / IR document (`ProjectMeta.schemaVersion`) — `migrateProject` brings
|
|
3
3
|
* older projects forward, one table step per bump. */
|
|
4
|
-
irSchema:
|
|
4
|
+
irSchema: 12;
|
|
5
5
|
/** Chunked-streaming manifest (`ChunkManifest.format`) — the loaders gate on it. */
|
|
6
6
|
chunkManifest: 1;
|
|
7
7
|
/** Script package (`nilvn.json` `format`) — `checkPackageManifest` gates on it. */
|
package/package.json
CHANGED