import { SocketService } from "./socket.service" ; export namespace RouterService { export function initGameState ( name , cb ) { SocketService . send ( "init_game_state" , { name } , cb ) ; } export function sendInteraction ( direction , force ) { let msg = { direction , force } ; SocketService . send ( "player_interaction" , msg ) ; } let messageMap = { "update" : [ ] , "remove_player" : [ ] } ; export function routeMessages ( msg ) { if ( messageMap [ msg . type ] !== undefined ) { messageMap [ msg . type ] . forEach ( func => { func ( msg ) ; } ) ; } } export function registerFunction ( type , func , context = null ) { if ( context !== null ) func = func . bind ( context ) ; messageMap [ type ] . push ( func ) ; } }