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

Method parseMap

src/components/UploadMap.jsx:37–65  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

35 }
36
37 parseMap(text) {
38 if (!this.verifyMap(text)) {
39 this.setState({ isDialogOpen: true });
40 return;
41 }
42
43 var lines = text.trim().split(/\r?\n/);
44 var height = parseInt(lines[1].split(" ")[1]);
45 var width = parseInt(lines[2].split(" ")[1]);
46 var map = Array(height)
47 .fill()
48 .map(() =>
49 new Array(width).fill().map(() => ({
50 isWall: false,
51 isStart: false,
52 isGoal: false,
53 agent: -1,
54 color: "",
55 }))
56 );
57 lines.slice(4).forEach((line, i) => {
58 [...line].forEach((char, j) => {
59 if (char === "@" || char === "T") {
60 map[i][j].isWall = true;
61 }
62 });
63 });
64 this.props.adjustMap(height, width, map);
65 }
66
67 verifyMap(text) {
68 try {

Callers 2

closeDropdownMethod · 0.95
uploadMapMethod · 0.95

Calls 2

verifyMapMethod · 0.95
adjustMapMethod · 0.45

Tested by

no test coverage detected