From 1658ddb9d75f0d862ee775654d5e9a99ebc9cdc7 Mon Sep 17 00:00:00 2001 From: Victor Chelaru Date: Tue, 21 Nov 2023 20:22:14 -0700 Subject: [PATCH] Oops caused too much codegen for forms. --- .../Managers/CodeGeneratorManager.cs | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/CodeGeneratorManager.cs b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/CodeGeneratorManager.cs index b50b90205..072f6706f 100644 --- a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/CodeGeneratorManager.cs +++ b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/CodeGeneratorManager.cs @@ -391,33 +391,39 @@ public GenerationResult GenerateCodeFor(Gum.DataTypes.ElementSave element, bool #region Custom Forms - string customFormsSaveLocation = CustomFormsCodeLocationFor(element).FullPath; - var customFormsCode = CustomCodeGenerator.Self.GetCustomFormsCodeTemplateCode(element); + // Check if generated code is created. If not, don't create a custom. + // Generated may not be created if this maps to a standard Forms object + // like Button. + if (shouldGeneratedFormsBeInProject) + { + string customFormsSaveLocation = CustomFormsCodeLocationFor(element).FullPath; + var customFormsCode = CustomCodeGenerator.Self.GetCustomFormsCodeTemplateCode(element); - if(string.IsNullOrEmpty(customFormsCode)) - { - resultToReturn.DidSaveCustomForms = false; - } - else if(!System.IO.File.Exists(customFormsSaveLocation)) - { - resultToReturn.DidSaveCustomForms = true; - } + if(string.IsNullOrEmpty(customFormsCode)) + { + resultToReturn.DidSaveCustomForms = false; + } + else if(!System.IO.File.Exists(customFormsSaveLocation)) + { + resultToReturn.DidSaveCustomForms = true; + } - if (resultToReturn.DidSaveCustomForms) - { + if (resultToReturn.DidSaveCustomForms) + { - var directory = FileManager.GetDirectory(customFormsSaveLocation); - System.IO.Directory.CreateDirectory(directory); + var directory = FileManager.GetDirectory(customFormsSaveLocation); + System.IO.Directory.CreateDirectory(directory); - GlueCommands.Self.TryMultipleTimes(() => - System.IO.File.WriteAllText(customFormsSaveLocation, customFormsCode)); + GlueCommands.Self.TryMultipleTimes(() => + System.IO.File.WriteAllText(customFormsSaveLocation, customFormsCode)); - bool wasAnythingAdded = - FlatRedBall.Glue.ProjectManager.CodeProjectHelper.AddFileToCodeProjectIfNotAlreadyAdded( - GlueState.Self.CurrentMainProject, customFormsSaveLocation); - if (wasAnythingAdded) - { - shouldSaveProject = true; + bool wasAnythingAdded = + FlatRedBall.Glue.ProjectManager.CodeProjectHelper.AddFileToCodeProjectIfNotAlreadyAdded( + GlueState.Self.CurrentMainProject, customFormsSaveLocation); + if (wasAnythingAdded) + { + shouldSaveProject = true; + } } }