@inglorious/engine 5.0.0 → 7.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/README.md
CHANGED
|
@@ -102,9 +102,11 @@ Here is a complete example showing how to set up and run a game using the engine
|
|
|
102
102
|
|
|
103
103
|
## License
|
|
104
104
|
|
|
105
|
-
MIT
|
|
105
|
+
**MIT License - Free and open source**
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
Created by [Matteo Antony Mistretta](https://github.com/IngloriousCoderz)
|
|
108
|
+
|
|
109
|
+
You're free to use, modify, and distribute this software. See [LICENSE](./LICENSE) for details.
|
|
108
110
|
|
|
109
111
|
---
|
|
110
112
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.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",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@inglorious/store": "5.
|
|
34
|
-
"@inglorious/utils": "3.6.
|
|
33
|
+
"@inglorious/store": "5.4.1",
|
|
34
|
+
"@inglorious/utils": "3.6.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@inglorious/store": "5.
|
|
38
|
-
"@inglorious/utils": "3.6.
|
|
37
|
+
"@inglorious/store": "5.4.1",
|
|
38
|
+
"@inglorious/utils": "3.6.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"prettier": "^3.5.3",
|
package/src/core/engine.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { audio } from "@inglorious/engine/behaviors/audio.js"
|
|
2
2
|
import { game } from "@inglorious/engine/behaviors/game.js"
|
|
3
3
|
import { images } from "@inglorious/engine/behaviors/images.js"
|
|
4
|
+
import { createApi } from "@inglorious/store/api.js"
|
|
4
5
|
import {
|
|
5
6
|
connectDevTools,
|
|
6
7
|
disconnectDevTools,
|
|
@@ -68,8 +69,7 @@ export class Engine {
|
|
|
68
69
|
)
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
this._store = createStore({ ...this._config, middlewares })
|
|
72
|
-
this._api = this._store.getApi()
|
|
72
|
+
this._store = createStore({ ...this._config, middlewares, mode: "batched" })
|
|
73
73
|
this._loop = new Loop[this._config.loop.type]()
|
|
74
74
|
|
|
75
75
|
if (this._devMode) {
|
|
@@ -78,11 +78,12 @@ export class Engine {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
async init() {
|
|
81
|
+
const api = createApi(this._store)
|
|
81
82
|
return Promise.all(
|
|
82
83
|
Object.values(this._config.entities).map((entity) => {
|
|
83
84
|
const originalType = this._config.types[entity.type]
|
|
84
85
|
const type = augmentType(originalType)
|
|
85
|
-
return type.init?.(entity, null,
|
|
86
|
+
return type.init?.(entity, null, api)
|
|
86
87
|
}),
|
|
87
88
|
)
|
|
88
89
|
}
|
|
@@ -91,7 +92,7 @@ export class Engine {
|
|
|
91
92
|
* Starts the game engine, initializing the loop and notifying the store.
|
|
92
93
|
*/
|
|
93
94
|
start() {
|
|
94
|
-
this.
|
|
95
|
+
this._store.notify("start")
|
|
95
96
|
this._loop.start(this, ONE_SECOND / this._config.loop.fps)
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -99,7 +100,7 @@ export class Engine {
|
|
|
99
100
|
* Stops the game engine, halting the loop and notifying the store.
|
|
100
101
|
*/
|
|
101
102
|
stop() {
|
|
102
|
-
this.
|
|
103
|
+
this._store.notify("stop")
|
|
103
104
|
this._store.update()
|
|
104
105
|
this._loop.stop()
|
|
105
106
|
}
|
|
@@ -109,7 +110,7 @@ export class Engine {
|
|
|
109
110
|
* @param {number} dt - Delta time since the last update in milliseconds.
|
|
110
111
|
*/
|
|
111
112
|
update(dt) {
|
|
112
|
-
this.
|
|
113
|
+
this._store.notify("update", dt)
|
|
113
114
|
const processedEvents = this._store.update()
|
|
114
115
|
const entities = this._store.getState()
|
|
115
116
|
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
import { createApi } from "@inglorious/store/api.js"
|
|
1
2
|
import { EventMap } from "@inglorious/store/event-map.js"
|
|
2
3
|
|
|
3
4
|
import { EntityPools } from "./entity-pools"
|
|
4
5
|
|
|
5
6
|
export function entityPoolMiddleware() {
|
|
6
|
-
return (store
|
|
7
|
+
return (store) => {
|
|
7
8
|
const pools = new EntityPools()
|
|
8
|
-
const types =
|
|
9
|
+
const types = store.getTypes()
|
|
9
10
|
const eventMap = new EventMap()
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
store.extras ??= {}
|
|
13
|
+
store.extras.getAllActivePoolEntities = () => pools.getAllActiveEntities()
|
|
12
14
|
|
|
13
|
-
const game =
|
|
15
|
+
const game = store.getState().game
|
|
14
16
|
if (game.devMode) {
|
|
15
|
-
|
|
17
|
+
store.extras.getEntityPoolsStats = () => pools.getStats()
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
const api = createApi(store)
|
|
21
|
+
|
|
18
22
|
return (next) => (event) => {
|
|
19
23
|
switch (event.type) {
|
|
20
24
|
case "spawn": {
|