MCPcopy Create free account
hub / github.com/akeranen/the-one / readMap

Method readMap

movement/MapBasedMovement.java:265–310  ·  view source on GitHub ↗

Reads a sim map from location set to the settings, mirrors the map and moves its upper left corner to origo. @return A new SimMap based on the settings

()

Source from the content-addressed store, hash-verified

263 * @return A new SimMap based on the settings
264 */
265 private SimMap readMap() {
266 SimMap simMap;
267 Settings settings = new Settings(MAP_BASE_MOVEMENT_NS);
268 WKTMapReader r = new WKTMapReader(true);
269
270 if (cachedMap == null) {
271 cachedMapFiles = new ArrayList<String>(); // no cache present
272 }
273 else { // something in cache
274 // check out if previously asked map was asked again
275 SimMap cached = checkCache(settings);
276 if (cached != null) {
277 nrofMapFilesRead = cachedMapFiles.size();
278 return cached; // we had right map cached -> return it
279 }
280 else { // no hit -> reset cache
281 cachedMapFiles = new ArrayList<String>();
282 cachedMap = null;
283 }
284 }
285
286 try {
287 int nrofMapFiles = settings.getInt(NROF_FILES_S);
288
289 for (int i = 1; i <= nrofMapFiles; i++ ) {
290 String pathFile = settings.getSetting(FILE_S + i);
291 cachedMapFiles.add(pathFile);
292 r.addPaths(new File(pathFile), i);
293 }
294
295 nrofMapFilesRead = nrofMapFiles;
296 } catch (IOException e) {
297 throw new SimError(e.toString(),e);
298 }
299
300 simMap = r.getMap();
301 checkMapConnectedness(simMap.getNodes());
302 // mirrors the map (y' = -y) and moves its upper left corner to origo
303 simMap.mirror();
304 Coord offset = simMap.getMinBound().clone();
305 simMap.translate(-offset.getX(), -offset.getY());
306 checkCoordValidity(simMap.getNodes());
307
308 cachedMap = simMap;
309 return simMap;
310 }
311
312 /**
313 * Checks that all map nodes can be reached from all other map nodes

Callers 1

MapBasedMovementMethod · 0.95

Calls 15

checkCacheMethod · 0.95
getIntMethod · 0.95
getSettingMethod · 0.95
addPathsMethod · 0.95
getMapMethod · 0.95
checkMapConnectednessMethod · 0.95
getNodesMethod · 0.95
mirrorMethod · 0.95
getMinBoundMethod · 0.95
translateMethod · 0.95
getXMethod · 0.95
getYMethod · 0.95

Tested by

no test coverage detected