diff --git a/MapsCollection.java b/MapsCollection.java index 1459e92..0c666b0 100644 --- a/MapsCollection.java +++ b/MapsCollection.java @@ -80,7 +80,11 @@ public class MapsCollection { } try(BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) { bw.write("SingleMap\n"); - bw.write("" + map_name + separatorDict +map.GetData(separatorDict.charAt(0), separatorData) + "\n"); + bw.write("" + map_name + "\n"); + bw.write("" + map.getClass() + "\n"); + for (var locomotive : map._setLocomotives.GetLocomotives()) { + bw.write("" + locomotive.getInfo() + "\n"); + } } catch (IOException ex) { System.out.println(ex.getMessage()); @@ -101,16 +105,18 @@ public class MapsCollection { if (!curLine.contains("SingleMap")) { return false; } - - curLine = br.readLine(); - var elems = curLine.split(separatorDict); - if (_mapStorages.containsKey(elems[0])) { - _mapStorages.get(elems[0])._setLocomotives.Clear(); - _mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); + String mapName = br.readLine(); + String mapClass = br.readLine(); + if (_mapStorages.containsKey(mapName)) { + _mapStorages.get(mapName)._setLocomotives.Clear(); + while((curLine = br.readLine()) != null) { + _mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine)); + } + _mapStorages.get(mapName)._setLocomotives.ReversePlaces(); return true; } AbstractMap map = null; - switch (elems[1]) + switch (mapClass) { case "class SimpleMap": map = new SimpleMap(); @@ -122,8 +128,11 @@ public class MapsCollection { map = new RailMap(); break; } - _mapStorages.put(elems[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); + _mapStorages.put(mapName, new MapWithSetLocomotivesGeneric<>(_pictureWidth, _pictureHeight, map)); + while((curLine = br.readLine()) != null) { + _mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine)); + } + _mapStorages.get(mapName)._setLocomotives.ReversePlaces(); } catch (IOException ex) { System.out.println(ex.getMessage()); diff --git a/SetLocomotivesGeneric.java b/SetLocomotivesGeneric.java index 9aff477..07fee4a 100644 --- a/SetLocomotivesGeneric.java +++ b/SetLocomotivesGeneric.java @@ -1,4 +1,5 @@ import java.util.ArrayList; +import java.util.Collections; public class SetLocomotivesGeneric { @@ -50,4 +51,7 @@ public class SetLocomotivesGeneric { return _places; } + public void ReversePlaces() { + Collections.reverse(_places); + } }