@gg-web-engine/core 0.0.57 → 0.0.59

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.
Files changed (97) hide show
  1. package/dist/2d/components/physics/i-physics-world-2d.component.d.ts +1 -1
  2. package/dist/2d/components/physics/i-rigid-body-2d.component.d.ts +1 -1
  3. package/dist/2d/components/physics/i-trigger-2d.component.d.ts +3 -3
  4. package/dist/2d/components/rendering/i-camera-2d.component.d.ts +5 -0
  5. package/dist/2d/components/rendering/i-display-object-2d.component.d.ts +1 -1
  6. package/dist/2d/components/rendering/i-renderer-2d.component.d.ts +1 -1
  7. package/dist/2d/components/rendering/i-visual-scene-2d.component.d.ts +2 -3
  8. package/dist/2d/entities/controllers/entity-2d-positioning.animator.d.ts +2 -2
  9. package/dist/2d/entities/entity-2d.d.ts +7 -7
  10. package/dist/2d/entities/i-renderable-2d.entity.d.ts +4 -4
  11. package/dist/2d/entities/renderer-2d.entity.d.ts +2 -1
  12. package/dist/2d/entities/trigger-2d.entity.d.ts +8 -4
  13. package/dist/2d/factories.d.ts +7 -7
  14. package/dist/2d/gg-2d-world.d.ts +38 -6
  15. package/dist/2d/gg-2d-world.js +27 -21
  16. package/dist/2d/index.d.ts +3 -0
  17. package/dist/2d/index.js +3 -0
  18. package/dist/2d/level-loader.d.ts +101 -0
  19. package/dist/2d/level-loader.js +88 -0
  20. package/dist/2d/loader.d.ts +11 -0
  21. package/dist/2d/loader.js +10 -0
  22. package/dist/3d/components/physics/i-physics-world-3d.component.d.ts +5 -5
  23. package/dist/3d/components/physics/i-raycast-vehicle.component.d.ts +1 -1
  24. package/dist/3d/components/physics/i-rigid-body-3d.component.d.ts +1 -1
  25. package/dist/3d/components/physics/i-trigger-3d.component.d.ts +3 -3
  26. package/dist/3d/components/rendering/{i-camera.component.d.ts → i-camera-3d.component.d.ts} +1 -1
  27. package/dist/3d/components/rendering/i-camera-3d.component.js +1 -0
  28. package/dist/3d/components/rendering/i-display-object-3d.component.d.ts +1 -1
  29. package/dist/3d/components/rendering/i-renderer-3d.component.d.ts +1 -2
  30. package/dist/3d/components/rendering/i-visual-scene-3d.component.d.ts +3 -4
  31. package/dist/3d/entities/camera-3d.entity.d.ts +24 -0
  32. package/dist/3d/entities/camera-3d.entity.js +35 -0
  33. package/dist/3d/entities/controllers/animators/camera-3d.animator.d.ts +3 -3
  34. package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.d.ts +2 -2
  35. package/dist/3d/entities/entity-3d.d.ts +6 -6
  36. package/dist/3d/entities/gg-car/gg-car.entity.d.ts +5 -5
  37. package/dist/3d/entities/i-renderable-3d.entity.d.ts +4 -4
  38. package/dist/3d/entities/map-graph-3d.entity.d.ts +6 -6
  39. package/dist/3d/entities/raycast-vehicle-3d.entity.d.ts +3 -3
  40. package/dist/3d/entities/renderer-3d.entity.d.ts +1 -6
  41. package/dist/3d/entities/renderer-3d.entity.js +0 -15
  42. package/dist/3d/entities/surface-following.entity.d.ts +3 -3
  43. package/dist/3d/entities/surface-following.entity.js +3 -0
  44. package/dist/3d/entities/trigger-3d.entity.d.ts +8 -4
  45. package/dist/3d/factories.d.ts +14 -14
  46. package/dist/3d/gg-3d-world.d.ts +37 -9
  47. package/dist/3d/gg-3d-world.js +23 -19
  48. package/dist/3d/index.d.ts +3 -1
  49. package/dist/3d/index.js +3 -1
  50. package/dist/3d/level-loader.d.ts +300 -0
  51. package/dist/3d/level-loader.js +267 -0
  52. package/dist/3d/loader.d.ts +55 -14
  53. package/dist/3d/loader.js +37 -8
  54. package/dist/3d/loaders.d.ts +4 -4
  55. package/dist/base/blueprint/blueprint-node.d.ts +75 -0
  56. package/dist/base/blueprint/blueprint-node.js +51 -0
  57. package/dist/base/blueprint/blueprint.d.ts +123 -0
  58. package/dist/base/blueprint/blueprint.js +86 -0
  59. package/dist/base/blueprint/nodes/remove-entity.node.d.ts +26 -0
  60. package/dist/base/blueprint/nodes/remove-entity.node.js +29 -0
  61. package/dist/base/components/i-world-component.d.ts +5 -5
  62. package/dist/base/components/physics/i-body.component.d.ts +5 -5
  63. package/dist/base/components/physics/i-physics-world.component.d.ts +13 -5
  64. package/dist/base/components/physics/i-rigid-body.component.d.ts +2 -2
  65. package/dist/base/components/physics/i-trigger.component.d.ts +4 -4
  66. package/dist/base/components/rendering/i-display-object.component.d.ts +6 -6
  67. package/dist/base/components/rendering/i-renderer.component.d.ts +5 -4
  68. package/dist/base/components/rendering/i-visual-scene.component.d.ts +4 -2
  69. package/dist/base/entities/controllers/animation-mixer.d.ts +3 -3
  70. package/dist/base/entities/group.entity.d.ts +17 -0
  71. package/dist/base/entities/group.entity.js +19 -0
  72. package/dist/base/entities/i-entity.d.ts +19 -8
  73. package/dist/base/entities/i-entity.js +28 -0
  74. package/dist/base/entities/i-renderable.entity.d.ts +2 -2
  75. package/dist/base/entities/i-renderer.entity.d.ts +11 -5
  76. package/dist/base/entities/i-renderer.entity.js +15 -0
  77. package/dist/base/gg-world.d.ts +42 -5
  78. package/dist/base/gg-world.js +45 -10
  79. package/dist/base/index.d.ts +6 -0
  80. package/dist/base/index.js +6 -0
  81. package/dist/base/inputs/mouse.input.js +1 -0
  82. package/dist/base/level-loader.d.ts +217 -0
  83. package/dist/base/level-loader.js +258 -0
  84. package/dist/base/math/numbers.d.ts +2 -1
  85. package/dist/base/math/numbers.js +7 -1
  86. package/dist/base/math/point2.d.ts +17 -1
  87. package/dist/base/math/point2.js +35 -0
  88. package/dist/base/math/point3.d.ts +2 -0
  89. package/dist/base/math/point3.js +15 -1
  90. package/dist/base/models/points.d.ts +20 -16
  91. package/dist/base/models/raycasting.d.ts +52 -0
  92. package/dist/base/models/raycasting.js +1 -0
  93. package/dist/version.d.ts +1 -1
  94. package/dist/version.js +1 -1
  95. package/package.json +1 -1
  96. package/tsconfig.json +3 -1
  97. /package/dist/{3d/components/rendering/i-camera.component.js → 2d/components/rendering/i-camera-2d.component.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { Point2 } from '../../models/points';
2
2
  import { Observable } from 'rxjs';
3
3
  import { IWorldComponent } from '../i-world-component';
4
- import { GgWorld, VisualTypeDocRepo } from '../../gg-world';
4
+ import { GgWorld, GgWorldTypeDocVPatch, VisualTypeDocRepo } from '../../gg-world';
5
5
  import { IEntity } from '../../entities/i-entity';
6
6
  import { IVisualSceneComponent } from './i-visual-scene.component';
7
7
  /**
@@ -20,10 +20,11 @@ export type RendererOptions = {
20
20
  forceResolution?: number;
21
21
  antialias: boolean;
22
22
  };
23
- export declare abstract class IRendererComponent<D, R, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> implements IWorldComponent<D, R, VTypeDoc> {
23
+ export declare abstract class IRendererComponent<D, R, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> implements IWorldComponent<D, R, GgWorldTypeDocVPatch<D, R, VTypeDoc>> {
24
24
  readonly scene: IVisualSceneComponent<D, R, VTypeDoc>;
25
25
  readonly canvas?: HTMLCanvasElement | undefined;
26
26
  entity: IEntity | null;
27
+ abstract camera: VTypeDoc['camera'];
27
28
  /** Specifies the options for the renderer. */
28
29
  readonly rendererOptions: RendererOptions & Partial<VTypeDoc['rendererExtraOpts']>;
29
30
  /** get flag whether renderer shows physics debugger view */
@@ -35,8 +36,8 @@ export declare abstract class IRendererComponent<D, R, VTypeDoc extends VisualTy
35
36
  * Renders the scene.
36
37
  */
37
38
  abstract render(): void;
38
- abstract addToWorld(world: GgWorld<D, R, VTypeDoc>): void;
39
- abstract removeFromWorld(world: GgWorld<D, R, VTypeDoc>): void;
39
+ abstract addToWorld(world: GgWorld<D, R, GgWorldTypeDocVPatch<D, R, VTypeDoc>>): void;
40
+ abstract removeFromWorld(world: GgWorld<D, R, GgWorldTypeDocVPatch<D, R, VTypeDoc>>): void;
40
41
  /**
41
42
  * Resizes the renderer to the specified size.
42
43
  * @param {Point2} newSize - The new size of the renderer.
@@ -1,6 +1,8 @@
1
1
  import { IComponent } from '../i-component';
2
2
  import { VisualTypeDocRepo } from '../../gg-world';
3
- export interface IVisualSceneComponent<D, R, TypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> extends IComponent {
4
- readonly factory: TypeDoc['factory'];
3
+ import { RendererOptions } from './i-renderer.component';
4
+ export interface IVisualSceneComponent<D, R, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> extends IComponent {
5
+ readonly factory: VTypeDoc['factory'];
5
6
  init(): Promise<void>;
7
+ createRenderer(camera: VTypeDoc['camera'], canvas?: HTMLCanvasElement, rendererOptions?: Partial<RendererOptions & VTypeDoc['rendererExtraOpts']>): VTypeDoc['renderer'];
6
8
  }
@@ -1,6 +1,6 @@
1
1
  import { IEntity } from '../i-entity';
2
2
  import { Observable, Subject } from 'rxjs';
3
- import { GgWorld, PhysicsTypeDocRepo, VisualTypeDocRepo } from '../../gg-world';
3
+ import { GgWorld, GgWorldTypeDocRepo } from '../../gg-world';
4
4
  export type AnimationFunction<T> = (elapsed: number, delta: number) => T;
5
5
  /**
6
6
  * A class that performs property animations for a specific type `T` by using provided animation function.
@@ -8,7 +8,7 @@ export type AnimationFunction<T> = (elapsed: number, delta: number) => T;
8
8
  * The current value of the animation can be subscribed to using the `subscribeToValue` property.
9
9
  * The animation function can be changed with `transitAnimationFunction` or `transitFromStaticState`.
10
10
  */
11
- export declare class AnimationMixer<T, D = any, R = any, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>, PTypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> extends IEntity<D, R, VTypeDoc, PTypeDoc> {
11
+ export declare class AnimationMixer<T, D = any, R = any, TypeDoc extends GgWorldTypeDocRepo<D, R> = GgWorldTypeDocRepo<D, R>> extends IEntity<D, R, TypeDoc> {
12
12
  protected _animationFunction: AnimationFunction<T>;
13
13
  protected _lerp: (a: T, b: T, t: number) => T;
14
14
  readonly tickOrder: number;
@@ -71,6 +71,6 @@ export declare class AnimationMixer<T, D = any, R = any, VTypeDoc extends Visual
71
71
  * @param easing an easing function for transition
72
72
  */
73
73
  transitAnimationFunction(newFunc: AnimationFunction<T>, transitionDuration: number, easing?: (t: number) => number): void;
74
- onSpawned(world: GgWorld<D, R, VTypeDoc, PTypeDoc>): void;
74
+ onSpawned(world: GgWorld<D, R, TypeDoc>): void;
75
75
  dispose(): void;
76
76
  }
@@ -0,0 +1,17 @@
1
+ import { GgWorldTypeDocRepo } from '../gg-world';
2
+ import { IEntity, TickOrder } from './i-entity';
3
+ /**
4
+ * A trivial entity with no rendering/physics of its own: it exists purely as a parent/grouping
5
+ * node. `LevelLoader.loadLevel`/`loadLevelFromUrl` hand one back for every loaded level - every
6
+ * entity the level's JSON produced is added as one of its children (see `IEntity.addChildren`),
7
+ * so the whole level can be torn down in a single call:
8
+ * `world.removeEntity(level, true)` cascades removal + disposal to every child
9
+ * (see `IEntity.onRemoved`/`dispose`). Also used internally to group the several entities a single
10
+ * multi-piece GLB load can produce under one name (see the built-in `"Glb"` level entity class).
11
+ * @template D - The position type
12
+ * @template R - The rotation type
13
+ * @template TypeDoc - The type document repository
14
+ */
15
+ export declare class GroupEntity<D = any, R = any, TypeDoc extends GgWorldTypeDocRepo<D, R> = GgWorldTypeDocRepo<D, R>> extends IEntity<D, R, TypeDoc> {
16
+ readonly tickOrder = TickOrder.OBJECTS_BINDING;
17
+ }
@@ -0,0 +1,19 @@
1
+ import { IEntity, TickOrder } from './i-entity';
2
+ /**
3
+ * A trivial entity with no rendering/physics of its own: it exists purely as a parent/grouping
4
+ * node. `LevelLoader.loadLevel`/`loadLevelFromUrl` hand one back for every loaded level - every
5
+ * entity the level's JSON produced is added as one of its children (see `IEntity.addChildren`),
6
+ * so the whole level can be torn down in a single call:
7
+ * `world.removeEntity(level, true)` cascades removal + disposal to every child
8
+ * (see `IEntity.onRemoved`/`dispose`). Also used internally to group the several entities a single
9
+ * multi-piece GLB load can produce under one name (see the built-in `"Glb"` level entity class).
10
+ * @template D - The position type
11
+ * @template R - The rotation type
12
+ * @template TypeDoc - The type document repository
13
+ */
14
+ export class GroupEntity extends IEntity {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.tickOrder = TickOrder.OBJECTS_BINDING;
18
+ }
19
+ }
@@ -1,4 +1,4 @@
1
- import { GgWorld, PhysicsTypeDocRepo, VisualTypeDocRepo } from '../gg-world';
1
+ import { GgWorld, GgWorldTypeDocRepo } from '../gg-world';
2
2
  import { Observable, Subject } from 'rxjs';
3
3
  import { IWorldComponent } from '../components/i-world-component';
4
4
  /**
@@ -13,7 +13,7 @@ export declare enum TickOrder {
13
13
  RENDERING = 1000,
14
14
  POST_RENDERING = 1200
15
15
  }
16
- export declare abstract class IEntity<D = any, R = any, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>, PTypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> {
16
+ export declare abstract class IEntity<D = any, R = any, TypeDoc extends GgWorldTypeDocRepo<D, R> = GgWorldTypeDocRepo<D, R>> {
17
17
  private static default_name_counter;
18
18
  /**
19
19
  * will receive [elapsed time, delta] of each world clock tick
@@ -26,8 +26,8 @@ export declare abstract class IEntity<D = any, R = any, VTypeDoc extends VisualT
26
26
  /**
27
27
  * a world reference, where this entity was added to
28
28
  */
29
- protected _world: GgWorld<D, R, VTypeDoc, PTypeDoc> | null;
30
- get world(): GgWorld<D, R, VTypeDoc, PTypeDoc> | null;
29
+ protected _world: GgWorld<D, R, TypeDoc> | null;
30
+ get world(): GgWorld<D, R, TypeDoc> | null;
31
31
  protected _name: string;
32
32
  get name(): string;
33
33
  set name(value: string);
@@ -42,15 +42,26 @@ export declare abstract class IEntity<D = any, R = any, VTypeDoc extends VisualT
42
42
  get children(): IEntity[];
43
43
  addChildren(...entities: IEntity[]): void;
44
44
  removeChildren(entities: IEntity[], dispose?: boolean): void;
45
+ /**
46
+ * Find a descendant entity by name, searching this entity's own children and their children
47
+ * recursively (depth-first) - not the whole world, just this entity's subtree. Useful e.g. to
48
+ * pull a specific entity back out of a `GroupEntity` a `LevelLoader` handed back:
49
+ * `level.getChildEntityByName('KillFloor')`.
50
+ * @param name - The descendant entity's `name`
51
+ * @returns The matching descendant
52
+ * @throws if no descendant has that name
53
+ */
54
+ getChildEntityByName<T extends IEntity = IEntity>(name: string): T;
55
+ private findChildEntityByName;
45
56
  private _components;
46
- get components(): IWorldComponent<D, R, VTypeDoc, PTypeDoc>[];
47
- addComponents(...components: IWorldComponent<D, R, VTypeDoc, PTypeDoc>[]): void;
48
- removeComponents(components: IWorldComponent<D, R, VTypeDoc, PTypeDoc>[], dispose?: boolean): void;
57
+ get components(): IWorldComponent<D, R, TypeDoc>[];
58
+ addComponents(...components: IWorldComponent<D, R, TypeDoc>[]): void;
59
+ removeComponents(components: IWorldComponent<D, R, TypeDoc>[], dispose?: boolean): void;
49
60
  protected _onSpawned$: Subject<void>;
50
61
  protected _onRemoved$: Subject<void>;
51
62
  get onSpawned$(): Observable<void>;
52
63
  get onRemoved$(): Observable<void>;
53
- onSpawned(world: GgWorld<D, R, VTypeDoc, PTypeDoc>): void;
64
+ onSpawned(world: GgWorld<D, R, TypeDoc>): void;
54
65
  onRemoved(): void;
55
66
  dispose(): void;
56
67
  }
