@inglorious/engine 14.0.0 → 14.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/engine",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.1",
|
|
4
4
|
"description": "A JavaScript game engine written with global state, immutability, and pure functions in mind. Have fun(ctional programming) with it!",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,18 +25,19 @@
|
|
|
25
25
|
"./*": "./src/*"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"src"
|
|
28
|
+
"src",
|
|
29
|
+
"!src/**/*.test.js"
|
|
29
30
|
],
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@inglorious/
|
|
35
|
-
"@inglorious/
|
|
35
|
+
"@inglorious/store": "8.0.1",
|
|
36
|
+
"@inglorious/utils": "3.7.1"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
|
-
"@inglorious/store": "8.0.
|
|
39
|
-
"@inglorious/utils": "3.7.
|
|
39
|
+
"@inglorious/store": "8.0.1",
|
|
40
|
+
"@inglorious/utils": "3.7.1"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"prettier": "^3.5.3",
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { v } from "@inglorious/utils/v.js"
|
|
2
|
-
import { expect, test } from "vitest"
|
|
3
|
-
|
|
4
|
-
import { seek } from "./seek.js"
|
|
5
|
-
|
|
6
|
-
test("it should move toward the target", () => {
|
|
7
|
-
const entity = { maxSpeed: 1, position: v(0, 0, 0) }
|
|
8
|
-
const target = { position: v(2, 0, 0) }
|
|
9
|
-
const dt = 1
|
|
10
|
-
const expectedResult = {
|
|
11
|
-
position: v(1, 0, 0),
|
|
12
|
-
velocity: v(1, 0, 0),
|
|
13
|
-
orientation: 0,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
expect(seek(entity, target, dt)).toStrictEqual(expectedResult)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test("it should eventually reach the target", () => {
|
|
20
|
-
const entity = { maxSpeed: 1, position: v(0, 0, 0) }
|
|
21
|
-
const target = { position: v(2, 0, 0) }
|
|
22
|
-
const dt = 2
|
|
23
|
-
const expectedResult = {
|
|
24
|
-
position: v(2, 0, 0),
|
|
25
|
-
velocity: v(1, 0, 0),
|
|
26
|
-
orientation: 0,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
expect(seek(entity, target, dt)).toStrictEqual(expectedResult)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test("it should overshoot when speed is too high", () => {
|
|
33
|
-
const entity = { maxSpeed: 10, position: v(0, 0, 0) }
|
|
34
|
-
const target = { position: v(2, 0, 0) }
|
|
35
|
-
const dt = 1
|
|
36
|
-
const expectedResult = {
|
|
37
|
-
position: v(10, 0, 0),
|
|
38
|
-
velocity: v(10, 0, 0),
|
|
39
|
-
orientation: 0,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
expect(seek(entity, target, dt)).toStrictEqual(expectedResult)
|
|
43
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { createStore } from "@inglorious/store/store.js"
|
|
2
|
-
import { expect, test } from "vitest"
|
|
3
|
-
|
|
4
|
-
import { fsm } from "./fsm.js"
|
|
5
|
-
|
|
6
|
-
test("it should add a finite state machine", () => {
|
|
7
|
-
const config = {
|
|
8
|
-
types: {
|
|
9
|
-
kitty: [
|
|
10
|
-
fsm({
|
|
11
|
-
default: {
|
|
12
|
-
meow(entity) {
|
|
13
|
-
entity.state = "meowing"
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
meowing: {
|
|
17
|
-
update(entity) {
|
|
18
|
-
entity.treats++
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
}),
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
entities: {
|
|
25
|
-
entity1: {
|
|
26
|
-
type: "kitty",
|
|
27
|
-
treats: 0,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
const afterState = {
|
|
32
|
-
entity1: {
|
|
33
|
-
id: "entity1",
|
|
34
|
-
type: "kitty",
|
|
35
|
-
state: "meowing",
|
|
36
|
-
treats: 1,
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const store = createStore(config)
|
|
41
|
-
store.notify("meow")
|
|
42
|
-
store.notify("update")
|
|
43
|
-
store.update()
|
|
44
|
-
|
|
45
|
-
const state = store.getState()
|
|
46
|
-
expect(state).toStrictEqual(afterState)
|
|
47
|
-
})
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { v } from "@inglorious/utils/v.js"
|
|
2
|
-
import { expect, test } from "vitest"
|
|
3
|
-
|
|
4
|
-
import { modernMove } from "./modern.js"
|
|
5
|
-
|
|
6
|
-
test("it should move following its velocity", () => {
|
|
7
|
-
const entity = { maxSpeed: 1, velocity: v(1, 0, 0), position: v(0, 0, 0) }
|
|
8
|
-
const dt = 1
|
|
9
|
-
const expectedResult = {
|
|
10
|
-
velocity: v(1, 0, 0),
|
|
11
|
-
position: v(1, 0, 0),
|
|
12
|
-
orientation: 0,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
expect(modernMove(entity, dt)).toStrictEqual(expectedResult)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test("it should limit the velocity to the max speed", () => {
|
|
19
|
-
const entity = { maxSpeed: 1, velocity: v(10, 0, 0), position: v(0, 0, 0) }
|
|
20
|
-
const dt = 1
|
|
21
|
-
const expectedResult = {
|
|
22
|
-
velocity: v(1, 0, 0),
|
|
23
|
-
position: v(1, 0, 0),
|
|
24
|
-
orientation: 0,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
expect(modernMove(entity, dt)).toStrictEqual(expectedResult)
|
|
28
|
-
})
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { v } from "@inglorious/utils/v.js"
|
|
2
|
-
import { expect, test } from "vitest"
|
|
3
|
-
|
|
4
|
-
import { calculateLandingPosition } from "./position.js"
|
|
5
|
-
|
|
6
|
-
test("it should calculate the landing position for a point entity on a platform", () => {
|
|
7
|
-
const entity = {
|
|
8
|
-
collisions: {
|
|
9
|
-
platform: { shape: "point" },
|
|
10
|
-
},
|
|
11
|
-
}
|
|
12
|
-
const target = {
|
|
13
|
-
position: v(0, 0, 0),
|
|
14
|
-
collisions: {
|
|
15
|
-
platform: { size: v(20, 10, 0) },
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
const collisionGroup = "platform"
|
|
19
|
-
|
|
20
|
-
const py = calculateLandingPosition(entity, target, collisionGroup)
|
|
21
|
-
|
|
22
|
-
expect(py).toBe(5)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test("it should calculate the landing position for a circular entity on a platform", () => {
|
|
26
|
-
const entity = {
|
|
27
|
-
collisions: {
|
|
28
|
-
platform: { shape: "circle", radius: 5 },
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
const target = {
|
|
32
|
-
position: v(0, 0, 0),
|
|
33
|
-
collisions: {
|
|
34
|
-
platform: { size: v(20, 10, 0) },
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
const collisionGroup = "platform"
|
|
38
|
-
|
|
39
|
-
const py = calculateLandingPosition(entity, target, collisionGroup)
|
|
40
|
-
|
|
41
|
-
expect(py).toBe(10)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test("it should calculate the landing position for a rectangular entity on a platform", () => {
|
|
45
|
-
const entity = {
|
|
46
|
-
size: v(10, 10, 0),
|
|
47
|
-
collisions: {
|
|
48
|
-
platform: { shape: "rectangle" },
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
const target = {
|
|
52
|
-
position: v(0, 0, 0),
|
|
53
|
-
collisions: {
|
|
54
|
-
platform: { size: v(20, 10, 0) },
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
const collisionGroup = "platform"
|
|
58
|
-
|
|
59
|
-
const py = calculateLandingPosition(entity, target, collisionGroup)
|
|
60
|
-
|
|
61
|
-
expect(py).toBe(10)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test("it should fallback to a rectangular calculation for an unknown entity shape", () => {
|
|
65
|
-
const entity = {
|
|
66
|
-
collisions: {
|
|
67
|
-
platform: { shape: "triangle" },
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
const target = {
|
|
71
|
-
position: v(0, 0, 0),
|
|
72
|
-
collisions: {
|
|
73
|
-
platform: { size: v(20, 10, 0) },
|
|
74
|
-
},
|
|
75
|
-
}
|
|
76
|
-
const collisionGroup = "platform"
|
|
77
|
-
|
|
78
|
-
const py = calculateLandingPosition(entity, target, collisionGroup)
|
|
79
|
-
|
|
80
|
-
expect(py).toBe(5)
|
|
81
|
-
})
|