Fix merge problem

This commit is contained in:
ExMatics HydrogenC
2023-12-01 18:06:25 +08:00
parent 3d139a241a
commit 3c5035d3e9

View File

@@ -14,7 +14,6 @@ using FlaxEditor.GUI.Tabs;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEngine.Json;
using FlaxEngine.Utilities;
namespace FlaxEditor.Windows
{
@@ -122,7 +121,7 @@ namespace FlaxEditor.Windows
url = desc.RepositoryUrl;
versionLabel.Font.Font.WaitForLoaded();
var font = versionLabel.Font.GetFont();
var authorWidth = FallbackTextUtils.MeasureText(font, desc.Author).X + 8;
var authorWidth = font.MeasureText(desc.Author).X + 8;
var authorLabel = new ClickableLabel
{
HorizontalAlignment = TextAlignment.Far,
@@ -392,6 +391,7 @@ namespace FlaxEditor.Windows
}
Editor.Log("Plugin project has been cloned.");
try
{
// Start git submodule clone
@@ -412,24 +412,28 @@ namespace FlaxEditor.Windows
}
// Find project config file. Could be different then what the user named the folder.
var files = Directory.GetFiles(clonePath);
string pluginProjectName = "";
foreach (var file in files)
foreach (var file in Directory.GetFiles(clonePath))
{
if (file.Contains(".flaxproj", StringComparison.OrdinalIgnoreCase))
{
pluginProjectName = Path.GetFileNameWithoutExtension(file);
Debug.Log(pluginProjectName);
break;
}
}
if (string.IsNullOrEmpty(pluginProjectName))
Editor.LogError("Failed to find plugin project file to add to Project config. Please add manually.");
else
{
await AddReferenceToProject(pluginName, pluginProjectName);
MessageBox.Show($"{pluginName} has been successfully cloned. Restart editor for changes to take effect.", "Plugin Project Created", MessageBoxButtons.OK);
Editor.LogError("Failed to find plugin project file to add to Project config. Please add manually.");
return;
}
await AddModuleReferencesInGameModule(clonePath);
await AddReferenceToProject(pluginName, pluginProjectName);
if (Editor.Options.Options.SourceCode.AutoGenerateScriptsProjectFiles)
Editor.ProgressReporting.GenerateScriptsProjectFiles.RunAsync();
MessageBox.Show($"{pluginName} has been successfully cloned. Restart editor for changes to take effect.", "Plugin Project Created", MessageBoxButtons.OK);
}
private void OnAddButtonClicked()
@@ -749,6 +753,37 @@ namespace FlaxEditor.Windows
MessageBox.Show($"{pluginName} has been successfully created. Restart editor for changes to take effect.", "Plugin Project Created", MessageBoxButtons.OK);
}
private async Task AddModuleReferencesInGameModule(string pluginFolderPath)
{
// Common game build script location
var gameScript = Path.Combine(Globals.ProjectFolder, "Source/Game/Game.Build.cs");
if (File.Exists(gameScript))
{
var gameScriptContents = await File.ReadAllTextAsync(gameScript);
var insertLocation = gameScriptContents.IndexOf("base.Setup(options);", StringComparison.Ordinal);
if (insertLocation != -1)
{
insertLocation += 20;
var modifiedAny = false;
// Find all code modules in a plugin to auto-reference them in game build script
foreach (var subDir in Directory.GetDirectories(Path.Combine(pluginFolderPath, "Source")))
{
var pluginModuleName = Path.GetFileName(subDir);
var pluginModuleScriptPath = Path.Combine(subDir, pluginModuleName + ".Build.cs");
if (File.Exists(pluginModuleScriptPath))
{
gameScriptContents = gameScriptContents.Insert(insertLocation, $"\n options.PublicDependencies.Add(\"{pluginModuleName}\");");
modifiedAny = true;
}
}
if (modifiedAny)
await File.WriteAllTextAsync(gameScript, gameScriptContents, Encoding.UTF8);
}
}
}
private async Task AddReferenceToProject(string pluginFolderName, string pluginName)
{
// Project flax config file