Exemplo n.º 1
0
        public static Span ConvertToSpan(RichTextPropertyValue value, Game game)
        {
            Game = game;
            Span span = new Span();

            InternalProcess(span, value.Value);
            return(span);
        }
Exemplo n.º 2
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
            };

            if (nameProp.Type is PropertyType.RichText)
            {
                var span = new RichSpan();
                span.Items.Add(new RichText()
                {
                    Text = "CardName"
                });
                var namePropValue = new RichTextPropertyValue();
                namePropValue.Value = span;
                _altCard.Properties.Add(nameProp, namePropValue);
            }
            else
            {
                _altCard.Properties.Add(nameProp, "CardName");
            }
            AltTypeVisibility = Visibility.Collapsed;

            Properties = new ObservableCollection <CardPropertyItemModel>();
        }
Exemplo n.º 3
0
        public static DataTable ToDataTable(this IEnumerable <Card> cards, Game game)
        {
            DataTable table = new DataTable();

            var values        = new object[game.CustomProperties.Count + 6];
            var defaultValues = new object[game.CustomProperties.Count + 6];
            var indexes       = new Dictionary <int, string>();
            var setCache      = new Dictionary <Guid, string>();
            var i             = 6;

            table.Columns.Add("Name", typeof(string));
            defaultValues[0] = "";
            table.Columns.Add("SetName", typeof(string));
            defaultValues[1] = "";
            table.Columns.Add("set_id", typeof(string));
            defaultValues[2] = "";
            table.Columns.Add("img_uri", typeof(string));
            defaultValues[3] = "";
            table.Columns.Add("id", typeof(string));
            defaultValues[4] = "";
            table.Columns.Add("Alternates", typeof(string));
            defaultValues[5] = "";
            foreach (var prop in game.CustomProperties)
            {
                switch (prop.Type)
                {
                case PropertyType.String:
                    table.Columns.Add(prop.Name, typeof(string));
                    defaultValues[i] = "";
                    break;

                case PropertyType.RichText:
                    table.Columns.Add(prop.Name, typeof(RichTextPropertyValue));
                    defaultValues[i] = new RichTextPropertyValue()
                    {
                        Value = new RichSpan()
                    };
                    break;

                case PropertyType.Integer:
                    table.Columns.Add(prop.Name, typeof(double));
                    defaultValues[i] = null;
                    break;

                case PropertyType.GUID:
                    table.Columns.Add(prop.Name, typeof(Guid));
                    defaultValues[i] = Guid.Empty;
                    break;

                case PropertyType.Char:
                    table.Columns.Add(prop.Name, typeof(char));
                    defaultValues[i] = 0;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                indexes.Add(i, prop.Name);
                i++;
            }

            foreach (Card item in cards)
            {
                for (i = 6; i < values.Length; i++)
                {
                    values[i] = defaultValues[i];
                }
                if (!setCache.ContainsKey(item.SetId))
                {
                    setCache.Add(item.SetId, item.GetSet().Name);
                }
                values[1] = setCache[item.SetId];
                values[2] = item.SetId;
                values[3] = item.GetImageUri();
                values[4] = item.Id;
                foreach (CardPropertySet alt in item.PropertySets.Values)
                {
                    values[5] = alt.Type;
                    values[0] = alt.Name;
                    foreach (var prop in alt.Properties)
                    {
                        var ix = indexes.Where(x => x.Value == prop.Key.Name).Select(x => new { x.Key, x.Value }).FirstOrDefault();
                        if (ix == null)
                        {
                            throw new UserMessageException(L.D.Exception__CanNotCreateDeckMissingCardProperty);
                        }
                        if (prop.Key.Type == PropertyType.Integer)
                        {
                            if (prop.Value == null || !int.TryParse(prop.Value as string, out _))
                            {
                                values[ix.Key] = null;
                                continue;
                            }
                        }
                        values[ix.Key] = prop.Value;
                    }
                    table.Rows.Add(values);
                }
            }
            return(table);
        }