Skip to content

Commit

Permalink
Fixed Gum code files not added to csproj or removed from csproj
Browse files Browse the repository at this point in the history
fixes #1273
  • Loading branch information
vchelaru committed Nov 22, 2023
1 parent 5002b43 commit a045cda
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
21 changes: 18 additions & 3 deletions FRBDK/Glue/GumPlugin/GumPlugin/MainGumPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ private void AssignEvents()

this.NewScreenCreated += HandleNewScreen;


this.ReactToScreenRemoved += HandleScreenRemoved;

#endregion

this.TryAddContainedObjects += ContainedObjectsManager.Self.HandleTryAddContainedObjects;
Expand Down Expand Up @@ -551,7 +551,7 @@ await TaskManager.Self.AddAsync(async () =>
}


private async void HandleScreenRemoved(FlatRedBall.Glue.SaveClasses.ScreenSave glueScreen, List<string> listToFillWithAdditionalFilesToRemove)
private void HandleScreenRemoved(FlatRedBall.Glue.SaveClasses.ScreenSave glueScreen, List<string> listToFillWithAdditionalFilesToRemove)
{
if (AppState.Self.GumProjectSave != null)
{
Expand All @@ -565,10 +565,25 @@ private async void HandleScreenRemoved(FlatRedBall.Glue.SaveClasses.ScreenSave g
String.Format(Localization.Texts.GumConfirmDeleteScreen,gumScreen.Name, glueScreen));
if(result == System.Windows.MessageBoxResult.Yes)
{
await GumPluginCommands.Self.RemoveScreen(gumScreen);
// don't await this, we want this method to immediately add to the lists
_=GumPluginCommands.Self.RemoveScreen(gumScreen);

listToFillWithAdditionalFilesToRemove.Add(CodeGeneratorManager.Self.CustomRuntimeCodeLocationFor(gumScreen).FullPath);
listToFillWithAdditionalFilesToRemove.Add(CodeGeneratorManager.Self.GeneratedRuntimeCodeLocationFor(gumScreen).FullPath);

// If there are forms screens, remove those too:
var formsCustomFilePath = CodeGeneratorManager.Self.CustomFormsCodeLocationFor(gumScreen);

if(formsCustomFilePath.Exists())
{
listToFillWithAdditionalFilesToRemove.Add(formsCustomFilePath.FullPath);
}

var formsGeneratedFilePath = CodeGeneratorManager.Self.GeneratedFormsCodeLocationFor(gumScreen);
if(formsGeneratedFilePath.Exists())
{
listToFillWithAdditionalFilesToRemove.Add(formsGeneratedFilePath.FullPath);
}
}

}
Expand Down
33 changes: 23 additions & 10 deletions FRBDK/Glue/GumPlugin/GumPlugin/Managers/CodeGeneratorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,22 @@ public class CodeGeneratorManager : Singleton<CodeGeneratorManager>
public FilePath CustomRuntimeCodeLocationFor(ElementSave gumElement) => GumRuntimesFolder + gumElement.Name + "Runtime.cs";
public FilePath GeneratedRuntimeCodeLocationFor(ElementSave gumElement) =>
GumRuntimesFolder + gumElement.Name + "Runtime.Generated.cs";
public FilePath CustomFormsCodeLocationFor(ElementSave gumElement)
{
var subfolder = gumElement is Gum.DataTypes.ScreenSave ? "Screens/"
: gumElement is ComponentSave ? "Components/"
: "Standard/";
return FormsFolder + subfolder + gumElement.Name + "Forms.cs";
}

public FilePath GeneratedFormsCodeLocationFor(ElementSave gumElement)
{
var subfolder = gumElement is Gum.DataTypes.ScreenSave ? "Screens/"
: gumElement is ComponentSave ? "Components/"
: "Standard/";

return FormsFolder + subfolder + gumElement.Name + "Forms.Generated.cs";
}

FilePath GumBehaviorsFolder => GumRuntimesFolder + @"Behaviors\";

Expand Down Expand Up @@ -326,7 +341,6 @@ public GenerationResult GenerateCodeFor(Gum.DataTypes.ElementSave element, bool
// creating the custom code files.
string generatedGumRuntimeCode = mGueDerivingClassCodeGenerator.GenerateCodeFor(element);

var formsFolder = FormsFolder;
var shouldGeneratedFormsBeInProject = false;
string generatedFormsCode = FormsClassCodeGenerator.Self.GenerateCodeFor(element);

Expand Down Expand Up @@ -377,9 +391,10 @@ public GenerationResult GenerateCodeFor(Gum.DataTypes.ElementSave element, bool

#region Custom Forms

string customFormsSaveLocation = formsFolder + subfolder + element.Name + "Forms.cs";
string customFormsSaveLocation = CustomFormsCodeLocationFor(element).FullPath;
var customFormsCode = CustomCodeGenerator.Self.GetCustomFormsCodeTemplateCode(element);

if(string.IsNullOrEmpty(generatedFormsCode))
if(string.IsNullOrEmpty(customFormsCode))
{
resultToReturn.DidSaveCustomForms = false;
}
Expand All @@ -390,17 +405,13 @@ public GenerationResult GenerateCodeFor(Gum.DataTypes.ElementSave element, bool

if (resultToReturn.DidSaveCustomForms)
{
var customCode = CustomCodeGenerator.Self.GetCustomFormsCodeTemplateCode(element);

var directory = FileManager.GetDirectory(customFormsSaveLocation);
System.IO.Directory.CreateDirectory(directory);

GlueCommands.Self.TryMultipleTimes(() =>
System.IO.File.WriteAllText(customFormsSaveLocation, customCode));
}

if(shouldGeneratedFormsBeInProject)
{
System.IO.File.WriteAllText(customFormsSaveLocation, customFormsCode));

bool wasAnythingAdded =
FlatRedBall.Glue.ProjectManager.CodeProjectHelper.AddFileToCodeProjectIfNotAlreadyAdded(
GlueState.Self.CurrentMainProject, customFormsSaveLocation);
Expand Down Expand Up @@ -477,7 +488,7 @@ public GenerationResult GenerateCodeFor(Gum.DataTypes.ElementSave element, bool

#region Generated Forms

FilePath generatedFormsSaveLocation = formsFolder + subfolder + element.Name + "Forms.Generated.cs";
FilePath generatedFormsSaveLocation = GeneratedFormsCodeLocationFor(element);

if(string.IsNullOrEmpty(generatedFormsCode))
{
Expand Down Expand Up @@ -529,6 +540,8 @@ public GenerationResult GenerateCodeFor(Gum.DataTypes.ElementSave element, bool

if (shouldSaveProject && saveProjects)
{
// November 21, 2023 - this isnt working but I'm not sure why - will investigate some time in the future.
// The Forms generated file wasn't embedded.
GlueCommands.Self.ProjectCommands.MakeGeneratedCodeItemsNested();
GlueCommands.Self.ProjectCommands.SaveProjects();
}
Expand Down
3 changes: 2 additions & 1 deletion FRBDK/Localization/Texts.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion FRBDK/Localization/Texts.resx
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@
<value>Gum Plugin - handle new FRB screen {0}</value>
</data>
<data name="GumConfirmDeleteScreen" xml:space="preserve">
<value>Delete the Gum Screen {0}\nfor {1}?</value>
<value>Delete the Gum Screen {0}
for {1}?</value>
</data>
<data name="GumProjectFileCanOnlyAddedToGlobal" xml:space="preserve">
<value>The Gum project file (.gumx) can only be added to global content.</value>
Expand Down

0 comments on commit a045cda

Please sign in to comment.