public void GetValueTwiceReturnsCachedValue() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); r.GetValue(); Assert.AreEqual(2, r.GetValue()); }
public void ChangingModifierChangesCachedValueLookups() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); r.modifierAdd.Set("a", 2f); r.GetValue(); r.modifierAdd.Set("a", 4f); Assert.AreEqual(6, r.GetValue()); }
void Update() { if (record != null) { // @NOTE Look at the record.DisplayType to customize how values are shown if (record.Definition.IsPercentile) { Value = string.Format("{0:0%}", record.GetValue()); } else { Value = record.GetValue().ToString(); } } }
public void GetValueUsesCustomOperatorOrderOnSettings() { var ooo = ScriptableObject.CreateInstance <OrderOfOperations>(); var o = ooo.Operators[0]; ooo.Operators.RemoveAt(0); ooo.Operators.Add(o); settings.OrderOfOperations = ooo; var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 4f); var r = new StatRecord(d); r.modifierAdd.Set("a", 4); r.modifierSubtract.Set("a", 2); r.modifierMultiply.Set("a", 4); r.modifierDivide.Set("a", 2); var result = 4 - 2; result += result * 4; result /= 2; result += 4; Assert.AreEqual(result, r.GetValue()); }
public void GetValueWithoutModifier() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); var result = r.GetValue(); Assert.AreEqual(2, result); }
/// <summary> /// Retrieve a float value by record with an optional index /// </summary> /// <param name="record"></param> /// <param name="index"></param> /// <returns></returns> public float GetStat(StatRecord record, float index = 0) { if (record == null) { return(0); } return(record.GetValue(index)); }
/// <summary> /// Retrieve an int value by record with an optional index /// </summary> /// <param name="record"></param> /// <param name="index"></param> /// <returns></returns> public int GetStatInt(StatRecord record, float index = 0) { if (record == null) { return(0); } return(Mathf.RoundToInt(record.GetValue(index))); }
public void GetValueRoundsForceRoundedDefinitions() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundResult", true); var r = new StatRecord(d); Assert.AreEqual(2, r.GetValue()); }
public void GetValueStoresLastRetrievedValue() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); r.modifierAdd.Set("a", 2f); r.GetValue(); Assert.AreEqual(4, r.LastRetrievedValue); }
public void ModifierIsNotForceRoundedWhenDefinitionForceRoundFalse() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundModifiers", false); var r = new StatRecord(d); r.modifierAdd.Set("a", 2.4f); Assert.AreEqual(4.8f, r.GetValue()); }
public void ModifierNotForceRoundedWithoutOperatorForceRound() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundResult", true); var r = new StatRecord(d); r.modifierMultiply.Set("a", 0.05f); Assert.AreEqual(3, r.GetValue(3f)); }
public void ModifierIsForceRoundedWithDefinitionForceRound() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundResult", true); SetPrivateField(d, "_roundModifiers", true); var r = new StatRecord(d); r.modifierAdd.Set("a", 2.4f); Assert.AreEqual(4, r.GetValue()); }
public void It_should_return_the_new_value_on_SetModifier() { _health.Value.GetValue().SetInt(0); StatRecord result = null; var copy = _container.CreateRuntimeCopy(); copy.OnStatChangeSubscribe("health", (record) => result = record); copy.SetModifier(OperatorType.Add, "health", "plus", 5f); Assert.AreEqual(5f, result.GetValue()); }
public void It_should_subscribe_with_a_definition() { _health.Value.GetValue().SetInt(0); StatRecord result = null; var copy = _container.CreateRuntimeCopy(); copy.OnStatChangeSubscribe(_health, (record) => result = record); copy.SetModifier(OperatorType.Add, "health", "plus", 5f); Assert.AreEqual(5f, result.GetValue()); }
public void GetValueWithEveryModifer() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); r.modifierAdd.Set("a", 4); r.modifierSubtract.Set("a", 2); r.modifierMultiply.Set("a", 3); r.modifierDivide.Set("a", 2); var result = r.GetValue(); Assert.AreEqual(8, result); }
public void It_should_trigger_an_event_on_RemoveModifier() { _health.Value.GetValue().SetInt(0); StatRecord result = null; var copy = _container.CreateRuntimeCopy(); copy.SetModifier(OperatorType.Add, "health", "plus", 5f); copy.OnStatChangeSubscribe("health", (record) => result = record); copy.RemoveModifier(OperatorType.Add, "health", "plus"); Assert.AreEqual(0f, result.GetValue()); }