/** * Save entities * * @param b the Board from which the Entities come * @param r the writer to which the entities should be written * @throws IOException Signals that an I/O exception has occurred. */ public static void saveEntities(GameBoard b, BufferedWriter r) throws IOException { Iterator<Entity> e = b.getIngameEntities().iterator(); while (e.hasNext()) { Entity en = e.next(); if (!Player.class.isAssignableFrom(en.getClass())) { r.write(en.saveToString()); r.newLine(); } } }
/** * Loads entities from a BufferedReader. Each entity is on it's own line and has it's own custom * method of parsing an Entity out of a String However, the first item in the declaration (items * are separated by colons) is the classpath of the Entity this has the potential for malware in * mods...maybe * * <p>at any rate, the general form is (Entity type, x, y, layer,....) * * @param target the GameBoard on to which the Entities should be loaded * @param r the BufferedReader from which to load * @return an ArrayList of all the Loaded Entities. Not really used at all, just there for the * sake of convenience and potential extension * @throws IOException Signals that an I/O exception has occurred. * @throws ClassNotFoundException the class not found exception * @throws InstantiationException the instantiation exception * @throws IllegalAccessException the illegal access exception */ public static void loadEntities(GameBoard target, BufferedReader r) throws SlickException { String definition; try { definition = r.readLine(); while (definition != null) { String[] defInfo = definition.split(":"); Class<? extends Entity> clas; clas = ModLoader.loadClass(defInfo[0]).asSubclass(Entity.class); Entity e = clas.newInstance().makeFromString(target, defInfo); target.placeEntity(e.getLocation(), e, e.getLayer()); definition = r.readLine(); } } catch (IOException e) { throw new SlickException("unable to load files for save", e); } catch (InstantiationException e) { throw new SlickException("unable to Instanciate class", e); } catch (IllegalAccessException e) { throw new SlickException("Dafuq is you doing?", e); } }