void SetAttributeValue(GameAttribute attribute, int?key, GameAttributeValue value) { KeyId keyid; keyid.Id = attribute.Id; keyid.Key = key; if (!_changedAttributes.Contains(keyid)) { _changedAttributes.Add(keyid); } if (attribute.EncodingType == GameAttributeEncoding.IntMinMax) { if (value.Value < attribute.Min.Value || value.Value > attribute.Max.Value) { throw new ArgumentOutOfRangeException("GameAttribute." + attribute.Name.Replace(' ', '_'), "Min: " + attribute.Min.Value + " Max: " + attribute.Max.Value + " Tried to set: " + value.Value); } } else if (attribute.EncodingType == GameAttributeEncoding.Float16) { if (value.ValueF < GameAttribute.Float16Min || value.ValueF > GameAttribute.Float16Max) { throw new ArgumentOutOfRangeException("GameAttribute." + attribute.Name.Replace(' ', '_'), "Min: " + GameAttribute.Float16Min + " Max " + GameAttribute.Float16Max + " Tried to set: " + value.ValueF); } } _attributeValues[keyid] = value; }
private void SetAttributeValue(GameAttribute attribute, int?key, GameAttributeValue value) { // error if scripted attribute and is not settable if (attribute.ScriptFunc != null && !attribute.ScriptedAndSettable) { var frame = new System.Diagnostics.StackFrame(2, true); Logger.Error("illegal value assignment for GameAttribute.{0} attempted at {1}:{2}", attribute.Name, frame.GetFileName(), frame.GetFileLineNumber()); } if (attribute.EncodingType == GameAttributeEncoding.IntMinMax) { if (value.Value < attribute.Min.Value || value.Value > attribute.Max.Value) { throw new ArgumentOutOfRangeException("GameAttribute." + attribute.Name.Replace(' ', '_'), "Min: " + attribute.Min.Value + " Max: " + attribute.Max.Value + " Tried to set: " + value.Value); } } else if (attribute.EncodingType == GameAttributeEncoding.Float16) { if (value.ValueF < GameAttribute.Float16Min || value.ValueF > GameAttribute.Float16Max) { throw new ArgumentOutOfRangeException("GameAttribute." + attribute.Name.Replace(' ', '_'), "Min: " + GameAttribute.Float16Min + " Max " + GameAttribute.Float16Max + " Tried to set: " + value.ValueF); } } RawSetAttributeValue(attribute, key, value); }
private void RawSetAttributeValue(GameAttribute attribute, int?key, GameAttributeValue value) { KeyId keyid; keyid.Id = attribute.Id; keyid.Key = key; _attributeValues[keyid] = value; if (!_changedAttributes.Contains(keyid)) { _changedAttributes.Add(keyid); } // mark dependant attributes as changed if (attribute.Dependents != null) { foreach (var dependent in attribute.Dependents) { int?usekey; if (dependent.IsManualDependency) { usekey = dependent.Key; } else { usekey = dependent.UsesExplicitKey ? null : key; } if (dependent.IsManualDependency || dependent.UsesExplicitKey == false || dependent.Key == key) { // TODO: always update dependent values for now, but eventually make this lazy RawSetAttributeValue(dependent.Attribute, usekey, dependent.Attribute.ScriptFunc(this, usekey)); } } } }