Skip to content

Commit

Permalink
Fixed copy/paste SpriteList into lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Dec 8, 2023
1 parent 06b09c1 commit 6c8bc09
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
37 changes: 31 additions & 6 deletions FRBDK/Glue/Glue/Elements/ObjectFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using FlatRedBall.Glue.GuiDisplay.Facades;
using FlatRedBall.Glue.Plugins.ExportedImplementations;
using FlatRedBall.Content.Instructions;
using System.Windows.Navigation;

namespace FlatRedBall.Glue.Elements;

Expand Down Expand Up @@ -998,8 +999,20 @@ public NamedObjectSave GetDefaultListToContain(NamedObjectSave namedObject, Glue

}

public List<NamedObjectSave> GetPossibleListsToContain(NamedObjectSave namedObject, GlueElement containerElement)
{
var namedObjectSourceClassType = namedObject.SourceClassType;
return GetPossibleListsToContain(namedObjectSourceClassType, containerElement);
}

public NamedObjectSave GetDefaultListToContain(string namedObjectSourceClassType, GlueElement containerElement)
{
return GetPossibleListsToContain(namedObjectSourceClassType, containerElement).FirstOrDefault();
}

public List<NamedObjectSave> GetPossibleListsToContain(string namedObjectSourceClassType, GlueElement containerElement)
{
List<NamedObjectSave> possibleContainers = new List<NamedObjectSave>();
var isNosShape = namedObjectSourceClassType == "FlatRedBall.Math.Geometry.Circle" ||
namedObjectSourceClassType == "FlatRedBall.Math.Geometry.AxisAlignedRectangle" ||
namedObjectSourceClassType == "FlatRedBall.Math.Geometry.Polygon";
Expand All @@ -1009,18 +1022,30 @@ public NamedObjectSave GetDefaultListToContain(string namedObjectSourceClassType

if (isNosShape)
{
return containerElement.NamedObjects.FirstOrDefault(item => item.GetAssetTypeInfo() == AvailableAssetTypes.CommonAtis.ShapeCollection);
possibleContainers.AddRange(containerElement.NamedObjects.Where(item => item.GetAssetTypeInfo() == AvailableAssetTypes.CommonAtis.ShapeCollection));
}

if (nosEntity != null)
{
possibleContainers.AddRange(GetPossibleListsToContain(nosEntity, containerElement));
}
else if (nosEntity != null)
else
{
return GetDefaultListToContain(nosEntity, containerElement);
possibleContainers.AddRange(containerElement.NamedObjects.Where(item => item.IsList && item.SourceClassGenericType == namedObjectSourceClassType));
}

return null;
return possibleContainers;
}

public NamedObjectSave GetDefaultListToContain(EntitySave nosEntity, GlueElement containerElement)
{
return GetPossibleListsToContain(nosEntity, containerElement).FirstOrDefault();
}

public List<NamedObjectSave> GetPossibleListsToContain(EntitySave nosEntity, GlueElement containerElement)
{
var toReturn = new List<NamedObjectSave>();

var baseEntityTypes = GetAllBaseElementsRecursively(nosEntity);

// Do the top-level NamedObjects instead of AllNamedObjects
Expand All @@ -1034,12 +1059,12 @@ public NamedObjectSave GetDefaultListToContain(EntitySave nosEntity, GlueElement
{
if (listEntityType == nosEntity || baseEntityTypes.Contains(listEntityType))
{
return listCandidate;
toReturn.Add(listCandidate);
}
}
}
}
return null;
return toReturn;
}

public NamedObjectSave GetRootDefiningObject(NamedObjectSave derivedNos)
Expand Down
5 changes: 4 additions & 1 deletion FRBDK/Glue/Glue/Managers/CopyPasteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ internal async Task HandlePaste()
}
else if(copiedObjectClone is NamedObjectSave asNos)
{
var response = await GlueCommands.Self.GluxCommands.CopyNamedObjectIntoElement(asNos, GlueState.Self.CurrentElement);
var response = await GlueCommands.Self.GluxCommands.CopyNamedObjectIntoElement(asNos, GlueState.Self.CurrentElement,
// pass the current nos so that we can attempt to add it to the current list
// This could be the list itself, or a child of the list - either is fine
GlueState.Self.CurrentNamedObjectSave);
if(response.Succeeded == false)
{
GlueCommands.Self.PrintError(response.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ await TaskManager.Self.AddAsync(() =>
var toReturn = new List<ToolsUtilities.GeneralResponse<NamedObjectSave>>();
foreach (var originalNos in nosList)
{
var response = await CopyNamedObjectIntoElementInner(originalNos, targetElement, performSaveAndGenerateCode:false, updateUi: false, notifyPlugins: false);
var response = await CopyNamedObjectIntoElementInner(originalNos, targetElement, targetNos:null, performSaveAndGenerateCode:false, updateUi: false, notifyPlugins: false);
toReturn.Add(response);
}

Expand Down Expand Up @@ -1893,7 +1893,7 @@ await TaskManager.Self.AddAsync(() =>
}


public async Task<ToolsUtilities.GeneralResponse<NamedObjectSave>> CopyNamedObjectIntoElementInner(NamedObjectSave originalNos, GlueElement targetElement, NamedObjectSave targetNos = null, bool performSaveAndGenerateCode, bool updateUi,
private async Task<ToolsUtilities.GeneralResponse<NamedObjectSave>> CopyNamedObjectIntoElementInner(NamedObjectSave originalNos, GlueElement targetElement, NamedObjectSave targetNos, bool performSaveAndGenerateCode, bool updateUi,
bool notifyPlugins)
{
bool succeeded = true;
Expand Down Expand Up @@ -1921,11 +1921,25 @@ await TaskManager.Self.AddAsync(() =>



NamedObjectSave listOfThisType = null;

// if the current object is a list, or if the current object is in a list that matches this type, then use that
var possibleLists = ObjectFinder.Self.GetPossibleListsToContain(newNos, targetElement);
NamedObjectSave listOfThisType = null;
if(targetNos != null)
{
// is it a list?
var targetList = targetNos.IsList ? targetNos :
targetElement.NamedObjects.FirstOrDefault(item => item.ContainedObjects?.Contains(targetNos) == true);

if(targetList != null && possibleLists.Contains(targetList))
{
listOfThisType = targetList;
}
}

listOfThisType = ObjectFinder.Self.GetDefaultListToContain(newNos, targetElement);
if(listOfThisType == null)
{
listOfThisType = ObjectFinder.Self.GetDefaultListToContain(newNos, targetElement);
}

if (listOfThisType != null)
{
Expand Down

0 comments on commit 6c8bc09

Please sign in to comment.