General Actions to handlers Refacto
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
|
||||
export const eventHandlers = {
|
||||
'arena:agents:*': {
|
||||
change(msg, chan) {
|
||||
const agentId = msg.sender
|
||||
if(!agentId || typeof(agentId) !== 'string') {
|
||||
console.warn(`[${this.redisId}] Agent event without sender`)
|
||||
return
|
||||
}
|
||||
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)
|
||||
},
|
||||
remove(msg, chan) {
|
||||
const agentId = msg.sender
|
||||
if(!agentId || typeof(agentId) !== 'string') {
|
||||
console.warn(`[${this.redisId}] Agent event without sender`)
|
||||
return
|
||||
}
|
||||
this.gpsSrv?.onAgentRemove(agentId)
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user