aboutsummaryrefslogtreecommitdiff
path: root/lib/factories/global.js
blob: 4f36a8e3bc96619926ecab859360a7c7ddf547fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Entity } from '@serpentity/serpentity';
import Position from '@serpentity/components.position';
import EulerAngle from '@serpentity/components.euler_angle';
import Velocity from '@serpentity/components.velocity';
import Radius from '../components/radius';
import Up from '../components/up';
import Configuration from '../components/configuration';

/**
  * This file is a factory for global objects. It doesn't enforce it, but
  * there should be only one of these entities in the engine at a given
  * time.
  */

/**
  * Creates a data entity that holds the configuration.
  */
export function configuration() {

  const entity = new Entity();
  entity.addComponent(new Configuration());

  return entity;
}

/**
  * Creates a camera, used to modify the 3D view.
  */
export function camera() {

  const entity = new Entity();
  entity.addComponent(new Position());
  entity.addComponent(new EulerAngle());
  entity.addComponent(new Velocity({
    x: 0,
    y: Math.PI / 30,
    z: 0,
  }));
  entity.addComponent(new Radius({
    radius: 5
  }));
  entity.addComponent(new Up());

  return entity;
}