Skip to content

Commit

Permalink
Fixed object stripping not considering HasPublicProperty
Browse files Browse the repository at this point in the history
Fixed object stripping removing objects that had SetByDerived == true
Added comments.
Fixed spacing and newlines on popup about removing instances.
  • Loading branch information
vchelaru committed Jan 26, 2024
1 parent 9d28595 commit 3f89dcd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
21 changes: 20 additions & 1 deletion FRBDK/Glue/Glue/Extensions/GlueProjectSaveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ private static bool DetermineIfShouldStripNos(List<GlueElement> 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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

namespace FlatRedBall.Glue.Plugins.CodeGenerators
{
/// <summary>
/// Base class for a code generator responsible for generating a stand-alone file. This is typically
/// used to inject utility classes or runtime objects.
/// </summary>
public abstract class FullFileCodeGenerator
{
public abstract string RelativeFile { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions FRBDK/Glue/Glue/Plugins/PluginBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,14 @@ List<Game1CodeGenerator> GameCodeGenerators
set;
} = new List<Game1CodeGenerator>();

/// <summary>
/// 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.
/// </summary>
/// <param name="codeGenerator">The component to add.</param>
public void RegisterCodeGenerator(ElementComponentCodeGenerator codeGenerator)
{
CodeGenerators.Add(codeGenerator);
Expand Down
1 change: 1 addition & 0 deletions FRBDK/Glue/Glue/SaveClasses/EntitySave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 3f89dcd

Please sign in to comment.