Обновлен класс PlanesGenericStorage

This commit is contained in:
Никита Потапов 2023-12-16 23:47:18 +04:00
parent 83e8f8850c
commit ac3e17579d
2 changed files with 36 additions and 10 deletions

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormtrooper
{
public class PlanesCollectionInfo : IEquatable<PlanesCollectionInfo>
{
public string Name { get; private set; }
public string Description { get; private set; }
public PlanesCollectionInfo(string name, string description)
{
Name = name;
Description = description;
}
public bool Equals(PlanesCollectionInfo? other)
{
return Name.Equals(other.Name);
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ProjectStormtrooper
{
@ -23,11 +24,11 @@ namespace ProjectStormtrooper
/// <summary>
/// Словарь (хранилище)
/// </summary>
readonly Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
readonly Dictionary<PlanesCollectionInfo, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<string> Keys => _planeStorages.Keys.ToList();
public List<PlanesCollectionInfo> Keys => _planeStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -43,7 +44,7 @@ namespace ProjectStormtrooper
/// <param name="pictureHeight"></param>
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
{
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>>();
_planeStorages = new Dictionary<PlanesCollectionInfo, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@ -53,7 +54,7 @@ namespace ProjectStormtrooper
/// <param name="name">Название набора</param>
public void AddSet(string name)
{
_planeStorages.Add(name, new PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>(_pictureWidth, _pictureHeight));
_planeStorages.Add(new PlanesCollectionInfo(name, ""), new PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>(_pictureWidth, _pictureHeight));
}
/// <summary>
/// Удаление набора
@ -61,8 +62,9 @@ namespace ProjectStormtrooper
/// <param name="name">Название набора</param>
public void DelSet(string name)
{
if (_planeStorages.ContainsKey(name))
_planeStorages.Remove(name);
var info = new PlanesCollectionInfo(name, "");
if (_planeStorages.ContainsKey(info))
_planeStorages.Remove(info);
}
/// <summary>
/// Доступ к набору
@ -73,8 +75,9 @@ namespace ProjectStormtrooper
{
get
{
if (_planeStorages.ContainsKey(ind))
return _planeStorages[ind];
var info = new PlanesCollectionInfo(ind, "");
if (_planeStorages.ContainsKey(info))
return _planeStorages[info];
return null;
}
}
@ -104,7 +107,7 @@ namespace ProjectStormtrooper
{
throw new Exception("Невалиданя операция, нет данных для сохранения");
}
sw.WriteLine($"{storage.Key}{_separatorForKeyValue}{storageString}");
sw.WriteLine($"{storage.Key.Name}{_separatorForKeyValue}{storageString}");
}
}
}
@ -152,7 +155,7 @@ namespace ProjectStormtrooper
}
}
}
_planeStorages.Add(record[0], collection);
_planeStorages.Add(new PlanesCollectionInfo(record[0], ""), collection);
currentLine = sr.ReadLine();
}
}