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}"; } } }