@inglorious/engine 7.0.0 → 8.0.0

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.
@@ -13,53 +13,52 @@ const Z = 2
13
13
  export function modernVelocity(params) {
14
14
  params = extend(DEFAULT_PARAMS, params)
15
15
 
16
- return (type) =>
17
- extend(type, {
18
- ...createMovementEventHandlers([
19
- "moveLeft",
20
- "moveRight",
21
- "moveUp",
22
- "moveDown",
23
- "moveLeftRight",
24
- "moveUpDown",
25
- ]),
16
+ return (type) => ({
17
+ ...createMovementEventHandlers([
18
+ "moveLeft",
19
+ "moveRight",
20
+ "moveUp",
21
+ "moveDown",
22
+ "moveLeftRight",
23
+ "moveUpDown",
24
+ ]),
26
25
 
27
- create(entity, entityId, api) {
28
- type.create?.(entity, entityId, api)
26
+ create(entity, entityId, api) {
27
+ type.create?.(entity, entityId, api)
29
28
 
30
- if (entityId !== entity.id) return
29
+ if (entityId !== entity.id) return
31
30
 
32
- entity.maxSpeed ??= params.maxSpeed
33
- entity.movement ??= {}
34
- },
31
+ entity.maxSpeed ??= params.maxSpeed
32
+ entity.movement ??= {}
33
+ },
35
34
 
36
- update(entity, dt, api) {
37
- type.update?.(entity, dt, api)
35
+ update(entity, dt, api) {
36
+ type.update?.(entity, dt, api)
38
37
 
39
- const { movement, maxSpeed } = entity
40
- entity.velocity = zero()
38
+ const { movement, maxSpeed } = entity
39
+ entity.velocity = zero()
41
40
 
42
- if (movement.moveLeft) {
43
- entity.velocity[X] = -maxSpeed
44
- }
45
- if (movement.moveRight) {
46
- entity.velocity[X] = maxSpeed
47
- }
48
- if (movement.moveUp) {
49
- entity.velocity[Z] = maxSpeed
50
- }
51
- if (movement.moveDown) {
52
- entity.velocity[Z] = -maxSpeed
53
- }
41
+ if (movement.moveLeft) {
42
+ entity.velocity[X] = -maxSpeed
43
+ }
44
+ if (movement.moveRight) {
45
+ entity.velocity[X] = maxSpeed
46
+ }
47
+ if (movement.moveUp) {
48
+ entity.velocity[Z] = maxSpeed
49
+ }
50
+ if (movement.moveDown) {
51
+ entity.velocity[Z] = -maxSpeed
52
+ }
54
53
 
55
- if (movement.moveLeftRight) {
56
- entity.velocity[X] += movement.moveLeftRight * maxSpeed
57
- }
58
- if (movement.moveUpDown) {
59
- entity.velocity[Z] += -movement.moveUpDown * maxSpeed
60
- }
61
- },
62
- })
54
+ if (movement.moveLeftRight) {
55
+ entity.velocity[X] += movement.moveLeftRight * maxSpeed
56
+ }
57
+ if (movement.moveUpDown) {
58
+ entity.velocity[Z] += -movement.moveUpDown * maxSpeed
59
+ }
60
+ },
61
+ })
63
62
  }
64
63
 
