public void Properties() { GameObject.CreateProperty <float>("X", "Layout", "blah", 0); GameObject.CreateProperty <string>("X", "Layout", "blah", string.Empty); GameObject.CreateProperty <bool>("IsEnabled", "Layout", "blah", false); var a = new GameObject("A"); Assert.Throws(typeof(ArgumentException), () => a.GetValue <float>("Not defined")); Assert.AreEqual(0, a.GetValue <float>("X")); var p = a.Properties.Get <float>("X"); Assert.AreEqual("X", p.Name); Assert.IsFalse(p.HasLocalValue); Assert.AreEqual(0, p.Value); p.Metadata.DefaultValue = 1; Assert.AreEqual(1, p.Value); p.Value = 2; Assert.AreEqual(2, p.Value); ((IGameProperty)p).Value = 3.0f; Assert.AreEqual(3, ((IGameProperty)p).Value); Assert.AreEqual(3, p.Value); }
public void Template() { GameObject.CreateProperty <float>("X", "Layout", "blah", 0); GameObject.CreateProperty <float>("Y", "Layout", "blah", 0); GameObject.CreateProperty <float>("Z", "Layout", "blah", 0); GameObject.CreateProperty <float>("W", "Layout", "blah", 0); var t = new GameObject(); t.SetValue("X", 10.0f); t.SetValue("Y", 20.0f); t.SetValue("Z", 30.0f); var a = new GameObject(); Assert.AreEqual(0, a.GetValue <float>("X")); a.Template = t; Assert.AreEqual(10, a.GetValue <float>("X")); Assert.AreEqual(20, a.GetValue <float>("Y")); Assert.AreEqual(30, a.GetValue <float>("Z")); Assert.IsFalse(a.Properties.Get <float>("X").HasLocalValue); Assert.IsFalse(a.Properties.Get <float>("Y").HasLocalValue); Assert.IsFalse(a.Properties.Get <float>("Z").HasLocalValue); a.SetValue("Y", 999.0f); Assert.AreEqual(10, a.GetValue <float>("X")); Assert.AreEqual(999, a.GetValue <float>("Y")); Assert.AreEqual(30, a.GetValue <float>("Z")); Assert.IsFalse(a.Properties.Get <float>("X").HasLocalValue); Assert.IsTrue(a.Properties.Get <float>("Y").HasLocalValue); Assert.IsFalse(a.Properties.Get <float>("Z").HasLocalValue); a.Properties.Get <float>("Y").Reset(); Assert.AreEqual(10, a.GetValue <float>("X")); Assert.AreEqual(20, a.GetValue <float>("Y")); Assert.AreEqual(30, a.GetValue <float>("Z")); Assert.IsFalse(a.Properties.Get <float>("X").HasLocalValue); Assert.IsFalse(a.Properties.Get <float>("Y").HasLocalValue); Assert.IsFalse(a.Properties.Get <float>("Z").HasLocalValue); // Enumerate properties. Assert.AreEqual(3, ((IEnumerable)a.Properties).Cast <IGameProperty>().Count()); _wasCalled = false; a.TemplateChanged += (s, e) => _wasCalled = true; a.Template = t; Assert.IsFalse(_wasCalled); a.Template = null; Assert.IsTrue(_wasCalled); }
public void PropertyConnection() { GameObject.CreateProperty <float>("X", "Layout", "blah", 1); GameObject.CreateProperty <float>("Y", "Layout", "blah", 1); var a = new GameObject(); var b = new GameObject(); var aX = a.Properties.Get <float>("X"); var bY = b.Properties.Get <float>("Y"); aX.Changed += bY.Change; aX.Value = 22; Assert.AreEqual(22, b.GetValue <float>("Y")); aX.Changed -= bY.Change; aX.Value = 23; Assert.AreEqual(22, b.GetValue <float>("Y")); }
public void Template() { GameObject.CreateProperty<float>("X", "Layout", "blah", 0); GameObject.CreateProperty<float>("Y", "Layout", "blah", 0); GameObject.CreateProperty<float>("Z", "Layout", "blah", 0); GameObject.CreateProperty<float>("W", "Layout", "blah", 0); var t = new GameObject(); t.SetValue("X", 10.0f); t.SetValue("Y", 20.0f); t.SetValue("Z", 30.0f); var a = new GameObject(); Assert.AreEqual(0, a.GetValue<float>("X")); a.Template = t; Assert.AreEqual(10, a.GetValue<float>("X")); Assert.AreEqual(20, a.GetValue<float>("Y")); Assert.AreEqual(30, a.GetValue<float>("Z")); Assert.IsFalse(a.Properties.Get<float>("X").HasLocalValue); Assert.IsFalse(a.Properties.Get<float>("Y").HasLocalValue); Assert.IsFalse(a.Properties.Get<float>("Z").HasLocalValue); a.SetValue("Y", 999.0f); Assert.AreEqual(10, a.GetValue<float>("X")); Assert.AreEqual(999, a.GetValue<float>("Y")); Assert.AreEqual(30, a.GetValue<float>("Z")); Assert.IsFalse(a.Properties.Get<float>("X").HasLocalValue); Assert.IsTrue(a.Properties.Get<float>("Y").HasLocalValue); Assert.IsFalse(a.Properties.Get<float>("Z").HasLocalValue); a.Properties.Get<float>("Y").Reset(); Assert.AreEqual(10, a.GetValue<float>("X")); Assert.AreEqual(20, a.GetValue<float>("Y")); Assert.AreEqual(30, a.GetValue<float>("Z")); Assert.IsFalse(a.Properties.Get<float>("X").HasLocalValue); Assert.IsFalse(a.Properties.Get<float>("Y").HasLocalValue); Assert.IsFalse(a.Properties.Get<float>("Z").HasLocalValue); // Enumerate properties. Assert.AreEqual(3, ((IEnumerable)a.Properties).Cast<IGameProperty>().Count()); _wasCalled = false; a.TemplateChanged += (s, e) => _wasCalled = true; a.Template = t; Assert.IsFalse(_wasCalled); a.Template = null; Assert.IsTrue(_wasCalled); }
public void PropertyConnection() { GameObject.CreateProperty<float>("X", "Layout", "blah", 1); GameObject.CreateProperty<float>("Y", "Layout", "blah", 1); var a = new GameObject(); var b = new GameObject(); var aX = a.Properties.Get<float>("X"); var bY = b.Properties.Get<float>("Y"); aX.Changed += bY.Change; aX.Value = 22; Assert.AreEqual(22, b.GetValue<float>("Y")); aX.Changed -= bY.Change; aX.Value = 23; Assert.AreEqual(22, b.GetValue<float>("Y")); }
public void Properties() { GameObject.CreateProperty<float>("X", "Layout", "blah", 0); GameObject.CreateProperty<string>("X", "Layout", "blah", string.Empty); GameObject.CreateProperty<bool>("IsEnabled", "Layout", "blah", false); var a = new GameObject("A"); Assert.Throws(typeof(ArgumentException), () => a.GetValue<float>("Not defined")); Assert.AreEqual(0, a.GetValue<float>("X")); var p = a.Properties.Get<float>("X"); Assert.AreEqual("X", p.Name); Assert.IsFalse(p.HasLocalValue); Assert.AreEqual(0, p.Value); p.Metadata.DefaultValue = 1; Assert.AreEqual(1, p.Value); p.Value = 2; Assert.AreEqual(2, p.Value); ((IGameProperty)p).Value = 3.0f; Assert.AreEqual(3, ((IGameProperty)p).Value); Assert.AreEqual(3, p.Value); }