@@ -74,6 +74,34 @@ export class IEntity {
74
74
  }
75
75
  }
76
76
  }
77
+ /**
78
+ * Find a descendant entity by name, searching this entity's own children and their children
79
+ * recursively (depth-first) - not the whole world, just this entity's subtree. Useful e.g. to
80
+ * pull a specific entity back out of a `GroupEntity` a `LevelLoader` handed back:
81
+ * `level.getChildEntityByName('KillFloor')`.
82
+ * @param name - The descendant entity's `name`
83
+ * @returns The matching descendant
84
+ * @throws if no descendant has that name
85
+ */
86
+ getChildEntityByName(name) {
87
+ const found = this.findChildEntityByName(name);
88
+ if (!found) {
89
+ throw new Error(`No child entity named "${name}" found under "${this.name}"`);
90
+ }
91
+ return found;
92
+ }
93
+ findChildEntityByName(name) {
94
+ for (const child of this._children) {
95
+ if (child.name === name) {
96
+ return child;
97
+ }
98
+ const found = child.findChildEntityByName(name);
99
+ if (found) {
100
+ return found;
101
+ }
102
+ }
103
+ return undefined;
104
+ }
77
105
  get components() {
78
106
  return [...this._components];
79
107
  }
@@ -1,6 +1,6 @@
1
1
  import { IEntity } from './i-entity';
