From a545b03451c882397c79798d0288697788d4bb04 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 19 Feb 2024 10:57:44 -0700 Subject: [PATCH] TileShapeCollections now have collision objects if referencing code Started working on parsing text for file references. --- .../TileShapeCollection.cs | 4 +- .../GumPlugin/GumPlugin/GumPluginCore.csproj | 1 + .../Managers/FileReferenceTracker.cs | 90 +++++++++++++++++-- ...leListVsTileShapeCollectionRelationship.cs | 4 +- ...idableVsTileShapeCollectionRelationship.cs | 4 +- 5 files changed, 88 insertions(+), 15 deletions(-) diff --git a/Engines/FlatRedBallAddOns/FlatRedBall.TileCollisions/TileShapeCollection.cs b/Engines/FlatRedBallAddOns/FlatRedBall.TileCollisions/TileShapeCollection.cs index 2d7fc5a9b..16be5a952 100644 --- a/Engines/FlatRedBallAddOns/FlatRedBall.TileCollisions/TileShapeCollection.cs +++ b/Engines/FlatRedBallAddOns/FlatRedBall.TileCollisions/TileShapeCollection.cs @@ -195,7 +195,7 @@ public Microsoft.Xna.Framework.Color Color ShapeCollection ICollidable.Collision => this.mShapes; -#if ICollidableHasItemsCollidedAgainst +#if ICollidableHasItemsCollidedAgainst || REFERENCES_FRB_SOURCE HashSet ICollidable.ItemsCollidedAgainst => this.mShapes.ItemsCollidedAgainst; @@ -204,7 +204,7 @@ public Microsoft.Xna.Framework.Color Color #endif -#if ICollidableHasObjectsCollidedAgainst +#if ICollidableHasObjectsCollidedAgainst|| REFERENCES_FRB_SOURCE HashSet ICollidable.ObjectsCollidedAgainst => this.mShapes.ObjectsCollidedAgainst; diff --git a/FRBDK/Glue/GumPlugin/GumPlugin/GumPluginCore.csproj b/FRBDK/Glue/GumPlugin/GumPlugin/GumPluginCore.csproj index fb5417863..e24f59160 100644 --- a/FRBDK/Glue/GumPlugin/GumPlugin/GumPluginCore.csproj +++ b/FRBDK/Glue/GumPlugin/GumPlugin/GumPluginCore.csproj @@ -267,6 +267,7 @@ + diff --git a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs index efab7160e..23a580de8 100644 --- a/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs +++ b/FRBDK/Glue/GumPlugin/GumPlugin/Managers/FileReferenceTracker.cs @@ -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 { @@ -266,6 +268,16 @@ private static bool IsNineSliceSource(Gum.DataTypes.Variables.VariableSave varia } + static HashSet fontTags = new HashSet(StringComparer.InvariantCultureIgnoreCase) + { + "font", + "fontsize", + "outlinethickness", + "isitalic", + "isbold", + "usefontsmoothing", + }; + private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive, List listToFill, Gum.DataTypes.Variables.StateSave state, bool includeReferenceInfo) { @@ -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) { @@ -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 listToFill, diff --git a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableListVsTileShapeCollectionRelationship.cs b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableListVsTileShapeCollectionRelationship.cs index 1ca48f376..e1430ec7b 100644 --- a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableListVsTileShapeCollectionRelationship.cs +++ b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableListVsTileShapeCollectionRelationship.cs @@ -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 } diff --git a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableVsTileShapeCollectionRelationship.cs b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableVsTileShapeCollectionRelationship.cs index a69c1fdd8..e0f6ca614 100644 --- a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableVsTileShapeCollectionRelationship.cs +++ b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/EmbeddedCodeFiles/CollidableVsTileShapeCollectionRelationship.cs @@ -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 }