From 3f89dcd18c85f3188c0a1adc7c9236f4202d7cb4 Mon Sep 17 00:00:00 2001 From: Victor Chelaru Date: Fri, 26 Jan 2024 16:57:11 -0700 Subject: [PATCH] Fixed object stripping not considering HasPublicProperty Fixed object stripping removing objects that had SetByDerived == true Added comments. Fixed spacing and newlines on popup about removing instances. --- .../Extensions/GlueProjectSaveExtensions.cs | 21 ++++++++++++++++++- .../CodeGenerators/FullFileCodeGenerator.cs | 4 ++++ .../CommandInterfaces/ElementCommands.cs | 1 + FRBDK/Glue/Glue/Plugins/PluginBase.cs | 8 +++++++ FRBDK/Glue/Glue/SaveClasses/EntitySave.cs | 1 + .../NamedObjectSaves/SetByDerivedSetLogic.cs | 4 ++-- 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/FRBDK/Glue/Glue/Extensions/GlueProjectSaveExtensions.cs b/FRBDK/Glue/Glue/Extensions/GlueProjectSaveExtensions.cs index 0b75f33e0..fab323dff 100644 --- a/FRBDK/Glue/Glue/Extensions/GlueProjectSaveExtensions.cs +++ b/FRBDK/Glue/Glue/Extensions/GlueProjectSaveExtensions.cs @@ -269,6 +269,24 @@ private static bool DetermineIfShouldStripNos(List baseElements, Na } } + // If + // * objectInDerived.DefinedByBase = true + // -- and -- + // * objectByBase.SetByDerived = true + // Then in most cases the derived will have its SetByDerived = false because + // there is a simple base/derived relationship. But if the inheritance chain + // is 3 long, then the middle one will have both DefinedByBase = true *and* SetByDerived = true. + // This differs from the most common case, and ElementCommands.cs assumes the default case + // the derived is to have SetByDerived = false; + if(shouldStrip) + { + if(nos.SetByDerived == true) + { + shouldStrip = false; + } + } + + if(shouldStrip) { // see if any properties differ from the base @@ -339,7 +357,8 @@ private static bool DoNativePropertiesDiffer(NamedObjectSave nos1, NamedObjectSa nos1.AddToManagers != nos2.AddToManagers || nos1.IncludeInICollidable != nos2.IncludeInICollidable || nos1.IncludeInIClickable != nos2.IncludeInIClickable || - nos1.SourceName != nos2.SourceName; + nos1.SourceName != nos2.SourceName || + nos1.HasPublicProperty != nos2.HasPublicProperty; return differ; } diff --git a/FRBDK/Glue/Glue/Plugins/CodeGenerators/FullFileCodeGenerator.cs b/FRBDK/Glue/Glue/Plugins/CodeGenerators/FullFileCodeGenerator.cs index 31fdb1b65..0e849ea48 100644 --- a/FRBDK/Glue/Glue/Plugins/CodeGenerators/FullFileCodeGenerator.cs +++ b/FRBDK/Glue/Glue/Plugins/CodeGenerators/FullFileCodeGenerator.cs @@ -9,6 +9,10 @@ namespace FlatRedBall.Glue.Plugins.CodeGenerators { + /// + /// Base class for a code generator responsible for generating a stand-alone file. This is typically + /// used to inject utility classes or runtime objects. + /// public abstract class FullFileCodeGenerator { public abstract string RelativeFile { get; } diff --git a/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ElementCommands.cs b/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ElementCommands.cs index 4f936ac85..035b26b25 100644 --- a/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ElementCommands.cs +++ b/FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/ElementCommands.cs @@ -1837,6 +1837,7 @@ private static NamedObjectSave AddSetByDerivedNos(INamedObjectContainer derivedC } } + // For more information on this property, see GlueProjectSaveExtensions.DetermineIfShouldStripNos newNamedObject.SetDefinedByBaseRecursively(true); newNamedObject.SetInstantiatedByBaseRecursively(instantiatedByBase); diff --git a/FRBDK/Glue/Glue/Plugins/PluginBase.cs b/FRBDK/Glue/Glue/Plugins/PluginBase.cs index a86423428..817cfb596 100644 --- a/FRBDK/Glue/Glue/Plugins/PluginBase.cs +++ b/FRBDK/Glue/Glue/Plugins/PluginBase.cs @@ -716,6 +716,14 @@ List GameCodeGenerators set; } = new List(); + /// + /// Registers the argument ElementComponentCodeGenerator to Glue's code generator list. + /// This method also registers the code generator so that it belongs to this plugin in case + /// the plugin wants to remove it later. + /// Code generators that are added here run on every element, and it is up to the + /// code generator to decide if it should actually write code. + /// + /// The component to add. public void RegisterCodeGenerator(ElementComponentCodeGenerator codeGenerator) { CodeGenerators.Add(codeGenerator); diff --git a/FRBDK/Glue/Glue/SaveClasses/EntitySave.cs b/FRBDK/Glue/Glue/SaveClasses/EntitySave.cs index 49568cb3d..6cd211a65 100644 --- a/FRBDK/Glue/Glue/SaveClasses/EntitySave.cs +++ b/FRBDK/Glue/Glue/SaveClasses/EntitySave.cs @@ -248,6 +248,7 @@ public VerticalOrHorizontal VerticalOrHorizontal [XmlIgnore] [JsonIgnore] [CategoryAttribute("Scrollable Entity List")] + [Obsolete("This is no longer used, it should never be assigned or read")] public string ItemType { get diff --git a/FRBDK/Glue/Glue/SetVariable/NamedObjectSaves/SetByDerivedSetLogic.cs b/FRBDK/Glue/Glue/SetVariable/NamedObjectSaves/SetByDerivedSetLogic.cs index e81b1d443..e070bd4a2 100644 --- a/FRBDK/Glue/Glue/SetVariable/NamedObjectSaves/SetByDerivedSetLogic.cs +++ b/FRBDK/Glue/Glue/SetVariable/NamedObjectSaves/SetByDerivedSetLogic.cs @@ -74,8 +74,8 @@ public static async Task ReactToChangedSetByDerived(NamedObjectSave namedObjectS var singleOrPluralPhrase = orphanedNoses.Count == 1 ? "object" : "objects"; var thisOrTheseObjects = orphanedNoses.Count == 1 ? "this object" : "these objects"; var message = - $"Changing SetByDerived will result in the following {singleOrPluralPhrase} no longer being defined by base. What" + - $"would you like to do with {thisOrTheseObjects}:"; + $"Changing SetByDerived will result in the following {singleOrPluralPhrase} no longer being defined by base. What " + + $"would you like to do with {thisOrTheseObjects}:\n"; foreach (var nos in orphanedNoses) {