From 900638fffa9fe438bded1143cfcc21e4656c43f5 Mon Sep 17 00:00:00 2001 From: CoderGamester Date: Mon, 4 Nov 2024 01:17:51 +0000 Subject: [PATCH] **Changed**: - Changed *CommandService* to now receive the *MessageBrokerService* in the command and help communication with the game architecture --- CHANGELOG.md | 5 ++++ Runtime/CommandService.cs | 29 ++++++++++++++++----- Tests/Editor/EditMode/CommandServiceTest.cs | 4 +-- package.json | 2 +- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65951ab..9750bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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**: diff --git a/Runtime/CommandService.cs b/Runtime/CommandService.cs index eed04a5..3506383 100644 --- a/Runtime/CommandService.cs +++ b/Runtime/CommandService.cs @@ -6,7 +6,22 @@ namespace GameLovers.Services /// Tags the interface as a /// public interface IGameCommandBase {} - + + /// + /// Contract for the command to be executed in the . + /// Implement this interface if you want logic to be executed ont he server + /// + /// + /// Follows the Command pattern + /// + public interface IGameServerCommand : IGameCommandBase where TGameLogic : class + { + /// + /// Executes the command logic defined by the implemention of this interface + /// + void ExecuteLogic(TGameLogic gameLogic); + } + /// /// Interface representing the command to be executed in the . /// Implement this interface with the proper command logic @@ -19,7 +34,7 @@ public interface IGameCommand : IGameCommandBase where TGameLogic /// /// Executes the command logic defined by the implemention of this interface /// - void Execute(TGameLogic gameLogic); + void Execute(TGameLogic gameLogic, IMessageBrokerService messageBroker); } /// @@ -42,16 +57,18 @@ public interface ICommandService where TGameLogic : class public class CommandService : ICommandService 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; } - + /// public void ExecuteCommand(TCommand command) where TCommand : IGameCommand { - command.Execute(_gameLogic); + command.Execute(_gameLogic, _messageBroker); } } } \ No newline at end of file diff --git a/Tests/Editor/EditMode/CommandServiceTest.cs b/Tests/Editor/EditMode/CommandServiceTest.cs index 952ff9d..659b392 100644 --- a/Tests/Editor/EditMode/CommandServiceTest.cs +++ b/Tests/Editor/EditMode/CommandServiceTest.cs @@ -22,7 +22,7 @@ private struct CommandMockup : IGameCommand { public int Payload; - public void Execute(IGameLogicMockup gameLogic) + public void Execute(IGameLogicMockup gameLogic, IMessageBrokerService messageBroker) { gameLogic.CallMockup(Payload); } @@ -32,7 +32,7 @@ public void Execute(IGameLogicMockup gameLogic) public void Init() { _gameLogicMockup = Substitute.For(); - _commandService = new CommandService(_gameLogicMockup); + _commandService = new CommandService(_gameLogicMockup, Substitute.For()); } [Test] diff --git a/package.json b/package.json index d825aa5..5c5950b 100644 --- a/package.json +++ b/package.json @@ -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",