55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using Monorail.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Monorail.DrawningObjects
|
|
{
|
|
public static class ExtentionDrawningMonorail
|
|
{
|
|
public static DrawningMonorail? CreateDrawningMonorail(this string info, char separatorForObject,
|
|
int width, int height)
|
|
{
|
|
string[] strs = info.Split(separatorForObject);
|
|
if(strs.Length == 5)
|
|
{
|
|
return new DrawningMonorail(Convert.ToInt32(strs[0]),
|
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]),
|
|
Color.FromName(strs[4]), width, height);
|
|
}
|
|
if (strs.Length == 9)
|
|
{
|
|
return new DrawningLocomotive(Convert.ToInt32(strs[0]),
|
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]),
|
|
Color.FromName(strs[4]), width, height, Convert.ToInt32(strs[5]),
|
|
Color.FromName(strs[6]), Convert.ToBoolean(strs[7]), Convert.ToBoolean(strs[8]));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static string GetDataForSave(this DrawningMonorail drawningMonorail, char separatorForObject)
|
|
{
|
|
var monorail = drawningMonorail.EntityMonorail;
|
|
if(monorail == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
var str = $"{monorail.Speed}{separatorForObject}{monorail.Weight}{separatorForObject}{monorail.BodyColor.Name}{separatorForObject}" +
|
|
$"{monorail.WheelColor.Name}{separatorForObject}{monorail.TireColor.Name}";
|
|
if (monorail is not EntityLocomotive locomotive)
|
|
{
|
|
return str;
|
|
}
|
|
return
|
|
$"{str}{separatorForObject}{locomotive.AddWheelsNumb}{separatorForObject}{locomotive.AdditionalColor.Name}" +
|
|
$"{separatorForObject}{locomotive.SecondCabine}{separatorForObject}{locomotive.MagniteRail}";
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|