Final
This commit is contained in:
parent
1e46cc1b61
commit
630bffbbe6
@ -51,7 +51,7 @@ public class ExtensionBus {
|
|||||||
public static String GetDataForSave(DrawingBus drawingBus)
|
public static String GetDataForSave(DrawingBus drawingBus)
|
||||||
{
|
{
|
||||||
var bus = drawingBus.Bus;
|
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));;
|
drawingBus._countOfDoors, CreateDoors(drawingBus.Doors));;
|
||||||
if (!(bus instanceof EntityDDB ddb))
|
if (!(bus instanceof EntityDDB ddb))
|
||||||
{
|
{
|
||||||
|
@ -171,7 +171,10 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
|||||||
public void LoadData(String data)
|
public void LoadData(String data)
|
||||||
{
|
{
|
||||||
_setBuses.Insert((T)(DrawingObjectBus.Create(data)));
|
_setBuses.Insert((T)(DrawingObjectBus.Create(data)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear() {
|
||||||
|
_setBuses.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,8 @@ import java.io.*;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class MapsCollection {
|
public class MapsCollection {
|
||||||
HashMap<String, MapWithSetBusesGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
HashMap<String, MapWithSetBusesGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||||
@ -86,6 +85,13 @@ public class MapsCollection {
|
|||||||
return true;
|
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
|
public boolean SaveStorage(String filename, String key) throws IOException
|
||||||
{
|
{
|
||||||
Files.deleteIfExists(Paths.get(filename));
|
Files.deleteIfExists(Paths.get(filename));
|
||||||
@ -95,11 +101,15 @@ public class MapsCollection {
|
|||||||
{
|
{
|
||||||
writer.write("MapsCollectionStorage" + System.lineSeparator());
|
writer.write("MapsCollectionStorage" + System.lineSeparator());
|
||||||
MapWithSetBusesGeneric<IDrawingObject, AbstractMap> storage = _mapStorages.get(key);
|
MapWithSetBusesGeneric<IDrawingObject, AbstractMap> storage = _mapStorages.get(key);
|
||||||
|
if (storage == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
String[] data = storage.GetData(separatorDict, separatorData).split("\\|");
|
String[] data = storage.GetData(separatorDict, separatorData).split("\\|");
|
||||||
|
|
||||||
writer.write(key + ":" + data[0] + System.lineSeparator());
|
writer.write(key + ":" + data[0] + System.lineSeparator());
|
||||||
for (var bus : data[1].split(";")) {
|
var buses = data[1].split(";");
|
||||||
writer.write(bus);
|
for (int i = buses.length - 1; i >= 0; i--) {
|
||||||
|
writer.write(buses[i]);
|
||||||
writer.write(System.lineSeparator());
|
writer.write(System.lineSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +133,6 @@ public class MapsCollection {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!str.contains("MapsCollectionStorage")) {
|
if (!str.contains("MapsCollectionStorage")) {
|
||||||
_mapStorages.clear();
|
|
||||||
while ((str = reader.readLine()) != null) {
|
while ((str = reader.readLine()) != null) {
|
||||||
String[] elem = str.split(String.format("\\%c", separatorDict));
|
String[] elem = str.split(String.format("\\%c", separatorDict));
|
||||||
AbstractMap map = switch (elem[1]) {
|
AbstractMap map = switch (elem[1]) {
|
||||||
@ -131,23 +140,26 @@ public class MapsCollection {
|
|||||||
case "WaterMap" -> new WaterMap();
|
case "WaterMap" -> new WaterMap();
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
_mapStorages.put(elem[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map));
|
|
||||||
if (elem.length == 3) {
|
if (elem.length == 3) {
|
||||||
|
|
||||||
_mapStorages.get(elem[0]).LoadData(elem[2].split(String.format("%c", separatorData)));
|
_mapStorages.get(elem[0]).LoadData(elem[2].split(String.format("%c", separatorData)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String[] data = reader.readLine().split(":");
|
String[] data = reader.readLine().split(":");
|
||||||
if (_mapStorages.containsKey(data[0])) {
|
|
||||||
_mapStorages.remove(data[0]);
|
|
||||||
}
|
|
||||||
AbstractMap map = switch (data[1]) {
|
AbstractMap map = switch (data[1]) {
|
||||||
case "SimpleMap" -> new SimpleMap();
|
case "SimpleMap" -> new SimpleMap();
|
||||||
case "WaterMap" -> new WaterMap();
|
case "WaterMap" -> new WaterMap();
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
|
if (_mapStorages.containsKey(data[0])) {
|
||||||
|
_mapStorages.get(data[0]).Clear();
|
||||||
|
}
|
||||||
|
else {
|
||||||
_mapStorages.put(data[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map));
|
_mapStorages.put(data[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
String k = reader.readLine();
|
String k = reader.readLine();
|
||||||
while (k != null) {
|
while (k != null) {
|
||||||
_mapStorages.get(data[0]).LoadData(k);
|
_mapStorages.get(data[0]).LoadData(k);
|
||||||
|
@ -59,6 +59,10 @@ class SetBusesGeneric<T> {
|
|||||||
public int Count() {
|
public int Count() {
|
||||||
return _places.size();
|
return _places.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear() {
|
||||||
|
_places.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user