Skip to content

Commit

Permalink
TileShapeCollections now have collision objects if referencing code
Browse files Browse the repository at this point in the history
Started working on parsing text for file references.
  • Loading branch information
vchelaru committed Feb 19, 2024
1 parent 41c2374 commit a545b03
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Microsoft.Xna.Framework.Color Color

ShapeCollection ICollidable.Collision => this.mShapes;

#if ICollidableHasItemsCollidedAgainst
#if ICollidableHasItemsCollidedAgainst || REFERENCES_FRB_SOURCE


HashSet<string> ICollidable.ItemsCollidedAgainst => this.mShapes.ItemsCollidedAgainst;
Expand All @@ -204,7 +204,7 @@ public Microsoft.Xna.Framework.Color Color

#endif

#if ICollidableHasObjectsCollidedAgainst
#if ICollidableHasObjectsCollidedAgainst|| REFERENCES_FRB_SOURCE

HashSet<object> ICollidable.ObjectsCollidedAgainst => this.mShapes.ObjectsCollidedAgainst;

Expand Down
1 change: 1 addition & 0 deletions FRBDK/Glue/GumPlugin/GumPlugin/GumPluginCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
<EmbeddedResource Include="..\..\..\..\..\Gum\RenderingLibrary\Math\Geometry\SolidRectangle.cs" Link="Embedded\LibraryFiles\RenderingLibrary\SolidRectangle.cs" />
<EmbeddedResource Include="..\..\..\..\..\Gum\RenderingLibrary\Math\MathFunctions.cs" Link="Embedded\LibraryFiles\RenderingLibrary\MathFunctions.cs" />
<EmbeddedResource Include="..\..\..\..\..\Gum\RenderingLibrary\SystemManagers.cs" Link="Embedded\LibraryFiles\RenderingLibrary\SystemManagers.cs" />
<Compile Include="..\..\..\..\..\Gum\GumRuntime\BbCodeParser.cs" Link="BbCodeParser.cs" />
<Compile Include="..\..\..\..\..\Gum\StateAnimationPlugin\SaveClasses\AnimatedStateSave.cs" Link="Animation\AnimatedStateSave.cs" />
<Compile Include="..\..\..\..\..\Gum\StateAnimationPlugin\SaveClasses\AnimationReferenceSave.cs" Link="Animation\AnimationReferenceSave.cs" />
<Compile Include="..\..\..\..\..\Gum\StateAnimationPlugin\SaveClasses\AnimationSave.cs" Link="Animation\AnimationSave.cs" />
Expand Down
90 changes: 81 additions & 9 deletions FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using FlatRedBall.Glue.IO;
using RenderingLibrary.Graphics;
using GeneralResponse = ToolsUtilities.GeneralResponse;
using static FlatRedBall.Glue.SaveClasses.GlueProjectSave;
using Gum.Wireframe;

namespace GumPlugin.Managers
{
Expand Down Expand Up @@ -266,6 +268,16 @@ private static bool IsNineSliceSource(Gum.DataTypes.Variables.VariableSave varia

}

static HashSet<string> fontTags = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
{
"font",
"fontsize",
"outlinethickness",
"isitalic",
"isbold",
"usefontsmoothing",
};

private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive, List<string> listToFill, Gum.DataTypes.Variables.StateSave state, bool includeReferenceInfo)
{

Expand All @@ -284,15 +296,22 @@ private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive
}

var fontVariables = state.Variables.Where(item =>
(item.GetRootName() == "Font" ||
item.GetRootName() == "FontSize" ||
item.GetRootName() == "OutlineThickness" ||
item.GetRootName() == "IsItalic" ||
item.GetRootName() == "IsBold" ||
item.GetRootName() == "UseFontSmoothing"
)
&& item.Value != null
);
{
if(item.Value == null)
{
return false;
}
var rootName = item.GetRootName();

var toReturn = rootName == "Font" ||
rootName == "FontSize" ||
rootName == "OutlineThickness" ||
rootName == "IsItalic" ||
rootName == "IsBold" ||
rootName == "UseFontSmoothing";

return toReturn;
});

foreach (var variable in fontVariables)
{
Expand Down Expand Up @@ -369,6 +388,59 @@ private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive
}
}
}

if(GlueState.Self.CurrentGlueProject.FileVersion >= (int)GluxVersions.GumTextSupportsBbCode)
{
var textVariables = state.Variables.Where(item => (item.Value as string)?.Contains("[") == true && item.GetRootName() == "Text");
foreach(var variable in textVariables)
{
var prefix = String.Empty;
var isTextObject = false;

if (variable.Name.Contains('.'))
{
var instanceName = FileManager.RemoveExtension(variable.Name);

prefix = FileManager.RemoveExtension(variable.Name) + ".";

var instance = state.ParentContainer.GetInstance(instanceName);

if (instance != null)
{
var basicElement = ObjectFinder.Self.GetRootStandardElementSave(instance.GetBaseElementSave());

isTextObject = basicElement?.Name == "Text";
}
else
{
// This code is used to
// determine whether a referenced
// file is necessary in the project.
// Since the instance doesn't exist, we
// won't actually use the variable for the
// instance, so we don't want to track the file.
// We can do this by marking isTextObject as false.
isTextObject = false;
}
}
else
{
isTextObject = isParentElementText;
}

var foundTags = BbCodeParser.Parse(variable.Value as string, fontTags);

if(foundTags.Count > 0)
{
foreach(var tag in foundTags)
{
// todo - Vic says - this is complicated and I'm not going to worry about it yet. Maybe in the future when someone reports it.
}
}

}

}
}

private static void TryAddFontFromSizeAndName(TopLevelOrRecursive topLevelOrRecursive, List<string> listToFill,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public override bool DoCollisions()
didCollisionOccur = true;
CollisionOccurred?.Invoke(singleObject, data.TileShapeCollection);

#if ICollidableHasItemsCollidedAgainst
#if ICollidableHasItemsCollidedAgainst || REFERENCES_FRB_SOURCE
singleObject.ItemsCollidedAgainst.Add(data.TileShapeCollection.Name);
#endif
#if ICollidableHasObjectsCollidedAgainst
#if ICollidableHasObjectsCollidedAgainst || REFERENCES_FRB_SOURCE
singleObject.ObjectsCollidedAgainst.Add(data.TileShapeCollection);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ public override bool DoCollisions()

didCollisionOccur = true;

#if ICollidableHasItemsCollidedAgainst
#if ICollidableHasItemsCollidedAgainst || REFERENCES_FRB_SOURCE
singleObject.ItemsCollidedAgainst.Add(data.TileShapeCollection.Name);
#endif
#if ICollidableHasObjectsCollidedAgainst
#if ICollidableHasObjectsCollidedAgainst || REFERENCES_FRB_SOURCE
singleObject.ObjectsCollidedAgainst.Add(data.TileShapeCollection);
#endif
}
Expand Down

0 comments on commit a545b03

Please sign in to comment.