on scene selection OK + keyframe model
This commit is contained in:
@@ -29,7 +29,7 @@ class KeyframeView extends WindozDomContent {
|
||||
|
||||
this.agentSprites = sprites
|
||||
this.agentTypes = types
|
||||
|
||||
this.currentAgentType = null
|
||||
|
||||
this.outputs.agentsSelector.fillOptions( this.agentTypes.map(item => {
|
||||
return({ markup: `<i class="icon-${item.atp_hascode ? 'bug' : 'atom1'}"></i>${item.atp_name}`, value: item.atp_id})
|
||||
@@ -48,44 +48,59 @@ class KeyframeView extends WindozDomContent {
|
||||
this.outputs.btnAddAgent.disabled = true
|
||||
this.outputs.btnRemoveAgent.disabled = true
|
||||
this.outputs.btnSaveKF.disabled = true
|
||||
|
||||
this.currentlySelectedAid = null
|
||||
}
|
||||
|
||||
async onChangeAgent(event){
|
||||
if(this.outputs.agentsSelector.value) this.agentPreview.setAgent(this.outputs.agentsSelector.value)
|
||||
if(!this.outputs.agentsSelector.value) return
|
||||
const agent = await this.models.agents.getProperties(this.outputs.agentsSelector.value)
|
||||
this.fillAgentProperties('', agent.atp_props)
|
||||
|
||||
if(this.notUserChange) {
|
||||
|
||||
} else {
|
||||
this.currentAgentType = await this.models.agents.getProperties(this.outputs.agentsSelector.value)
|
||||
this.fillAgentProperties('', this.currentAgentType.atp_props)
|
||||
// Deselect any on-scene selection
|
||||
this.kfArena.highlighted3DObjects.length = 0
|
||||
this.currentlySelectedAid = null
|
||||
}
|
||||
}
|
||||
|
||||
onclickAgent(aid){
|
||||
console.log('Agent clicked:', aid)
|
||||
onclickAgent(obj3D){
|
||||
const aid = obj3D.name
|
||||
this.kfArena.highlighted3DObjects.length = 0 //truncate but keep the ref !
|
||||
if(this.currentlySelectedAid == aid){ // Deselect
|
||||
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
|
||||
}
|
||||
this.updateKfButtons()
|
||||
}
|
||||
|
||||
onAddAgent(event){
|
||||
//TODO prevent collisions !
|
||||
|
||||
const aid = crypto.randomUUIDv7()
|
||||
this.output('agentId', `ID: ${aid}`)
|
||||
this.kfArena.addAgent(this.outputs.agentsSelector.value, aid, {
|
||||
position: {
|
||||
x: document.querySelector('[name="position.x"]').value,
|
||||
y: document.querySelector('[name="position.y"]').value,
|
||||
z: document.querySelector('[name="position.z"]').value,
|
||||
}
|
||||
})
|
||||
const AgentValues = this.getFieldsValues('div[data-output="agentProperties"]')
|
||||
this.kfArena.addAgent(this.outputs.agentsSelector.value, aid, this.currentAgentType.atp_props , AgentValues)
|
||||
this.updateKfButtons()
|
||||
}
|
||||
|
||||
updateKfButtons(){
|
||||
if(this.kfArena.agents.length > 0) this.outputs.btnSaveKF.disabled = false
|
||||
if(Object.keys(this.kfArena.agents).length > 0) this.outputs.btnSaveKF.disabled = false
|
||||
}
|
||||
|
||||
fillAgentProperties(aid, agentProps){
|
||||
fillAgentProperties(aid, agentProps, agentValues = {}){
|
||||
this.outputs.agentProperties.innerHTML = `
|
||||
<div data-output="agentId">ID: ${aid}</div>
|
||||
`
|
||||
this.outputs.agentProperties.append(...this.fieldsFromJSON(agentProps, 'Internal properties'))
|
||||
this.outputs.agentProperties.append(...this.fieldsFromJSON(agentProps, agentValues, 'Internal properties'))
|
||||
this.outputs.agentProperties.append(...this.fieldsFromJSON({
|
||||
"position.x": {
|
||||
label: "Position X",
|
||||
@@ -102,7 +117,7 @@ class KeyframeView extends WindozDomContent {
|
||||
type: "number",
|
||||
default: "0"
|
||||
},
|
||||
}, 'Coordinates'))
|
||||
}, agentValues, 'Coordinates'))
|
||||
this.outputs.agentProperties.append(...this.fieldsFromJSON({
|
||||
"speed.x": {
|
||||
label: "Speed X",
|
||||
@@ -119,13 +134,14 @@ class KeyframeView extends WindozDomContent {
|
||||
type: "number",
|
||||
default: "0"
|
||||
},
|
||||
}, 'Speed vector'))
|
||||
}, agentValues, 'Speed vector'))
|
||||
this.outputs.btnAddAgent.disabled = false
|
||||
this.setupRefs()
|
||||
}
|
||||
|
||||
onSaveKF(evt){
|
||||
console.log('SAVE:',this.kfArena.agents)
|
||||
async onSaveKF(evt){
|
||||
console.log('SAVE:',this.kfArena.agents)
|
||||
await this.models.keyframe.save(this.kfArena.agents)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user