Created
December 5, 2022 20:47
-
-
Save paprikka/db9ad86a95eccf93575c8c68e1b02c03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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