コード例 #1
0
        /**
         * Override the contents of this definition set with another.
         */
        public virtual void OverrideBy(MyDefinitionSet definitionSet)
        {
            MyDefinitionPostprocessor.Bundle myBundle = new MyDefinitionPostprocessor.Bundle()
            {
                Set     = this,
                Context = Context
            };

            MyDefinitionPostprocessor.Bundle thyBundle = new MyDefinitionPostprocessor.Bundle()
            {
                Set     = definitionSet,
                Context = definitionSet.Context
            };

            foreach (var defgrp in definitionSet.Definitions)
            {
                Dictionary <MyStringHash, MyDefinitionBase> dict;
                if (!Definitions.TryGetValue(defgrp.Key, out dict))
                {
                    dict = new Dictionary <MyStringHash, MyDefinitionBase>();
                    Definitions[defgrp.Key] = dict;
                }

                var pp = MyDefinitionManagerBase.GetPostProcessor(defgrp.Key);

                myBundle.Definitions  = dict;
                thyBundle.Definitions = defgrp.Value;

                pp.OverrideBy(ref myBundle, ref thyBundle);
            }
        }
コード例 #2
0
        /**
         * Get all definitions of a given type.
         */
        public IEnumerable <T> GetDefinitionsOfType <T>() where T : MyDefinitionBase
        {
            Dictionary <MyStringHash, MyDefinitionBase> definitions = null;

            if (Definitions.TryGetValue(MyDefinitionManagerBase.GetObjectBuilderType(typeof(T)), out definitions))
            {
                return(definitions.Values.Cast <T>());
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public T GetDefinition <T>(MyStringHash subtypeId) where T : MyDefinitionBase
        {
            MyDefinitionBase definitionBase = null;

            var ob = MyDefinitionManagerBase.GetObjectBuilderType(typeof(T));
            Dictionary <MyStringHash, MyDefinitionBase> dictionary;

            if (Definitions.TryGetValue(ob, out dictionary))
            {
                dictionary.TryGetValue(subtypeId, out definitionBase);
            }

            return((T)definitionBase);
        }
コード例 #4
0
        public virtual MyObjectBuilder_DefinitionBase GetObjectBuilder()
        {
            var builder = MyDefinitionManagerBase.GetObjectFactory().CreateObjectBuilder <MyObjectBuilder_DefinitionBase>(this);

            builder.Id          = Id;
            builder.Description = (DescriptionEnum.HasValue) ? DescriptionEnum.Value.ToString() : DescriptionString != null?DescriptionString.ToString() : null;

            builder.DisplayName = (DisplayNameEnum.HasValue) ? DisplayNameEnum.Value.ToString() : DisplayNameString != null?DisplayNameString.ToString() : null;

            builder.Icons   = Icons;
            builder.Public  = Public;
            builder.Enabled = Enabled;

            builder.AvailableInSurvival = AvailableInSurvival;

            return(builder);
        }
コード例 #5
0
ファイル: MyDefinitionSet.cs プロジェクト: viktorius/Viktor
        /**
         * Get all definitions of a given type.
         */
        public IEnumerable <T> GetDefinitionsOfTypeAndSubtypes <T>() where T : MyDefinitionBase
        {
            var subtypes = MyDefinitionManagerBase.Static.GetSubtypes <T>();

            Dictionary <MyStringHash, MyDefinitionBase> definitions = null;

            if (subtypes == null)
            {
                if (Definitions.TryGetValue(MyDefinitionManagerBase.GetObjectBuilderType(typeof(T)), out definitions))
                {
                    return(definitions.Values.Cast <T>());
                }
                return(null);
            }

            return(subtypes.SelectMany(x => Definitions.GetOrEmpty(MyDefinitionManagerBase.GetObjectBuilderType(x)).Cast <T>()));
        }
コード例 #6
0
ファイル: MyDefinitionSet.cs プロジェクト: viktorius/Viktor
        /**
         * Override the contents of this definition set with another.
         */
        public virtual void OverrideBy(MyDefinitionSet definitionSet)
        {
            MyDefinitionPostprocessor.Bundle myBundle = new MyDefinitionPostprocessor.Bundle()
            {
                Set     = this,
                Context = Context
            };

            MyDefinitionPostprocessor.Bundle thyBundle = new MyDefinitionPostprocessor.Bundle()
            {
                Set     = definitionSet,
                Context = definitionSet.Context
            };

            foreach (var defgrp in definitionSet.Definitions)
            {
                Dictionary <MyStringHash, MyDefinitionBase> dict;
                if (!Definitions.TryGetValue(defgrp.Key, out dict))
                {
                    dict = new Dictionary <MyStringHash, MyDefinitionBase>();
                    Definitions[defgrp.Key] = dict;
                }

                // TODO: Postprocessing should be per definition type, not typeid.
                var pp = MyDefinitionManagerBase.GetPostProcessor(defgrp.Key);

                // Since that is too big a refactor this should fix it in the meantime.
                // This line gets me sick :(
                if (pp == null)
                {
                    pp = MyDefinitionManagerBase.GetPostProcessor(
                        MyDefinitionManagerBase.GetObjectBuilderType(defgrp.Value.First().Value.GetType()));
                }

                myBundle.Definitions  = dict;
                thyBundle.Definitions = defgrp.Value;

                pp.OverrideBy(ref myBundle, ref thyBundle);
            }
        }
コード例 #7
0
 /**
  * Get all definitions of a given type.
  */
 public IEnumerable <T> GetDefinitionsOfType <T>() where T : MyDefinitionBase
 {
     return(Definitions[MyDefinitionManagerBase.GetObjectBuilderType(typeof(T))].Values.Cast <T>());
 }