示例#1
0
文件: Alternate.cs 项目: wlk0/OCTGN
        public AlternateModel(AlternateModel a, IdeCollection <IdeBaseItem> source) : base(source) //for copying the item
        {
            _altDef = new CardPropertySet()
            {
                Size       = a._altDef.Size,
                Properties = a._altDef.Properties.ToDictionary(x => x.Key, x => x.Value),
                Name       = a.Name
            };
            Type  = a.Type;
            Items = new IdeCollection <CardPropertyModel>(this);
            Items.CollectionChanged += (c, b) =>
            {
                BuildAltDef(b);
            };
            foreach (var prop in _altDef.Properties)
            {
                Items.Add(new CardPropertyModel
                {
                    Property   = ViewModelLocator.PropertyTabViewModel.Items.First(y => (y as PropertyItemModel)._property.Equals(prop.Key)) as PropertyItemModel,
                    _value     = prop.Value,
                    _isDefined = prop.Value != null,
                    Parent     = this
                });
            }

            DeleteImageCommand = new RelayCommand(DeleteImage);
            Messenger.Default.Register <CustomPropertyChangedMessage>(this, action => CustomPropertyChanged(action));
            Messenger.Default.Register <CardSizeChangedMesssage>(this, action => CardSizeChanged(action));
        }
示例#2
0
        public AltItemModel(CardPropertySet props) //for loading an existing collection
        {
            _altCard   = props;
            CardSize   = ViewModelLocator.SizeTabViewModel.Items.FirstOrDefault(x => props.Size == x._size) ?? ViewModelLocator.SizeTabViewModel.Items.First(x => x.Default);
            Properties = new ObservableCollection <CardPropertyItemModel>(props.Properties.Where(x => x.Key.Name != "Name").Select(x => new CardPropertyItemModel(x.Key, x.Value)
            {
                _alt = this
            }));

            AltTypeVisibility = (Alt == "") ? Visibility.Collapsed : Visibility.Visible;
        }
示例#3
0
 public AltItemModel(AltItemModel a) //for copying the item
 {
     _altCard      = a._altCard.Clone() as CardPropertySet;
     _altCard.Type = Guid.NewGuid().ToString();
     ParentCard    = a.ParentCard;
     CardSize      = a.CardSize;
     Properties    = new ObservableCollection <CardPropertyItemModel>(_altCard.Properties.Where(x => x.Key.Name != "Name").Select(x => new CardPropertyItemModel(x.Key, x.Value)
     {
         _alt = this
     }));
     AltTypeVisibility = Visibility.Visible;
 }
示例#4
0
        public AlternateModel(CardPropertySet altData, IdeCollection <IdeBaseItem> source) : base(source) //for loading an existing collection
        {
            _altDef = altData;

            //    foreach (var prop in altData.Properties)
            //    {
            //        Items.Add(new CardPropertyModel(this, ViewModelLocator.PropertyTabViewModel.Items.First(x => (x as PropertyItemModel)._property.Equals(prop.Key)) as PropertyItemModel));
            //    }

            DeleteImageCommand = new RelayCommand(DeleteImage);
            //   Messenger.Default.Register<CustomPropertyChangedMessage>(this, action => CustomPropertyChanged(action));
            Messenger.Default.Register <CardSizeChangedMesssage>(this, action => CardSizeChanged(action));
        }
示例#5
0
        public AlternateModel(AlternateModel a, IdeCollection <IdeBaseItem> source) : base(source) //for copying the item
        {
            _altDef = new CardPropertySet()
            {
                Size       = a._altDef.Size,
                Properties = a._altDef.Properties.ToDictionary(x => x.Key, x => x.Value),
                Name       = a.Name
            };
            Type = a.Type;

            DeleteImageCommand = new RelayCommand(DeleteImage);
            //  Messenger.Default.Register<CustomPropertyChangedMessage>(this, action => CustomPropertyChanged(action));
            Messenger.Default.Register <CardSizeChangedMesssage>(this, action => CardSizeChanged(action));
        }
示例#6
0
        public AlternateModel(IdeCollection <IdeBaseItem> source) : base(source) //for adding new items
        {
            _altDef = new CardPropertySet
            {
                Properties = new Dictionary <PropertyDef, object>(),
                Size       = ((SizeItemModel)CardSizes.DefaultItem)._size,
                Name       = "Card",
            };
            Type = "";

            DeleteImageCommand = new RelayCommand(DeleteImage);
            //     Messenger.Default.Register<CustomPropertyChangedMessage>(this, action => CustomPropertyChanged(action));
            Messenger.Default.Register <CardSizeChangedMesssage>(this, action => CardSizeChanged(action));
        }
 public SetCardAltItemViewModel(CardPropertySet altData) //for loading an existing collection
 {
     DeleteImageCommand = new RelayCommand(DeleteImage);
     _altDef            = altData;
     CardSize           = (SizeItemViewModel)ViewModelLocator.PreviewTabViewModel.CardSizes.FirstOrDefault(x => altData.Size == (x as SizeItemViewModel)._size) ?? ViewModelLocator.PreviewTabViewModel.DefaultSize;
     Items = new ObservableCollection <CardPropertyItemModel>();
     Items.CollectionChanged += (a, b) =>
     {
         UpdateAltPropertySet();
     };
     foreach (var alt in altData.Properties)
     {
         var LinkedProperty = ViewModelLocator.PropertyTabViewModel.Items.First(x => (x as PropertyItemViewModel).Name == alt.Key.Name) as PropertyItemViewModel;
         Items.Add(new CardPropertyItemModel(LinkedProperty, alt, this));
     }
     //  UpdateProxyTemplate();
 }
