Добавлено расширение ExtensionArtillery
This commit is contained in:
parent
c141d70193
commit
07f2ccc482
49
SelfPropelledArtilleryUnit/ExtensionArtillery.cs
Normal file
49
SelfPropelledArtilleryUnit/ExtensionArtillery.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artilleries {
|
||||
internal static class ExtensionArtillery
|
||||
{
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
public static DrawingArtillery CreateDrawingArtillery(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingArtillery(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawingAdvancedArtillery(
|
||||
Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5])
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetDateForSave(this DrawingArtillery drawingArtillery)
|
||||
{
|
||||
var artillery = drawingArtillery.Artillery;
|
||||
var str = $"{artillery.Speed}{_separatorForObject}{artillery.Weight}{_separatorForObject}{artillery.BodyColor.Name}";
|
||||
|
||||
if (artillery is not EntityAdvancedArtillery advanced)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return $"{str}{_separatorForObject}{advanced.DopColor.Name}{_separatorForObject}{advanced.Weapon}{_separatorForObject}{advanced.SalvoBattery}";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user