public UDMFFieldAssociation(string property, UDMFFieldAssociationModifier modify, bool nevershoweventlines)
 {
     Property            = property;
     Modify              = modify;
     NeverShowEventLines = nevershoweventlines;
 }
        // Constructor
        internal UniversalFieldInfo(string path, string name, string configname, Configuration cfg, IDictionary <string, EnumList> enums)
        {
            string setting = "universalfields." + path + "." + name;

            // Initialize
            this.name    = name.ToLowerInvariant();
            associations = new Dictionary <string, UDMFFieldAssociation>();

            // Read type
            this.type         = cfg.ReadSetting(setting + ".type", int.MinValue);
            this.defaultvalue = cfg.ReadSettingObject(setting + ".default", null);

            //mxd. Check type
            if (this.type == int.MinValue)
            {
                General.ErrorLogger.Add(ErrorType.Warning, "No type is defined for universal field \"" + name + "\" defined in \"" + configname + "\". Integer type will be used.");
                this.type = (int)UniversalType.Integer;
            }

            TypeHandler th = General.Types.GetFieldHandler(this);

            if (th is NullHandler)
            {
                General.ErrorLogger.Add(ErrorType.Warning, "Universal field \"" + name + "\" defined in \"" + configname + "\" has unknown type " + this.type + ". String type will be used instead.");
                this.type = (int)UniversalType.String;
                if (this.defaultvalue == null)
                {
                    this.defaultvalue = "";
                }
            }

            //mxd. Default value is missing? Get it from typehandler
            if (this.defaultvalue == null)
            {
                this.defaultvalue = th.GetDefaultValue();
            }

            // Read enum
            object enumsetting = cfg.ReadSettingObject(setting + ".enum", null);

            if (enumsetting != null)
            {
                // Reference to existing enums list?
                if (enumsetting is string)
                {
                    // Link to it
                    enumlist = enums[enumsetting.ToString()];
                }
                else if (enumsetting is IDictionary)
                {
                    // Make list
                    enumlist = new EnumList(enumsetting as IDictionary);
                }
            }

            // Read associations
            IDictionary assocdict = cfg.ReadSetting(setting + ".associations", new Hashtable());

            foreach (DictionaryEntry section in assocdict)
            {
                string property                   = cfg.ReadSetting(setting + ".associations." + section.Key + ".property", string.Empty);
                string modifystr                  = cfg.ReadSetting(setting + ".associations." + section.Key + ".modify", string.Empty);
                bool   nevershoweventlines        = cfg.ReadSetting(setting + ".associations." + section.Key + ".nevershoweventlines", false);
                UDMFFieldAssociationModifier ufam = UDMFFieldAssociationModifier.None;

                if (!string.IsNullOrWhiteSpace(property))
                {
                    switch (modifystr)
                    {
                    case "abs":
                        ufam = UDMFFieldAssociationModifier.Absolute;
                        break;
                    }

                    associations[property] = new UDMFFieldAssociation(property, ufam, nevershoweventlines);
                }
            }

            // We have no destructor
            GC.SuppressFinalize(this);
        }
Beispiel #3
0
        /// <summary>
        /// Checks if the type and value of two UniValues match. Takes modifiers into account
        /// </summary>
        /// <param name="uv1">First UniValue</param>
        /// <param name="uv2">Second UniValue</param>
        /// <param name="ufam">Modifier</param>
        /// <returns>True if values match</returns>
        private bool UniValuesMatch(UniValue uv1, UniValue uv2, UDMFFieldAssociationModifier ufam, object def)
        {
            if (uv1.Type != uv2.Type)
            {
                return(false);
            }

            switch ((UniversalType)uv1.Type)
            {
            case UniversalType.AngleRadians:
            case UniversalType.AngleDegreesFloat:
            case UniversalType.Float:
                double d1 = (double)uv1.Value;
                double d2 = (double)uv2.Value;

                if (ufam == UDMFFieldAssociationModifier.Absolute)
                {
                    d1 = Math.Abs(d1);
                    d2 = Math.Abs(d2);
                }

                if (d1 == d2)
                {
                    return(true);
                }

                break;

            case UniversalType.AngleDegrees:
            case UniversalType.AngleByte:
            case UniversalType.Color:
            case UniversalType.EnumBits:
            case UniversalType.EnumOption:
            case UniversalType.Integer:
            case UniversalType.LinedefTag:
            case UniversalType.LinedefType:
            case UniversalType.SectorEffect:
            case UniversalType.SectorTag:
            case UniversalType.ThingTag:
            case UniversalType.ThingType:
                int i1 = (int)uv1.Value;
                int i2 = (int)uv2.Value;

                if (ufam == UDMFFieldAssociationModifier.Absolute)
                {
                    i1 = Math.Abs(i1);
                    i2 = Math.Abs(i2);
                }

                if (i1 == i2 && i1 != (int)def)
                {
                    return(true);
                }

                break;

            case UniversalType.Boolean:
                if ((bool)uv1.Value == (bool)uv2.Value)
                {
                    return(true);
                }
                break;

            case UniversalType.Flat:
            case UniversalType.String:
            case UniversalType.Texture:
            case UniversalType.EnumStrings:
            case UniversalType.ThingClass:
                if ((string)uv1.Value == (string)uv2.Value)
                {
                    return(true);
                }
                break;
            }

            return(false);
        }