@godot-scene-web/core 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +155 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tomás Fox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
type GodotDocumentKind = "scene" | "resource";
|
|
3
|
+
/** Renderer-neutral 3×3 linear RGB transform. */
|
|
4
|
+
type ColorMatrix = {
|
|
5
|
+
rows: readonly [readonly [number, number, number], readonly [number, number, number], readonly [number, number, number]];
|
|
6
|
+
};
|
|
7
|
+
interface GodotParseDiagnostic {
|
|
8
|
+
severity: "warning" | "error";
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
column?: number;
|
|
13
|
+
}
|
|
14
|
+
interface GodotResource {
|
|
15
|
+
type?: string;
|
|
16
|
+
header: GodotSectionHeader | null;
|
|
17
|
+
extResources: GodotExtResource[];
|
|
18
|
+
subResources: GodotSubResource[];
|
|
19
|
+
properties: Record<string, GodotVariant>;
|
|
20
|
+
diagnostics: GodotParseDiagnostic[];
|
|
21
|
+
}
|
|
22
|
+
interface GodotSceneState {
|
|
23
|
+
kind: "scene";
|
|
24
|
+
nodes: GodotSceneStateNode[];
|
|
25
|
+
connections: GodotSceneStateConnection[];
|
|
26
|
+
extResources: GodotExtResource[];
|
|
27
|
+
subResources: GodotSubResource[];
|
|
28
|
+
editableInstances: string[];
|
|
29
|
+
basePath?: string;
|
|
30
|
+
diagnostics: GodotParseDiagnostic[];
|
|
31
|
+
}
|
|
32
|
+
interface GodotSceneStateNode {
|
|
33
|
+
index: number;
|
|
34
|
+
siblingIndex?: number;
|
|
35
|
+
name: string;
|
|
36
|
+
type?: string;
|
|
37
|
+
parent?: string;
|
|
38
|
+
owner?: string;
|
|
39
|
+
instance?: GodotResourceRefValue;
|
|
40
|
+
instancePlaceholder?: string;
|
|
41
|
+
groups: string[];
|
|
42
|
+
properties: GodotOrderedProperty[];
|
|
43
|
+
}
|
|
44
|
+
interface GodotOrderedProperty {
|
|
45
|
+
name: string;
|
|
46
|
+
value: GodotVariant;
|
|
47
|
+
}
|
|
48
|
+
interface GodotSceneStateConnection {
|
|
49
|
+
signal?: string;
|
|
50
|
+
from?: string;
|
|
51
|
+
to?: string;
|
|
52
|
+
method?: string;
|
|
53
|
+
flags?: number;
|
|
54
|
+
binds?: GodotVariant[];
|
|
55
|
+
unbinds?: number;
|
|
56
|
+
}
|
|
57
|
+
interface GodotSectionHeader {
|
|
58
|
+
section: string;
|
|
59
|
+
attributes: Record<string, GodotVariant>;
|
|
60
|
+
}
|
|
61
|
+
interface GodotExtResource {
|
|
62
|
+
id: string;
|
|
63
|
+
type?: string;
|
|
64
|
+
path?: string;
|
|
65
|
+
uid?: string;
|
|
66
|
+
attributes: Record<string, GodotVariant>;
|
|
67
|
+
properties: Record<string, GodotVariant>;
|
|
68
|
+
}
|
|
69
|
+
interface GodotSubResource {
|
|
70
|
+
id: string;
|
|
71
|
+
type?: string;
|
|
72
|
+
attributes: Record<string, GodotVariant>;
|
|
73
|
+
properties: Record<string, GodotVariant>;
|
|
74
|
+
}
|
|
75
|
+
interface GodotNode {
|
|
76
|
+
name: string;
|
|
77
|
+
type?: string;
|
|
78
|
+
parent?: string;
|
|
79
|
+
instance?: GodotResourceRefValue;
|
|
80
|
+
attributes: Record<string, GodotVariant>;
|
|
81
|
+
properties: Record<string, GodotVariant>;
|
|
82
|
+
propertyEntries?: GodotOrderedProperty[];
|
|
83
|
+
}
|
|
84
|
+
interface GodotConnection {
|
|
85
|
+
signal?: string;
|
|
86
|
+
from?: string;
|
|
87
|
+
to?: string;
|
|
88
|
+
method?: string;
|
|
89
|
+
attributes: Record<string, GodotVariant>;
|
|
90
|
+
}
|
|
91
|
+
interface GodotEditable {
|
|
92
|
+
path?: string;
|
|
93
|
+
attributes: Record<string, GodotVariant>;
|
|
94
|
+
}
|
|
95
|
+
type GodotVariant = null | boolean | number | string | GodotStringNameVariant | GodotVectorVariant | GodotColorVariant | GodotRectVariant | GodotNodePathVariant | GodotResourceRefValue | GodotCallVariant | GodotVariant[] | {
|
|
96
|
+
[key: string]: GodotVariant;
|
|
97
|
+
};
|
|
98
|
+
interface GodotVectorVariant {
|
|
99
|
+
type: "Vector2" | "Vector2i" | "Vector3" | "Vector3i" | "Vector4" | "Vector4i";
|
|
100
|
+
args: number[];
|
|
101
|
+
}
|
|
102
|
+
interface GodotColorVariant {
|
|
103
|
+
type: "Color";
|
|
104
|
+
args: number[];
|
|
105
|
+
}
|
|
106
|
+
interface GodotStringNameVariant {
|
|
107
|
+
type: "StringName";
|
|
108
|
+
args: string[];
|
|
109
|
+
}
|
|
110
|
+
interface GodotRectVariant {
|
|
111
|
+
type: "Rect2" | "Rect2i";
|
|
112
|
+
args: number[];
|
|
113
|
+
}
|
|
114
|
+
interface GodotNodePathVariant {
|
|
115
|
+
type: "NodePath";
|
|
116
|
+
args: string[];
|
|
117
|
+
}
|
|
118
|
+
interface GodotResourceRefValue {
|
|
119
|
+
type: "ExtResource" | "SubResource";
|
|
120
|
+
id?: string;
|
|
121
|
+
path?: string;
|
|
122
|
+
}
|
|
123
|
+
interface GodotCallVariant {
|
|
124
|
+
type: string;
|
|
125
|
+
args: GodotVariant[];
|
|
126
|
+
}
|
|
127
|
+
interface GodotRect {
|
|
128
|
+
x: number;
|
|
129
|
+
y: number;
|
|
130
|
+
width: number;
|
|
131
|
+
height: number;
|
|
132
|
+
}
|
|
133
|
+
declare function isColorValue(value: GodotVariant | undefined): value is GodotColorVariant;
|
|
134
|
+
declare function isRectValue(value: GodotVariant | undefined): value is GodotRectVariant;
|
|
135
|
+
declare function asNumber(value: GodotVariant | undefined): number | undefined;
|
|
136
|
+
declare function asBoolean(value: GodotVariant | undefined): boolean | undefined;
|
|
137
|
+
declare function asString(value: GodotVariant | undefined): string | undefined;
|
|
138
|
+
declare function asVector2(value: GodotVariant | undefined): {
|
|
139
|
+
x: number;
|
|
140
|
+
y: number;
|
|
141
|
+
} | undefined;
|
|
142
|
+
declare function asRect2(value: GodotVariant | undefined): {
|
|
143
|
+
x: number;
|
|
144
|
+
y: number;
|
|
145
|
+
width: number;
|
|
146
|
+
height: number;
|
|
147
|
+
} | undefined;
|
|
148
|
+
declare function asResourceRef(value: GodotVariant | undefined): GodotResourceRefValue | undefined;
|
|
149
|
+
declare function decodeFromNativeValue(value: GodotVariant): GodotVariant;
|
|
150
|
+
declare function isGodotSceneState(value: unknown): value is GodotSceneState;
|
|
151
|
+
declare function godotNodePath(node: GodotNode): string;
|
|
152
|
+
declare function godotParentPath(node: GodotNode): string | null;
|
|
153
|
+
//#endregion
|
|
154
|
+
export { ColorMatrix, GodotCallVariant, GodotColorVariant, GodotConnection, GodotDocumentKind, GodotEditable, GodotExtResource, GodotNode, GodotNodePathVariant, GodotOrderedProperty, GodotParseDiagnostic, GodotRect, GodotRectVariant, GodotResource, GodotResourceRefValue, GodotSceneState, GodotSceneStateConnection, GodotSceneStateNode, GodotSectionHeader, GodotStringNameVariant, GodotSubResource, GodotVariant, GodotVectorVariant, asBoolean, asNumber, asRect2, asResourceRef, asString, asVector2, decodeFromNativeValue, godotNodePath, godotParentPath, isColorValue, isGodotSceneState, isRectValue };
|
|
155
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";KAAY,iBAAA;AAAZ;AAAA,KAGY,WAAA;EACV,IAAI;AAAA;AAAA,UAOW,oBAAA;EACf,QAAA;EACA,IAAA;EACA,OAAA;EACA,IAAA;EACA,MAAA;AAAA;AAAA,UAGe,aAAA;EACf,IAAA;EACA,MAAA,EAAQ,kBAAA;EACR,YAAA,EAAc,gBAAA;EACd,YAAA,EAAc,gBAAA;EACd,UAAA,EAAY,MAAA,SAAe,YAAA;EAC3B,WAAA,EAAa,oBAAA;AAAA;AAAA,UAGE,eAAA;EACf,IAAA;EACA,KAAA,EAAO,mBAAA;EACP,WAAA,EAAa,yBAAA;EACb,YAAA,EAAc,gBAAA;EACd,YAAA,EAAc,gBAAA;EACd,iBAAA;EACA,QAAA;EACA,WAAA,EAAa,oBAAA;AAAA;AAAA,UAGE,mBAAA;EACf,KAAA;EACA,YAAA;EACA,IAAA;EACA,IAAA;EACA,MAAA;E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EACA,IAAI;AAAA;AAAA,UAGW,gBAAA;EACf,IAAA;EACA,IAAI;AAAA;AAAA,UAGW,oBAAA;EACf,IAAA;EACA,IAAI;AAAA;AAAA,UAQW,qBAAA;EACf,IAAA;EACA,EAAA;EACA,IAAA;AAAA;AAAA,UAMe,gBAAA;EACf,IAAA;EACA,IAAA,EAAM,YAAY;AAAA;AAAA,UAGH,SAAA;EACf,CAAA;EACA,CAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,iBAGc,YAAA,CACd,KAAA,EAAO,YAAA,eACN,KAAA,IAAS,iBAAiB;AAAA,iBAIb,WAAA,CACd,KAAA,EAAO,YAAA,eACN,KAAA,IAAS,gBAAgB;AAAA,iBAQZ,QAAA,CAAS,KAA+B,EAAxB,YAAY;AAAA,iBAM5B,SAAA,CACd,KAA+B,EAAxB,YAAY;AAAA,iBAKL,QAAA,CAAS,KAA+B,EAAxB,YAAY;AAAA,iBAI5B,SAAA,CACd,KAAA,EAAO,YAAY;EAChB,CAAA;EAAW,CAAA;AAAA;AAAA,iBAiBA,OAAA,CACd,KAAA,EAAO,YAAY;EAChB,CAAA;EAAW,CAAA;EAAW,KAAA;EAAe,MAAA;AAAA;AAAA,iBAiB1B,aAAA,CACd,KAAA,EAAO,YAAA,eACN,qBAAqB;AAAA,iBA6BR,qBAAA,CAAsB,KAAA,EAAO,YAAA,GAAe,YAAY;AAAA,iBAuExD,iBAAA,CAAkB,KAAA,YAAiB,KAAA,IAAS,eAAe;AAAA,iBAc3D,aAAA,CAAc,IAAe,EAAT,SAAS;AAAA,iBAO7B,eAAA,CAAgB,IAAe,EAAT,SAAS"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
function isColorValue(value) {
|
|
3
|
+
return isObject(value) && value.type === "Color" && Array.isArray(value.args);
|
|
4
|
+
}
|
|
5
|
+
function isRectValue(value) {
|
|
6
|
+
return isObject(value) && (value.type === "Rect2" || value.type === "Rect2i") && Array.isArray(value.args);
|
|
7
|
+
}
|
|
8
|
+
function asNumber(value) {
|
|
9
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
10
|
+
}
|
|
11
|
+
function asBoolean(value) {
|
|
12
|
+
return typeof value === "boolean" ? value : void 0;
|
|
13
|
+
}
|
|
14
|
+
function asString(value) {
|
|
15
|
+
return typeof value === "string" ? value : void 0;
|
|
16
|
+
}
|
|
17
|
+
function asVector2(value) {
|
|
18
|
+
if (!isObject(value) || value.type !== "Vector2" && value.type !== "Vector2i" || !Array.isArray(value.args)) return;
|
|
19
|
+
const [x, y] = value.args;
|
|
20
|
+
return typeof x === "number" && typeof y === "number" && Number.isFinite(x) && Number.isFinite(y) ? {
|
|
21
|
+
x,
|
|
22
|
+
y
|
|
23
|
+
} : void 0;
|
|
24
|
+
}
|
|
25
|
+
function asRect2(value) {
|
|
26
|
+
if (!isRectValue(value)) return;
|
|
27
|
+
const [x, y, width, height] = value.args;
|
|
28
|
+
return typeof x === "number" && typeof y === "number" && typeof width === "number" && typeof height === "number" && Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && Number.isFinite(height) ? {
|
|
29
|
+
x,
|
|
30
|
+
y,
|
|
31
|
+
width,
|
|
32
|
+
height
|
|
33
|
+
} : void 0;
|
|
34
|
+
}
|
|
35
|
+
function asResourceRef(value) {
|
|
36
|
+
if (!isObject(value) || value.type !== "ExtResource" && value.type !== "SubResource") return;
|
|
37
|
+
const id = typeof value.id === "string" ? value.id : void 0;
|
|
38
|
+
const path = typeof value.path === "string" ? value.path : void 0;
|
|
39
|
+
if (id === void 0 && path === void 0) return;
|
|
40
|
+
return {
|
|
41
|
+
type: value.type,
|
|
42
|
+
...id !== void 0 ? { id } : {},
|
|
43
|
+
...path !== void 0 ? { path } : {}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function decodeFromNativeValue(value) {
|
|
47
|
+
if (typeof value === "string") return decodeFromNativeScalar(value);
|
|
48
|
+
if (Array.isArray(value)) return value.map(decodeFromNativeValue);
|
|
49
|
+
if (isObject(value)) {
|
|
50
|
+
const type = typeof value.type === "string" ? value.type : void 0;
|
|
51
|
+
if (type === "Array" || type === "Dictionary") return Array.isArray(value.args) ? {
|
|
52
|
+
...value,
|
|
53
|
+
args: value.args.map(decodeFromNativeValue)
|
|
54
|
+
} : value;
|
|
55
|
+
if (type !== void 0) return value;
|
|
56
|
+
const decoded = {};
|
|
57
|
+
for (const [key, entry] of Object.entries(value)) decoded[key] = decodeFromNativeValue(entry);
|
|
58
|
+
return decoded;
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function decodeFromNativeScalar(value) {
|
|
63
|
+
if (value.startsWith("i:")) {
|
|
64
|
+
const parsed = Number.parseInt(value.slice(2), 10);
|
|
65
|
+
return Number.isNaN(parsed) ? value : parsed;
|
|
66
|
+
}
|
|
67
|
+
if (value.startsWith("f:")) {
|
|
68
|
+
const parsed = decodeFromNativeFloat(value.slice(2));
|
|
69
|
+
return parsed === void 0 ? value : parsed;
|
|
70
|
+
}
|
|
71
|
+
if (value.startsWith("s:")) return value.slice(2);
|
|
72
|
+
if (value.startsWith("sn:")) return value.slice(3);
|
|
73
|
+
if (value.startsWith("np:")) return {
|
|
74
|
+
type: "NodePath",
|
|
75
|
+
args: [value.slice(3)]
|
|
76
|
+
};
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
function decodeFromNativeFloat(text) {
|
|
80
|
+
switch (text) {
|
|
81
|
+
case "inf": return Infinity;
|
|
82
|
+
case "-inf": return -Infinity;
|
|
83
|
+
case "nan": return NaN;
|
|
84
|
+
default: {
|
|
85
|
+
const parsed = Number.parseFloat(text);
|
|
86
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function isGodotSceneState(value) {
|
|
91
|
+
if (!isObject(value) || value.kind !== "scene") return false;
|
|
92
|
+
return Array.isArray(value.nodes) && value.nodes.every(isGodotSceneStateNode) && Array.isArray(value.connections) && Array.isArray(value.extResources) && Array.isArray(value.subResources) && Array.isArray(value.diagnostics);
|
|
93
|
+
}
|
|
94
|
+
function godotNodePath(node) {
|
|
95
|
+
if (!node.parent || node.parent === ".") return node.name;
|
|
96
|
+
return `${node.parent}/${node.name}`;
|
|
97
|
+
}
|
|
98
|
+
function godotParentPath(node) {
|
|
99
|
+
return node.parent ?? null;
|
|
100
|
+
}
|
|
101
|
+
function isObject(value) {
|
|
102
|
+
return typeof value === "object" && value !== null;
|
|
103
|
+
}
|
|
104
|
+
function isGodotSceneStateNode(value) {
|
|
105
|
+
return isObject(value) && typeof value.index === "number" && (value.siblingIndex === void 0 || typeof value.siblingIndex === "number") && typeof value.name === "string" && Array.isArray(value.groups) && Array.isArray(value.properties);
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { asBoolean, asNumber, asRect2, asResourceRef, asString, asVector2, decodeFromNativeValue, godotNodePath, godotParentPath, isColorValue, isGodotSceneState, isRectValue };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type GodotDocumentKind = \"scene\" | \"resource\";\n\n/** Renderer-neutral 3×3 linear RGB transform. */\nexport type ColorMatrix = {\n rows: readonly [\n readonly [number, number, number],\n readonly [number, number, number],\n readonly [number, number, number],\n ];\n};\n\nexport interface GodotParseDiagnostic {\n severity: \"warning\" | \"error\";\n code: string;\n message: string;\n line?: number;\n column?: number;\n}\n\nexport interface GodotResource {\n type?: string;\n header: GodotSectionHeader | null;\n extResources: GodotExtResource[];\n subResources: GodotSubResource[];\n properties: Record<string, GodotVariant>;\n diagnostics: GodotParseDiagnostic[];\n}\n\nexport interface GodotSceneState {\n kind: \"scene\";\n nodes: GodotSceneStateNode[];\n connections: GodotSceneStateConnection[];\n extResources: GodotExtResource[];\n subResources: GodotSubResource[];\n editableInstances: string[];\n basePath?: string;\n diagnostics: GodotParseDiagnostic[];\n}\n\nexport interface GodotSceneStateNode {\n index: number;\n siblingIndex?: number;\n name: string;\n type?: string;\n parent?: string;\n owner?: string;\n instance?: GodotResourceRefValue;\n instancePlaceholder?: string;\n groups: string[];\n properties: GodotOrderedProperty[];\n}\n\nexport interface GodotOrderedProperty {\n name: string;\n value: GodotVariant;\n}\n\nexport interface GodotSceneStateConnection {\n signal?: string;\n from?: string;\n to?: string;\n method?: string;\n flags?: number;\n binds?: GodotVariant[];\n unbinds?: number;\n}\n\nexport interface GodotSectionHeader {\n section: string;\n attributes: Record<string, GodotVariant>;\n}\n\nexport interface GodotExtResource {\n id: string;\n type?: string;\n path?: string;\n uid?: string;\n attributes: Record<string, GodotVariant>;\n properties: Record<string, GodotVariant>;\n}\n\nexport interface GodotSubResource {\n id: string;\n type?: string;\n attributes: Record<string, GodotVariant>;\n properties: Record<string, GodotVariant>;\n}\n\nexport interface GodotNode {\n name: string;\n type?: string;\n parent?: string;\n instance?: GodotResourceRefValue;\n attributes: Record<string, GodotVariant>;\n properties: Record<string, GodotVariant>;\n propertyEntries?: GodotOrderedProperty[];\n}\n\nexport interface GodotConnection {\n signal?: string;\n from?: string;\n to?: string;\n method?: string;\n attributes: Record<string, GodotVariant>;\n}\n\nexport interface GodotEditable {\n path?: string;\n attributes: Record<string, GodotVariant>;\n}\n\n// Canonical Variant value contract — what every consumer (the `layout`/`html`\n// interpreters and the `as*` accessors below) reads, and what the text parser's\n// `callValue` emits:\n// - scalars are raw JS primitives: `null`, `boolean`, `number`, `string`;\n// - engine math types use `{ type, args }`, where `type` is the Godot\n// constructor name (`Vector2`, `Color`, `Rect2`, `Transform2D`, …) and\n// `args` are its positional components;\n// - resource refs use `{ type:\"ExtResource\"|\"SubResource\", id|path }`.\n// A live producer may instead emit Godot's `JSON.from_native` output, which\n// tags basic scalars as strings (`i:`/`f:`/`s:`/`sn:`/`np:`). That tagged shape\n// is decoded back to this canonical contract at the JSON-ingest boundary when\n// the document opts in with `valueEncoding:\"from_native\"` — see\n// `decodeFromNativeValue`. The accessors themselves stay raw-only: they are\n// shared with the text path, where a literal string like `\"f:stop\"` is real.\nexport type GodotVariant =\n | null\n | boolean\n | number\n | string\n | GodotStringNameVariant\n | GodotVectorVariant\n | GodotColorVariant\n | GodotRectVariant\n | GodotNodePathVariant\n | GodotResourceRefValue\n | GodotCallVariant\n | GodotVariant[]\n | { [key: string]: GodotVariant };\n\nexport interface GodotVectorVariant {\n type:\n | \"Vector2\"\n | \"Vector2i\"\n | \"Vector3\"\n | \"Vector3i\"\n | \"Vector4\"\n | \"Vector4i\";\n args: number[];\n}\n\nexport interface GodotColorVariant {\n type: \"Color\";\n args: number[];\n}\n\nexport interface GodotStringNameVariant {\n type: \"StringName\";\n args: string[];\n}\n\nexport interface GodotRectVariant {\n type: \"Rect2\" | \"Rect2i\";\n args: number[];\n}\n\nexport interface GodotNodePathVariant {\n type: \"NodePath\";\n args: string[];\n}\n\n// A reference into a scene's ext/sub resource table. This is gsw's own\n// scene-file concept (not a Godot Variant), so it stays path/id-keyed rather\n// than `args`-based. Text producers emit a scene-local `id`; runtime producers\n// (which hold loaded `Resource` objects) emit a `res://` `path`. Resolution is\n// path-first, id-fallback — both are first-class.\nexport interface GodotResourceRefValue {\n type: \"ExtResource\" | \"SubResource\";\n id?: string;\n path?: string;\n}\n\n// Any other constructor-style Variant (`Type(args...)`), e.g. PackedVector2Array\n// or Transform2D. The former `Call` kind folded into this uniform shape: the\n// constructor name lives in `type`.\nexport interface GodotCallVariant {\n type: string;\n args: GodotVariant[];\n}\n\nexport interface GodotRect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport function isColorValue(\n value: GodotVariant | undefined,\n): value is GodotColorVariant {\n return isObject(value) && value.type === \"Color\" && Array.isArray(value.args);\n}\n\nexport function isRectValue(\n value: GodotVariant | undefined,\n): value is GodotRectVariant {\n return (\n isObject(value) &&\n (value.type === \"Rect2\" || value.type === \"Rect2i\") &&\n Array.isArray(value.args)\n );\n}\n\nexport function asNumber(value: GodotVariant | undefined): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value)\n ? value\n : undefined;\n}\n\nexport function asBoolean(\n value: GodotVariant | undefined,\n): boolean | undefined {\n return typeof value === \"boolean\" ? value : undefined;\n}\n\nexport function asString(value: GodotVariant | undefined): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n}\n\nexport function asVector2(\n value: GodotVariant | undefined,\n): { x: number; y: number } | undefined {\n if (\n !isObject(value) ||\n (value.type !== \"Vector2\" && value.type !== \"Vector2i\") ||\n !Array.isArray(value.args)\n ) {\n return undefined;\n }\n const [x, y] = value.args as unknown[];\n return typeof x === \"number\" &&\n typeof y === \"number\" &&\n Number.isFinite(x) &&\n Number.isFinite(y)\n ? { x, y }\n : undefined;\n}\n\nexport function asRect2(\n value: GodotVariant | undefined,\n): { x: number; y: number; width: number; height: number } | undefined {\n if (!isRectValue(value)) {\n return undefined;\n }\n const [x, y, width, height] = value.args as unknown[];\n return typeof x === \"number\" &&\n typeof y === \"number\" &&\n typeof width === \"number\" &&\n typeof height === \"number\" &&\n Number.isFinite(x) &&\n Number.isFinite(y) &&\n Number.isFinite(width) &&\n Number.isFinite(height)\n ? { x, y, width, height }\n : undefined;\n}\n\nexport function asResourceRef(\n value: GodotVariant | undefined,\n): GodotResourceRefValue | undefined {\n if (\n !isObject(value) ||\n (value.type !== \"ExtResource\" && value.type !== \"SubResource\")\n ) {\n return undefined;\n }\n const id = typeof value.id === \"string\" ? value.id : undefined;\n const path = typeof value.path === \"string\" ? value.path : undefined;\n if (id === undefined && path === undefined) {\n return undefined;\n }\n return {\n type: value.type,\n ...(id !== undefined ? { id } : {}),\n ...(path !== undefined ? { path } : {}),\n };\n}\n\n// Decode a value produced by Godot's `JSON.from_native` into gsw's canonical\n// Variant contract (see the `GodotVariant` note above). `from_native` tags basic\n// scalars as strings — `i:`/`f:` (int/float), `s:`/`sn:` (String/StringName),\n// `np:` (NodePath) — and passes `null`/`bool` through; math types already arrive\n// as `{ type, args }`. This inverts the scalar tags, recursing through untyped\n// arrays and `Array`/`Dictionary` wrappers (whose elements `from_native` also\n// tags) while leaving every other `{ type, args }` wrapper — math types, packed\n// arrays (raw `args`), resource refs — and untagged strings untouched. Intended\n// only for the JSON-ingest boundary on `valueEncoding:\"from_native\"` documents;\n// never run it on text-parsed values, where a literal `\"i:3\"` is a real string.\nexport function decodeFromNativeValue(value: GodotVariant): GodotVariant {\n if (typeof value === \"string\") {\n return decodeFromNativeScalar(value);\n }\n if (Array.isArray(value)) {\n // Untyped `from_native` arrays arrive as bare JSON arrays of tagged elements.\n return value.map(decodeFromNativeValue);\n }\n if (isObject(value)) {\n const type = typeof value.type === \"string\" ? value.type : undefined;\n // Only `Array`/`Dictionary` wrappers tag their `args`; every other wrapper\n // (`Vector*`, `Color`, packed arrays, resource refs, …) carries canonical or\n // deliberately-raw `args` that must not be re-decoded.\n if (type === \"Array\" || type === \"Dictionary\") {\n return Array.isArray(value.args)\n ? { ...value, args: value.args.map(decodeFromNativeValue) }\n : (value as GodotVariant);\n }\n if (type !== undefined) {\n return value as GodotVariant;\n }\n // A bare object/dictionary map (no recognized variant `type`): decode each\n // value position.\n const decoded: Record<string, GodotVariant> = {};\n for (const [key, entry] of Object.entries(value)) {\n decoded[key] = decodeFromNativeValue(entry as GodotVariant);\n }\n return decoded;\n }\n return value;\n}\n\nfunction decodeFromNativeScalar(value: string): GodotVariant {\n if (value.startsWith(\"i:\")) {\n const parsed = Number.parseInt(value.slice(2), 10);\n return Number.isNaN(parsed) ? value : parsed;\n }\n if (value.startsWith(\"f:\")) {\n const parsed = decodeFromNativeFloat(value.slice(2));\n return parsed === undefined ? value : parsed;\n }\n if (value.startsWith(\"s:\")) {\n return value.slice(2);\n }\n if (value.startsWith(\"sn:\")) {\n return value.slice(3);\n }\n if (value.startsWith(\"np:\")) {\n return { type: \"NodePath\", args: [value.slice(3)] };\n }\n return value;\n}\n\nfunction decodeFromNativeFloat(text: string): number | undefined {\n // `from_native` prints floats via Godot's `String(float)`: finite values, plus\n // `inf` / `-inf` / `nan` for the non-finite ones. `undefined` signals an\n // unparseable tag so the caller can keep the original string verbatim.\n switch (text) {\n case \"inf\":\n return Infinity;\n case \"-inf\":\n return -Infinity;\n case \"nan\":\n return Number.NaN;\n default: {\n const parsed = Number.parseFloat(text);\n return Number.isNaN(parsed) ? undefined : parsed;\n }\n }\n}\n\nexport function isGodotSceneState(value: unknown): value is GodotSceneState {\n if (!isObject(value) || value.kind !== \"scene\") {\n return false;\n }\n return (\n Array.isArray(value.nodes) &&\n value.nodes.every(isGodotSceneStateNode) &&\n Array.isArray(value.connections) &&\n Array.isArray(value.extResources) &&\n Array.isArray(value.subResources) &&\n Array.isArray(value.diagnostics)\n );\n}\n\nexport function godotNodePath(node: GodotNode): string {\n if (!node.parent || node.parent === \".\") {\n return node.name;\n }\n return `${node.parent}/${node.name}`;\n}\n\nexport function godotParentPath(node: GodotNode): string | null {\n return node.parent ?? null;\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isGodotSceneStateNode(value: unknown): value is GodotSceneStateNode {\n return (\n isObject(value) &&\n typeof value.index === \"number\" &&\n (value.siblingIndex === undefined ||\n typeof value.siblingIndex === \"number\") &&\n typeof value.name === \"string\" &&\n Array.isArray(value.groups) &&\n Array.isArray(value.properties)\n );\n}\n"],"mappings":";AAqMA,SAAgB,aACd,OAC4B;CAC5B,OAAO,SAAS,KAAK,KAAK,MAAM,SAAS,WAAW,MAAM,QAAQ,MAAM,IAAI;AAC9E;AAEA,SAAgB,YACd,OAC2B;CAC3B,OACE,SAAS,KAAK,MACb,MAAM,SAAS,WAAW,MAAM,SAAS,aAC1C,MAAM,QAAQ,MAAM,IAAI;AAE5B;AAEA,SAAgB,SAAS,OAAqD;CAC5E,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IACrD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,OAAO,WAAW,IAAI;GACrC,OAAO,OAAO,MAAM,MAAM,IAAI,KAAA,IAAY;EAC5C;CACF;AACF;AAEA,SAAgB,kBAAkB,OAA0C;CAC1E,IAAI,CAAC,SAAS,KAAK,KAAK,MAAM,SAAS,SACrC,OAAO;CAET,OACE,MAAM,QAAQ,MAAM,KAAK,KACzB,MAAM,MAAM,MAAM,qBAAqB,KACvC,MAAM,QAAQ,MAAM,WAAW,KAC/B,MAAM,QAAQ,MAAM,YAAY,KAChC,MAAM,QAAQ,MAAM,YAAY,KAChC,MAAM,QAAQ,MAAM,WAAW;AAEnC;AAEA,SAAgB,cAAc,MAAyB;CACrD,IAAI,CAAC,KAAK,UAAU,KAAK,WAAW,KAClC,OAAO,KAAK;CAEd,OAAO,GAAG,KAAK,OAAO,GAAG,KAAK;AAChC;AAEA,SAAgB,gBAAgB,MAAgC;CAC9D,OAAO,KAAK,UAAU;AACxB;AAEA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAS,sBAAsB,OAA8C;CAC3E,OACE,SAAS,KAAK,KACd,OAAO,MAAM,UAAU,aACtB,MAAM,iBAAiB,KAAA,KACtB,OAAO,MAAM,iBAAiB,aAChC,OAAO,MAAM,SAAS,YACtB,MAAM,QAAQ,MAAM,MAAM,KAC1B,MAAM,QAAQ,MAAM,UAAU;AAElC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@godot-scene-web/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Shared Godot-like AST types and value helpers for godot-scene-web.",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/tfoxy/godot-scene-web.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/tfoxy/godot-scene-web#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/tfoxy/godot-scene-web/issues"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"development": "./src/index.ts",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
36
|
+
"test": "vitest run --root ../.. --config ../../vitest.config.ts packages/core/test"
|
|
37
|
+
}
|
|
38
|
+
}
|