зафиксировать всё
This commit is contained in:
parent
18cfa60a37
commit
41542e271d
54
ProjectBoat_base/ProjectBoat_bae/ExtentionBoat.cs
Normal file
54
ProjectBoat_base/ProjectBoat_bae/ExtentionBoat.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using ProjectBoat_bae.DrawningObjects;
|
||||
using ProjectBoat_bae.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBoat_bae
|
||||
{
|
||||
public static class ExtentionBoat
|
||||
{
|
||||
// Разделитель для записи информации по объекту в файл
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
// Создание объекта из строки
|
||||
public static Drawningboat CreateDrawningBoat(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new Drawningboat(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawningMotorBoat(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningCar"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDataForSave(this DrawningBoat drawningBoat)
|
||||
{
|
||||
var boat = drawningBoat.Boat;
|
||||
var str =
|
||||
$"{boat.Speed}{_separatorForObject}{boat.Weight}{_separatorForObject}{boat.BodyColor.Name}";
|
||||
if (boat is not EntityMotorBoat motorBoat)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{_separatorForObject}{motorBoat.DopColor.Name}{_separatorForObject}{motorBoat.BodyKit}{_separatorForObject}{motorBoat.Wing}{_separatorForObject}{motorBoat.SportLine}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user