Load KF works

This commit is contained in:
STEINNI
2025-10-29 17:41:29 +00:00
parent f349ff38f4
commit dfab013abe
8 changed files with 105 additions and 21 deletions
+46 -11
View File
@@ -44,6 +44,16 @@ class KeyframeView extends WindozDomContent {
this.agentPreview.startRendering()
this.agentPreview.animation = true
this.models.keyframes.list('', null).then(data => data.payload).then(kflist => {
this.outputs.keyframesSelector.fillOptions(kflist.map(item => {
return({
markup: item.ekf_name,
value: item.ekf_uuid
})
}))
})
this.outputs.keyframesSelector.addEventListener('change',this.onChangeKeyframe.bind(this))
this.kfArena = new app.LoadedModules.kfArena(this.outputs.kfArenaCanvas, this.agentSprites)
this.kfArena.onclickAgent = this.onclickAgent.bind(this)
this.kfArena.startRendering()
@@ -70,6 +80,17 @@ class KeyframeView extends WindozDomContent {
}
}
async onChangeKeyframe(event){
if(!this.outputs.keyframesSelector.value) return
let kfData = await this.models.keyframes.getKeyframe(this.outputs.keyframesSelector.value).then(data => data.payload)
this.currentKeyframe = {
kfId: kfData.info.ekf_uuid,
kfName: kfData.info.ekf_name,
prevKfId: kfData.info.ekf_prev_uuid,
}
this.kfArena.reloadAgents(kfData.agents)
}
onclickAgent(obj3D){
const aid = obj3D.name
this.kfArena.highlighted3DObjects.length = 0 //truncate but keep the ref !
@@ -77,11 +98,13 @@ class KeyframeView extends WindozDomContent {
this.currentlySelectedAid = null
} else { // Select
this.currentlySelectedAid = aid
this.kfArena.highlighted3DObjects.push(obj3D)
this.fillAgentProperties(aid, this.kfArena.agents[aid].props, this.kfArena.agents[aid].values)
this.notUserChange = true
this.outputs.agentsSelector.value = this.kfArena.agents[aid].type
this.notUserChange = false
if(this.kfArena.agents[aid]) {
this.kfArena.highlighted3DObjects.push(obj3D)
this.fillAgentProperties(aid, this.kfArena.agents[aid].props, this.kfArena.agents[aid].values)
this.notUserChange = true
this.outputs.agentsSelector.value = this.kfArena.agents[aid].type
this.notUserChange = false
}
}
this.updateKfButtons()
}
@@ -100,11 +123,18 @@ class KeyframeView extends WindozDomContent {
else { this.outputs.btnSaveKF.disabled = true }
}
onPropsChanged(evt, comp){
console.log('onPropsChanged', comp, evt)
if(this.currentlySelectedAid && this.kfArena.agents[this.currentlySelectedAid]){
}
}
fillAgentProperties(aid, agentProps, agentValues = {}){
this.outputs.agentProperties.innerHTML = `
<div data-output="agentId">ID: ${aid}</div>
`
this.outputs.agentProperties.append(...this.fieldsFromJSON(agentProps, agentValues, 'Internal properties'))
this.outputs.agentProperties.append(...this.fieldsFromJSON(agentProps, agentValues, 'Internal properties', this.onPropsChanged.bind(this)))
this.outputs.agentProperties.append(...this.fieldsFromJSON({
"position.x": {
label: "Position X",
@@ -121,7 +151,7 @@ class KeyframeView extends WindozDomContent {
type: "number",
default: "0"
},
}, agentValues, 'Coordinates'))
}, agentValues, 'Coordinates', this.onPropsChanged.bind(this)))
this.outputs.agentProperties.append(...this.fieldsFromJSON({
"speed.x": {
label: "Speed X",
@@ -138,21 +168,26 @@ class KeyframeView extends WindozDomContent {
type: "number",
default: "0"
},
}, agentValues, 'Speed vector'))
}, agentValues, 'Speed vector', this.onPropsChanged.bind(this)))
this.outputs.btnAddAgent.disabled = false
this.setupRefs()
}
async onSaveKF(evt){
let result = { success: true }
if(!this.currentKeyframe.kfId){ // Create first (and get new kfId)
this.currentKeyframe.kfName = this.outputs.kfName.value
const result = await this.models.keyframes.create(this.currentKeyframe)
result = await this.models.keyframes.create(this.currentKeyframe)
this.currentKeyframe.kfId = result.payload.kfId
} else if(this.currentKeyframe.kfName != this.outputs.kfName.value){ //rename
this.currentKeyframe.kfName = this.outputs.kfName.value
const result = await this.models.keyframes.rename(this.currentKeyframe)
result = await this.models.keyframes.rename(this.currentKeyframe)
console.log(result)
}
await this.models.keyframes.save(this.currentKeyframe.kfId, this.kfArena.agents)
if(result.success){
await this.models.keyframes.save(this.currentKeyframe.kfId, this.kfArena.agents)
}
}
}