65
64
  export function modernControls(params) {
@@ -20,65 +20,64 @@ export function shooterControls(params) {
20
20
  const DEADZONE = 0.1
21
21
  const NO_MOVEMENT = 0
22
22
 
23
- return (type) =>
24
- extend(type, {
25
- ...createMovementEventHandlers([
26
- "moveLeft",
27
- "moveRight",
28
- "moveUp",
29
- "moveDown",
30
- "move",
31
- "strafe",
32
- "turn",
33
- ]),
23
+ return (type) => ({
24
+ ...createMovementEventHandlers([
25
+ "moveLeft",
26
+ "moveRight",
27
+ "moveUp",
28
+ "moveDown",
29
+ "move",
30
+ "strafe",
31
+ "turn",
32
+ ]),
34
33
 
35
- create(entity, entityId, api) {
36
- type.create?.(entity, entityId, api)
34
+ create(entity, entityId, api) {
35
+ type.create?.(entity, entityId, api)
37
36
 
38
- if (entityId !== entity.id) return
37
+ if (entityId !== entity.id) return
39
38
 
40
- entity.maxSpeed ??= params.maxSpeed
41
- entity.maxAngularSpeed ??= params.maxAngularSpeed
42
- entity.movement ??= {}
43
- },
39
+ entity.maxSpeed ??= params.maxSpeed
40
+ entity.maxAngularSpeed ??= params.maxAngularSpeed
41
+ entity.movement ??= {}
42
+ },
44
43
 
45
- update(entity, dt, api) {
46
- const mouse = api.getEntity("mouse")
44
+ update(entity, dt, api) {
45
+ const mouse = api.getEntity("mouse")
47
46
 
48
- const { movement, maxSpeed, maxAngularSpeed } = entity
49
- entity.velocity = zero()
47
+ const { movement, maxSpeed, maxAngularSpeed } = entity
48
+ entity.velocity = zero()
50
49
 
51
- if (movement.moveLeft) {
52
- entity.velocity[Z] = -maxSpeed
53
- }
54
- if (movement.moveRight) {
55
- entity.velocity[Z] = maxSpeed
56
- }
57
- if (movement.moveUp) {
58
- entity.velocity[X] = maxSpeed
59
- }
60
- if (movement.moveDown) {
61
- entity.velocity[X] = -maxSpeed
62
- }
50
+ if (movement.moveLeft) {
51
+ entity.velocity[Z] = -maxSpeed
52
+ }
53
+ if (movement.moveRight) {
54
+ entity.velocity[Z] = maxSpeed
55
+ }
56
+ if (movement.moveUp) {
57
+ entity.velocity[X] = maxSpeed
58
+ }
59
+ if (movement.moveDown) {
60
+ entity.velocity[X] = -maxSpeed
61
+ }
63
62
 
64
- if (movement.strafe) {
65
- entity.velocity[Z] += movement.strafe * maxSpeed
66
- }
67
- if (movement.move) {
68
- entity.velocity[X] += -movement.move * maxSpeed
69
- }
70
- if (movement.turn) {
71
- entity.orientation += -movement.turn * maxAngularSpeed * dt
72
- }
63
+ if (movement.strafe) {
64
+ entity.velocity[Z] += movement.strafe * maxSpeed
65
+ }
66
+ if (movement.move) {
67
+ entity.velocity[X] += -movement.move * maxSpeed
68
+ }
69
+ if (movement.turn) {
70
+ entity.orientation += -movement.turn * maxAngularSpeed * dt
71
+ }
73
72
 
74
- const isUsingAnalogMovement =
75
- Math.abs(movement.move ?? NO_MOVEMENT) > DEADZONE ||
76
- Math.abs(movement.strafe ?? NO_MOVEMENT) > DEADZONE
73
+ const isUsingAnalogMovement =
74
+ Math.abs(movement.move ?? NO_MOVEMENT) > DEADZONE ||
75
+ Math.abs(movement.strafe ?? NO_MOVEMENT) > DEADZONE
77
76
 
78
- if (!isUsingAnalogMovement) {
79
- merge(entity, face(entity, mouse, dt))
80
- }
81
- merge(entity, tankMove(entity, dt))
82
- },
83
- })
77
+ if (!isUsingAnalogMovement) {
78
+ merge(entity, face(entity, mouse, dt))
79
+ }
80
+ merge(entity, tankMove(entity, dt))
81
+ },
82
+ })
84
83
  }
@@ -14,56 +14,55 @@ const Z = 2
14
14
  export function tankControls(params) {
15
15
  params = extend(DEFAULT_PARAMS, params)
16
16
 
17
- return (type) =>
18
- extend(type, {
19
- ...createMovementEventHandlers([
20
- "turnLeft",
21
- "turnRight",
22
- "moveForward",
23
- "moveBackward",
24
- "strafe",
25
- "move",
26
- "turn",
27
- ]),
17
+ return (type) => ({
18
+ ...createMovementEventHandlers([
19
+ "turnLeft",
20
+ "turnRight",
21
+ "moveForward",
22
+ "moveBackward",
23
+ "strafe",
24
+ "move",
25
+ "turn",
26
+ ]),
28
27
 
29
- create(entity, entityId, api) {
30
- type.create?.(entity, entityId, api)
28
+ create(entity, entityId, api) {
29
+ type.create?.(entity, entityId, api)
31
30
 
32
- if (entityId !== entity.id) return
31
+ if (entityId !== entity.id) return
33
32
 
34
- entity.maxSpeed ??= params.maxSpeed
35
- entity.maxAngularSpeed ??= params.maxAngularSpeed
36
- entity.movement ??= {}
37
- },
33
+ entity.maxSpeed ??= params.maxSpeed
34
+ entity.maxAngularSpeed ??= params.maxAngularSpeed
35
+ entity.movement ??= {}
36
+ },
38
37
 
39
- update(entity, dt) {
40
- const { movement, maxSpeed, maxAngularSpeed } = entity
41
- entity.velocity = zero()
38
+ update(entity, dt) {
39
+ const { movement, maxSpeed, maxAngularSpeed } = entity
40
+ entity.velocity = zero()
42
41
 
43
- if (movement.turnLeft) {
44
- entity.orientation += maxAngularSpeed * dt
45
- }
46
- if (movement.turnRight) {
47
- entity.orientation -= maxAngularSpeed * dt
48
- }
49
- if (movement.moveForward) {
50
- entity.velocity[X] = maxSpeed
51
- }
52
- if (movement.moveBackward) {
53
- entity.velocity[X] = -maxSpeed
54
- }
42
+ if (movement.turnLeft) {
43
+ entity.orientation += maxAngularSpeed * dt
44
+ }
45
+ if (movement.turnRight) {
46
+ entity.orientation -= maxAngularSpeed * dt
47
+ }
48
+ if (movement.moveForward) {
49
+ entity.velocity[X] = maxSpeed
50
+ }
51
+ if (movement.moveBackward) {
52
+ entity.velocity[X] = -maxSpeed
53
+ }
55
54
 
56
- if (movement.strafe) {
57
- entity.velocity[Z] += movement.strafe * maxSpeed
58
- }
59
- if (movement.move) {
60
- entity.velocity[X] += -movement.move * maxSpeed
61
- }
62
- if (movement.turn) {
63
- entity.orientation += -movement.turn * maxAngularSpeed * dt
64
- }
55
+ if (movement.strafe) {
56
+ entity.velocity[Z] += movement.strafe * maxSpeed
57
+ }
58
+ if (movement.move) {
59
+ entity.velocity[X] += -movement.move * maxSpeed
60
+ }
61
+ if (movement.turn) {
62
+ entity.orientation += -movement.turn * maxAngularSpeed * dt
63
+ }
65
64
 
66
- merge(entity, tankMove(entity, dt))
67
- },
68
- })
65
+ merge(entity, tankMove(entity, dt))
66
+ },
67
+ })
69
68
  }
@@ -1,29 +1,26 @@
1
- import { extend } from "@inglorious/utils/data-structures/objects.js"
2
-
3
1
  export function collisionGizmos(params) {
4
- return (type) =>
5
- extend(type, {
6
- render(entity, ctx, api) {
7
- type.render(entity, ctx, api)
2
+ return (type) => ({
3
+ render(entity, ctx, api) {
4
+ type.render(entity, ctx, api)
8
5
 
9
- const game = api.getEntity("game")
6
+ const game = api.getEntity("game")
10
7
 
11
- if (!game.debug) {
12
- return
13
- }
8
+ if (!game.debug) {
9
+ return
10
+ }
14
11
 
15
- if (!params?.shapes) {
16
- return
17
- }
12
+ if (!params?.shapes) {
13
+ return
14
+ }
18
15
 
19
- ctx.save()
16
+ ctx.save()
20
17
 
21
- Object.values(entity.collisions).forEach((collision) => {
22
- const render = params.shapes[collision.shape]
23
- render?.({ ...entity, ...collision, color: "#00FF00" }, ctx, api)
24
- })
18
+ Object.values(entity.collisions).forEach((collision) => {
19
+ const render = params.shapes[collision.shape]
20
+ render?.({ ...entity, ...collision, color: "#00FF00" }, ctx, api)
21
+ })
25
22
 
26
- ctx.restore()
27
- },
28
- })
23
+ ctx.restore()
24
+ },
25
+ })
29
26
  }
@@ -1,5 +1,3 @@
1
- import { extend } from "@inglorious/utils/data-structures/objects.js"
2
-
3
1
  const DEFAULT_STATE = "default"
4
2
 
5
3
  export function fsm(states) {
@@ -8,7 +6,7 @@ export function fsm(states) {
8
6
  ]
9
7
 
10
8
  return (type) => {
11
- return extend(type, {
9
+ return {
12
10
  create(entity, entityId, api) {
13
11
  type.create?.(entity, entityId, api)
14
12
 
@@ -30,6 +28,6 @@ export function fsm(states) {
30
28
  }),
31
29
  {},
32
30
  ),
33
- })
31
+ }
34
32
  }
35
33
  }
