export const construct = (redisCnx) => { const tickMs = redisCnx.gpsSrv?.getGpsSettings().collisionTickMs ?? 100 setInterval(() => { redisCnx.gpsSrv?.tickArena() }, tickMs) } export const methods = { handleAgentEvent(msg) { const agentId = msg.sender if(!agentId || typeof(agentId) !== 'string') { console.warn(`[${this.redisId}] Agent event without sender`) return } if(msg.eventType === 'change') { const newVector = msg.payload?.newVector if(!newVector || typeof(newVector.x) !== 'number' || typeof(newVector.y) !== 'number' || typeof(newVector.z) !== 'number') { console.warn(`[${this.redisId}] Invalid newVector from ${agentId}`) return } const newPosition = msg.payload?.newPosition ?? null this.gpsSrv.onVectorChange(agentId, newVector, newPosition) return } if(msg.eventType === 'remove') { this.gpsSrv.onAgentRemove(agentId) return } }, dispatchArenaMessage(msg, chan) { const gps = this.config.gps if(!gps || !this.gpsSrv) return false if(this.matchesChan(chan, gps.agentVectorChangeChannel)) { this.handleAgentEvent(msg) return(true) } return(false) }, }