public object Clone() { var ret = new CardPropertySet() { Type = this.Type.Clone() as string, Properties = this.Properties.ToDictionary( x => x.Key.Clone() as PropertyDef, x => x.Value) }; return ret; }
public object Clone() { var ret = new CardPropertySet() { Type = this.Type.Clone() as string, Properties = this.Properties.ToDictionary( x => x.Key.Clone() as PropertyDef, x => x.Value) }; return(ret); }
public object Clone() { var ret = new CardPropertySet() { Name = this.Name.Clone() as string, Type = this.Type.Clone() as string, Size = this.Size as CardSize, Properties = this.Properties.ToDictionary( x => x.Key, x => x.Value) }; return(ret); }
public object Deserialize(string fileName) { //var timer = new Stopwatch(); //timer.Start(); var ret = new Set(); var directory = new FileInfo(fileName).Directory.FullName; using (var fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { var settings = new XmlReaderSettings(); settings.Schemas.Add(SetSchema); var doc = XDocument.Load(fs); doc.Validate(settings.Schemas, (a, b) => { Console.WriteLine(b.Exception); }); ret.Cards = new List<Card>(); var root = doc.Element("set"); ret.Id = new Guid(root.Attribute("id").Value); ret.Name = root.Attribute("name").Value; ret.Filename = fileName; ret.GameId = new Guid(root.Attribute("gameId").Value); ret.Cards = new List<Card>(); ret.GameVersion = new Version(root.Attribute("gameVersion").Value); ret.Markers = new List<Marker>(); ret.Packs = new List<Pack>(); ret.Version = new Version(root.Attribute("version").Value); ret.PackageName = ""; ret.InstallPath = directory; ret.DeckPath = Path.Combine(ret.InstallPath, "Decks"); ret.PackUri = Path.Combine(ret.InstallPath, "Cards"); var gameImageInstallPath = Path.Combine(Config.Instance.Paths.ImageDatabasePath, ret.GameId.ToString()); ret.ImageInstallPath = Path.Combine(gameImageInstallPath, "Sets", ret.Id.ToString()); ret.ImagePackUri = Path.Combine(ret.ImageInstallPath, "Cards"); ret.ProxyPackUri = Path.Combine(ret.ImagePackUri, "Proxies"); if (!Directory.Exists(ret.PackUri)) Directory.CreateDirectory(ret.PackUri); if (!Directory.Exists(ret.ImagePackUri)) Directory.CreateDirectory(ret.ImagePackUri); if (!Directory.Exists(ret.ProxyPackUri)) Directory.CreateDirectory(ret.ProxyPackUri); var game = DbContext.Get().Games.First(x => x.Id == ret.GameId); foreach (var c in doc.Document.Descendants("card")) { var card = new Card(new Guid(c.Attribute("id").Value), ret.Id, c.Attribute("name").Value,c.Attribute("id").Value, "",game.CardSizes["Default"],new Dictionary<string, CardPropertySet>()); //var card = new Card // { // Id = new Guid(c.Attribute("id").Value), // Name = c.Attribute("name").Value, // SetId = ret.Id, // Properties = new Dictionary<string, CardPropertySet>(), // ImageUri = c.Attribute("id").Value, // Alternate = "", // Size = game.CardSizes["Default"] // }; var cs = c.Attribute("size"); if (cs != null) { if(game.CardSizes.ContainsKey(cs.Value) == false) throw new UserMessageException(Octgn.Library.Localization.L.D.Exception__BrokenGameContactDev_Format, game.Name); card.Size = game.CardSizes[cs.Value]; } var defaultProperties = new CardPropertySet(); defaultProperties.Type = ""; defaultProperties.Properties = new Dictionary<PropertyDef, object>(); foreach (var p in c.Descendants("property").Where(x => x.Parent.Name == "card")) { var pd = game.CustomProperties.FirstOrDefault(x => x.Name == p.Attribute("name").Value); if (pd == null) { throw new UserMessageException(Octgn.Library.Localization.L.D.Exception__BrokenGameContactDev_Format, game.Name); } var newpd = pd.Clone() as PropertyDef; defaultProperties.Properties.Add(newpd, p.Attribute("value").Value); } foreach (var cp in game.CustomProperties) { if (!defaultProperties.Properties.ContainsKey(cp)) { var cpnew = cp.Clone() as PropertyDef; cpnew.IsUndefined = true; defaultProperties.Properties.Add(cpnew, ""); } } var np = new PropertyDef() { Hidden = false, Name = "Name", Type = PropertyType.String, TextKind = PropertyTextKind.FreeText, IgnoreText = false, IsUndefined = false }; if (defaultProperties.Properties.ContainsKey(np)) defaultProperties.Properties.Remove(np); defaultProperties.Properties.Add(np, card.Name); card.Properties.Add("", defaultProperties); // Add all of the other property sets foreach (var a in c.Descendants("alternate")) { var propset = new CardPropertySet(); propset.Properties = new Dictionary<PropertyDef, object>(); propset.Type = a.Attribute("type").Value; var thisName = a.Attribute("name").Value; foreach (var p in a.Descendants("property")) { var pd = game.CustomProperties.First(x => x.Name.Equals(p.Attribute("name").Value, StringComparison.InvariantCultureIgnoreCase)); var newprop = pd.Clone() as PropertyDef; var val = p.Attribute("value").Value; propset.Properties.Add(newprop, val); } foreach (var cp in game.CustomProperties) { if (!propset.Properties.ContainsKey(cp)) { var cpnew = cp.Clone() as PropertyDef; cpnew.IsUndefined = true; propset.Properties.Add(cpnew, ""); } } var np2 = new PropertyDef() { Hidden = false, Name = "Name", Type = PropertyType.String, TextKind = PropertyTextKind.FreeText, IgnoreText = false, IsUndefined = false }; if (propset.Properties.ContainsKey(np2)) propset.Properties.Remove(np2); propset.Properties.Add(np2, thisName); card.Properties.Add(propset.Type, propset); } (ret.Cards as List<Card>).Add(card); } foreach (var p in doc.Document.Descendants("pack")) { var pack = new Pack(); pack.Id = new Guid(p.Attribute("id").Value); pack.Name = p.Attribute("name").Value; pack.Definition = DeserializePack(p.Elements()); pack.SetId = ret.Id; (ret.Packs as List<Pack>).Add(pack); } foreach (var m in doc.Document.Descendants("marker")) { var marker = new Marker(); marker.Id = new Guid(m.Attribute("id").Value); marker.Name = m.Attribute("name").Value; var mpathd = new DirectoryInfo(Path.Combine(directory, "Markers")); var mpath = mpathd.Exists == false ? null : mpathd.GetFiles(marker.Id.ToString() + ".*", SearchOption.TopDirectoryOnly).First(); marker.IconUri = mpath == null ? null : Path.Combine(directory, "Markers", mpath.FullName); (ret.Markers as List<Marker>).Add(marker); } } if (ret.Cards == null) ret.Cards = new Card[0]; if (ret.Markers == null) ret.Markers = new Marker[0]; if (ret.Packs == null) ret.Packs = new Pack[0]; //Console.WriteLine(timer.ElapsedMilliseconds); return ret; }