This commit is contained in:
shadowik 2022-12-18 16:07:38 +04:00
parent 1e46cc1b61
commit 630bffbbe6
4 changed files with 31 additions and 12 deletions

View File

@ -51,7 +51,7 @@ public class ExtensionBus {
public static String GetDataForSave(DrawingBus drawingBus)
{
var bus = drawingBus.Bus;
var str = String.format("%d:%f:%s:%d:%s", drawingBus._speed, drawingBus._weight, drawingBus._bodyColor.toString(),
var str = String.format("%d:%f:%s:%d:%s", bus.Speed, bus.Weight, bus.BodyColor.toString(),
drawingBus._countOfDoors, CreateDoors(drawingBus.Doors));;
if (!(bus instanceof EntityDDB ddb))
{

View File

@ -171,7 +171,10 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
public void LoadData(String data)
{
_setBuses.Insert((T)(DrawingObjectBus.Create(data)));
}
public void Clear() {
_setBuses.Clear();
}
}

View File

@ -7,9 +7,8 @@ import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.*;
public class MapsCollection {
HashMap<String, MapWithSetBusesGeneric<IDrawingObject, AbstractMap>> _mapStorages;
@ -86,6 +85,13 @@ public class MapsCollection {
return true;
}
static String[] reverse(String myArray[])
{
Collections.reverse(Arrays.asList(myArray));
return (String[]) Arrays.stream(myArray).toArray();
}
public boolean SaveStorage(String filename, String key) throws IOException
{
Files.deleteIfExists(Paths.get(filename));
@ -95,11 +101,15 @@ public class MapsCollection {
{
writer.write("MapsCollectionStorage" + System.lineSeparator());
MapWithSetBusesGeneric<IDrawingObject, AbstractMap> storage = _mapStorages.get(key);
if (storage == null) {
return false;
}
String[] data = storage.GetData(separatorDict, separatorData).split("\\|");
writer.write(key + ":" + data[0] + System.lineSeparator());
for (var bus : data[1].split(";")) {
writer.write(bus);
var buses = data[1].split(";");
for (int i = buses.length - 1; i >= 0; i--) {
writer.write(buses[i]);
writer.write(System.lineSeparator());
}
@ -123,7 +133,6 @@ public class MapsCollection {
return false;
}
if (!str.contains("MapsCollectionStorage")) {
_mapStorages.clear();
while ((str = reader.readLine()) != null) {
String[] elem = str.split(String.format("\\%c", separatorDict));
AbstractMap map = switch (elem[1]) {
@ -131,23 +140,26 @@ public class MapsCollection {
case "WaterMap" -> new WaterMap();
default -> null;
};
_mapStorages.put(elem[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map));
if (elem.length == 3) {
_mapStorages.get(elem[0]).LoadData(elem[2].split(String.format("%c", separatorData)));
}
}
}
else {
String[] data = reader.readLine().split(":");
if (_mapStorages.containsKey(data[0])) {
_mapStorages.remove(data[0]);
}
AbstractMap map = switch (data[1]) {
case "SimpleMap" -> new SimpleMap();
case "WaterMap" -> new WaterMap();
default -> null;
};
if (_mapStorages.containsKey(data[0])) {
_mapStorages.get(data[0]).Clear();
}
else {
_mapStorages.put(data[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map));
}
String k = reader.readLine();
while (k != null) {
_mapStorages.get(data[0]).LoadData(k);

View File

@ -59,6 +59,10 @@ class SetBusesGeneric<T> {
public int Count() {
return _places.size();
}
public void Clear() {
_places.clear();
}
}