Merge branch 'fix-module-names' of https://github.com/MineBill/FlaxEngine into MineBill-fix-module-names

This commit is contained in:
Wojtek Figat
2023-10-20 12:29:00 +02:00

View File

@@ -369,7 +369,7 @@ namespace FlaxEditor.Windows
}
var pluginPath = Path.Combine(Globals.ProjectFolder, "Source", nameTextBox.Text);
if (Directory.Exists(pluginPath))
if (!IsValidModuleName(nameTextBox.Text) || Directory.Exists(pluginPath))
{
nameTextBox.BorderColor = Color.Red;
nameTextBox.BorderSelectedColor = Color.Red;
@@ -429,6 +429,12 @@ namespace FlaxEditor.Windows
submitButton.Clicked += () =>
{
// TODO: Check all modules in project including plugins
if (!IsValidModuleName(nameTextBox.Text))
{
Editor.LogWarning("Invalid module name. Module names cannot contain spaces, start with a number or contain non-alphanumeric characters.");
return;
}
if (Directory.Exists(Path.Combine(Globals.ProjectFolder, "Source", nameTextBox.Text)))
{
Editor.LogWarning("Cannot create module due to name conflict.");
@@ -460,5 +466,16 @@ namespace FlaxEditor.Windows
button.ParentContextMenu.Hide();
};
}
private static bool IsValidModuleName(string text)
{
if (text.Contains(' '))
return false;
if (char.IsDigit(text[0]))
return false;
if (text.Any(c => !char.IsLetterOrDigit(c) && c != '_'))
return false;
return true;
}
}
}