updateAgent API & snippet in KF console
This commit is contained in:
@@ -44,7 +44,7 @@ log(agtIds)
|
||||
await removeAgent('00000000-aaaa-bbbb-cccc-dddddddddddd')
|
||||
</div>
|
||||
<div class="snippet" data-snippet="updateAgent" style="display:none;">
|
||||
|
||||
await updateAgent('00000000-aaaa-bbbb-cccc-dddddddddddd', { position: { x: 5, y: 10, z: 0 } })
|
||||
</div>
|
||||
<div class="snippet" data-snippet="selectAgent" style="display:none;">
|
||||
await selectAgent('00000000-aaaa-bbbb-cccc-dddddddddddd')
|
||||
|
||||
@@ -48,7 +48,16 @@ app.helpers.kfConsole = {
|
||||
this.kfArena.removeAgent(aid)
|
||||
},
|
||||
updateAgent: async (aid, properties) => {
|
||||
|
||||
if(!Object.keys(this.kfArena.agents).includes(aid)) throw(`Agent ${aid} not on scene !`)
|
||||
const agent = this.kfArena.agents[aid]
|
||||
const values = { ...agent.values, ...properties }
|
||||
if(properties.position) values.position = { ...agent.values.position, ...properties.position }
|
||||
if(properties.speed) values.speed = { ...agent.values.speed, ...properties.speed }
|
||||
agent.values = values
|
||||
if(properties.position) this.kfArena.moveAgent(aid, values.position)
|
||||
if(properties.speed) this.kfArena.changeAgentSpeed(aid, values.speed)
|
||||
if(this.currentlySelectedAid === aid) this.fillAgentProperties(aid, agent.props, agent.values)
|
||||
this.updateKfButtons()
|
||||
},
|
||||
selectAgent: async (aid) => {
|
||||
if(!Object.keys(this.kfArena.agents).includes(aid)) throw(`Agent ${aid} not on scene !`)
|
||||
|
||||
Reference in New Issue
Block a user