Socket
Socket
Sign inDemoInstall

@burninggarden/engine

Package Overview
Dependencies
233
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

src/action-creators/add-entity.ts

4

package.json
{
"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;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc