@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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/components.d.ts +47 -0
- package/dist/components.js +93 -0
- package/dist/format.d.ts +53 -0
- package/dist/format.js +6 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +121 -0
- package/dist/instances.d.ts +120 -0
- package/dist/instances.js +1295 -0
- package/dist/prefab-file.d.ts +40 -0
- package/dist/prefab-file.js +446 -0
- package/dist/procedural.d.ts +36 -0
- package/dist/procedural.js +84 -0
- package/dist/scene.d.ts +93 -0
- package/dist/scene.js +736 -0
- package/dist/schema.d.ts +11 -0
- package/dist/schema.js +122 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Dias
|
|
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/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AssetStore } from '@aethervtt/shard-assets';
|
|
2
|
+
import { type Entity, type JsonValue } from '@aethervtt/shard-core';
|
|
3
|
+
import type { PrefabFile, SceneEntity, SceneFile } from './format.js';
|
|
4
|
+
/** Marks entities that came from a scene file. */
|
|
5
|
+
export declare const SceneMember: import("@aethervtt/shard-core").ComponentDef<{
|
|
6
|
+
readonly scene: import("@aethervtt/shard-core").FieldType<string, "object">;
|
|
7
|
+
readonly path: import("@aethervtt/shard-core").FieldType<string, "object">;
|
|
8
|
+
}>;
|
|
9
|
+
export interface LoadedScene {
|
|
10
|
+
id: string;
|
|
11
|
+
file: SceneFile;
|
|
12
|
+
/** Paths in file order (depth-first), and their entities. */
|
|
13
|
+
order: string[];
|
|
14
|
+
entities: Map<string, Entity>;
|
|
15
|
+
authored: Map<Entity, SceneEntity>;
|
|
16
|
+
/** Serialized component values right after load, to tell which fields changed since. */
|
|
17
|
+
loaded: Map<Entity, Map<string, Record<string, JsonValue>>>;
|
|
18
|
+
loadedResources: Map<string, JsonValue>;
|
|
19
|
+
/** Guids of every asset the scene referenced, requested at load. */
|
|
20
|
+
assets: Set<string>;
|
|
21
|
+
}
|
|
22
|
+
export declare const SceneIndex: import("@aethervtt/shard-core").ResourceDef<Map<string, LoadedScene>>;
|
|
23
|
+
/** Scene files loaded as assets (a glTF's node tree), by guid. */
|
|
24
|
+
export declare const SceneAssets: import("@aethervtt/shard-core").ResourceDef<AssetStore<SceneFile, "Scene">>;
|
|
25
|
+
/**
|
|
26
|
+
* Scene assets. References inside them written as `#Label` point at sibling sub-assets of the same
|
|
27
|
+
* source; they're resolved against the source's current path at load, so moving the file is safe.
|
|
28
|
+
*/
|
|
29
|
+
export declare const SceneAssetType: import("@aethervtt/shard-assets").AssetTypeDef<SceneFile>;
|
|
30
|
+
/** Prefabs by guid: the resolved tree (variants already flattened onto their base). */
|
|
31
|
+
export declare const PrefabAssets: import("@aethervtt/shard-core").ResourceDef<AssetStore<PrefabFile, "Prefab">>;
|
|
32
|
+
export declare const PrefabAssetType: import("@aethervtt/shard-assets").AssetTypeDef<PrefabFile>;
|
|
33
|
+
/** Places a scene asset (e.g. `assets/ship.glb#Scene`) as generated children of this entity. */
|
|
34
|
+
export declare const SceneInstance: import("@aethervtt/shard-core").ComponentDef<{
|
|
35
|
+
readonly scene: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"Scene"> | null, "object">;
|
|
36
|
+
readonly overrides: import("@aethervtt/shard-core").FieldType<JsonValue, "object">;
|
|
37
|
+
}>;
|
|
38
|
+
/** Makes this entity an instance of a prefab: the prefab root's components and children. */
|
|
39
|
+
export declare const PrefabInstance: import("@aethervtt/shard-core").ComponentDef<{
|
|
40
|
+
readonly prefab: import("@aethervtt/shard-core").FieldType<import("@aethervtt/shard-core").AssetRef<"Prefab"> | null, "object">;
|
|
41
|
+
readonly overrides: import("@aethervtt/shard-core").FieldType<JsonValue, "object">;
|
|
42
|
+
}>;
|
|
43
|
+
/** Marks entities an instance generated (they're rebuilt from the prefab or model, never saved). */
|
|
44
|
+
export declare const InstancePart: import("@aethervtt/shard-core").ComponentDef<{
|
|
45
|
+
readonly instance: import("@aethervtt/shard-core").FieldType<number | null, "f64">;
|
|
46
|
+
readonly path: import("@aethervtt/shard-core").FieldType<string, "object">;
|
|
47
|
+
}>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { AssetStore, defineAssetType } from "@aethervtt/shard-assets";
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
defineResource,
|
|
5
|
+
t
|
|
6
|
+
} from "@aethervtt/shard-core";
|
|
7
|
+
const SceneMember = defineComponent(
|
|
8
|
+
"scene/SceneMember",
|
|
9
|
+
{
|
|
10
|
+
scene: t.string({ description: "Id of the scene this entity was loaded from." }),
|
|
11
|
+
path: t.string({ description: 'Path within the scene, e.g. "ship/camera".' })
|
|
12
|
+
},
|
|
13
|
+
{ description: "Set by the scene loader.", serialize: false }
|
|
14
|
+
);
|
|
15
|
+
const SceneIndex = defineResource("scene/Index", {
|
|
16
|
+
description: "Loaded scenes: paths, entities, and what was authored.",
|
|
17
|
+
init: () => /* @__PURE__ */ new Map()
|
|
18
|
+
});
|
|
19
|
+
const SceneAssets = defineResource("scene/SceneAssets", {
|
|
20
|
+
description: "Scene assets (node trees) by guid.",
|
|
21
|
+
init: () => new AssetStore("Scene")
|
|
22
|
+
});
|
|
23
|
+
const SceneAssetType = defineAssetType("Scene", {
|
|
24
|
+
store: SceneAssets,
|
|
25
|
+
load: (artifact, ctx) => {
|
|
26
|
+
const base = ctx.path.split("#")[0];
|
|
27
|
+
const resolve = (value) => {
|
|
28
|
+
if (Array.isArray(value)) return value.map(resolve);
|
|
29
|
+
if (!value || typeof value !== "object") return value;
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const [k, v] of Object.entries(value)) {
|
|
32
|
+
out[k] = k === "path" && typeof v === "string" && v.startsWith("#") ? `${base}${v}` : resolve(v);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
};
|
|
36
|
+
return resolve(artifact.json);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const PrefabAssets = defineResource("scene/PrefabAssets", {
|
|
40
|
+
description: "Prefab assets (resolved entity trees) by guid.",
|
|
41
|
+
init: () => new AssetStore("Prefab")
|
|
42
|
+
});
|
|
43
|
+
const PrefabAssetType = defineAssetType("Prefab", {
|
|
44
|
+
store: PrefabAssets,
|
|
45
|
+
load: (artifact) => artifact.json
|
|
46
|
+
});
|
|
47
|
+
const overridesField = () => t.json({
|
|
48
|
+
default: {},
|
|
49
|
+
description: 'Changes to generated entities by path relative to this entity: { "Exhaust": { "particles/ParticleSystem": { "timeScale": 2 } } } sets fields, { "Hull/Antenna": null } removes an entity, { "Exhaust/particles/ParticleEmitterOverrides": null } removes a component. Paths reach into nested instances.'
|
|
50
|
+
});
|
|
51
|
+
const SceneInstance = defineComponent(
|
|
52
|
+
"scene/SceneInstance",
|
|
53
|
+
{
|
|
54
|
+
scene: t.handle("Scene", {
|
|
55
|
+
description: 'The scene to place, e.g. { "path": "assets/ship.glb#Scene" }.'
|
|
56
|
+
}),
|
|
57
|
+
overrides: overridesField()
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
description: "Spawns a scene asset (a model's node tree) as children, addressable by path (ship/Hull). The children are generated: saving writes only this entity and its overrides, and they respawn when the asset changes."
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
const PrefabInstance = defineComponent(
|
|
64
|
+
"scene/PrefabInstance",
|
|
65
|
+
{
|
|
66
|
+
prefab: t.handle("Prefab", {
|
|
67
|
+
description: 'The prefab to place, e.g. { "path": "prefabs/ship.prefab.json" }.'
|
|
68
|
+
}),
|
|
69
|
+
overrides: overridesField()
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
description: "Makes this entity an instance of a prefab. The prefab root's components merge into it (fields the entity sets win) and the root's children spawn under it, addressable by path (player-ship/Exhaust). Changes to the children are saved as overrides."
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
const InstancePart = defineComponent(
|
|
76
|
+
"scene/InstancePart",
|
|
77
|
+
{
|
|
78
|
+
instance: t.entity({ description: "The instance entity that generated this one." }),
|
|
79
|
+
path: t.string({ description: 'Path relative to the instance, e.g. "Hull/Cockpit".' })
|
|
80
|
+
},
|
|
81
|
+
{ description: "Set on entities a SceneInstance or PrefabInstance spawned.", serialize: false }
|
|
82
|
+
);
|
|
83
|
+
export {
|
|
84
|
+
InstancePart,
|
|
85
|
+
PrefabAssetType,
|
|
86
|
+
PrefabAssets,
|
|
87
|
+
PrefabInstance,
|
|
88
|
+
SceneAssetType,
|
|
89
|
+
SceneAssets,
|
|
90
|
+
SceneIndex,
|
|
91
|
+
SceneInstance,
|
|
92
|
+
SceneMember
|
|
93
|
+
};
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { JsonValue } from '@aethervtt/shard-core';
|
|
2
|
+
/** A `*.scene.json` file. */
|
|
3
|
+
export interface SceneFile {
|
|
4
|
+
$schema?: string;
|
|
5
|
+
version: number;
|
|
6
|
+
/** Scene-local assets, referenced as `{ "path": "#name" }`. */
|
|
7
|
+
assets?: Record<string, SceneAsset>;
|
|
8
|
+
/** Resource values by registered name, merged into the world's resources on load. */
|
|
9
|
+
resources?: Record<string, JsonValue>;
|
|
10
|
+
entities: SceneEntity[];
|
|
11
|
+
}
|
|
12
|
+
export type SceneAsset = {
|
|
13
|
+
type: 'Material';
|
|
14
|
+
value: Record<string, JsonValue>;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'Mesh';
|
|
17
|
+
procedural: string;
|
|
18
|
+
params?: Record<string, number>;
|
|
19
|
+
};
|
|
20
|
+
export interface SceneEntity {
|
|
21
|
+
/** Unique among siblings; joined with '/' into the entity's path. */
|
|
22
|
+
name: string;
|
|
23
|
+
components?: Record<string, Record<string, JsonValue>>;
|
|
24
|
+
children?: SceneEntity[];
|
|
25
|
+
}
|
|
26
|
+
export declare const SCENE_VERSION = 1;
|
|
27
|
+
/**
|
|
28
|
+
* Changes to an instance's generated entities, keyed by path relative to the instance:
|
|
29
|
+
* `{ "Exhaust": { "particles/ParticleSystem": { "timeScale": 2 } } }` sets fields (adding the
|
|
30
|
+
* component if missing), `{ "Hull/Antenna": null }` removes an entity and its subtree, and
|
|
31
|
+
* `{ "Exhaust/particles/ParticleEmitterOverrides": null }` removes one component.
|
|
32
|
+
*/
|
|
33
|
+
export type Overrides = Record<string, Record<string, Record<string, JsonValue> | null> | null>;
|
|
34
|
+
/** A `*.prefab.json` file: one root entity, or a variant that extends another prefab. */
|
|
35
|
+
export interface PrefabFile {
|
|
36
|
+
$schema?: string;
|
|
37
|
+
version: number;
|
|
38
|
+
/** Prefab-local assets, referenced as `{ "path": "#name" }`. */
|
|
39
|
+
assets?: Record<string, SceneAsset>;
|
|
40
|
+
root?: SceneEntity;
|
|
41
|
+
/** Variants only: the base prefab. */
|
|
42
|
+
extends?: {
|
|
43
|
+
path?: string;
|
|
44
|
+
guid?: string;
|
|
45
|
+
};
|
|
46
|
+
/** Variants only: fields set on the base's root components (added if missing). */
|
|
47
|
+
rootComponents?: Record<string, Record<string, JsonValue>>;
|
|
48
|
+
/** Variants only: overrides applied to the base's entities. */
|
|
49
|
+
overrides?: Overrides;
|
|
50
|
+
/** Variants only: extra children under the root. */
|
|
51
|
+
children?: SceneEntity[];
|
|
52
|
+
}
|
|
53
|
+
export declare const PREFAB_VERSION = 1;
|
package/dist/format.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { InstancePart, PrefabAssets, PrefabAssetType, PrefabInstance, SceneAssets, SceneAssetType, SceneIndex, SceneInstance, SceneMember, } from './components.js';
|
|
2
|
+
export { type Overrides, PREFAB_VERSION, type PrefabFile, SCENE_VERSION, type SceneAsset, type SceneEntity, type SceneFile, } from './format.js';
|
|
3
|
+
export { currentOverrides, defineInstanceKind, hookInstances, type InstanceKind, instanceEntities, instanceKindOf, instanceKinds, instanceOf, loadInstanceAssets, loadPrefab, mergeOverridesIntoPrefab, prefabOfInstance, prefabRootComponents, releaseSceneHooks, ScenePlugin, type SpawnPrefabOptions, sceneInstancesSystem, settleInstances, spawnPrefab, updateInstances, } from './instances.js';
|
|
4
|
+
export { applyToPrefab, applyVariant, type PrefabFiles, PrefabImporter, registeredPrefab, registerPrefab, validatePrefab, } from './prefab-file.js';
|
|
5
|
+
export { allProceduralSources, defineProceduralSource, PROCEDURAL_MESHES, type ProceduralRef, type ProceduralSource, parseProcedural, proceduralSourceFor, } from './procedural.js';
|
|
6
|
+
export { addSceneReadyCheck, expandComponentAliases, findEntityByPath, type LoadedSceneHandle, loadScene, pathOfEntity, reloadScene, saveScene, stringifyScene, unloadScene, validateScene, whenSceneReady, worldSchemaContext, } from './scene.js';
|
|
7
|
+
export { prefabJsonSchema, sceneJsonSchema } from './schema.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InstancePart,
|
|
3
|
+
PrefabAssets,
|
|
4
|
+
PrefabAssetType,
|
|
5
|
+
PrefabInstance,
|
|
6
|
+
SceneAssets,
|
|
7
|
+
SceneAssetType,
|
|
8
|
+
SceneIndex,
|
|
9
|
+
SceneInstance,
|
|
10
|
+
SceneMember
|
|
11
|
+
} from "./components.js";
|
|
12
|
+
import {
|
|
13
|
+
PREFAB_VERSION,
|
|
14
|
+
SCENE_VERSION
|
|
15
|
+
} from "./format.js";
|
|
16
|
+
import {
|
|
17
|
+
currentOverrides,
|
|
18
|
+
defineInstanceKind,
|
|
19
|
+
hookInstances,
|
|
20
|
+
instanceEntities,
|
|
21
|
+
instanceKindOf,
|
|
22
|
+
instanceKinds,
|
|
23
|
+
instanceOf,
|
|
24
|
+
loadInstanceAssets,
|
|
25
|
+
loadPrefab,
|
|
26
|
+
mergeOverridesIntoPrefab,
|
|
27
|
+
prefabOfInstance,
|
|
28
|
+
prefabRootComponents,
|
|
29
|
+
releaseSceneHooks,
|
|
30
|
+
ScenePlugin,
|
|
31
|
+
sceneInstancesSystem,
|
|
32
|
+
settleInstances,
|
|
33
|
+
spawnPrefab,
|
|
34
|
+
updateInstances
|
|
35
|
+
} from "./instances.js";
|
|
36
|
+
import {
|
|
37
|
+
applyToPrefab,
|
|
38
|
+
applyVariant,
|
|
39
|
+
PrefabImporter,
|
|
40
|
+
registeredPrefab,
|
|
41
|
+
registerPrefab,
|
|
42
|
+
validatePrefab
|
|
43
|
+
} from "./prefab-file.js";
|
|
44
|
+
import {
|
|
45
|
+
allProceduralSources,
|
|
46
|
+
defineProceduralSource,
|
|
47
|
+
PROCEDURAL_MESHES,
|
|
48
|
+
parseProcedural,
|
|
49
|
+
proceduralSourceFor
|
|
50
|
+
} from "./procedural.js";
|
|
51
|
+
import {
|
|
52
|
+
addSceneReadyCheck,
|
|
53
|
+
expandComponentAliases,
|
|
54
|
+
findEntityByPath,
|
|
55
|
+
loadScene,
|
|
56
|
+
pathOfEntity,
|
|
57
|
+
reloadScene,
|
|
58
|
+
saveScene,
|
|
59
|
+
stringifyScene,
|
|
60
|
+
unloadScene,
|
|
61
|
+
validateScene,
|
|
62
|
+
whenSceneReady,
|
|
63
|
+
worldSchemaContext
|
|
64
|
+
} from "./scene.js";
|
|
65
|
+
import { prefabJsonSchema, sceneJsonSchema } from "./schema.js";
|
|
66
|
+
export {
|
|
67
|
+
InstancePart,
|
|
68
|
+
PREFAB_VERSION,
|
|
69
|
+
PROCEDURAL_MESHES,
|
|
70
|
+
PrefabAssetType,
|
|
71
|
+
PrefabAssets,
|
|
72
|
+
PrefabImporter,
|
|
73
|
+
PrefabInstance,
|
|
74
|
+
SCENE_VERSION,
|
|
75
|
+
SceneAssetType,
|
|
76
|
+
SceneAssets,
|
|
77
|
+
SceneIndex,
|
|
78
|
+
SceneInstance,
|
|
79
|
+
SceneMember,
|
|
80
|
+
ScenePlugin,
|
|
81
|
+
addSceneReadyCheck,
|
|
82
|
+
allProceduralSources,
|
|
83
|
+
applyToPrefab,
|
|
84
|
+
applyVariant,
|
|
85
|
+
currentOverrides,
|
|
86
|
+
defineInstanceKind,
|
|
87
|
+
defineProceduralSource,
|
|
88
|
+
expandComponentAliases,
|
|
89
|
+
findEntityByPath,
|
|
90
|
+
hookInstances,
|
|
91
|
+
instanceEntities,
|
|
92
|
+
instanceKindOf,
|
|
93
|
+
instanceKinds,
|
|
94
|
+
instanceOf,
|
|
95
|
+
loadInstanceAssets,
|
|
96
|
+
loadPrefab,
|
|
97
|
+
loadScene,
|
|
98
|
+
mergeOverridesIntoPrefab,
|
|
99
|
+
parseProcedural,
|
|
100
|
+
pathOfEntity,
|
|
101
|
+
prefabJsonSchema,
|
|
102
|
+
prefabOfInstance,
|
|
103
|
+
prefabRootComponents,
|
|
104
|
+
proceduralSourceFor,
|
|
105
|
+
registerPrefab,
|
|
106
|
+
registeredPrefab,
|
|
107
|
+
releaseSceneHooks,
|
|
108
|
+
reloadScene,
|
|
109
|
+
saveScene,
|
|
110
|
+
sceneInstancesSystem,
|
|
111
|
+
sceneJsonSchema,
|
|
112
|
+
settleInstances,
|
|
113
|
+
spawnPrefab,
|
|
114
|
+
stringifyScene,
|
|
115
|
+
unloadScene,
|
|
116
|
+
updateInstances,
|
|
117
|
+
validatePrefab,
|
|
118
|
+
validateScene,
|
|
119
|
+
whenSceneReady,
|
|
120
|
+
worldSchemaContext
|
|
121
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type AssetEntry } from '@aethervtt/shard-assets';
|
|
2
|
+
import { type AssetRef, Commands, type ComponentDef, type Entity, type JsonValue, ShardError, World } from '@aethervtt/shard-core';
|
|
3
|
+
import { type Plugin } from '@aethervtt/shard-runtime';
|
|
4
|
+
import type { Overrides, PrefabFile } from './format.js';
|
|
5
|
+
import { type FlatEntity } from './scene.js';
|
|
6
|
+
type InstanceDef = ComponentDef;
|
|
7
|
+
/**
|
|
8
|
+
* A component that spawns a Prefab or Scene asset as generated children: SceneInstance,
|
|
9
|
+
* PrefabInstance, and kinds other packages add (procgen's GeneratorInstance). The component needs
|
|
10
|
+
* an `overrides` json field; saves write the children's changes there.
|
|
11
|
+
*/
|
|
12
|
+
export interface InstanceKind {
|
|
13
|
+
readonly def: ComponentDef;
|
|
14
|
+
/**
|
|
15
|
+
* The Prefab or Scene asset an instance with this value spawns: registered (it may still be
|
|
16
|
+
* loading; unloaded ones are requested), or undefined when there's nothing to spawn.
|
|
17
|
+
*/
|
|
18
|
+
source(world: World, value: Record<string, unknown>, entity: Entity): AssetEntry | undefined;
|
|
19
|
+
/** Respawns reuse the entities whose path is unchanged, so references to them survive. */
|
|
20
|
+
readonly keepIds?: boolean;
|
|
21
|
+
/** A tag added to every entity this kind spawns (procgen/Generated). */
|
|
22
|
+
readonly mark?: ComponentDef;
|
|
23
|
+
/**
|
|
24
|
+
* Instances on generated entities spawn their own children (lazily, as part of nothing). Without
|
|
25
|
+
* it, instances inside a prefab are inlined into it.
|
|
26
|
+
*/
|
|
27
|
+
readonly nested?: boolean;
|
|
28
|
+
/** Extra checks of the component's JSON in scene and prefab files. */
|
|
29
|
+
validate?(world: World, json: Record<string, JsonValue>, base: string, errors: ShardError[], options: {
|
|
30
|
+
catalog: boolean;
|
|
31
|
+
}): void;
|
|
32
|
+
}
|
|
33
|
+
export declare const sceneInstanceKind: InstanceKind;
|
|
34
|
+
export declare const prefabInstanceKind: InstanceKind;
|
|
35
|
+
/** Adds a kind of instance component (see InstanceKind). */
|
|
36
|
+
export declare function defineInstanceKind(kind: InstanceKind): InstanceKind;
|
|
37
|
+
/** Every instance kind: SceneInstance, PrefabInstance, then added ones. */
|
|
38
|
+
export declare function instanceKinds(): readonly InstanceKind[];
|
|
39
|
+
export declare function instanceKindOf(def: ComponentDef): InstanceKind | undefined;
|
|
40
|
+
/** Installs the instance hooks for a world (asset reloads respawn instances, even between frames). */
|
|
41
|
+
export declare function hookInstances(world: World): void;
|
|
42
|
+
/** Detaches a world's scene hooks from its asset server (for worlds that share another's server). */
|
|
43
|
+
export declare function releaseSceneHooks(world: World): void;
|
|
44
|
+
/** Spawns instances system: does nothing on frames without instance or asset changes. */
|
|
45
|
+
export declare const sceneInstancesSystem: import("@aethervtt/shard-core").SystemDef<undefined>;
|
|
46
|
+
/** Scene support for apps: spawns instance children added while the app runs. */
|
|
47
|
+
export declare const ScenePlugin: Plugin;
|
|
48
|
+
/**
|
|
49
|
+
* Spawns the children of every SceneInstance and PrefabInstance whose asset is loaded (requesting
|
|
50
|
+
* it otherwise), respawns those whose asset, dependencies, or overrides changed, and cleans up after
|
|
51
|
+
* removed instances. Instances inlined into another instance are part of it and skipped.
|
|
52
|
+
*/
|
|
53
|
+
export declare function updateInstances(world: World): void;
|
|
54
|
+
/** Waits for instance assets to load and spawns them (repeatedly, for nested instances). */
|
|
55
|
+
export declare function settleInstances(world: World): Promise<void>;
|
|
56
|
+
export interface SpawnPrefabOptions {
|
|
57
|
+
/** Fields of the root's Transform (the rest come from the prefab). */
|
|
58
|
+
transform?: {
|
|
59
|
+
translation?: readonly number[];
|
|
60
|
+
rotation?: readonly number[];
|
|
61
|
+
scale?: readonly number[];
|
|
62
|
+
};
|
|
63
|
+
/** Changes to generated entities, as in a scene's `PrefabInstance.overrides`. */
|
|
64
|
+
overrides?: Overrides;
|
|
65
|
+
parent?: Entity;
|
|
66
|
+
}
|
|
67
|
+
type PrefabRef = string | AssetRef | {
|
|
68
|
+
guid?: string;
|
|
69
|
+
path?: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Loads a prefab (and everything it uses) so `spawnPrefab` can spawn it. Resolves with its
|
|
73
|
+
* template ready.
|
|
74
|
+
*/
|
|
75
|
+
export declare function loadPrefab(world: World, ref: PrefabRef): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Spawns a prefab instance now (or, given a system's Commands, when they apply) and returns its
|
|
78
|
+
* root. The prefab must be loaded (`loadPrefab`); spawning copies a compiled template, so it's cheap
|
|
79
|
+
* enough for bullets. Scene files place prefabs with `scene/PrefabInstance`, which waits for loading.
|
|
80
|
+
*/
|
|
81
|
+
export declare function spawnPrefab(target: World | Commands, ref: PrefabRef, options?: SpawnPrefabOptions): Entity;
|
|
82
|
+
/** The generated entities of an instance, by path relative to it (e.g. "Hull/Cockpit"). */
|
|
83
|
+
export declare function instanceEntities(world: World, entity: Entity): Map<string, Entity>;
|
|
84
|
+
/**
|
|
85
|
+
* The components a prefab instance's root got from its prefab, as JSON (entity fields as paths
|
|
86
|
+
* relative to the instance, "." for itself). Undefined for entities that aren't spawned prefab
|
|
87
|
+
* instances. Saves compare against it to write only what changed.
|
|
88
|
+
*/
|
|
89
|
+
export declare function prefabRootComponents(world: World, entity: Entity): ReadonlyMap<string, Record<string, JsonValue>> | undefined;
|
|
90
|
+
/** The instance entity (prefab or model) at the top of a generated entity, or the entity itself. */
|
|
91
|
+
export declare function instanceOf(world: World, entity: Entity): Entity | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* An instance's current differences from its prefab or model, as overrides: what a save writes.
|
|
94
|
+
* Overrides already in the file keep their order and authored form while unchanged; stale ones
|
|
95
|
+
* (paths that no longer exist) are kept. Undefined for entities that aren't spawned instances.
|
|
96
|
+
*/
|
|
97
|
+
export declare function currentOverrides(world: World, entity: Entity): Overrides | undefined;
|
|
98
|
+
/** What `applyToPrefab` needs from the host: the prefab file's JSON, and where to write it. */
|
|
99
|
+
export interface PrefabSource {
|
|
100
|
+
read(path: string): Promise<unknown>;
|
|
101
|
+
write(path: string, json: unknown): Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Merges overrides into a prefab file's JSON: component patches merge into the authored components,
|
|
105
|
+
* removals delete, and paths inside a nested instance land in that instance's overrides. Variants
|
|
106
|
+
* (files with "extends") merge into their own "overrides". Returns the new JSON.
|
|
107
|
+
*/
|
|
108
|
+
export declare function mergeOverridesIntoPrefab(file: PrefabFile, overrides: Overrides, onUnknown?: (key: string) => void): PrefabFile;
|
|
109
|
+
/** The prefab asset an instance entity places, or undefined. */
|
|
110
|
+
export declare function prefabOfInstance(world: World, entity: Entity): AssetEntry | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Checks an instance component's overrides in a scene or prefab file: shape always; paths and
|
|
113
|
+
* values when the asset is loaded (so `shard validate` preloads them with `loadInstanceAssets`).
|
|
114
|
+
*/
|
|
115
|
+
export declare function validateInstance(world: World, def: InstanceDef, json: Record<string, JsonValue>, base: string, f: FlatEntity, errors: ShardError[], options: {
|
|
116
|
+
catalog: boolean;
|
|
117
|
+
}): void;
|
|
118
|
+
/** Loads the prefab and model assets a scene's instances use, so validation can check overrides. */
|
|
119
|
+
export declare function loadInstanceAssets(world: World, json: unknown): Promise<void>;
|
|
120
|
+
export {};
|