|
|
@@ -1,6 +1,8 @@
|
|
1
|
|
-const { makeContainerT } = require('./system.js')
|
|
2
|
|
-const { Container } = require('./container.js')
|
|
3
|
|
-const { fill, drain } = require('./utils.js')
|
|
|
1
|
+import { EventEmitter } from 'node:events'
|
|
|
2
|
+
|
|
|
3
|
+import loop from './loop.js'
|
|
|
4
|
+import { System, makeContainerT } from './system.js'
|
|
|
5
|
+import { Container } from './container.js'
|
|
4
|
6
|
|
|
5
|
7
|
const fromConfig = {
|
|
6
|
8
|
tank_1: {
|
|
|
@@ -36,23 +38,26 @@ const digestConfig = config => {
|
|
36
|
38
|
/** Holds systems or containers */
|
|
37
|
39
|
class Controller {}
|
|
38
|
40
|
|
|
39
|
|
-mySystem = digestConfig(fromConfig)
|
|
40
|
|
-
|
|
41
|
|
-console.log('mySystem :>> ', mySystem.inventory)
|
|
42
|
|
-console.log('\ntank capacity:>> ', mySystem.containers[0].liquidVolumeCapacity)
|
|
43
|
|
-console.log('tank level:>> ', mySystem.containers[0].liquidVolumeFilled)
|
|
44
|
|
-console.log('pass:>> ', mySystem.containers[0].liquidVolumeFilled === 0)
|
|
|
41
|
+const mySystem = digestConfig(fromConfig)
|
|
45
|
42
|
|
|
46
|
|
-const postFill = fill({ container: mySystem.containers[0], amount: 10 })
|
|
47
|
|
-mySystem.replaceContainer(postFill)
|
|
48
|
|
-console.log('\nfilled tank :>> ', mySystem.containers[0].liquidVolumeFilled)
|
|
49
|
|
-console.log('pass:>> ', mySystem.containers[0].liquidVolumeFilled === 10)
|
|
|
43
|
+// Start the loop!
|
|
|
44
|
+const emitter = new EventEmitter()
|
|
|
45
|
+emitter.on('onUpdate', ({ delta }) => {
|
|
|
46
|
+ const start = Date.now()
|
|
|
47
|
+ const milli = 111
|
|
|
48
|
+ while (Date.now() < start + milli) {
|
|
|
49
|
+ console.log(new Date(start).toISOString())
|
|
|
50
|
+ console.log(delta)
|
|
|
51
|
+ }
|
|
50
|
52
|
|
|
51
|
|
-const postDrain = drain({ container: mySystem.containers[0], amount: 3 })
|
|
52
|
|
-mySystem.replaceContainer(postDrain)
|
|
53
|
|
-console.log('\ndrained tank :>> ', mySystem.containers[0].liquidVolumeFilled)
|
|
54
|
|
-console.log('pass:>> ', mySystem.containers[0].liquidVolumeFilled === 7)
|
|
|
53
|
+ // Check all inputs
|
|
|
54
|
+ // Queue tasks based on inputs
|
|
|
55
|
+ // Queue one-off tasks based on date/time
|
|
|
56
|
+ // Execute the task queue
|
|
|
57
|
+})
|
|
|
58
|
+loop.start(emitter)
|
|
55
|
59
|
|
|
56
|
|
-console.log('\ninputs + outputs')
|
|
57
|
|
-console.log('inputs :>> ', mySystem.inputsFor(mySystem.containers[0]))
|
|
58
|
|
-console.log('outputs :>> ', mySystem.outputsFor(mySystem.containers[0]))
|
|
|
60
|
+setTimeout(function () {
|
|
|
61
|
+ console.log('6000ms passed, stopping the game loop')
|
|
|
62
|
+ loop.active.splice(loop.active.indexOf(0), 1)
|
|
|
63
|
+}, 6000)
|