PIbd-22_Kurbanova_A.A.Warml.../WarmlyLocomotive/ExtentionDrawningWarmlyLocomotive.cs
2023-12-23 13:58:32 +04:00

45 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarmlyLocomotive.DrawningObjects;
using WarmlyLocomotive.Entities;
namespace WarmlyLocomotive.DrawningObjects
{
public static class ExtentionDrawningWarmlyLocomotive
{
public static DrawningWarmlyLocomotive? CreateDrawningWarmlyLocomotive(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawningWarmlyLocomotive(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 6)
{
return new DrawningWarmlyLocomotiveWithTrumpet(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 DrawningWarmlyLocomotive drawningwarmlylocomotive, char separatorForObject)
{
var warmlylocomotive = drawningwarmlylocomotive.EntityWarmlyLocomotive;
if (warmlylocomotive == null)
{
return string.Empty;
}
var str = $"{warmlylocomotive.Speed}{separatorForObject}{warmlylocomotive.Weight}{separatorForObject}{warmlylocomotive.BodyColor.Name}";
if (warmlylocomotive is not EntityWarmlyLocomotiveWithTrumpet warmlyLocomotiveWithTrumpet)
{
return str;
}
return
$"{str}{separatorForObject}{warmlyLocomotiveWithTrumpet.AdditionalColor.Name}{separatorForObject}{warmlyLocomotiveWithTrumpet.Trumpet}" +
$"{separatorForObject}{warmlyLocomotiveWithTrumpet.Luggage}";
}
}
}