Exemplo n.º 1
0
        public PropertyTemplate(BinTreePropertyViewModel viewModel)
        {
            this.Name = viewModel.Name;
            this.Type = viewModel.TreeProperty.Type;

            if (viewModel is BinTreeContainerViewModel containerViewModel)
            {
                this.PrimaryType = (containerViewModel.TreeProperty as BinTreeContainer).PropertiesType;
            }
            else if (viewModel is BinTreeUnorderedContainerViewModel unorderedContainerViewModel)
            {
                this.PrimaryType = (unorderedContainerViewModel.TreeProperty as BinTreeContainer).PropertiesType;
            }
            else if (viewModel is BinTreeMapViewModel mapViewModel)
            {
                BinTreeMap map = mapViewModel.TreeProperty as BinTreeMap;

                this.PrimaryType   = map.KeyType;
                this.SecondaryType = map.ValueType;
            }
            else if (viewModel is BinTreeOptionalViewModel optionalViewModel)
            {
                BinTreeOptional optional = optionalViewModel.TreeProperty as BinTreeOptional;

                this.PrimaryType = optional.ValueType;
            }
            else if (viewModel is BinTreeStructureViewModel structureViewModel)
            {
                this.MetaClass = structureViewModel.MetaClass;
            }
            else if (viewModel is BinTreeEmbeddedViewModel embeddedViewModel)
            {
                this.MetaClass = embeddedViewModel.MetaClass;
            }
        }
Exemplo n.º 2
0
 public static BinTreePropertyViewModel ConstructTreePropertyViewModel(BinTreeParentViewModel parent, BinTreeProperty genericProperty)
 {
     return(genericProperty switch
     {
         BinTreeNone property => new BinTreePropertyViewModel(parent, property),
         BinTreeBool property => new BinTreeBoolViewModel(parent, property),
         BinTreeSByte property => new BinTreeSByteViewModel(parent, property),
         BinTreeByte property => new BinTreeByteViewModel(parent, property),
         BinTreeInt16 property => new BinTreeInt16ViewModel(parent, property),
         BinTreeUInt16 property => new BinTreeUInt16ViewModel(parent, property),
         BinTreeInt32 property => new BinTreeInt32ViewModel(parent, property),
         BinTreeUInt32 property => new BinTreeUInt32ViewModel(parent, property),
         BinTreeInt64 property => new BinTreeInt64ViewModel(parent, property),
         BinTreeUInt64 property => new BinTreeUInt64ViewModel(parent, property),
         BinTreeFloat property => new BinTreeFloatViewModel(parent, property),
         BinTreeVector2 property => new BinTreeVector2ViewModel(parent, property),
         BinTreeVector3 property => new BinTreeVector3ViewModel(parent, property),
         BinTreeVector4 property => new BinTreeVector4ViewModel(parent, property),
         BinTreeMatrix44 property => new BinTreeMatrix44ViewModel(parent, property),
         BinTreeColor property => new BinTreeColorViewModel(parent, property),
         BinTreeHash property => new BinTreeHashViewModel(parent, property),
         BinTreeWadEntryLink property => new BinTreeWadEntryLinkViewModel(parent, property),
         BinTreeUnorderedContainer property => new BinTreeUnorderedContainerViewModel(parent, property),
         BinTreeContainer property => new BinTreeContainerViewModel(parent, property),
         BinTreeString property => new BinTreeStringViewModel(parent, property),
         BinTreeEmbedded property => new BinTreeEmbeddedViewModel(parent, property),
         BinTreeStructure property => new BinTreeStructureViewModel(parent, property),
         BinTreeObjectLink property => new BinTreeObjectLinkViewModel(parent, property),
         BinTreeOptional property => new BinTreeOptionalViewModel(parent, property),
         BinTreeMap property => new BinTreeMapViewModel(parent, property),
         BinTreeBitBool property => new BinTreeBitBoolViewModel(parent, property),
         _ => null,
     });
Exemplo n.º 3
0
 private static IEnumerable <string> ProcessBinTreeProperty(BinTreeProperty treeProperty)
 {
     return(treeProperty switch
     {
         BinTreeString property => ProcessBinTreeString(property),
         BinTreeOptional property => ProcessBinTreeOptional(property),
         BinTreeContainer property => ProcessBinTreeContainer(property),
         BinTreeStructure property => ProcessBinTreeStructure(property),
         BinTreeMap property => ProcessBinTreeMap(property),
         _ => Enumerable.Empty <string>()
     });
Exemplo n.º 4
0
        private void OnBinTreeMapAddItem(object sender, RoutedEventArgs e)
        {
            if (e.Source is FrameworkElement frameworkElement &&
                frameworkElement.DataContext is BinTreeMapViewModel mapViewModel)
            {
                BinTreeMap      map           = mapViewModel.TreeProperty as BinTreeMap;
                BinTreeProperty keyProperty   = BinTreeUtilities.BuildProperty("", "", map, map.KeyType, BinPropertyType.None, BinPropertyType.None);
                BinTreeProperty valueProperty = BinTreeUtilities.BuildProperty("", "", map, map.ValueType, BinPropertyType.None, BinPropertyType.None);

                BinTreeMapEntryViewModel newEntryViewModel = new BinTreeMapEntryViewModel(mapViewModel, new KeyValuePair <BinTreeProperty, BinTreeProperty>(keyProperty, valueProperty));

                mapViewModel.Children.Add(newEntryViewModel);
            }
        }
Exemplo n.º 5
0
        private static object DeserializeMap(MetaEnvironment environment, Type propertyType, BinTreeMap map)
        {
            // Invalid key type
            if (IsValidMapKey(map.KeyType) is false)
            {
                return(null);
            }

            object     mapDictionary     = Activator.CreateInstance(propertyType);
            Type       mapDictionaryType = mapDictionary.GetType();
            MethodInfo addMethod         = mapDictionaryType.GetMethod("Add");

            foreach (var propertyPair in map.Map)
            {
                // Key types can only be primitive so we can fetch their value easily
                object keyValue   = FetchPrimitivePropertyValue(propertyPair.Key);
                object valueValue = DeserializeTreeProperty(environment, propertyPair.Value);

                addMethod.Invoke(mapDictionary, new[] { keyValue, valueValue });
            }

            return(mapDictionary);
        }