@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,93 @@
1
+ import { type AssetRef, type ComponentDef, type Entity, type JsonValue, type ResolvedAsset, type SchemaContext, ShardError, type World } from '@aethervtt/shard-core';
2
+ import { type SceneAsset, type SceneEntity, type SceneFile } from './format.js';
3
+ export interface LoadedSceneHandle {
4
+ id: string;
5
+ /** Scene path → entity. */
6
+ entities: ReadonlyMap<string, Entity>;
7
+ }
8
+ /** Authoring-only fields: written in files, converted on load, written back when unchanged. */
9
+ export declare const ALIASES: Record<string, Record<string, {
10
+ field: string;
11
+ decode(json: unknown): JsonValue;
12
+ }>>;
13
+ export declare function expandAliases(name: string, json: Record<string, JsonValue>, base: string, errors: ShardError[] | undefined): Record<string, JsonValue>;
14
+ export declare function resolveAssets(world: World, file: {
15
+ assets?: Record<string, SceneAsset>;
16
+ }, sceneId: string, mode: 'check' | 'create', requested?: Set<string>): (ref: {
17
+ guid?: string;
18
+ path?: string;
19
+ }) => ResolvedAsset | undefined;
20
+ /**
21
+ * Schema context for component JSON outside a scene file (protocol, tools): entity fields accept
22
+ * scene paths, handles accept asset paths, procedural refs (`procedural:sphere?radius=1`), and guids.
23
+ */
24
+ export declare function worldSchemaContext(world: World): SchemaContext;
25
+ /** Expands authoring aliases (e.g. Transform `rotationEuler`) in one component's JSON. */
26
+ export declare function expandComponentAliases(name: string, json: Record<string, JsonValue>): Record<string, JsonValue>;
27
+ export interface FlatEntity {
28
+ path: string;
29
+ parent: string | undefined;
30
+ entity: SceneEntity;
31
+ pointer: string;
32
+ }
33
+ export declare function flatten(entities: readonly SceneEntity[], base: string, parent: string | undefined, out: FlatEntity[]): void;
34
+ export declare function rebase(err: ShardError, base: string): ShardError;
35
+ export declare function componentDef(name: string): ComponentDef | undefined;
36
+ /** Every problem in a scene file, each with a JSON pointer. Empty means it will load. */
37
+ export declare function validateScene(world: World, json: unknown, options?: {
38
+ id?: string;
39
+ }): ShardError[];
40
+ /** Checks a file's `assets` block (scene-local materials and procedural meshes). */
41
+ export declare function validateAssetsBlock(assets: Record<string, SceneAsset> | undefined, errors: ShardError[]): void;
42
+ export interface TreeOptions {
43
+ id: string;
44
+ /**
45
+ * False when there's no catalog to check asset paths against (importing a prefab): only
46
+ * file-local `#name` refs are checked; the rest are checked when a scene using it validates.
47
+ */
48
+ catalog?: boolean;
49
+ /** Entity paths that resolve besides the tree's own (a prefab's root is "."). */
50
+ extraPaths?: readonly string[];
51
+ /** A prefab tree: the first entity is the root, at path ".". */
52
+ root?: boolean;
53
+ /** A variant: `#name` refs may name the base's assets, so missing ones aren't errors here. */
54
+ inheritsAssets?: boolean;
55
+ }
56
+ /** Names, components, entity paths, and instance overrides of a flattened entity tree. */
57
+ export declare function validateTree(world: World, file: {
58
+ assets?: Record<string, SceneAsset>;
59
+ }, flat: readonly FlatEntity[], errors: ShardError[], options: TreeOptions): void;
60
+ /** A specific scene error beats the generic asset-not-found for the same field; drop duplicates. */
61
+ export declare function dedupeErrors(errors: ShardError[]): ShardError[];
62
+ /** Validates, then spawns the scene. Throws `scene/invalid` (with every error in `details`) if invalid. */
63
+ export declare function loadScene(world: World, json: unknown, options?: {
64
+ id?: string;
65
+ }): LoadedSceneHandle;
66
+ /**
67
+ * Resolves once every asset the scene referenced has loaded or failed (following their
68
+ * dependencies). Tools wait for this before capturing, so screenshots never show half a scene.
69
+ */
70
+ export declare function whenSceneReady(world: World, id: string): Promise<void>;
71
+ export declare function addSceneReadyCheck(check: (world: World, sceneId: string) => Promise<void>): void;
72
+ /** Despawns a loaded scene's entities and loads the new file under the same id. */
73
+ export declare function reloadScene(world: World, id: string, json: unknown): LoadedSceneHandle;
74
+ /** Despawns a scene's entities, then unloads assets nothing references any more. */
75
+ export declare function unloadScene(world: World, id: string, options?: {
76
+ collect?: boolean;
77
+ }): void;
78
+ /** Finds a scene entity by path (`ship/camera`), or `sceneId:path` when several scenes are loaded. */
79
+ export declare function findEntityByPath(world: World, path: string): Entity | undefined;
80
+ /** The scene path of an entity, if it came from a scene. */
81
+ export declare function pathOfEntity(world: World, entity: Entity): string | undefined;
82
+ export declare function toJson(value: unknown): JsonValue;
83
+ export declare function equal(a: unknown, b: unknown): boolean;
84
+ export declare function serializeComponents(world: World, entity: Entity): Map<string, Record<string, JsonValue>>;
85
+ /**
86
+ * Serializes a loaded scene back to its file format. Fields unchanged since load are written exactly
87
+ * as authored (preset names, hex colors, "#asset" refs, rotationEuler, key order), so saving an
88
+ * untouched scene reproduces the file and edits make minimal diffs.
89
+ */
90
+ export declare function saveScene(world: World, id: string): SceneFile;
91
+ /** Scene JSON as written to disk: 2-space indent, trailing newline. */
92
+ export declare function stringifyScene(file: SceneFile): string;
93
+ export type { AssetRef };