Исправления загрузки построчно
This commit is contained in:
parent
8768836c29
commit
99886df933
@ -118,47 +118,40 @@ namespace ArmoredCar
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Файл не найден");
|
||||
}
|
||||
string bufferTextFromFile = "";
|
||||
using (StreamReader fs = new(filename))
|
||||
{
|
||||
|
||||
if (!fs.ReadLine().Contains("MapsCollection"))
|
||||
//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
string? line;
|
||||
//очищаем записи
|
||||
_mapStorages.Clear();
|
||||
while ((line = fs.ReadLine()) != null)
|
||||
{
|
||||
bufferTextFromFile += line + "\r\n";
|
||||
bufferTextFromFile += line;
|
||||
var elem = line.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "MyMapLabirinth":
|
||||
map = new MyMapLabirinth();
|
||||
break;
|
||||
case "MyMapWooden":
|
||||
map = new MyMapWooden();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetArmoredCarsGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (!strs[0].Contains("MapsCollection"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
}
|
||||
//очищаем записи
|
||||
_mapStorages.Clear();
|
||||
for (int i = 1; i < strs.Length; ++i)
|
||||
{
|
||||
var elem = strs[i].Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "MyMapLabirinth":
|
||||
map = new MyMapLabirinth();
|
||||
break;
|
||||
case "MyMapWooden":
|
||||
map = new MyMapWooden();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetArmoredCarsGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user