예제 #1
0
        public void GetValueTwiceReturnsCachedValue()
        {
            var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2);
            var r = new StatRecord(d);

            r.GetValue();

            Assert.AreEqual(2, r.GetValue());
        }
예제 #2
0
        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());
        }
예제 #3
0
 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();
         }
     }
 }
예제 #4
0
        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());
        }
예제 #5
0
        public void GetValueWithoutModifier()
        {
            var d      = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2);
            var r      = new StatRecord(d);
            var result = r.GetValue();

            Assert.AreEqual(2, result);
        }
예제 #6
0
 /// <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));
 }
예제 #7
0
 /// <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)));
 }
예제 #8
0
        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());
        }
예제 #9
0
        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);
        }
예제 #10
0
        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());
        }
예제 #11
0
        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));
        }
예제 #12
0
        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());
        }
예제 #13
0
            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());
            }
예제 #14
0
            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());
            }
예제 #15
0
        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);
        }
예제 #16
0
            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());
            }