diff --git a/FRBDK/Glue/CompilerPlugin/CompilerPlugin.cs b/FRBDK/Glue/CompilerPlugin/CompilerPlugin.cs index 14b11a880..cc245e25e 100644 --- a/FRBDK/Glue/CompilerPlugin/CompilerPlugin.cs +++ b/FRBDK/Glue/CompilerPlugin/CompilerPlugin.cs @@ -45,7 +45,7 @@ public override void StartUp() }; _runner.OutputReceived += (output) => { - ReactToPluginEvent("Compiler_Output_Standard", output); + HandleOutput(output); }; _runner.ErrorReceived += output => { @@ -133,7 +133,7 @@ private void AssignControlEvents() MainControl.BuildClicked += async (not, used) => { var compileResponse = await _compiler.Compile( - (value) => ReactToPluginEvent("Compiler_Output_Standard", value), + (value) => HandleOutput(value), (value) => ReactToPluginEvent("Compiler_Output_Error", value), _compilerViewModel.Configuration, _compilerViewModel.IsPrintMsBuildCommandChecked); @@ -150,7 +150,7 @@ private void AssignControlEvents() MainControl.RunClicked += async (not, used) => { - var response = await _compiler.Compile((value) => ReactToPluginEvent("Compiler_Output_Standard", value), (value) => ReactToPluginEvent("Compiler_Output_Error", value), _compilerViewModel.Configuration, _compilerViewModel.IsPrintMsBuildCommandChecked); + var response = await _compiler.Compile((value) => HandleOutput(value), (value) => ReactToPluginEvent("Compiler_Output_Error", value), _compilerViewModel.Configuration, _compilerViewModel.IsPrintMsBuildCommandChecked); if (response.Succeeded) { _runner.IsRunning = false; @@ -192,8 +192,12 @@ private void AssignControlEvents() #endregion + public void HandleOutput(string output) => MainControl.PrintOutput(output); + #region Overrided Method + + public override void HandleEvent(string eventName, string payload) { base.HandleEvent(eventName, payload); @@ -212,12 +216,6 @@ public override void HandleEvent(string eventName, string payload) ); } break; - case "Compiler_Output_Standard": - { - MainControl.PrintOutput(payload); - - } - break; case "Compiler_Output_Error": { MainControl.PrintError(payload); @@ -235,7 +233,7 @@ public async Task Compile(string configuration, bool printMsBuildCommand, Compil try { var result = await _compiler.Compile( - (value) => ReactToPluginEvent("Compiler_Output_Standard", value), + (value) => HandleOutput(value), (value) => ReactToPluginEvent("Compiler_Output_Error", value), configuration, printMsBuildCommand diff --git a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandReceiving/CommandReceiver.cs b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandReceiving/CommandReceiver.cs index 1cb71955c..f67935246 100644 --- a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandReceiving/CommandReceiver.cs +++ b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandReceiving/CommandReceiver.cs @@ -885,7 +885,7 @@ private async Task SendResponseBackToGame(FacadeCommandB { response.Content = JsonConvert.SerializeObject(contentToGame); } - await CommandSender.Self.Send(response); + await CommandSender.Self.Send(response, waitForResponse:false); return response; } diff --git a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandSending/CommandSender.cs b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandSending/CommandSender.cs index 05969b0e4..b13d0d151 100644 --- a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandSending/CommandSender.cs +++ b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/CommandSending/CommandSender.cs @@ -28,7 +28,7 @@ public class CommandSender #region Fields/Properties public Action PrintOutput { get; set; } - public Func>> SendPacket { get; set; } + public Func>> SendPacket { get; set; } SemaphoreSlim sendCommandSemaphore = new SemaphoreSlim(1, 1); public GlueViewSettingsViewModel GlueViewSettingsViewModel { get; set; } @@ -62,13 +62,13 @@ private CommandSender() { } #region General Send - public async Task> Send(object dto, SendImportance importance = SendImportance.Normal) + public async Task> Send(object dto, SendImportance importance = SendImportance.Normal, bool waitForResponse = true) { var dtoTypeName = dto.GetType().Name; var serialized = JsonConvert.SerializeObject(dto); - return await SendCommand($"{dtoTypeName}:{serialized}", importance); + return await SendCommand($"{dtoTypeName}:{serialized}", importance, waitForResponse:waitForResponse); } public async Task> Send(object dto, SendImportance importance = SendImportance.Normal) @@ -103,7 +103,7 @@ private CommandSender() { } } string lastSend; - private async Task> SendCommand(string text, SendImportance importance = SendImportance.Normal) + private async Task> SendCommand(string text, SendImportance importance = SendImportance.Normal, bool waitForResponse = true) { var isImportant = importance != SendImportance.IfNotBusy; var shouldPrint = isImportant && text?.StartsWith("SelectObjectDto:") == false; @@ -140,7 +140,12 @@ private CommandSender() { } { if (!isSemaphoreAvailable) { + + var textPrefix = text?.Contains(":")==true ? text.Substring(0, text.IndexOf(":")) : text; + var lastPrefix = lastSend?.Contains(":")==true ? lastSend.Substring(0, lastSend.IndexOf(":")) : lastSend; + GlueCommands.Self.PrintOutput($"Waiting to send {textPrefix}\nWaiting on {lastPrefix}"); await sendCommandSemaphore.WaitAsync(); + GlueCommands.Self.PrintOutput($"--Done with {textPrefix}"); } lastSend = text; @@ -151,7 +156,7 @@ private CommandSender() { } while(result.Succeeded == false && triesLeft > 0) { triesLeft--; - result = await SendCommandNoSemaphore(text, isImportant, shouldPrint); + result = await SendCommandNoSemaphore(text, isImportant, shouldPrint, waitForResponse); } return result; } @@ -162,9 +167,9 @@ private CommandSender() { } } - private async Task> SendCommandNoSemaphore(string text, bool isImportant, bool shouldPrint ) + private async Task> SendCommandNoSemaphore(string text, bool isImportant, bool shouldPrint, bool waitForResponse ) { - var returnValue = await SendPacket(text); + var returnValue = await SendPacket(text, waitForResponse); if (returnValue == null) { diff --git a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/MainCompilerPlugin.cs b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/MainCompilerPlugin.cs index f621997b9..03df46375 100644 --- a/FRBDK/Glue/GameCommunicationPlugin/GlueControl/MainCompilerPlugin.cs +++ b/FRBDK/Glue/GameCommunicationPlugin/GlueControl/MainCompilerPlugin.cs @@ -102,7 +102,9 @@ public override Version Version public override void StartUp() { _refreshManager = new RefreshManager(ReactToPluginEventWithReturn, ReactToPluginEvent); - _refreshManager.InitializeEvents((value) => this.ReactToPluginEvent("Compiler_Output_Standard", value), (value) => this.ReactToPluginEvent("Compiler_Output_Error", value)); + _refreshManager.InitializeEvents( + (value) => PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", value), + (value) => this.ReactToPluginEvent("Compiler_Output_Error", value)); _dragDropManagerGameWindow = new DragDropManagerGameWindow(_refreshManager); _variableSendingManager = new VariableSendingManager(_refreshManager); @@ -112,7 +114,7 @@ public override void StartUp() CreateToolbar(); - Output.Initialize((value) => this.ReactToPluginEvent("Compiler_Output_Standard", value)); + Output.Initialize((value) => PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", value)); game1GlueControlGenerator = new Game1GlueControlGenerator(); @@ -538,7 +540,7 @@ private void CreateGameTab() //pluginTab = base.CreateAndAddTab(GameHostView, "Game Contrll", TabLocation.Bottom); _gameHostController = new GameHostController(); - _gameHostController.Initialize(gameHostView, (value) => ReactToPluginEvent("Compiler_Output_Standard", value), + _gameHostController.Initialize(gameHostView, (value) => PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", value), CompilerViewModel, GlueViewSettingsViewModel, glueViewSettingsTab, @@ -623,7 +625,7 @@ private void CreateBuildControl() _refreshManager.ViewModel = CompilerViewModel; _dragDropManagerGameWindow.CompilerViewModel = CompilerViewModel; _commandReceiver.CompilerViewModel = CompilerViewModel; - _commandReceiver.PrintOutput = (value) => ReactToPluginEvent("Compiler_Output_Standard", value); + _commandReceiver.PrintOutput = (value) => PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", value); _refreshManager.GlueViewSettingsViewModel = GlueViewSettingsViewModel; _variableSendingManager.ViewModel = CompilerViewModel; @@ -631,20 +633,31 @@ private void CreateBuildControl() CommandSender.Self.GlueViewSettingsViewModel = GlueViewSettingsViewModel; CommandSender.Self.CompilerViewModel = CompilerViewModel; - CommandSender.Self.PrintOutput = (value) => ReactToPluginEvent("Compiler_Output_Standard", value); - CommandSender.Self.SendPacket = async (value) => + CommandSender.Self.PrintOutput = (value) => PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", value); + CommandSender.Self.SendPacket = async (value, waitForResponse) => { - var response = await GameJsonCommunicationPlugin.Common.GameConnectionManager.Self.SendItemWithResponse(new GameJsonCommunicationPlugin.Common.GameConnectionManager.Packet + var whatToSend = new GameJsonCommunicationPlugin.Common.GameConnectionManager.Packet { PacketType = "OldDTO", Payload = value - }); + }; - var toReturn = new global::ToolsUtilities.GeneralResponse(); - toReturn.SetFrom(response); - toReturn.Data = response?.Data?.Payload; + if(waitForResponse) + { + var response = await GameJsonCommunicationPlugin.Common.GameConnectionManager.Self.SendItemWithResponse(whatToSend); - return toReturn; + var toReturn = new global::ToolsUtilities.GeneralResponse(); + toReturn.SetFrom(response); + toReturn.Data = response?.Data?.Payload; + + return toReturn; + } + else + { + GameJsonCommunicationPlugin.Common.GameConnectionManager.Self.SendItem(whatToSend); + // I guess we return success? + return new global::ToolsUtilities.GeneralResponse() { Succeeded=true }; + } }; //ReactToPluginEventWithReturn("GameCommunication_Send_OldDTO", value); @@ -782,7 +795,8 @@ private async Task ReactToPlayOrEditSet() { message += $"Game sent back the following message: {response.Message}"; } - ReactToPluginEvent("Compiler_Output_Standard", message); + PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", message); + GlueCommands.Self.PrintOutput(message); } else if (CommandSender.Self.IsConnected == false) @@ -861,7 +875,7 @@ private async Task ReactToPlayOrEditSet() private async Task HandlePortOrGenerateCheckedChanged(string propertyName) { - ReactToPluginEvent("Compiler_Output_Standard", "Applying changes"); + PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", "Applying Changes"); game1GlueControlGenerator.IsGlueControlManagerGenerationEnabled = GlueViewSettingsViewModel.EnableLiveEdit && IsFrbNewEnough(); game1GlueControlGenerator.PortNumber = GlueViewSettingsViewModel.PortNumber; _refreshManager.PortNumber = GlueViewSettingsViewModel.PortNumber; @@ -891,9 +905,10 @@ private async Task HandlePortOrGenerateCheckedChanged(string propertyName) _refreshManager.CreateStopAndRestartTask($"{propertyName} changed"); - ReactToPluginEvent("Compiler_Output_Standard", "Waiting for tasks to finish..."); + PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", "Waiting for tasks to finish..."); await TaskManager.Self.WaitForAllTasksFinished(); - ReactToPluginEvent("Compiler_Output_Standard", "Finishined adding/generating code for GlueControlManager"); + + PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", "Finishined adding/generating code for GlueControlManager"); } private static void AddNewtonsoft() @@ -986,12 +1001,12 @@ private void OutputSuccessOrFailure(bool succeeded) { if (succeeded) { - ReactToPluginEvent("Compiler_Output_Standard", $"{DateTime.Now.ToLongTimeString()} Build succeeded"); + PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", $"{DateTime.Now.ToLongTimeString()} Build succeeded"); + } else { - ReactToPluginEvent("Compiler_Output_Standard", $"{DateTime.Now.ToLongTimeString()} Build failed"); - + PluginManager.CallPluginMethod("Compiler Plugin", "HandleOutput", $"{DateTime.Now.ToLongTimeString()} Build failed"); } }