class AgentsModel extends WindozModel { constructor() { super() this.ressource = '/agents' this.agentProps = {} } async getTypes(family) { let endpoint = {...app.config.api[this.ressource].getTypes} endpoint.uri = endpoint.uri.replace('{family}', family) return ( this.request(endpoint.uri, endpoint.method) .then( async serverData => serverData.payload.agentTypes) ) } async getSprites(group) { let endpoint = {...app.config.api[this.ressource].getSprites} endpoint.uri = endpoint.uri.replace('{group}', group) return ( this.request(endpoint.uri, endpoint.method) .then( async serverData => serverData.payload.agentSprites) ) } async getProperties(id, force=false) { if((!(id in this.agentProps)) || force){ let endpoint = {...app.config.api[this.ressource].getProperties} endpoint.uri = endpoint.uri.replace('{id}', id) return ( this.request(endpoint.uri, endpoint.method) .then( async serverData => { this.agentProps[id] = serverData.payload.agentProperties.atp_props return(serverData.payload.agentProperties.atp_props) }) ) } else { return(this.agentProps[id]) } } 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 return(defaults) } } app.registerClass('AgentsModel', AgentsModel);