better default agent props & speed & position numeric, not strings

This commit is contained in:
STEINNI
2026-06-21 12:08:25 +00:00
parent 54db203e86
commit 06a7868882
5 changed files with 106 additions and 9 deletions
+9 -1
View File
@@ -43,7 +43,15 @@ class AgentsModel extends WindozModel {
async getDefaultProps(id){
const aprops = await this.getProperties(id)
const defaults={ position: { x:0, y:0, z:0 }, speed: { x:0, y:0, z:0 }}
for(const p in aprops) defaults[p] = aprops[p].default
for(const p in aprops) {
const prop = aprops[p]
if(prop?.type === 'number') {
const n = Number(prop.default)
defaults[p] = Number.isFinite(n) ? n : 0
} else {
defaults[p] = prop.default
}
}
return(defaults)
}
}
+18 -1
View File
@@ -38,14 +38,31 @@ class KeyframesModel extends WindozModel {
)
}
#normalizeAxisVector(vec) {
if(!vec || typeof(vec) !== 'object') return(null)
const axes = ['x', 'y', 'z']
const out = {}
for(const axis of axes) {
const n = Number(vec[axis])
if(!Number.isFinite(n)) return(null)
out[axis] = n
}
return(out)
}
async save(kfId, data) {
const kfData = Object.keys(data).map(aid => {
const { position, speed, ...storeValues} = data[aid].values
const gpsPosition = this.#normalizeAxisVector(position)
const gpsSpeed = this.#normalizeAxisVector(speed)
if(!gpsPosition || !gpsSpeed) {
throw(new Error(`Agent ${aid}: position and speed must be numeric vectors`))
}
return({
aid: aid,
type: data[aid].type,
storeValues: storeValues,
gpsValues: { position: data[aid].values.position, speed: data[aid].values.speed }
gpsValues: { position: gpsPosition, speed: gpsSpeed },
})
})