2
- import { PhysicsTypeDocRepo, VisualTypeDocRepo } from '../gg-world';
3
- export declare abstract class IRenderableEntity<D = any, R = any, TypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>, PTypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> extends IEntity<D, R, TypeDoc, PTypeDoc> {
2
+ import { GgWorldTypeDocRepo } from '../gg-world';
3
+ export declare abstract class IRenderableEntity<D = any, R = any, TypeDoc extends GgWorldTypeDocRepo<D, R> = GgWorldTypeDocRepo<D, R>> extends IEntity<D, R, TypeDoc> {
4
4
  private _visible;
5
5
  get visible(): boolean;
6
6
  get worldVisible(): boolean;
@@ -1,14 +1,15 @@
1
1
  import { IEntity, TickOrder } from './i-entity';
2
- import { GgWorld, VisualTypeDocRepo } from '../gg-world';
2
+ import { GgWorld, GgWorldTypeDocVPatch, VisualTypeDocRepo } from '../gg-world';
3
3
  import { BehaviorSubject, Observable } from 'rxjs';
4
4
  import { Point2 } from '../models/points';
5
5
  import { RendererOptions } from '../components/rendering/i-renderer.component';
6
+ import { IPositionable } from '../interfaces/i-positionable';
6
7
  /**
7
8
  * Represents a base class for a renderer entity.
8
9
  * @class
9
10
  */
10
- export declare abstract class IRendererEntity<D, R, TypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> extends IEntity<D, R, TypeDoc> {
11
- readonly renderer: TypeDoc['renderer'];
11
+ export declare abstract class IRendererEntity<D, R, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> extends IEntity<D, R, GgWorldTypeDocVPatch<D, R, VTypeDoc>> implements IPositionable<D, R> {
12
+ readonly renderer: VTypeDoc['renderer'];
12
13
  readonly tickOrder = TickOrder.RENDERING;
13
14
  /** Represents the current size of the renderer. */
14
15
  protected _rendererSize$: BehaviorSubject<Point2 | null>;
@@ -23,6 +24,11 @@ export declare abstract class IRendererEntity<D, R, TypeDoc extends VisualTypeDo
23
24
  */
24
25
  get rendererSize(): Point2 | null;
25
26
  get rendererOptions(): RendererOptions;
27
+ get camera(): VTypeDoc['camera'];
28
+ get position(): D;
29
+ set position(value: D);
30
+ get rotation(): R;
31
+ set rotation(value: R);
26
32
  /** get flag whether renderer shows physics debugger view */
27
33
  get physicsDebugViewActive(): boolean;
28
34
  /** turns on/off physics debugger view for this renderer */
@@ -31,7 +37,7 @@ export declare abstract class IRendererEntity<D, R, TypeDoc extends VisualTypeDo
31
37
  Initializes a new instance of the BaseGgRenderer class.
32
38
  * @param renderer
33
39
  */
34
- constructor(renderer: TypeDoc['renderer']);
35
- onSpawned(world: GgWorld<D, R, TypeDoc>): void;
40
+ constructor(renderer: VTypeDoc['renderer']);
41
+ onSpawned(world: GgWorld<D, R, GgWorldTypeDocVPatch<D, R, VTypeDoc>>): void;
36
42
  dispose(): void;
37
43
  }
@@ -23,6 +23,21 @@ export class IRendererEntity extends IEntity {
23
23
  get rendererOptions() {
24
24
  return this.renderer.rendererOptions;
25
25
  }
26
+ get camera() {
27
+ return this.renderer.camera;
28
+ }
29
+ get position() {
30
+ return this.camera.position;
31
+ }
32
+ set position(value) {
33
+ this.renderer.camera.position = value;
34
+ }
35
+ get rotation() {
36
+ return this.renderer.camera.rotation;
37
+ }
38
+ set rotation(value) {
39
+ this.renderer.camera.rotation = value;
40
+ }
26
41
  /** get flag whether renderer shows physics debugger view */
27
42
  get physicsDebugViewActive() {
28
43
  return this.renderer.physicsDebugViewActive;
@@ -1,23 +1,47 @@
1
1
  import { IDisplayObjectComponent, IEntity, IPhysicsWorldComponent, IPositionable, IRenderableEntity, IRendererComponent, IRendererEntity, IRigidBodyComponent, ITriggerComponent, IVisualSceneComponent, KeyboardInput, PausableClock } from '../base';
2
2
  import { Subject } from 'rxjs';
3
+ import { IVisualScene2dComponent, VisualTypeDocRepo2D } from '../2d';
3
4
  export type VisualTypeDocRepo<D, R> = {
4
5
  factory: unknown;
5
6
  displayObject: IDisplayObjectComponent<D, R>;
6
7
  renderer: IRendererComponent<D, R>;
7
8
  rendererExtraOpts: {};
9
+ camera: IPositionable<D, R>;
8
10
  };
9
11
  export type PhysicsTypeDocRepo<D, R> = {
10
12
  factory: unknown;
11
13
  rigidBody: IRigidBodyComponent<D, R>;
12
14
  trigger: ITriggerComponent<D, R>;
13
15
  };
14
- export declare abstract class GgWorld<D, R, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>, PTypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>, VS extends IVisualSceneComponent<D, R, VTypeDoc> = IVisualSceneComponent<D, R, VTypeDoc>, PW extends IPhysicsWorldComponent<D, R, PTypeDoc> = IPhysicsWorldComponent<D, R, PTypeDoc>> {
15
- readonly visualScene: VS;
16
- readonly physicsWorld: PW;
16
+ export type GgWorldTypeDocRepo<D, R> = {
17
+ vTypeDoc: VisualTypeDocRepo<D, R>;
18
+ pTypeDoc: PhysicsTypeDocRepo<D, R>;
19
+ };
20
+ export type GgWorldTypeDocVPatch<D, R, VTypeDoc extends VisualTypeDocRepo<D, R>> = Omit<GgWorldTypeDocRepo<D, R>, 'vTypeDoc'> & {
21
+ vTypeDoc: VTypeDoc;
22
+ };
23
+ export type GgWorldTypeDocPPatch<D, R, PTypeDoc extends PhysicsTypeDocRepo<D, R>> = Omit<GgWorldTypeDocRepo<D, R>, 'pTypeDoc'> & {
24
+ pTypeDoc: PTypeDoc;
25
+ };
26
+ export type GgWorldSceneTypeRepo<D, R, TypeDoc extends GgWorldTypeDocRepo<D, R> = GgWorldTypeDocRepo<D, R>> = {
27
+ visualScene: IVisualSceneComponent<D, R, TypeDoc['vTypeDoc']> | null;
28
+ physicsWorld: IPhysicsWorldComponent<D, R, TypeDoc['pTypeDoc']> | null;
29
+ };
30
+ export type GgWorldSceneTypeDocVPatch<D, R, VTypeDoc extends VisualTypeDocRepo2D, VS extends IVisualScene2dComponent<VTypeDoc> | null> = Omit<GgWorldSceneTypeRepo<D, R>, 'visualScene'> & {
31
+ visualScene: VS;
32
+ };
33
+ export type GgWorldSceneTypeDocPPatch<D, R, PTypeDoc extends PhysicsTypeDocRepo<D, R>, PW extends IPhysicsWorldComponent<D, R, PTypeDoc> | null> = Omit<GgWorldSceneTypeRepo<D, R>, 'physicsWorld'> & {
34
+ physicsWorld: PW;
35
+ };
36
+ export type TypeDocOf<W extends GgWorld<any, any>> = W extends GgWorld<infer D, infer R, infer TypeDoc> ? TypeDoc : never;
37
+ export type SceneTypeDocOf<W extends GgWorld<any, any>> = W extends GgWorld<infer D, infer R, infer TypeDoc, infer SceneTypeDoc> ? SceneTypeDoc : never;
38
+ export declare abstract class GgWorld<D, R, TypeDoc extends GgWorldTypeDocRepo<D, R> = GgWorldTypeDocRepo<D, R>, SceneTypeDoc extends GgWorldSceneTypeRepo<D, R, TypeDoc> = GgWorldSceneTypeRepo<D, R, TypeDoc>> {
17
39
  private static default_name_counter;
18
40
  private static _documentWorlds;
19
41
  static readonly worldCreated$: Subject<GgWorld<any, any>>;
20
42
  static get documentWorlds(): GgWorld<any, any>[];
43
+ readonly visualScene: SceneTypeDoc['visualScene'];
44
+ readonly physicsWorld: SceneTypeDoc['physicsWorld'];
21
45
  readonly worldClock: PausableClock;
22
46
  readonly keyboardInput: KeyboardInput;
23
47
  name: string;
@@ -29,7 +53,10 @@ export declare abstract class GgWorld<D, R, VTypeDoc extends VisualTypeDocRepo<D
29
53
  readonly tickForwardedTo$: Subject<IEntity | 'PHYSICS_WORLD'>;
30
54
  readonly paused$: Subject<boolean>;
31
55
  readonly disposed$: Subject<void>;
32
- protected constructor(visualScene: VS, physicsWorld: PW);
56
+ protected constructor(args: {
57
+ visualScene?: SceneTypeDoc['visualScene'];
58
+ physicsWorld?: SceneTypeDoc['physicsWorld'];
59
+ });
33
60
  init(): Promise<void>;
34
61
  start(): void;
35
62
  pauseWorld(): void;
@@ -40,9 +67,19 @@ export declare abstract class GgWorld<D, R, VTypeDoc extends VisualTypeDocRepo<D
40
67
  createClock(autoStart: boolean): PausableClock;
41
68
  dispose(): void;
42
69
  abstract addPrimitiveRigidBody(descr: unknown, // type defined in subclasses
43
- position?: D, rotation?: R, material?: unknown): IPositionable<D, R> & IRenderableEntity<D, R, VTypeDoc>;
70
+ position?: D, rotation?: R, material?: unknown): IPositionable<D, R> & IRenderableEntity<D, R, TypeDoc>;
44
71
  addEntity(entity: IEntity): void;
45
72
  removeEntity(entity: IEntity, dispose?: boolean): void;
73
+ /**
74
+ * Find an entity anywhere in the world by name. `children` is a flat list of every entity ever
75
+ * added via `addEntity` (nested entities included - `addChildren`/`onSpawned` cascade into it
76
+ * too), so this is a plain linear scan, not a tree walk; to search inside one particular
77
+ * entity's own subtree instead, use `IEntity.getChildEntityByName`.
78
+ * @param name - The entity's `name`
79
+ * @returns The first entity found with that name (insertion order), if more than one shares it
80
+ * @throws if no entity in the world has that name
81
+ */
82
+ getEntityByName<T extends IEntity = IEntity>(name: string): T;
46
83
  private onGgStaticInitialized;
47
84
  protected registerConsoleCommands(ggstatic: {
48
85
  registerConsoleCommand: (world: GgWorld<any, any> | null, command: string, handler: (...args: string[]) => Promise<string>, doc?: string) => void;
@@ -17,9 +17,7 @@ export class GgWorld {
17
17
  get renderers() {
18
18
  return this.tickListeners.filter(e => e instanceof IRendererEntity);
19
19
  }
20
- constructor(visualScene, physicsWorld) {
21
- this.visualScene = visualScene;
22
- this.physicsWorld = physicsWorld;
20
+ constructor(args) {
23
21
  this.worldClock = new PausableClock(false);
24
22
  this.keyboardInput = new KeyboardInput();
25
23
  this.name = 'w0x' + (GgWorld.default_name_counter++).toString(16);
@@ -32,6 +30,8 @@ export class GgWorld {
32
30
  this.tickForwardedTo$ = new Subject();
33
31
  this.paused$ = new Subject();
34
32
  this.disposed$ = new Subject();
33
+ this.visualScene = args.visualScene || null;
34
+ this.physicsWorld = args.physicsWorld || null;
35
35
  this.keyboardInput.start();
36
36
  if (window.ggstatic) {
37
37
  this.registerConsoleCommands(window.ggstatic);
@@ -46,7 +46,14 @@ export class GgWorld {
46
46
  }
47
47
  init() {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
- yield Promise.all([this.physicsWorld.init(), this.visualScene.init()]);
49
+ const initPromises = [];
50
+ if (this.visualScene) {
51
+ initPromises.push(this.visualScene.init());
52
+ }
53
+ if (this.physicsWorld) {
54
+ initPromises.push(this.physicsWorld.init());
55
+ }
56
+ yield Promise.all(initPromises);
50
57
  const forwardTick = (listener, elapsed, delta) => {
51
58
  if (listener.active) {
52
59
  this.tickForwardTo$.next(listener);
@@ -65,9 +72,11 @@ export class GgWorld {
65
72
  forwardTick(this.tickListeners[i], elapsed, delta);
66
73
  }
67
74
  // run physics simulation
68
- this.tickForwardTo$.next('PHYSICS_WORLD');
69
- this.physicsWorld.simulate(delta);
70
- this.tickForwardedTo$.next('PHYSICS_WORLD');
75
+ if (this.physicsWorld) {
76
+ this.tickForwardTo$.next('PHYSICS_WORLD');
77
+ this.physicsWorld.simulate(delta);
78
+ this.tickForwardedTo$.next('PHYSICS_WORLD');
79
+ }
71
80
  // emit tick to all remained entities
72
81
  for (i; i < this.tickListeners.length; i++) {
73
82
  forwardTick(this.tickListeners[i], elapsed, delta);
@@ -114,14 +123,24 @@ export class GgWorld {
114
123
  }
115
124
  this.children.splice(0, this.children.length);
116
125
  this.tickListeners.splice(0, this.tickListeners.length);
117
- this.physicsWorld.dispose();
118
- this.visualScene.dispose();
126
+ if (this.physicsWorld) {
127
+ this.physicsWorld.dispose();
128
+ }
129
+ if (this.visualScene) {
130
+ this.visualScene.dispose();
131
+ }
119
132
  GgWorld._documentWorlds.splice(GgWorld._documentWorlds.indexOf(this), 1);
120
133
  this.disposed$.next();
121
134
  this.disposed$.complete();
122
135
  }
123
136
  addEntity(entity) {
124
- if (!!entity.world) {
137
+ if (entity.world === this) {
138
+ // Already a member of this world - e.g. reparented (via addChildren) after having been
139
+ // added directly, as level-loaded entities are. Not an error: just a no-op, since
140
+ // addChildren already updated the parent/children bookkeeping before calling back in here.
141
+ return;
142
+ }
143
+ if (entity.world) {
125
144
  console.warn('Trying to spawn entity, which is already spawned');
126
145
  return;
127
146
  }
@@ -143,6 +162,22 @@ export class GgWorld {
143
162
  entity.dispose();
144
163
  }
145
164
  }
165
+ /**
166
+ * Find an entity anywhere in the world by name. `children` is a flat list of every entity ever
167
+ * added via `addEntity` (nested entities included - `addChildren`/`onSpawned` cascade into it
168
+ * too), so this is a plain linear scan, not a tree walk; to search inside one particular
169
+ * entity's own subtree instead, use `IEntity.getChildEntityByName`.
170
+ * @param name - The entity's `name`
171
+ * @returns The first entity found with that name (insertion order), if more than one shares it
172
+ * @throws if no entity in the world has that name
173
+ */
174
+ getEntityByName(name) {
175
+ const found = this.children.find(e => e.name === name);
176
+ if (!found) {
177
+ throw new Error(`No entity named "${name}" found in the world`);
178
+ }
179
+ return found;
180
+ }
146
181
  onGgStaticInitialized() {
147
182
  window.removeEventListener('ggstatic_added', this.onGgStaticInitialized);
148
183
  this.registerConsoleCommands(window.ggstatic);
@@ -1,3 +1,6 @@
1
+ export * from './blueprint/blueprint';
2
+ export * from './blueprint/blueprint-node';
3
+ export * from './blueprint/nodes/remove-entity.node';
1
4
  export * from './clock/global-clock';
2
5
  export * from './clock/i-clock';
3
6
  export * from './clock/pausable-clock';
@@ -14,6 +17,7 @@ export * from './data-structures/bitmask';
14
17
  export * from './data-structures/graph';
15
18
  export * from './entities/controllers/animation-mixer';
16
19
  export * from './entities/controllers/inline-controller';
20
+ export * from './entities/group.entity';
17
21
  export * from './entities/i-entity';
18
22
  export * from './entities/i-renderer.entity';
19
23
  export * from './entities/i-renderable.entity';
@@ -26,6 +30,7 @@ export * from './models/axis-directions';
26
30
  export * from './models/body-options';
27
31
  export * from './models/geometry-nodes';
28
32
  export * from './models/points';
33
+ export * from './models/raycasting';
29
34
  export * from './math/box';
30
35
  export * from './math/point2';
31
36
  export * from './math/point3';
@@ -35,3 +40,4 @@ export * from './math/matrix4';
35
40
  export * from './math/splines';
36
41
  export * from './pipes/gg-elastic.pipe';
37
42
  export * from './gg-world';
43
+ export * from './level-loader';
@@ -1,3 +1,6 @@
1
+ export * from './blueprint/blueprint';
2
+ export * from './blueprint/blueprint-node';
3
+ export * from './blueprint/nodes/remove-entity.node';
1
4
  export * from './clock/global-clock';
2
5
  export * from './clock/i-clock';
3
6
  export * from './clock/pausable-clock';
@@ -14,6 +17,7 @@ export * from './data-structures/bitmask';
14
17
  export * from './data-structures/graph';
15
18
  export * from './entities/controllers/animation-mixer';
16
19
  export * from './entities/controllers/inline-controller';
20
+ export * from './entities/group.entity';
17
21
  export * from './entities/i-entity';
18
22
  export * from './entities/i-renderer.entity';
19
23
  export * from './entities/i-renderable.entity';
@@ -26,6 +30,7 @@ export * from './models/axis-directions';
26
30
  export * from './models/body-options';
27
31
  export * from './models/geometry-nodes';
28
32
  export * from './models/points';
33
+ export * from './models/raycasting';
29
34
  export * from './math/box';
30
35
  export * from './math/point2';
31
36
  export * from './math/point3';
@@ -35,3 +40,4 @@ export * from './math/matrix4';
35
40
  export * from './math/splines';
36
41
  export * from './pipes/gg-elastic.pipe';
37
42
  export * from './gg-world';
43
+ export * from './level-loader';
@@ -10,6 +10,7 @@ const DEFAULT_MOUSE_INPUT_OPTIONS = {
10
10
  */
11
11
  export var MouseInputState;
12
12
  (function (MouseInputState) {
13
+ //MouseInputState {
13
14
  /**
14
15
  No mouse or touch input is detected. Mouse move can still be emitted
15
16
  */