Skip to content

Instantly share code, notes, and snippets.

@paprikka
Created December 5, 2022 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paprikka/db9ad86a95eccf93575c8c68e1b02c03 to your computer and use it in GitHub Desktop.
Save paprikka/db9ad86a95eccf93575c8c68e1b02c03 to your computer and use it in GitHub Desktop.
import {Observable} from 'rx';
const INTERVAL = 1000 / 10;
const ticker = Observable.interval(INTERVAL);
import notifySystem from './systems/notify';
import locationSystem from './systems/location';
import arSceneSystem from './systems/ar-scene';
import userStatsSystem from './systems/user-stats';
import reactViewSystem from './systems/react-view';
const systems = [
locationSystem,
arSceneSystem,
userStatsSystem,
notifySystem,
reactViewSystem
];
function runSystems (nextState, system) { return system(nextState); }
import userInputSystem from './systems/user-input';
function engineReducer(state) {
const currentGame = state.get('currentGame');
if (!currentGame) return state;
const hasEntities = currentGame.has('entities');
if (!hasEntities) return state;
return systems.reduce(runSystems, state);
}
export default function engine() {
console.log('Engine initialised');
return ticker
.map( () => engineReducer )
.merge( userInputSystem() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment