Observer embryo, Maestro done
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
export const construct = (redisCnx) => {
|
||||
const tickMs = redisCnx.gpsSrv?.getGpsSettings().collisionTickMs ?? 100
|
||||
// Interval always runs; tickArena no-ops until LIVE (see gpsServer.tickArena)
|
||||
setInterval(() => {
|
||||
redisCnx.gpsSrv?.tickArena()
|
||||
}, tickMs)
|
||||
@@ -8,6 +9,24 @@ export const construct = (redisCnx) => {
|
||||
|
||||
export const methods = {
|
||||
|
||||
handleLifecycleEvent(msg) {
|
||||
const srv = this.gpsSrv
|
||||
if(!srv) return
|
||||
|
||||
if(msg.eventType === 'onYourMarks') {
|
||||
srv.onYourMarks(msg.payload ?? {}).catch(err => {
|
||||
console.error(`[${this.redisId}] onYourMarks failed:`, err)
|
||||
srv.publishReadyToStart({ success: false, err: err.message ?? 'onYourMarks failed' })
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if(msg.eventType === 'bigBang') {
|
||||
srv.onBigBang(msg.payload ?? {})
|
||||
return
|
||||
}
|
||||
},
|
||||
|
||||
handleAgentEvent(msg) {
|
||||
const agentId = msg.sender
|
||||
if(!agentId || typeof(agentId) !== 'string') {
|
||||
@@ -34,7 +53,12 @@ export const methods = {
|
||||
|
||||
dispatchArenaMessage(msg, chan) {
|
||||
const gps = this.config.gps
|
||||
if(!gps || !this.gpsSrv) return false
|
||||
if(!gps || !this.gpsSrv) return(false)
|
||||
|
||||
if(this.matchesChan(chan, gps.lifecycle?.arenaChannel ?? 'arena:lifecycle')) {
|
||||
this.handleLifecycleEvent(msg)
|
||||
return(true)
|
||||
}
|
||||
|
||||
if(this.matchesChan(chan, gps.agentVectorChangeChannel)) {
|
||||
this.handleAgentEvent(msg)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
export function dispatchMessage(redisCnx, msg, chan) {
|
||||
if(!redisCnx.config.gps || typeof(redisCnx.dispatchArenaMessage) !== 'function') return
|
||||
redisCnx.dispatchArenaMessage(msg, chan)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { methods as arenaMethods, construct as arenaConstruct } from './arenaHandlers.js'
|
||||
import { dispatchMessage } from './dispatch.js'
|
||||
|
||||
export const afterLoginMethods = [
|
||||
arenaConstruct,
|
||||
@@ -7,3 +8,4 @@ export const afterLoginMethods = [
|
||||
export const meshActions = {
|
||||
...arenaMethods,
|
||||
}
|
||||
export { dispatchMessage }
|
||||
|
||||
Reference in New Issue
Block a user