PIbd-22_Shabunov_O.A._AirBo.../AirBomber/Rendering/ExtensionBomberRenderer.cs

57 lines
1.8 KiB
C#
Raw Normal View History

using AirBomber.Entities;
namespace AirBomber.Rendering
{
public static class ExtensionBomberRenderer
{
public static BomberRendererBase? DeserializeRenderer(this string Info, char Delimiter, int Width, int Height)
{
string[] Properties = Info.Split(Delimiter);
if (Properties.Length == 3)
{
return new BomberRendererBase(
Convert.ToInt32(Properties[0]),
Convert.ToInt32(Properties[1]),
Color.FromName(Properties[2]),
Width,
Height
);
}
if (Properties.Length == 6)
{
return new BomberRenderer(
Convert.ToInt32(Properties[0]),
Convert.ToInt32(Properties[1]),
Color.FromName(Properties[2]),
Color.FromName(Properties[3]),
Convert.ToBoolean(Properties[4]),
Convert.ToBoolean(Properties[5]),
Width,
Height
);
}
return null;
}
public static string SerializeRenderer(this BomberRendererBase Renderer, char Delimiter)
{
var Bomber = Renderer.EntityBomber;
if (Bomber is null)
return string.Empty;
string ResultString = string.Empty;
ResultString += $"{Bomber.Speed}{Delimiter}{Bomber.Weight}{Delimiter}{Bomber.BodyColor.Name}";
if (Bomber is BomberEntity AdvancedBomber)
ResultString += $"{Delimiter}{AdvancedBomber.AdditionalColor.Name}" +
$"{Delimiter}{AdvancedBomber.Bombs}{Delimiter}{AdvancedBomber.FuelTanks}";
return ResultString;
}
}
}