Skip to content

Commit

Permalink
More fixes to selection bugs. Whew
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Apr 14, 2024
1 parent 192cadd commit 085654e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
18 changes: 8 additions & 10 deletions FRBDK/Glue/CompilerPlugin/CompilerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void StartUp()
};
_runner.OutputReceived += (output) =>
{
ReactToPluginEvent("Compiler_Output_Standard", output);
HandleOutput(output);
};
_runner.ErrorReceived += output =>
{
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ private async Task<ResponseWithContentDto> SendResponseBackToGame(FacadeCommandB
{
response.Content = JsonConvert.SerializeObject(contentToGame);
}
await CommandSender.Self.Send(response);
await CommandSender.Self.Send(response, waitForResponse:false);
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CommandSender
#region Fields/Properties

public Action<string> PrintOutput { get; set; }
public Func<string, Task<GeneralResponse<string>>> SendPacket { get; set; }
public Func<string, bool, Task<GeneralResponse<string>>> SendPacket { get; set; }
SemaphoreSlim sendCommandSemaphore = new SemaphoreSlim(1, 1);

public GlueViewSettingsViewModel GlueViewSettingsViewModel { get; set; }
Expand Down Expand Up @@ -62,13 +62,13 @@ private CommandSender() { }
#region General Send


public async Task<ToolsUtilities.GeneralResponse<string>> Send(object dto, SendImportance importance = SendImportance.Normal)
public async Task<ToolsUtilities.GeneralResponse<string>> 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<ToolsUtilities.GeneralResponse<T>> Send<T>(object dto, SendImportance importance = SendImportance.Normal)
Expand Down Expand Up @@ -103,7 +103,7 @@ private CommandSender() { }
}

string lastSend;
private async Task<ToolsUtilities.GeneralResponse<string>> SendCommand(string text, SendImportance importance = SendImportance.Normal)
private async Task<ToolsUtilities.GeneralResponse<string>> SendCommand(string text, SendImportance importance = SendImportance.Normal, bool waitForResponse = true)
{
var isImportant = importance != SendImportance.IfNotBusy;
var shouldPrint = isImportant && text?.StartsWith("SelectObjectDto:") == false;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -162,9 +167,9 @@ private CommandSender() { }

}

private async Task<ToolsUtilities.GeneralResponse<string>> SendCommandNoSemaphore(string text, bool isImportant, bool shouldPrint )
private async Task<ToolsUtilities.GeneralResponse<string>> SendCommandNoSemaphore(string text, bool isImportant, bool shouldPrint, bool waitForResponse )
{
var returnValue = await SendPacket(text);
var returnValue = await SendPacket(text, waitForResponse);

if (returnValue == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -623,28 +625,39 @@ 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;
_variableSendingManager.GlueViewSettingsViewModel = GlueViewSettingsViewModel;

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<string>();
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<string>();
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<string>() { Succeeded=true };
}

};
//ReactToPluginEventWithReturn("GameCommunication_Send_OldDTO", value);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
}
}

Expand Down

0 comments on commit 085654e

Please sign in to comment.