Some method
parent
c2abd4b292
commit
0e3c775bc5
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Encompass
|
||||
{
|
||||
|
@ -116,5 +117,17 @@ namespace Encompass
|
|||
throw new IllegalMessageReadException("Engine {0} tried to read undeclared Message {1}", this.GetType().Name, typeof(TMessage).Name);
|
||||
}
|
||||
}
|
||||
|
||||
protected bool Some<TMessage>() where TMessage : struct, IMessage
|
||||
{
|
||||
if (readMessageTypes.Contains(typeof(TMessage)))
|
||||
{
|
||||
return messageManager.GetMessagesByType<TMessage>().Count() > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalMessageReadException("Engine {0} tried to read undeclared Message {1}", this.GetType().Name, typeof(TMessage).Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,5 +237,42 @@ namespace Tests
|
|||
var ex = Assert.Throws<IllegalMessageEmitException>(() => world.Update(0.01f));
|
||||
Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredMessageEmitEngine tried to emit undeclared Message MockMessage"));
|
||||
}
|
||||
|
||||
static bool someTest;
|
||||
|
||||
[Emits(typeof(MockMessage))]
|
||||
class EmitMockMessageEngine : Engine
|
||||
{
|
||||
public override void Update(float dt)
|
||||
{
|
||||
MockMessage message;
|
||||
message.myString = "howdy";
|
||||
|
||||
this.EmitMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
[Reads(typeof(MockMessage))]
|
||||
class SomeTestEngine : Engine
|
||||
{
|
||||
public override void Update(float dt)
|
||||
{
|
||||
someTest = this.Some<MockMessage>();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Some()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<EmitMockMessageEngine>();
|
||||
worldBuilder.AddEngine<SomeTestEngine>();
|
||||
|
||||
var world = worldBuilder.Build();
|
||||
|
||||
world.Update(0.01f);
|
||||
|
||||
Assert.That(someTest, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue