49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
|
using ProjectBulldozer.Drawning;
|
|||
|
using ProjectBulldozer.Entities;
|
|||
|
namespace ProjectBulldozer.Drawing
|
|||
|
{
|
|||
|
public static class ExtentionDrawingTractor
|
|||
|
{
|
|||
|
public static DrawingTractor? CreateDrawingTractor(this string info,
|
|||
|
char separatorForObject, int width, int height)
|
|||
|
{
|
|||
|
string[] strs = info.Split(separatorForObject);
|
|||
|
if (strs.Length == 3)
|
|||
|
{
|
|||
|
return new DrawingTractor(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
|
|||
|
Color.FromName(strs[2]), width, height);
|
|||
|
}
|
|||
|
if (strs.Length == 7)
|
|||
|
{
|
|||
|
return new DrawingBulldozer(Convert.ToInt32(strs[0]),
|
|||
|
Convert.ToInt32(strs[1]),
|
|||
|
Color.FromName(strs[2]),
|
|||
|
Color.FromName(strs[3]),
|
|||
|
Convert.ToBoolean(strs[4]),
|
|||
|
Convert.ToBoolean(strs[5]),
|
|||
|
width, height);
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
public static string GetDataForSave(this DrawingTractor drawingTractor,
|
|||
|
char separatorForObject)
|
|||
|
{
|
|||
|
var tractor = drawingTractor.EntityTractor;
|
|||
|
if (tractor == null)
|
|||
|
{
|
|||
|
return string.Empty;
|
|||
|
}
|
|||
|
var str =
|
|||
|
$"{tractor.Speed}{separatorForObject}{tractor.Weight}{separatorForObject}{tractor.BodyColor.Name}";
|
|||
|
if (tractor is not EntityBulldozer bulldozer)
|
|||
|
{
|
|||
|
return str;
|
|||
|
}
|
|||
|
return
|
|||
|
$"{str}{separatorForObject}{bulldozer.AdditionalColor.Name}{separatorForObject}" +
|
|||
|
$"{bulldozer.ThirdWheel}{separatorForObject}{bulldozer.Otval}{separatorForObject}";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|