@ringozz/godot 4.7.2-680 → 4.7.2-683
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/package.json +4 -4
- package/src/bake.ts +33 -0
- package/src/load.ts +18 -14
- package/src/pack.ts +30 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ringozz/godot",
|
|
3
3
|
"author": "Vladimir Davidovich",
|
|
4
|
-
"version": "4.7.2-
|
|
4
|
+
"version": "4.7.2-683",
|
|
5
5
|
"description": "Node-API bindings for Godot Engine — call Godot classes from JavaScript",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"precision": "single"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
|
-
"@ringozz/godot-macos-arm64": "^4.7.2-
|
|
71
|
-
"@ringozz/godot-windows-x86_64": "^4.7.2-
|
|
72
|
-
"@ringozz/godot-web-wasm32": "^4.7.2-
|
|
70
|
+
"@ringozz/godot-macos-arm64": "^4.7.2-683",
|
|
71
|
+
"@ringozz/godot-windows-x86_64": "^4.7.2-683",
|
|
72
|
+
"@ringozz/godot-web-wasm32": "^4.7.2-683"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@types/bun": "*"
|
package/src/bake.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
packEntries,
|
|
23
23
|
pckOf,
|
|
24
24
|
serializeDoc,
|
|
25
|
+
uidText,
|
|
25
26
|
type Exports,
|
|
26
27
|
type PackDoc,
|
|
27
28
|
type Release,
|
|
@@ -161,6 +162,8 @@ export async function buildAssetPacks(opts: BuildAssetPackOptions = {}, run?: Ru
|
|
|
161
162
|
|
|
162
163
|
// A plan's routes are relative to the converter's output root, which is where the packs live.
|
|
163
164
|
const ctx: Bake = { run: exec, cwd, cfg, preset, base: excludeFilter(cfg), all, planBase: resPath(dlc) };
|
|
165
|
+
// One read of the editor's uid table for the whole bake: every pack's map is a slice of it.
|
|
166
|
+
const uidTable = uidCache(cwd);
|
|
164
167
|
try {
|
|
165
168
|
// **One dump for the whole project**, sliced per scope below (a loose file is staged by the pack
|
|
166
169
|
// that *owns* it, whoever needs it). One dump is also one editor run instead of one per pack.
|
|
@@ -198,6 +201,7 @@ export async function buildAssetPacks(opts: BuildAssetPackOptions = {}, run?: Ru
|
|
|
198
201
|
version,
|
|
199
202
|
dependencies: pack.dependencies,
|
|
200
203
|
exports: withoutTypes(pack.exports),
|
|
204
|
+
uids: uidsUnder(uidTable, pack.dir),
|
|
201
205
|
needs: own.needs,
|
|
202
206
|
stage: own.stage,
|
|
203
207
|
}),
|
|
@@ -339,6 +343,35 @@ function runDump(ctx: Bake, scope: string[]): Record<string, Dumped> {
|
|
|
339
343
|
const resPath = (rel: string) => `res://${rel.replace(/^res:\/\//, '')}`;
|
|
340
344
|
const rel = (res: string) => res.replace(/^res:\/\//, '').replace(/\/+$/, '');
|
|
341
345
|
|
|
346
|
+
/**
|
|
347
|
+
* The project's uid table, as [uid, `res://` path] pairs — the editor's own `.godot/uid_cache.bin`
|
|
348
|
+
* (a `u32` header, then `id u64 · length u32 · utf8 path` to the end of the file).
|
|
349
|
+
*
|
|
350
|
+
* The engine keeps one process-wide map from that file, loaded from the **boot** pack; a mounted
|
|
351
|
+
* content pack's own cache is never read. A reference that crosses packs (a level's batched meshes
|
|
352
|
+
* live in the assets pack) therefore arrives unknown, and the engine falls back to the stored path
|
|
353
|
+
* with an `invalid UID` warning. Shipping the pairs with the pack that owns them, and registering
|
|
354
|
+
* them at mount (`load.ts`), is what lets the reference resolve as the uid it is.
|
|
355
|
+
*/
|
|
356
|
+
function uidCache(cwd: string): [string, string][] {
|
|
357
|
+
const file = resolve(cwd, '.godot', 'uid_cache.bin');
|
|
358
|
+
if (!existsSync(file)) return [];
|
|
359
|
+
const buf = readFileSync(file);
|
|
360
|
+
const pairs: [string, string][] = [];
|
|
361
|
+
for (let at = 4; at + 12 <= buf.length; ) {
|
|
362
|
+
const id = buf.readBigUInt64LE(at);
|
|
363
|
+
const length = buf.readUInt32LE(at + 8);
|
|
364
|
+
at += 12;
|
|
365
|
+
pairs.push([uidText(id), buf.toString('utf8', at, at + length)]);
|
|
366
|
+
at += length;
|
|
367
|
+
}
|
|
368
|
+
return pairs;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** The `uid://` → `res://` map of the resources under `dir`, taken from the project's uid table. */
|
|
372
|
+
const uidsUnder = (cache: [string, string][], dir: string): Record<string, string> =>
|
|
373
|
+
Object.fromEntries(cache.filter(([, path]) => path.startsWith(`${resPath(dir)}/`)));
|
|
374
|
+
|
|
342
375
|
/** Fails the bake on a reference that leaves the pack (a sibling, or a source no pack owns). */
|
|
343
376
|
function assertRefs(what: string, external: string[], allowed: string[]): void {
|
|
344
377
|
const illegal = external.filter((ref) => !allowed.some((dir) => ref.startsWith(`${dir}/`)));
|
package/src/load.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
parseRelease,
|
|
19
19
|
pckOf,
|
|
20
20
|
resolveEntry,
|
|
21
|
+
uidId,
|
|
21
22
|
type PackDoc,
|
|
22
23
|
type Release,
|
|
23
24
|
type ResolvedEntry,
|
|
@@ -88,19 +89,8 @@ const COMPRESSED_TEXTURE_RE = /\.(ctex|ctexarray|ccube|ccubearray)$/;
|
|
|
88
89
|
// md5, which is what the pattern keys on.
|
|
89
90
|
const EXACT_TEXTURE_RE = /(^|\/)height\.webp-[0-9a-f]+\.ctex$/;
|
|
90
91
|
|
|
91
|
-
// Godot
|
|
92
|
-
//
|
|
93
|
-
// returns a JS number, and these ids exceed `Number.MAX_SAFE_INTEGER`, so the
|
|
94
|
-
// low digits would be lost. BigInt flows through `_C` losslessly (int64).
|
|
95
|
-
const UID_CHARS = 'abcdefghijklmnopqrstuvwxy012345678';
|
|
96
|
-
|
|
97
|
-
function uidToId(uid: string): bigint {
|
|
98
|
-
let id = 0n;
|
|
99
|
-
for (let i = 6; i < uid.length; i++) {
|
|
100
|
-
id = id * 34n + BigInt(UID_CHARS.indexOf(uid[i]));
|
|
101
|
-
}
|
|
102
|
-
return id;
|
|
103
|
-
}
|
|
92
|
+
// Godot resolves a scene's ext_resource `uid://` references through one process-wide map; these are the
|
|
93
|
+
// registrations that fill it (see `uidText`/`uidId` for the numbering).
|
|
104
94
|
|
|
105
95
|
/**
|
|
106
96
|
* Registers an asset's `uid://` → `res://` path so scene ext_resource references
|
|
@@ -108,12 +98,23 @@ function uidToId(uid: string): bigint {
|
|
|
108
98
|
* the stored text path. Idempotent; skips unknown/malformed uids.
|
|
109
99
|
*/
|
|
110
100
|
function registerAssetUid(uid: string, resPath: string): void {
|
|
111
|
-
const id =
|
|
101
|
+
const id = uidId(uid);
|
|
112
102
|
if (id !== 0n && !ResourceUID.hasId(id as unknown as number)) {
|
|
113
103
|
ResourceUID.addId(id as unknown as number, resPath);
|
|
114
104
|
}
|
|
115
105
|
}
|
|
116
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Registers a pack document's `uids` — the resources the pack ships. A reference that crosses packs
|
|
109
|
+
* (a level's batched meshes live in the assets pack) is in the document of the pack that owns them,
|
|
110
|
+
* never in the one that names them, so every mounted document has to be applied here.
|
|
111
|
+
*/
|
|
112
|
+
function registerDocUids(doc: PackDoc): void {
|
|
113
|
+
for (const [uid, resPath] of Object.entries(doc.uids ?? {})) {
|
|
114
|
+
registerAssetUid(uid, resPath);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
117
118
|
// res:// paths already staged, or being staged: MEMFS cannot be read back reliably — the engine's
|
|
118
119
|
// `res://` lookup and the Emscripten path disagree by a leading slash — so `FileAccess.fileExists`
|
|
119
120
|
// cannot answer "is this staged?", and two asset modules needing the same file would fetch and
|
|
@@ -458,6 +459,9 @@ export async function loadPackEntry<C extends ResourceConstructor>(
|
|
|
458
459
|
await Promise.all(
|
|
459
460
|
names.map(async (name): Promise<[string, PackDoc]> => {
|
|
460
461
|
const doc = parseDoc(await readText(url(name, PACK_DOC)));
|
|
462
|
+
// The pack's own uids, before its entry loads: a scene it carries may name a resource
|
|
463
|
+
// that another mounted pack ships (a level's meshes live in the assets pack).
|
|
464
|
+
registerDocUids(doc);
|
|
461
465
|
// A base that serves a version it wasn't asked for is the one thing a client cannot see:
|
|
462
466
|
// production's URLs are immutable, and a dev server pointed at a local bake serves content
|
|
463
467
|
// at another version on purpose. Say so; the load still works.
|
package/src/pack.ts
CHANGED
|
@@ -141,6 +141,9 @@ export interface PackDoc {
|
|
|
141
141
|
dependencies?: Record<string, string>;
|
|
142
142
|
/** Declared entries verbatim — a subpath → its conditions, one of which is `godot`. */
|
|
143
143
|
exports?: Exports;
|
|
144
|
+
/** The resources this pack ships, as `uid://…` → `res://…` (see `uidText`). Registered at mount, so
|
|
145
|
+
* a scene's ext_resource uid resolves even when the resource lives in another pack. */
|
|
146
|
+
uids?: Record<string, string>;
|
|
144
147
|
/** Packed source → the loose files it needs (paths, whoever owns them). */
|
|
145
148
|
needs: Record<string, string[]>;
|
|
146
149
|
/** A loose source this pack owns → the sidecar text and the product it remaps to. */
|
|
@@ -171,6 +174,33 @@ export function serializeDoc(value: PackDoc | Release): string {
|
|
|
171
174
|
return `${JSON.stringify(value, null, '\t')}\n`;
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Godot's `uid://` numbering: base 34 over `a-y` then `0-8` (`core/io/resource_uid.cpp`).
|
|
179
|
+
*
|
|
180
|
+
* The ids are 64-bit, so both directions go through BigInt — `ResourceUID.textToId` returns a JS
|
|
181
|
+
* number, which silently loses the low digits, while BigInt flows through the bindings' int64
|
|
182
|
+
* arguments losslessly.
|
|
183
|
+
*/
|
|
184
|
+
const UID_CHARS = 'abcdefghijklmnopqrstuvwxy012345678';
|
|
185
|
+
|
|
186
|
+
/** The text form of a uid id (`ResourceUID::id_to_text`). */
|
|
187
|
+
export function uidText(id: bigint): string {
|
|
188
|
+
let text = '';
|
|
189
|
+
for (let n = id; n > 0n; n /= 34n) {
|
|
190
|
+
text = UID_CHARS[Number(n % 34n)] + text;
|
|
191
|
+
}
|
|
192
|
+
return `uid://${text}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The id a `uid://` text names (`ResourceUID::text_to_id`), or `0n` when it is not one. */
|
|
196
|
+
export function uidId(uid: string): bigint {
|
|
197
|
+
let id = 0n;
|
|
198
|
+
for (let i = 6; i < uid.length; i++) {
|
|
199
|
+
id = id * 34n + BigInt(UID_CHARS.indexOf(uid[i]));
|
|
200
|
+
}
|
|
201
|
+
return id;
|
|
202
|
+
}
|
|
203
|
+
|
|
174
204
|
/**
|
|
175
205
|
* The `res://` path one declared entry names — the subpath's `godot` condition. A pack declares its
|
|
176
206
|
* entries once, in its `package.json`; the bake copies that declaration into the document it emits, so
|