@aethervtt/shard-scene 0.0.1

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.
@@ -0,0 +1,11 @@
1
+ import { type JsonSchema } from '@aethervtt/shard-core';
2
+ /**
3
+ * JSON Schema for scene files, composed from every defined component's schema. Written to
4
+ * `.shard/schemas/scene.schema.json` so editors and agents validate while writing.
5
+ */
6
+ export declare function sceneJsonSchema(): JsonSchema;
7
+ /**
8
+ * JSON Schema for prefab files: a root entity (the scene schema's entity), or a variant with
9
+ * "extends", "rootComponents", "overrides", and "children". Written to `.shard/schemas/`.
10
+ */
11
+ export declare function prefabJsonSchema(): JsonSchema;
package/dist/schema.js ADDED
@@ -0,0 +1,122 @@
1
+ import { allComponents, ChildOf } from "@aethervtt/shard-core";
2
+ import { StandardMaterial } from "@aethervtt/shard-render";
3
+ import { PREFAB_VERSION, SCENE_VERSION } from "./format.js";
4
+ import { PROCEDURAL_MESHES } from "./procedural.js";
5
+ function sceneJsonSchema() {
6
+ const components = {};
7
+ for (const def of allComponents()) {
8
+ if (!def.serializable || def === ChildOf) continue;
9
+ const schema = def.jsonSchema();
10
+ delete schema.$schema;
11
+ if (def.name === "core/Transform") {
12
+ const props = schema.properties;
13
+ props.rotationEuler = {
14
+ type: "array",
15
+ items: { type: "number" },
16
+ minItems: 3,
17
+ maxItems: 3,
18
+ description: "Authoring alternative to rotation: degrees, applied X then Y then Z."
19
+ };
20
+ schema.not = { required: ["rotation", "rotationEuler"] };
21
+ }
22
+ components[def.name] = schema;
23
+ }
24
+ const material = StandardMaterial.jsonSchema();
25
+ delete material.$schema;
26
+ return {
27
+ $schema: "https://json-schema.org/draft/2020-12/schema",
28
+ title: "Shard scene",
29
+ type: "object",
30
+ required: ["version", "entities"],
31
+ additionalProperties: false,
32
+ properties: {
33
+ $schema: { type: "string" },
34
+ version: { const: SCENE_VERSION },
35
+ assets: {
36
+ type: "object",
37
+ additionalProperties: {
38
+ oneOf: [
39
+ {
40
+ type: "object",
41
+ properties: { type: { const: "Material" }, value: material },
42
+ required: ["type", "value"],
43
+ additionalProperties: false
44
+ },
45
+ {
46
+ type: "object",
47
+ properties: {
48
+ type: { const: "Mesh" },
49
+ procedural: { enum: Object.keys(PROCEDURAL_MESHES) },
50
+ params: { type: "object", additionalProperties: { type: "number" } }
51
+ },
52
+ required: ["type", "procedural"],
53
+ additionalProperties: false
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ resources: { type: "object", additionalProperties: { type: "object" } },
59
+ entities: { type: "array", items: { $ref: "#/$defs/entity" } }
60
+ },
61
+ $defs: {
62
+ entity: {
63
+ type: "object",
64
+ required: ["name"],
65
+ additionalProperties: false,
66
+ properties: {
67
+ name: { type: "string", minLength: 1, pattern: "^[^/]+$" },
68
+ components: { type: "object", properties: components, additionalProperties: false },
69
+ children: { type: "array", items: { $ref: "#/$defs/entity" } }
70
+ }
71
+ }
72
+ }
73
+ };
74
+ }
75
+ function prefabJsonSchema() {
76
+ const scene = sceneJsonSchema();
77
+ const props = scene.properties;
78
+ const components = { $ref: "#/$defs/entity/properties/components" };
79
+ const patch = { anyOf: [{ type: "null" }, { type: "object" }] };
80
+ return {
81
+ $schema: "https://json-schema.org/draft/2020-12/schema",
82
+ title: "Shard prefab",
83
+ type: "object",
84
+ required: ["version"],
85
+ additionalProperties: false,
86
+ properties: {
87
+ $schema: { type: "string" },
88
+ version: { const: PREFAB_VERSION },
89
+ assets: props.assets,
90
+ root: { $ref: "#/$defs/entity" },
91
+ extends: {
92
+ type: "object",
93
+ description: 'Variants: the base prefab, e.g. { "path": "prefabs/ship.prefab.json" }.',
94
+ properties: { guid: { type: "string" }, path: { type: "string" } },
95
+ additionalProperties: false,
96
+ minProperties: 1
97
+ },
98
+ rootComponents: {
99
+ ...components,
100
+ description: "Variants: fields set on the base's root components (added if missing)."
101
+ },
102
+ overrides: {
103
+ type: "object",
104
+ description: `Variants: changes to the base's entities by path from the root. { "Hull": { "<component>": { fields } } } sets fields, { "Hull/Antenna": null } removes an entity, { "Hull/<component>": null } removes a component.`,
105
+ additionalProperties: {
106
+ anyOf: [{ type: "null" }, { type: "object", additionalProperties: patch }]
107
+ }
108
+ },
109
+ children: {
110
+ type: "array",
111
+ description: "Variants: extra children under the root.",
112
+ items: { $ref: "#/$defs/entity" }
113
+ }
114
+ },
115
+ oneOf: [{ required: ["root"] }, { required: ["extends"] }],
116
+ $defs: scene.$defs
117
+ };
118
+ }
119
+ export {
120
+ prefabJsonSchema,
121
+ sceneJsonSchema
122
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@aethervtt/shard-scene",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "LICENSE",
16
+ "README.md"
17
+ ],
18
+ "dependencies": {
19
+ "@aethervtt/shard-assets": "0.0.1",
20
+ "@aethervtt/shard-core": "0.0.1",
21
+ "@aethervtt/shard-mesh": "0.0.1",
22
+ "@aethervtt/shard-render": "0.0.1",
23
+ "@aethervtt/shard-runtime": "0.0.1",
24
+ "@aethervtt/shard-transform": "0.0.1"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/aethervtt/shard.git",
29
+ "directory": "packages/scene"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "provenance": true
34
+ },
35
+ "shard": {
36
+ "buildSha": "d6c5c6aef4675575c878b02cf2c8f738b4190229"
37
+ }
38
+ }