MCPcopy Create free account
hub / github.com/StevenLyt/mapf-visualizer / playAnimation

Method playAnimation

src/LAMAPFVisualizer.jsx:236–270  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

234 }
235
236 playAnimation() {
237 this.setState({ isAnimationFinished: false });
238 var finishTime = 0;
239 const paths = this.state.paths;
240 for (var t = 0; t < paths.length; t++) {
241 finishTime = Math.max(finishTime, paths[t].length);
242 }
243 for (let t = 0; t < finishTime; t++) {
244 setTimeout(() => {
245 let map = this.state.map;
246 for (let i = 0; i < map.length; i++) {
247 for (let j = 0; j < map[i].length; j++) {
248 map[i][j].isStart = false;
249 map[i][j].agent = -1;
250 map[i][j].color = "";
251 }
252 }
253 for (let i = 0; i < paths.length; i++) {
254 let loc = this.decodeLocation(paths[i][paths[i].length > t ? t : paths[i].length - 1]);
255 for (let x = loc.r; x < loc.r + this.state.agents[i].height; x++) {
256 for (let y = loc.c; y < loc.c + this.state.agents[i].width; y++) {
257 map[x][y].isStart = true;
258 map[x][y].agent = i + 1;
259 map[x][y].color = this.state.agents[i].color;
260 }
261 }
262 }
263 this.setState({ map: map });
264 }, 1000 * this.state.speed * t);
265 }
266 setTimeout(
267 () => this.setState({ isAnimationFinished: true }),
268 1000 * this.state.speed * finishTime
269 );
270 }
271
272 removeAgent() {
273 this.setState({ toDelete: true });

Callers 2

requestSolutionMethod · 0.95
renderMethod · 0.95

Calls 1

decodeLocationMethod · 0.95

Tested by

no test coverage detected