/** * Loads a scenario (an SVG file specifiing location and shape of surfaces and objects in the * arena)from a file. * * @param svgFileName specifies the file the scenario is loaded from. */ public void loadScenario(String svgFileName) { this.svgFileName = svgFileName; SVGShapeLoader loader = new SVGShapeLoader(svgFileName); try { loader.start(); loader.join(); } catch (InterruptedException e) { e.printStackTrace(); } screenWidth = loader.getWidth(); screenHeight = loader.getHeight(); positions = new ArrayList<PositionMark>(); paintable = new ArrayList<VivaeObject>(); Vector<HashMap<String, Vector<Shape>>> shapeMap = loader.getShapesWithTypeMap(); int l = 1; for (HashMap<String, Vector<Shape>> m : shapeMap) { if (m == null) ; // System.out.println("No shapes loaded on layer " + l); else { Vector<ArenaPart> v = ArenaPartsGenerator.createParts(m, l, this); for (ArenaPart vivae : v) { if (Surface.class.isAssignableFrom(vivae.getClass())) { addSurface((Surface) vivae); } else if (PositionMark.class.isAssignableFrom(vivae.getClass())) { addPosition((PositionMark) vivae); } else if (Passive.class.isAssignableFrom(vivae.getClass())) { addPassive((Passive) vivae); // this should not happen anymore - actives (robots added by // experiment, not SVG file !!!) // } else if (Active.class.isAssignableFrom(vivae.getClass())) { // activesPositions.add((Active) vivae); } } } l++; } }
/** * Loads a scenario (an SVG file specifiing location and shape of surfaces and objects in the * arena)from a file. * * @param svgFileName specifies the file the scenario is loaded from. */ public void loadScenario(String svgFileName) { SVGShapeLoader loader = new SVGShapeLoader(svgFileName); try { loader.start(); loader.join(); } catch (InterruptedException e) { e.printStackTrace(); } screenWidth = loader.getWidth(); screenHeight = loader.getHeight(); Vector<HashMap<String, Vector<Shape>>> shapeMap = loader.getShapesWithTypeMap(); int l = 1; for (HashMap<String, Vector<Shape>> m : shapeMap) { if (m == null) ; // System.out.println("No shapes loaded on layer " + l); else { Vector<ArenaPart> v = ArenaPartsGenerator.createParts(m, l, this); for (ArenaPart vivae : v) { if (Surface.class.isAssignableFrom(vivae.getClass())) { addSurface((Surface) vivae); } else if (Passive.class.isAssignableFrom(vivae.getClass())) { addPassive((Passive) vivae); } else if (Active.class.isAssignableFrom(vivae.getClass())) { addActive((Active) vivae); } } /* Vector<Surface> lsurfaces = new Vector<Surface>(); Vector<Passive> lpassives = new Vector<Passive>(); for (ArenaPart vivae : v) { if (vivae instanceof Surface) { Surface p = (Surface) vivae; //System.out.println("Adding a Surface to Arena."); lsurfaces.add(p); } else if (vivae instanceof Obstacle) { Obstacle o = (Obstacle) vivae; //System.out.println("Adding an Obstacle to Arena."); lpassives.add(o); //getVivaes().add(o); // doubled instances } else if (vivae instanceof FixedObstacle) { FixedObstacle o = (FixedObstacle) vivae; //System.out.println("Adding an Obstacle to Arena."); lpassives.add(o); //getVivaes().add(o); // doubled instances } else if (vivae instanceof BigPuck) { BigPuck bp = (BigPuck) vivae; //System.out.println("Adding a Puck to Arena."); lpassives.add(bp); //getVivaes().add(bp); // doubled instances } else if (vivae instanceof Robot) { Robot robot = (Robot) vivae; actives.add(robot); getVivaes().add(robot); } } if (!lsurfaces.isEmpty()) { this.addSurfaces(lsurfaces); } if (!lpassives.isEmpty()) { this.addPassives(lpassives); } */ } l++; } }