Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.13.0] - 2024-11-04

**Changed**:
- Changed *CommandService* to now receive the *MessageBrokerService* in the command and help communication with the game architecture

## [0.12.2] - 2024-11-02

**Fixed**:
Expand Down
29 changes: 23 additions & 6 deletions Runtime/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ namespace GameLovers.Services
/// Tags the interface as a <see cref="IGameCommand{TGameLogic}"/>
/// </summary>
public interface IGameCommandBase {}


/// <summary>
/// Contract for the command to be executed in the <see cref="ICommandService{TGameLogic}"/>.
/// Implement this interface if you want logic to be executed ont he server
/// </summary>
/// <remarks>
/// Follows the Command pattern <see cref="https://en.wikipedia.org/wiki/Command_pattern"/>
/// </remarks>
public interface IGameServerCommand<in TGameLogic> : IGameCommandBase where TGameLogic : class
{
/// <summary>
/// Executes the command logic defined by the implemention of this interface
/// </summary>
void ExecuteLogic(TGameLogic gameLogic);
}

/// <summary>
/// Interface representing the command to be executed in the <see cref="ICommandService{TGameLogic}"/>.
/// Implement this interface with the proper command logic
Expand All @@ -19,7 +34,7 @@ public interface IGameCommand<in TGameLogic> : IGameCommandBase where TGameLogic
/// <summary>
/// Executes the command logic defined by the implemention of this interface
/// </summary>
void Execute(TGameLogic gameLogic);
void Execute(TGameLogic gameLogic, IMessageBrokerService messageBroker);
}

/// <summary>
Expand All @@ -42,16 +57,18 @@ public interface ICommandService<out TGameLogic> where TGameLogic : class
public class CommandService<TGameLogic> : ICommandService<TGameLogic> where TGameLogic : class
{
private readonly TGameLogic _gameLogic;

public CommandService(TGameLogic gameLogic)
private readonly IMessageBrokerService _messageBroker;

public CommandService(TGameLogic gameLogic, IMessageBrokerService messageBroker)
{
_gameLogic = gameLogic;
_messageBroker = messageBroker;
}

/// <inheritdoc />
public void ExecuteCommand<TCommand>(TCommand command) where TCommand : IGameCommand<TGameLogic>
{
command.Execute(_gameLogic);
command.Execute(_gameLogic, _messageBroker);
}
}
}
4 changes: 2 additions & 2 deletions Tests/Editor/EditMode/CommandServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private struct CommandMockup : IGameCommand<IGameLogicMockup>
{
public int Payload;

public void Execute(IGameLogicMockup gameLogic)
public void Execute(IGameLogicMockup gameLogic, IMessageBrokerService messageBroker)
{
gameLogic.CallMockup(Payload);
}
Expand All @@ -32,7 +32,7 @@ public void Execute(IGameLogicMockup gameLogic)
public void Init()
{
_gameLogicMockup = Substitute.For<IGameLogicMockup>();
_commandService = new CommandService<IGameLogicMockup>(_gameLogicMockup);
_commandService = new CommandService<IGameLogicMockup>(_gameLogicMockup, Substitute.For<IMessageBrokerService>());
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.gamelovers.services",
"displayName": "Services",
"author": "Miguel Tomas",
"version": "0.12.2",
"version": "0.13.0",
"unity": "2022.3",
"license": "MIT",
"description": "The purpose of this package is to provide a set of services to ease the development of a basic game architecture",
Expand Down