Esempio n. 1
0
        public void ValidateParameter <T>(PermutationParameterKey <T> key, T value)
        {
            // Check if value was existing and/or same
            var index = effectValuesValidated++;

            if (index < EffectValues.Count)
            {
                var currentEffectValue = EffectValues.Items[index];
                if (currentEffectValue.Key == key && EqualityComparer <T> .Default.Equals((T)currentEffectValue.Value, value))
                {
                    // Everything same, let's keep going
                    return;
                }

                // Something was different, let's replace item and clear end of list
                EffectValues[index] = new EffectParameterEntry(key, value);
                EffectValues.Count  = effectValuesValidated;
                effectChanged       = true;
            }
            else
            {
                EffectValues.Add(new EffectParameterEntry(key, value));
                effectChanged = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets an accessor to get and set permutations more quickly.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameterKey"></param>
        /// <returns></returns>
        public PermutationParameter <T> GetAccessor <T>(PermutationParameterKey <T> parameterKey, bool createIfNew = true)
        {
            // Remap it as PermutationParameter
            var accessor = GetObjectParameterHelper(parameterKey, createIfNew);

            return(new PermutationParameter <T>(accessor.Offset, accessor.Count));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a permutation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public T Get <T>(PermutationParameterKey <T> parameter, bool createIfNew = false)
        {
            var accessor = GetAccessor(parameter, createIfNew);

            if (accessor.BindingSlot == -1)
            {
                return(parameter.DefaultValueMetadataT.DefaultValue);
            }

            return(Get(accessor));
        }
Esempio n. 4
0
        public override void Serialize(ref PermutationParameterKey <T> obj, ArchiveMode mode, SerializationStream stream)
        {
            if (mode == ArchiveMode.Serialize)
            {
                stream.Write(obj.Name);
                stream.Write(obj.Length);
            }
            else
            {
                var parameterName   = stream.ReadString();
                var parameterLength = stream.ReadInt32();
                obj = (PermutationParameterKey <T>)ParameterKeys.FindByName(parameterName);

                // If parameter could not be found, create one matching this type.
                if (obj == null)
                {
                    var metadata = new ParameterKeyValueMetadata <T>();
                    obj = new PermutationParameterKey <T>(parameterName, parameterLength, metadata);
                    ParameterKeys.Merge(obj, null, parameterName);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Sets a permutation.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="parameter"></param>
 /// <param name="value"></param>
 public void Set <T>(PermutationParameterKey <T> parameter, T value)
 {
     Set(GetAccessor(parameter), value);
 }