示例#8
0
文件: Alternate.cs 项目: wlk0/OCTGN
 public AlternateModel(IdeCollection <IdeBaseItem> source) : base(source) //for adding new items
 {
     _altDef = new CardPropertySet
     {
         Properties = new Dictionary <PropertyDef, object>(),
         Size       = ((SizeItemModel)CardSizes.DefaultItem)._size,
         Name       = "Card",
     };
     Type  = (Source.Count == 0) ? "" : "alt";
     Items = new ObservableCollection <CardPropertyModel>();
     Items.CollectionChanged += (a, b) =>
     {
         BuildAltDef(b);
     };
     DeleteImageCommand = new RelayCommand(DeleteImage);
     Messenger.Default.Register <CustomPropertyChangedMessage>(this, action => CustomPropertyChanged(action));
     Messenger.Default.Register <CardSizeChangedMesssage>(this, action => CardSizeChanged(action));
 }
 public SetCardAltItemViewModel(SetCardAltItemViewModel a) //for copying the item
 {
     DeleteImageCommand = new RelayCommand(DeleteImage);
     Parent             = a.Parent;
     ItemSource         = a.ItemSource;
     _altDef            = a._altDef.Clone() as CardPropertySet;
     _altDef.Type       = Utils.GetUniqueName(a.Name, a.ItemSource.Select(x => (x as SetCardAltItemViewModel).Name));
     CardSize           = a.CardSize;
     Items = new ObservableCollection <CardPropertyItemModel>();
     Items.CollectionChanged += (x, b) =>
     {
         UpdateAltPropertySet();
     };
     foreach (var alt in _altDef.Properties)
     {
         var LinkedProperty = ViewModelLocator.PropertyTabViewModel.Items.First(x => (x as PropertyItemViewModel).Name == alt.Key.Name) as PropertyItemViewModel;
         Items.Add(new CardPropertyItemModel(LinkedProperty, alt, this));
     }
     // UpdateProxyTemplate();
 }
        public SetCardAltItemViewModel() //for adding new items
        {
            DeleteImageCommand = new RelayCommand(DeleteImage);

            _altDef = new CardPropertySet
            {
                Properties = new Dictionary <PropertyDef, object>(),
            };
            CardSize = ViewModelLocator.PreviewTabViewModel.DefaultSize;
            Items    = new ObservableCollection <CardPropertyItemModel>();
            Items.CollectionChanged += (a, b) =>
            {
                UpdateAltPropertySet();
            };
            Items.Add(new CardPropertyItemModel(ViewModelLocator.PropertyTabViewModel.NameProperty)
            {
                Parent = this
            });                                                                                                         //adds the card name property
            //  UpdateProxyTemplate();
        }
示例#11
0
        public AltItemModel() //for adding new items
        {
            _altCard            = new CardPropertySet();
            _altCard.Type       = Guid.NewGuid().ToString();
            CardSize            = ViewModelLocator.SizeTabViewModel.Items.First(x => x.Default);
            _altCard.Properties = new Dictionary <PropertyDef, object>();

            var nameProp = new PropertyDef()
            {
                Hidden      = false,
                Name        = "Name",
                Type        = PropertyType.String,
                TextKind    = PropertyTextKind.FreeText,
                IgnoreText  = false,
                IsUndefined = false
            };

            _altCard.Properties.Add(nameProp, "CardName");
            AltTypeVisibility = Visibility.Collapsed;

            Properties = new ObservableCollection <CardPropertyItemModel>();
        }
示例#12
0
文件: Alternate.cs 项目: wlk0/OCTGN
        public AlternateModel(CardPropertySet altData, IdeCollection <IdeBaseItem> source) : base(source) //for loading an existing collection
        {
            _altDef = altData;

            Items = new ObservableCollection <CardPropertyModel>();
            foreach (var prop in altData.Properties)
            {
                Items.Add(new CardPropertyModel
                {
                    Property   = ViewModelLocator.PropertyTabViewModel.Items.First(y => (y as PropertyItemModel)._property.Equals(prop.Key)) as PropertyItemModel,
                    _value     = prop.Value,
                    Parent     = this,
                    _isDefined = prop.Value != null
                });
            }
            Items.CollectionChanged += (a, b) =>
            {
                BuildAltDef(b);
            };
            DeleteImageCommand = new RelayCommand(DeleteImage);
            Messenger.Default.Register <CustomPropertyChangedMessage>(this, action => CustomPropertyChanged(action));
            Messenger.Default.Register <CardSizeChangedMesssage>(this, action => CardSizeChanged(action));
        }
示例#13
0
        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(Paths.Get().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
                    {
                        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  = ""
                    };
                    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("The game {0} you are trying to install/update/play is broken. Please contact the game developer.", 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);
        }