예제 #1
0
        private static bool CustomFieldsMatch(UniFields fields1, UniFields fields2, MapElementType type)
        {
            // Collect non-UI fields
            UniFields filtered1 = new UniFields();
            UniFields filtered2 = new UniFields();

            foreach (string key in fields1.Keys)
            {
                if (!General.Map.FormatInterface.UIFields[type].ContainsKey(key))
                {
                    filtered1.Add(key, fields1[key]);
                }
            }

            foreach (string key in fields2.Keys)
            {
                if (!General.Map.FormatInterface.UIFields[type].ContainsKey(key))
                {
                    filtered2.Add(key, fields2[key]);
                }
            }

            if (filtered1.Keys.Count != filtered2.Keys.Count)
            {
                return(false);
            }
            return(AllFieldsMatch(filtered1, filtered2));
        }
예제 #2
0
        // Serialize / deserialize
        internal void ReadWrite(IReadWriteStream s)
        {
            int c = fields.Count;

            s.rwInt(ref c);

            if (s.IsWriting)
            {
                foreach (KeyValuePair <string, UniValue> f in fields)
                {
                    s.wString(f.Key);
                    f.Value.ReadWrite(s);
                }
            }
            else
            {
                fields = new UniFields(this, c);
                for (int i = 0; i < c; i++)
                {
                    string   t; s.rString(out t);
                    UniValue v = new UniValue(); v.ReadWrite(s);
                    fields.Add(t, v);
                }
            }
        }
예제 #3
0
 // String
 public static void SetString(UniFields fields, string key, string value, string defaultvalue)
 {
     if (fields == null)
     {
         return;
     }
     if (value != defaultvalue)
     {
         if (!fields.ContainsKey(key))
         {
             fields.Add(key, new UniValue(UniversalType.String, value));
         }
         else
         {
             fields[key].Value = value;
         }
     }
     // Don't save default value
     else if (fields.ContainsKey(key))
     {
         fields.Remove(key);
     }
 }
예제 #4
0
        // ano - for calling from outside, makes sure to make an undo snapshot
        // can throw ArgumentException if the new value's type
        // is not int, float, string, or bool
        // or the value is null
        public void SetField(string key, object value)
        {
            if (key == null)
            {
                return;
            }
            if (IsDisposed)
            {
                return;
            }

            key = UniValue.ValidateName(key);

            if (key == "")
            {
                return;
            }

            if (fields.ContainsKey(key))
            {
                // ano - we don't want to record an undo for
                // this element if the values aren't changing
                if (fields[key].Value == value)
                {
                    return;
                }

                BeforeFieldsChange();

                Type new_type = value.GetType();
                if (!fields[key].Value.GetType().IsAssignableFrom(new_type))
                {
                    if (value is float)
                    {
                        fields[key].Type = (int)UniversalType.Float;
                    }
                    else if (value is int)
                    {
                        fields[key].Type = (int)UniversalType.Integer;
                    }
                    else if (value is bool)
                    {
                        fields[key].Type = (int)UniversalType.Boolean;
                    }
                    else if (value is string)
                    {
                        fields[key].Type = (int)UniversalType.String;
                    }

                    // ano - other cases are handled by the argument exception
                }
                // ano - ArgumentException can be thrown here
                fields[key].Value = value;
            }
            else
            {
                UniValue new_field = new UniValue();

                // ano - ArgumentException can be thrown here
                new_field.Value = value;

                // ano - undo snapshot recorded after exception
                // in this case, because we can
                BeforeFieldsChange();

                // ano - other cases are handled by the ArgumentException before
                if (value is float)
                {
                    new_field.Type = (int)UniversalType.Float;
                }
                else if (value is int)
                {
                    new_field.Type = (int)UniversalType.Integer;
                }
                else if (value is bool)
                {
                    new_field.Type = (int)UniversalType.Boolean;
                }
                else if (value is string)
                {
                    new_field.Type = (int)UniversalType.String;
                }

                fields.Add(key, new_field);
            }
        }