@@ -8,21 +8,20 @@ const DEFAULT_PARAMS = {
8
8
  export function bouncy(params) {
9
9
  params = extend(DEFAULT_PARAMS, params)
10
10
 
11
- return (type) =>
12
- extend(type, {
13
- create(entity, entityId, api) {
14
- type.create?.(entity, entityId, api)
11
+ return (type) => ({
12
+ create(entity, entityId, api) {
13
+ type.create?.(entity, entityId, api)
15
14
 
16
- if (entityId !== entity.id) return
15
+ if (entityId !== entity.id) return
17
16
 
18
- defaults(entity, params)
19
- },
17
+ defaults(entity, params)
18
+ },
20
19
 
21
- land(entity, entityId) {
22
- if (entity.id === entityId) {
23
- entity.vy = jump(entity) * entity.bounciness
24
- entity.groundObject = undefined
25
- }
26
- },
27
- })
20
+ land(entity, entityId) {
21
+ if (entity.id === entityId) {
22
+ entity.vy = jump(entity) * entity.bounciness
23
+ entity.groundObject = undefined
24
+ }
25
+ },
26
+ })
28
27
  }
@@ -9,30 +9,29 @@ const DEFAULT_PARAMS = {
9
9
  export function clamped(params) {
10
10
  params = extend(DEFAULT_PARAMS, params)
11
11
 
12
- return (type) =>
13
- extend(type, {
14
- create(entity, entityId, api) {
15
- type.create?.(entity, entityId, api)
12
+ return (type) => ({
13
+ create(entity, entityId, api) {
14
+ type.create?.(entity, entityId, api)
16
15
 
17
- if (entityId !== entity.id) return
16
+ if (entityId !== entity.id) return
18
17
 
19
- entity.collisions ??= {}
20
- entity.collisions[params.collisionGroup] ??= {}
21
- entity.collisions[params.collisionGroup].shape ??= "rectangle"
22
- },
18
+ entity.collisions ??= {}
19
+ entity.collisions[params.collisionGroup] ??= {}
20
+ entity.collisions[params.collisionGroup].shape ??= "rectangle"
21
+ },
23
22
 
24
- update(entity, dt, api) {
25
- type.update?.(entity, dt, api)
23
+ update(entity, dt, api) {
24
+ type.update?.(entity, dt, api)
26
25
 
27
- const game = api.getEntity("game")
28
- merge(entity, {
29
- position: clampToBounds(
30
- entity,
31
- game.size,
32
- params.collisionGroup,
33
- params.depthAxis,
34
- ),
35
- })
36
- },
37
- })
26
+ const game = api.getEntity("game")
27
+ merge(entity, {
28
+ position: clampToBounds(
29
+ entity,
30
+ game.size,
31
+ params.collisionGroup,
32
+ params.depthAxis,
33
+ ),
34
+ })
35
+ },
36
+ })
38
37
  }