public void PropertyWithStateAndDelegate() { // Register Item mapper.RegisterItem <DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property int caller = 0; mapper.RegisterItemPropertyS <DebugItemProperty1, DebugItemStateProperty1>(extensionPack, "Debug", (i, p) => { caller++; return(new DebugItemStateProperty1(i, (DebugItemProperty1)p)); }); // Attach Property mapper.AttachItemProperty <DebugItem, DebugItemProperty1>(extensionPack, "Debug"); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); var prop = item.GetProperty <DebugItemProperty1>(); Assert.IsNotNull(prop); var state = item.GetState(); Assert.AreEqual(1, state.Properties.Count()); var stateProp = state.GetProperty <DebugItemStateProperty1>(); Assert.IsNotNull(stateProp); Assert.AreEqual(1, caller); var info = item.GetItemInfo(item2); Assert.AreEqual(0, info.Properties.Count()); var infoProp = info.GetProperty <DebugItemInfoProperty1>(); Assert.IsNull(infoProp); }
public void ExtenderOrder() { // Register Item mapper.RegisterItem <DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); List <int> caller = new List <int>(); // Register Extender mapper.RegisterItemExtender <DebugItem>(extensionPack, "Debug", (i) => { caller.Add(1); }, 10); mapper.RegisterItemExtender <DebugItem>(extensionPack, "Debug", (i) => { caller.Add(2); }, 20); mapper.RegisterItemExtender <Item>(extensionPack, "Debug", (i) => { caller.Add(3); }, 5); mapper.RegisterItemExtender <Item>(extensionPack, "Debug", (i) => { caller.Add(4); }, 15); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Left); Assert.AreEqual(4, caller.Count); Assert.AreEqual(3, caller[0]); Assert.AreEqual(1, caller[1]); Assert.AreEqual(4, caller[2]); Assert.AreEqual(2, caller[3]); }