KF console API

This commit is contained in:
STEINNI
2025-12-06 21:09:09 +00:00
parent c1d0a16cf3
commit 122861dbee
5 changed files with 43 additions and 34 deletions
+20 -15
View File
@@ -24,30 +24,35 @@ Special commands:<br>
<ul>
<li>Log here: <b>log()</b> - any number of arguments of any type</li>
<li>Create an agent: <b>createAgent(type, properties)</b> - Promise returning the AID <button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="createAgent">Snippet</button></li>
<li>Remove an agent: <b>removeAgent(aid)</b> <button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="removeAgent">Snippet</button></li>
<li>Update an agent: <b>updateAgent(aid, properties)</b> <button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="updateAgent">Snippet</button></li>
<li>List agent types: <b>listAgentTypes()</b> <button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="listAgentTypes">Snippet</button></li>
<li>List agents on scene: <b>listAgentsOnScene()</b> <button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="listAgentsOnScene">Snippet</button></li>
<li>Remove an agent: <b>removeAgent(aid)</b> - Promise<button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="removeAgent">Snippet</button></li>
<li>Update an agent: <b>updateAgent(aid, properties)</b> - Promise <button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="updateAgent">Snippet</button></li>
<li>Toggle selection of an agent: <b>selectAgent(aid)</b> - Promise<button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="selectAgent">Snippet</button></li>
<li>List agent types: <b>listAgentTypes()</b> - Promise<button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="listAgentTypes">Snippet</button></li>
<li>List agents on scene: <b>listAgentsOnScene()</b> - Promise<button eicbutton info xxsmall data-trigger="onSnippet" data-snippet="listAgentsOnScene">Snippet</button></li>
</ul>
</div>
<div class="snippet" data-snippet="createAgent" style="display:none">
const agtIds = []
for(let i=0; i<360; i+=22.5){
const agtIds = []
for(let i=0; i<360; i+=22.5){
agtIds.push(
await createAgent(1, { position: { x: 10*Math.sin(i*Math.PI/180), y: 10*Math.cos(i*Math.PI/180), z: 0 } } )
)
}
log(agtIds)
}
log(agtIds)
</div>
<div class="snippet" data-snippet="removeAgent" style="display:none">
<div class="snippet" data-snippet="removeAgent" style="display:none;">
await removeAgent('00000000-aaaa-bbbb-cccc-dddddddddddd')
</div>
<div class="snippet" data-snippet="updateAgent" style="display:none;">
</div>
<div class="snippet" data-snippet="updateAgent" style="display:none">
<div class="snippet" data-snippet="selectAgent" style="display:none;">
await selectAgent('00000000-aaaa-bbbb-cccc-dddddddddddd')
</div>
<div class="snippet" data-snippet="listAgentTypes" style="display:none">
for(const agt of listAgentTypes() console.log(agt)
<div class="snippet" data-snippet="listAgentTypes" style="display:none;">
for(const agt of await listAgentTypes()) { log(agt.atp_id+':'+agt.atp_name)
</div>
<div class="snippet" data-snippet="listAgentsOnScene" style="display:none">
for(const agt of listAgentsOnScene() console.log(agt)
<div class="snippet" data-snippet="listAgentsOnScene" style="display:none;">
const agts = await listAgentsOnScene()
for(const aid in agts){ log(`${aid}:${JSON.stringify(agts[aid])}`,'----------') }
</div>
+15 -7
View File
@@ -38,20 +38,27 @@ app.helpers.kfConsole = {
createAgent: async (type, properties) => {
if(Array.from(this.outputs.agentsSelector.options).find(item => item.value==type)){
const defaultValues = await this.models.agents.getDefaultProps(type)
console.log('==deflt===>', defaultValues,)
return(await this.newAgent(type, { ...defaultValues, ...properties })) //TODO: deepMerge
} else {
throw(`Invalid agent type: ${type}`)
}
},
removeAgent: (aid) => {
removeAgent: async (aid) => {
if(!Object.keys(this.kfArena.agents).includes(aid)) throw(`Agent ${aid} not on scene !`)
this.kfArena.removeAgent(aid)
},
updateAgent: async (aid, properties) => {
},
updateAgent: (aid, properties) => {
selectAgent: async (aid) => {
if(!Object.keys(this.kfArena.agents).includes(aid)) throw(`Agent ${aid} not on scene !`)
this.onclickAgent(this.kfArena.scene.getObjectByName(aid))
},
listagentTypes: () => {
listAgentTypes: async () => {
return(this.agentTypes)
},
listAgentsOnScene: async () => {
return(this.kfArena.agents)
},
}
try {
@@ -81,7 +88,8 @@ app.helpers.kfConsole = {
+'</div>'
)
} catch (err) {
return(`<div class="error">${err.name}: ${err.message}</div>`)
const msg = (err && err.message) ? err.message : String(err)
return(`<div class="error">${(err && err.name) ? err.name +': ': ''}${(err && err.message) ? err.message : String(err)}</div>`)
}
},
}
+2 -2
View File
@@ -119,10 +119,10 @@
color: white;
}
.kf-editor .kfArena .inner-console .results .error{
border-top: 1px solid red;
border-bottom: 1px solid red;
border-bottom: 2px solid black;
background-color: #FDD;
color: black;
padding: 0.1em 0.5em 0.1em 0.5em;
}
</style>
<div class="kf-editor cols-3">
+2 -6
View File
@@ -136,7 +136,6 @@ class KeyframeView extends WindozDomContent {
return(aid)
}
updateKfButtons(){
if((Object.keys(this.kfArena.agents).length > 0) && (this.outputs.kfName.value.length > 5)) { this.outputs.btnSaveKF.disabled = false }
else { this.outputs.btnSaveKF.disabled = true }
@@ -164,9 +163,7 @@ class KeyframeView extends WindozDomContent {
}
fillAgentProperties(aid, agentProps, agentValues = {}){
this.outputs.agentProperties.innerHTML = `
<div data-output="agentId">ID: ${aid}</div>
`
this.outputs.agentProperties.innerHTML = `<div data-output="agentId">ID: ${aid}</div>`
this.outputs.agentProperties.append(...this.fieldsFromJSON(agentProps, agentValues, 'Internal properties', this.onPropsChanged.bind(this)))
this.outputs.agentProperties.append(...this.fieldsFromJSON({
"position.x": {
@@ -242,7 +239,6 @@ if unsavec changes in scene => confirm before reloading
Bugs
=> reselect same scene resets it
=> Added with API = non-selectable
=> loaded from KF => loosing internal props
*/
+1 -1
View File
@@ -217,7 +217,7 @@ export class kfArena{
this.removeAgent(aid)
}
for(const agent of agents){
this.addAgent(agent.ekfs_atp_id, agent.aid, agent.props, {...agent.gps_values, ...agent.store_values})
this.addAgent(agent.ekfs_atp_id, agent.aid, agent.atp_props, {...agent.gps_values, ...agent.store_values})
}
}