@burninggarden/engine
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@burninggarden/engine", | ||
"description": "Core game runtime engine", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"private": false, | ||
@@ -11,2 +11,3 @@ "author": "Burning Garden", | ||
"@types/node": "10.9.4", | ||
"redux": "4.0.1", | ||
"tap": "^12.6.1", | ||
@@ -19,2 +20,3 @@ "typescript": "3.2.1" | ||
"eslint": "^5.15.3", | ||
"faker": "4.1.0", | ||
"tap": "12.5.1", | ||
@@ -21,0 +23,0 @@ "typescript": "3.0.3", |
@@ -1,2 +0,2 @@ | ||
import System from 'system'; | ||
import BaseSystem from 'systems/base'; | ||
@@ -8,3 +8,3 @@ class Clock { | ||
private timer : null | number | NodeJS.Timer; | ||
private systems : System[]; | ||
private systems : BaseSystem[]; | ||
private tick_rate : number = 10; | ||
@@ -34,3 +34,3 @@ | ||
public addSystem(system: System) : void { | ||
public addSystem(system: BaseSystem) : void { | ||
return void this.getSystems().push(system); | ||
@@ -48,14 +48,16 @@ } | ||
private tick() : void { | ||
const | ||
now = Date.now(), | ||
elapsed_milliseconds = now - this.getLastTickTime(); | ||
const milliseconds = this.getMillisecondsSinceLastTick(); | ||
this.getSystems().forEach((system) => { | ||
system.tick(elapsed_milliseconds); | ||
system.tick(milliseconds); | ||
}); | ||
this.setLastTickTime(now); | ||
this.setLastTickTime(Date.now()); | ||
this.queueNextTick(); | ||
} | ||
private getMillisecondsSinceLastTick() : number { | ||
return Date.now() - this.getLastTickTime(); | ||
} | ||
private getLastTickTime() : number { | ||
@@ -85,6 +87,3 @@ if (!this.last_tick_time) { | ||
/** | ||
* @returns {Game_System[]} | ||
*/ | ||
private getSystems() { | ||
private getSystems() : BaseSystem[] { | ||
if (!this.systems) { | ||
@@ -91,0 +90,0 @@ this.systems = [ ]; |
@@ -9,12 +9,34 @@ /** | ||
import Clock from 'clock'; | ||
import System from 'system'; | ||
import Clock from 'clock'; | ||
import Redux from 'redux'; | ||
import Reducers from 'reducers'; | ||
import BaseSystem from 'systems/base'; | ||
import BaseAction from 'actions/base'; | ||
import { | ||
AnyAction, | ||
applyMiddleware, | ||
combineReducers, | ||
createStore, | ||
Dispatch, | ||
Middleware, | ||
MiddlewareAPI, | ||
StoreEnhancer | ||
} from 'redux'; | ||
class Engine { | ||
private clock : Clock; | ||
private systems : System[]; | ||
private systems : BaseSystem[]; | ||
private store : Redux.Store; | ||
public addSystem(system: System) : this { | ||
public addSystem(system: BaseSystem) : this { | ||
this.getSystems().push(system); | ||
system.setStore(this.getStore()); | ||
if (system.isSubjectToClockUpdates()) { | ||
this.getClock().addSystem(system); | ||
} | ||
return this; | ||
@@ -31,2 +53,10 @@ } | ||
private handleAction(action: BaseAction) : void { | ||
console.log(this.getStore().getState()); | ||
this.getSystems().forEach(system => { | ||
system.handleAction(action); | ||
}); | ||
} | ||
private getClock() : Clock { | ||
@@ -46,3 +76,3 @@ if (!this.clock) { | ||
private getSystems() : System[] { | ||
private getSystems() : BaseSystem[] { | ||
if (!this.systems) { | ||
@@ -55,4 +85,33 @@ this.systems = [ ]; | ||
private getStore() : Redux.Store { | ||
if (!this.store) { | ||
this.store = this.createStore(); | ||
} | ||
return this.store; | ||
} | ||
private createStore() : Redux.Store { | ||
return createStore( | ||
Reducers, | ||
this.createMiddleware() | ||
); | ||
} | ||
private createMiddleware() : StoreEnhancer { | ||
return applyMiddleware(this.getMiddleware()); | ||
} | ||
private getMiddleware() : Middleware { | ||
return (store: MiddlewareAPI<any>) => (next: Dispatch<AnyAction>) => { | ||
return (action: AnyAction) : void => { | ||
next(action); | ||
this.handleAction(action); | ||
}; | ||
}; | ||
} | ||
} | ||
export default Engine; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
32543
55
1006
4
7
1
+ Addedredux@4.0.1
+ Addedloose-envify@1.4.0(transitive)
+ Addedredux@4.0.1(transitive)
+ Addedsymbol-observable@1.2.0(transitive)