Skip to content
Permalink
Browse files

Use generic ActionMessage<T>, remove messages for Inventory-, Room-

  • Loading branch information...
bobbymcr committed Dec 22, 2018
1 parent 287b3fe commit cb3b5256b2971aba625445dfb34e0bf1c1e7f8cc
@@ -24,7 +24,7 @@ public Inventory(MessageBus bus)
this.take = bus.Subscribe<TakeItemMessage>(m => this.Take(m.Verb, m.Noun, m.Item));
this.drop = bus.Subscribe<DropItemMessage>(m => this.Drop(m.Verb, m.Noun, m.Items));
this.look = bus.Subscribe<LookItemMessage>(m => this.Look(m.Noun));
this.act = bus.Subscribe<InventoryActionMessage>(m => m.Act(this));
this.act = bus.Subscribe<ActionMessage<Inventory>>(m => m.Act(this));
this.items = new Items(this.bus);
this.items.Activate();
}
@@ -48,6 +48,6 @@ public bool Drop()

protected void Output(string text) => this.Bus.Output(text);

protected void SendRoom(Action<Room> act) => this.Bus.Send(new RoomActionMessage(act));
protected void SendRoom(Action<Room> act) => this.Bus.Send(new ActionMessage<Room>(act));
}
}
@@ -0,0 +1,18 @@
// <copyright file="ActionMessage.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure.Messages
{
using System;

public sealed class ActionMessage<T>
{
public ActionMessage(Action<T> act)
{
this.Act = act;
}

public Action<T> Act { get; }
}
}

This file was deleted.

This file was deleted.

@@ -37,7 +37,7 @@ public void Enter()
this.items.Activate();
this.process = this.bus.Subscribe<SentenceMessage>(m => this.Process(m));
this.look = this.bus.Subscribe<LookItemMessage>(m => this.LookAt(m.Noun));
this.act = this.bus.Subscribe<RoomActionMessage>(m => m.Act(this));
this.act = this.bus.Subscribe<ActionMessage<Room>>(m => m.Act(this));
this.EnterCore();
this.Look(new Word(string.Empty, string.Empty));
}
@@ -309,7 +309,7 @@ public void ProcessInventoryAction()
bus.Subscribe<OutputMessage>(m => messages.Add(m.Text));
using (Inventory inv = new Inventory(bus))
{
bus.Send(new InventoryActionMessage(i => i.Add("key", new TestItem(bus))));
bus.Send(new ActionMessage<Inventory>(i => i.Add("key", new TestItem(bus))));
bus.Send(new ShowInventoryMessage());

messages.Should().Equal("You are carrying:", "a key");
@@ -326,7 +326,7 @@ public void ProcessInventoryActionAfterDispose()
Inventory inv2 = null;

inv.Dispose();
bus.Send(new InventoryActionMessage(i => inv2 = i));
bus.Send(new ActionMessage<Inventory>(i => inv2 = i));

inv2.Should().BeNull();
}
@@ -530,7 +530,7 @@ public void ProcessRoomAction()
Room room = new TestRoom(bus);

room.Enter();
bus.Send(new RoomActionMessage(r => r.Add("coin", new TestCoin(bus))));
bus.Send(new ActionMessage<Room>(r => r.Add("coin", new TestCoin(bus))));
bus.Send(new SentenceMessage(new Word("look", "LOOK"), new Word(string.Empty, string.Empty)));

output.Should().Equal(
@@ -549,7 +549,7 @@ public void ProcessRoomActionAfterLeave()

room.Enter();
room.Leave();
bus.Send(new RoomActionMessage(r => r.Add("coin", new TestCoin(bus))));
bus.Send(new ActionMessage<Room>(r => r.Add("coin", new TestCoin(bus))));
room.Enter();

output.Should().Equal(

0 comments on commit cb3b525

Please sign in to comment.
You can’t perform that action at this time.