logs in console, caching in getAgentProps, console createAgent independent of GUI
This commit is contained in:
@@ -2,8 +2,7 @@ class KeyframeView extends WindozDomContent {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
Object.assign(this, app.helpers.activeAttributes)
|
||||
Object.assign(this, app.helpers.formBuilder)
|
||||
Object.assign(this, app.helpers.activeAttributes, app.helpers.formBuilder, app.helpers.kfConsole)
|
||||
}
|
||||
|
||||
DOMContentFocused(options) {
|
||||
@@ -65,67 +64,6 @@ class KeyframeView extends WindozDomContent {
|
||||
this.currentlySelectedAid = null
|
||||
}
|
||||
|
||||
async execCommand(event){
|
||||
console.log('cmd:', this.outputs.commands)
|
||||
if(this.outputs.commands.value.trim()=='\\help'){
|
||||
this.outputs.results.innerHTML += await app.Assets.loadHtml({ name: 'help/KFconsoleHelp.html' })
|
||||
} else if(this.outputs.commands.value.trim()=='\\clear'){
|
||||
this.outputs.results.innerHTML = ''
|
||||
} else {
|
||||
this.outputs.results.innerHTML += await this.evalCmd(this.outputs.commands.value)
|
||||
}
|
||||
const lines = this.outputs.results.querySelectorAll('div.line')
|
||||
if(lines.length > 100) {
|
||||
for(let i=0; i<(lines.length-100); i++) lines[i].remove()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async evalCmd(code){
|
||||
const api = {
|
||||
newAgent: async (type, properties) => {
|
||||
if(Array.from(this.outputs.agentsSelector.options).find(item => item.value==type)){
|
||||
this.outputs.agentsSelector.value = type
|
||||
await this.onChangeAgent()
|
||||
const defaultValues = this.getFieldsValues('div[data-output="agentProperties"]')
|
||||
return(await this.newAgent(type, { ...defaultValues, ...properties })) //TODO: deepMerge
|
||||
} else {
|
||||
throw(`Invalid agent type: ${type}`)
|
||||
}
|
||||
},
|
||||
removeAgent: (aid) => {
|
||||
|
||||
},
|
||||
updateAgent: (aid, properties) => {
|
||||
|
||||
},
|
||||
}
|
||||
try {
|
||||
const fn = new Function(...Object.keys(api), `
|
||||
return(
|
||||
(async () => {
|
||||
const logs = []
|
||||
const log = (item) => { logs.push(item) }
|
||||
${code}
|
||||
return(logs)
|
||||
})()
|
||||
)
|
||||
`)
|
||||
|
||||
const res = await fn(...Object.values(api))
|
||||
return(
|
||||
'<div class="line">'+
|
||||
res.map(item => {
|
||||
if(typeof(item) == 'object') return(JSON.stringify(item))
|
||||
return(item)
|
||||
}).join('</div><div class="line">')
|
||||
+'</div>'
|
||||
)
|
||||
} catch (err) {
|
||||
return(`<div class="error">${err.name}: ${err.message}</div>`)
|
||||
}
|
||||
}
|
||||
|
||||
async onChangeAgent(event){
|
||||
if(this.outputs.agentsSelector.value) this.agentPreview.setAgent(this.outputs.agentsSelector.value)
|
||||
if(!this.outputs.agentsSelector.value) return
|
||||
@@ -134,7 +72,7 @@ class KeyframeView extends WindozDomContent {
|
||||
|
||||
} else {
|
||||
this.currentAgentType = await this.models.agents.getProperties(this.outputs.agentsSelector.value)
|
||||
this.fillAgentProperties('', this.currentAgentType.atp_props)
|
||||
this.fillAgentProperties('', this.currentAgentType)
|
||||
// Deselect any on-scene selection
|
||||
if(this.currentlySelectedAid){
|
||||
this.kfArena.clearHighlight3DObj(this.kfArena.scene.getObjectByName(this.currentlySelectedAid), this.kfArena.scene)
|
||||
@@ -191,9 +129,10 @@ class KeyframeView extends WindozDomContent {
|
||||
this.kfArena.removeAgent(this.currentlySelectedAid)
|
||||
}
|
||||
|
||||
newAgent(aType, AgentValues){
|
||||
async newAgent(aType, AgentValues){
|
||||
const aid = crypto.randomUUIDv7()
|
||||
this.kfArena.addAgent(aType, aid, this.currentAgentType.atp_props , AgentValues)
|
||||
const agentProps = await this.models.agents.getProperties(aType)
|
||||
this.kfArena.addAgent(aType, aid, agentProps, AgentValues)
|
||||
return(aid)
|
||||
}
|
||||
|
||||
@@ -291,3 +230,19 @@ class KeyframeView extends WindozDomContent {
|
||||
|
||||
app.registerClass('KeyframeView', KeyframeView)
|
||||
|
||||
//TODO :
|
||||
/*
|
||||
|
||||
API update
|
||||
API remove
|
||||
API listAgentTypes
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user