diff --git a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/CodeGeneration/TileShapeCollectionCodeGenerator.cs b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/CodeGeneration/TileShapeCollectionCodeGenerator.cs index 0c2249f37..34a92c218 100644 --- a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/CodeGeneration/TileShapeCollectionCodeGenerator.cs +++ b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/CodeGeneration/TileShapeCollectionCodeGenerator.cs @@ -1,12 +1,15 @@ using FlatRedBall.Glue.CodeGeneration; using FlatRedBall.Glue.CodeGeneration.CodeBuilder; +using FlatRedBall.Glue.GuiDisplay; using FlatRedBall.Glue.Plugins.ICollidablePlugins; using FlatRedBall.Glue.SaveClasses; using FlatRedBall.Math; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using TileGraphicsPlugin.ViewModels; @@ -79,12 +82,7 @@ public override ICodeBlock GenerateAddToManagers(ICodeBlock codeBlock, IElement foreach (var shapeCollection in tileShapeCollections) { - T Get(string name) - { - return shapeCollection.Properties.GetValue(name); - } - - var creationOptions = Get( + var creationOptions = Get(shapeCollection, nameof(TileShapeCollectionPropertiesViewModel.CollisionCreationOptions)); var variable = shapeCollection.GetCustomVariable("Visible"); @@ -107,12 +105,7 @@ T Get(string name) public static string GenerateConstructorFor(NamedObjectSave namedObjectSave) { - T Get(string name) - { - return namedObjectSave.Properties.GetValue(name); - } - - var creationOptions = Get( + var creationOptions = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionCreationOptions)); bool comesFromLayer = creationOptions == CollisionCreationOptions.FromLayer; @@ -120,9 +113,9 @@ T Get(string name) if(comesFromLayer) { var instanceName = namedObjectSave.FieldName; - var mapName = Get(nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); - var layerName = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionLayerName)); - var typeNameInLayer = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionLayerTileType)); + var mapName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); + var layerName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionLayerName)); + var typeNameInLayer = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionLayerTileType)); var effectiveName = layerName; if (!string.IsNullOrEmpty(typeNameInLayer)) @@ -159,11 +152,7 @@ T Get(string name) private void GenerateInitializeCodeFor(NamedObjectSave namedObjectSave, ICodeBlock codeBlock) { - T Get(string name) - { - return namedObjectSave.Properties.GetValue(name); - } - var creationOptions = Get( + var creationOptions = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionCreationOptions)); // Victor Chelaru Sept 6 2021 @@ -248,8 +237,8 @@ T Get(string name) void GenerateFromMapCollision(NamedObjectSave namedObjectSave, ICodeBlock codeBlock) { - var mapName = Get(nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); - var tmxCollisionName = Get(nameof(TileShapeCollectionPropertiesViewModel.TmxCollisionName)); + var mapName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); + var tmxCollisionName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.TmxCollisionName)); var instanceName = namedObjectSave.FieldName; // If we do FirstOrDefault this doesn't fail, but codegen will fail later on. This gives a more informative error @@ -276,25 +265,44 @@ void GenerateFromMapCollision(NamedObjectSave namedObjectSave, ICodeBlock codeBl } - private void GenerateBorderOutline(NamedObjectSave namedObjectSave, ICodeBlock codeBlock) + static T Get(NamedObjectSave namedObjectSave, string name) { - - T Get(string name) + var property = namedObjectSave.Properties.Find(item => item.Name == name); + if(property == null) + { + // go to the view model, get the default value: + var viewModelType = typeof(TileShapeCollectionPropertiesViewModel); + var propertyInfo = viewModelType.GetProperty(name); + var attribute = propertyInfo.GetCustomAttribute(); + if(attribute != null) + { + return (T)attribute.Value; + } + else + { + return default; + } + } + else { return namedObjectSave.Properties.GetValue(name); } + } + private void GenerateBorderOutline(NamedObjectSave namedObjectSave, ICodeBlock codeBlock) + { + string FloatString(float value) => value.ToString(CultureInfo.InvariantCulture) + "f"; - var tileSize = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionTileSize)); + var tileSize = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionTileSize)); var tileSizeString = FloatString(tileSize); - var leftFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillLeft)); + var leftFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillLeft)); var leftFillString = FloatString(leftFill); - var topFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillTop)); + var topFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillTop)); var topFillString = FloatString(topFill); - var borderOutlineType = (BorderOutlineType)Get( + var borderOutlineType = (BorderOutlineType)Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.BorderOutlineType)); var remainderX = leftFill % tileSize; @@ -313,15 +321,15 @@ T Get(string name) codeBlock.Line($"{instanceName}.SortAxis = FlatRedBall.Math.Axis.X;"); //TileShapeCollectionInstance.SortAxis = FlatRedBall.Math.Axis.X; - var widthFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillWidth)); - var heightFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillHeight)); + var widthFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillWidth)); + var heightFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillHeight)); if(borderOutlineType == BorderOutlineType.InnerSize) { - var innerWidth = Get( + var innerWidth = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.InnerSizeWidth)); - var innerHeight = Get( + var innerHeight = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.InnerSizeHeight)); var additionalWidth = 2 * tileSize; @@ -365,22 +373,18 @@ T Get(string name) private void GenerateFillCompletely(NamedObjectSave namedObjectSave, ICodeBlock codeBlock) { - T Get(string name) - { - return namedObjectSave.Properties.GetValue(name); - } - var tileSize = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionTileSize)); + var tileSize = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionTileSize)); var tileSizeString = tileSize.ToString(CultureInfo.InvariantCulture) + "f"; - var leftFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillLeft)); + var leftFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillLeft)); var leftFillString = leftFill.ToString(CultureInfo.InvariantCulture) + "f"; - var topFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillTop)); + var topFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillTop)); var topFillString = topFill.ToString(CultureInfo.InvariantCulture) + "f"; - var widthFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillWidth)); - var heightFill = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionFillHeight)); + var widthFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillWidth)); + var heightFill = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionFillHeight)); var remainderX = leftFill % tileSize; var remainderY = topFill % tileSize; @@ -417,13 +421,9 @@ T Get(string name) private void GenerateFromProperties(NamedObjectSave namedObjectSave, ICodeBlock codeBlock) { - T Get(string name) - { - return namedObjectSave.Properties.GetValue(name); - } - var mapName = Get(nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); - var propertyName = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionPropertyName)); + var mapName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); + var propertyName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionPropertyName)); if(!string.IsNullOrEmpty(mapName) && !string.IsNullOrEmpty(propertyName)) { @@ -441,15 +441,11 @@ T Get(string name) private void GenerateFromTileType(NamedObjectSave namedObjectSave, ICodeBlock codeBlock) { - T Get(string name) - { - return namedObjectSave.Properties.GetValue(name); - } - var mapName = Get(nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); - var typeName = Get(nameof(TileShapeCollectionPropertiesViewModel.CollisionTileTypeName)); - var removeTiles = Get(nameof(TileShapeCollectionPropertiesViewModel.RemoveTilesAfterCreatingCollision)); - var isMerged = Get(nameof(TileShapeCollectionPropertiesViewModel.IsCollisionMerged)); + var mapName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.SourceTmxName)); + var typeName = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.CollisionTileTypeName)); + var removeTiles = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.RemoveTilesAfterCreatingCollision)); + var isMerged = Get(namedObjectSave, nameof(TileShapeCollectionPropertiesViewModel.IsCollisionMerged)); if (!string.IsNullOrEmpty(mapName) && !string.IsNullOrEmpty(typeName)) { string method = "AddCollisionFromTilesWithType"; @@ -478,11 +474,7 @@ public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, IElem else { // override it if it's an outline: - T Get(string name) - { - return tileShapeCollection.Properties.GetValue(name); - } - var creationOptions = Get( + var creationOptions = Get(tileShapeCollection, nameof(TileShapeCollectionPropertiesViewModel.CollisionCreationOptions)); if(creationOptions == CollisionCreationOptions.BorderOutline) diff --git a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/Views/TileNodeNetworkProperties.xaml b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/Views/TileNodeNetworkProperties.xaml index c93d0f36f..e4d107551 100644 --- a/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/Views/TileNodeNetworkProperties.xaml +++ b/FRBDK/Glue/TileGraphicsPlugin/TileGraphicsPlugin/Views/TileNodeNetworkProperties.xaml @@ -9,46 +9,46 @@ - + - - + + - - + + + IsChecked="{Binding IsEmptyChecked}" Content="Empty" /> + IsChecked="{Binding IsFillCompletelyChecked}" Content="Fill Completely" /> - + - + - + - + - + @@ -56,14 +56,14 @@ + IsChecked="{Binding IsFromTypeChecked}" Content="From Type:" /> - + - + + IsChecked="{Binding IsFromLayerChecked}" Content="From Layer:" /> - + + IsChecked="{Binding IsEmptyChecked}" Content="Empty" /> + IsChecked="{Binding IsFillCompletelyChecked}" Content="Fill Completely" /> - + @@ -61,7 +61,7 @@ - + @@ -190,7 +190,7 @@ + IsChecked="{Binding IsFromLayerChecked}" Content="From Layer:" /> - /// Looks up a localized string similar to Activate. - /// - public static string Activate { - get { - return ResourceManager.GetString("Activate", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Add. - /// - public static string Add { - get { - return ResourceManager.GetString("Add", resourceCulture); - } - } - /// /// Looks up a localized string similar to Add FRB Source. /// @@ -1491,15 +1473,6 @@ public static string EmbedNAudioClasses { } } - /// - /// Looks up a localized string similar to Empty. - /// - public static string Empty { - get { - return ResourceManager.GetString("Empty", resourceCulture); - } - } - /// /// Looks up a localized string similar to All empty. /// @@ -2454,15 +2427,6 @@ public static string FileXNotRelativeToContentFolder { } } - /// - /// Looks up a localized string similar to Fill Completely. - /// - public static string FillCompletely { - get { - return ResourceManager.GetString("FillCompletely", resourceCulture); - } - } - /// /// Looks up a localized string similar to Fill values from default?. /// @@ -3868,15 +3832,6 @@ public static string HintThisWillReplacePoints { } } - /// - /// Looks up a localized string similar to This TileShapeCollection is defined in a base Screen. Changes must be made in the base screen.. - /// - public static string HintTileShapeCollection { - get { - return ResourceManager.GetString("HintTileShapeCollection", resourceCulture); - } - } - /// /// Looks up a localized string similar to The amount of time that the player can hold the jump button to jump higher. While the button is held, gravity is disabled.. /// @@ -4300,15 +4255,6 @@ public static string LayeredTileMapAdd { } } - /// - /// Looks up a localized string similar to From layer:. - /// - public static string LayerFrom { - get { - return ResourceManager.GetString("LayerFrom", resourceCulture); - } - } - /// /// Looks up a localized string similar to Layer name:. /// @@ -4381,15 +4327,6 @@ public static string LinkGameToFrbSource { } } - /// - /// Looks up a localized string similar to Links Per Node. - /// - public static string LinksPerNode { - get { - return ResourceManager.GetString("LinksPerNode", resourceCulture); - } - } - /// /// Looks up a localized string similar to . /// @@ -7090,15 +7027,6 @@ public static string TilesHigh { } } - /// - /// Looks up a localized string similar to Tile Size:. - /// - public static string TileSize { - get { - return ResourceManager.GetString("TileSize", resourceCulture); - } - } - /// /// Looks up a localized string similar to Remove Tiles. /// diff --git a/FRBDK/Localization/Texts.de.resx b/FRBDK/Localization/Texts.de.resx index a7a84b396..eb61aff3e 100644 --- a/FRBDK/Localization/Texts.de.resx +++ b/FRBDK/Localization/Texts.de.resx @@ -1116,9 +1116,6 @@ Zu: - - Aktivieren - Ausführen @@ -1506,9 +1503,6 @@ Höhe: - - Hinzufügen - Entfernen @@ -1779,33 +1773,21 @@ XML für gekachelte Objekte anzeigen - - Links pro Knoten - Vier Acht - - Leer - Erstellungsoptionen - - Vollständig ausfüllen - Eliminieren Sie abgeschnittene Ecken Links: - - Fliesengröße: - Spitze: @@ -1827,18 +1809,12 @@ Eigenschaft: - - Von der schicht: - Schicht: Alles leer - - Diese TileShapeCollection wird in einem Basisbildschirm definiert. Änderungen müssen im Basisbildschirm vorgenommen werden. - Grenzumriss diff --git a/FRBDK/Localization/Texts.fr.resx b/FRBDK/Localization/Texts.fr.resx index ac665ef57..f296160db 100644 --- a/FRBDK/Localization/Texts.fr.resx +++ b/FRBDK/Localization/Texts.fr.resx @@ -1116,9 +1116,6 @@ Vers: - - Activer - Exécuter @@ -1506,9 +1503,6 @@ Hauteur: - - Ajouter - Supprimer @@ -1779,33 +1773,21 @@ Afficher les objets en mosaïque XML - - Liens par nœud - Quatre Huit - - Vide - Options de création - - Remplissez complètement - Éliminez les coins coupés Gauche: - - Taille des carreaux : - Haut: @@ -1827,18 +1809,12 @@ Propriété: - - À partir du calque : - Couche: Tout vide - - Cette TileShapeCollection est définie dans un écran de base. Les modifications doivent être apportées dans l'écran de base. - Contour de la frontière diff --git a/FRBDK/Localization/Texts.nl.resx b/FRBDK/Localization/Texts.nl.resx index 8ad69c8b7..1136c2483 100644 --- a/FRBDK/Localization/Texts.nl.resx +++ b/FRBDK/Localization/Texts.nl.resx @@ -1116,9 +1116,6 @@ Tot: - - Activeren - Uitvoeren @@ -1506,9 +1503,6 @@ Hoogte: - - Toevoegen - Verwijderen @@ -1779,33 +1773,21 @@ Bekijk betegelde objecten XML - - Links per knooppunt - Vier Acht - - Leeg - Creatie opties - - Vul volledig - Elimineer snijhoeken Links: - - Tegelgrootte: - Boven: @@ -1827,18 +1809,12 @@ Eigenschap: - - Van laag: - Laag: Allemaal leeg - - Deze TileShapeCollection wordt gedefinieerd in een basisscherm. Wijzigingen moeten in het basisscherm worden aangebracht. - Randlijn diff --git a/FRBDK/Localization/Texts.resx b/FRBDK/Localization/Texts.resx index 6dd857b70..652ce4aea 100644 --- a/FRBDK/Localization/Texts.resx +++ b/FRBDK/Localization/Texts.resx @@ -1117,9 +1117,6 @@ for {1}? To - - Activate - Execute @@ -1507,9 +1504,6 @@ for {1}? Height: - - Add - Remove @@ -1780,33 +1774,21 @@ for {1}? View Tiled Objects XML - - Links Per Node - Four Eight - - Empty - Creation Options - - Fill Completely - Eliminate Cut Corners Left: - - Tile Size: - Top: @@ -1828,18 +1810,12 @@ for {1}? Property: - - From layer: - Layer: All empty - - This TileShapeCollection is defined in a base Screen. Changes must be made in the base screen. - Border Outline @@ -2716,4 +2692,4 @@ for {1}? - \ No newline at end of file + diff --git a/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/CollisionScreen.glsj b/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/CollisionScreen.glsj index c4471574c..ab11b8d9e 100644 --- a/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/CollisionScreen.glsj +++ b/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/CollisionScreen.glsj @@ -677,6 +677,78 @@ "SourceFile": "FlatRedBall.Math.Collision.ListVsListRelationship", "AttachToContainer": true, "GenerateTimedEmit": true + }, + { + "InstanceName": "FillCompletelyWithDefaultValues", + "SourceClassType": "FlatRedBall.TileCollisions.TileShapeCollection", + "Properties": [ + { + "Name": "AssociateWithFactory", + "Value": true, + "Type": "bool" + }, + { + "Name": "CollisionCreationOptions", + "Value": 1, + "Type": "int" + } + ], + "InstructionSaves": [], + "SourceType": 2, + "SourceFile": "TileShapeCollection", + "AttachToContainer": true, + "GenerateTimedEmit": true + }, + { + "InstanceName": "CollidableListVsFillCompletelyWithDefaultValues", + "SourceClassType": "FlatRedBall.Math.Collision.CollidableListVsTileShapeCollectionRelationship", + "Properties": [ + { + "Name": "AssociateWithFactory", + "Value": true, + "Type": "bool" + }, + { + "Name": "IsAutoNameEnabled", + "Value": true, + "Type": "bool" + }, + { + "Name": "FirstCollisionName", + "Value": "CollidableList", + "Type": "String" + }, + { + "Name": "SecondCollisionName", + "Value": "FillCompletelyWithDefaultValues", + "Type": "String" + }, + { + "Name": "CollisionType", + "Value": 2, + "Type": "int" + }, + { + "Name": "IsDealDamageChecked", + "Value": true, + "Type": "Object" + }, + { + "Name": "FirstCollisionMass", + "Value": 0.0, + "Type": "float" + }, + { + "Name": "SecondCollisionMass", + "Value": 1.0, + "Type": "float" + } + ], + "InstructionSaves": [], + "SourceType": 2, + "SourceFile": "FlatRedBall.Math.Collision.CollidableListVsTileShapeCollectionRelationship", + "AttachToContainer": true, + "GenerateTimedEmit": true } ], "Name": "Screens\\CollisionScreen", diff --git a/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/TileShapeCollectionScreen.glsj b/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/TileShapeCollectionScreen.glsj index ec18b6fda..07708795e 100644 --- a/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/TileShapeCollectionScreen.glsj +++ b/Tests/TestProjectDesktopNet6/TestProjectDesktopNet6/Screens/TileShapeCollectionScreen.glsj @@ -235,6 +235,62 @@ "AttachToContainer": true, "GenerateTimedEmit": true, "IndependentOfCamera": true + }, + { + "InstanceName": "DefaultEmpty", + "SourceClassType": "FlatRedBall.TileCollisions.TileShapeCollection", + "Properties": [ + { + "Name": "AssociateWithFactory", + "Value": true, + "Type": "bool" + } + ], + "InstructionSaves": [], + "SourceType": 2, + "SourceFile": "TileShapeCollection", + "AttachToContainer": true, + "GenerateTimedEmit": true + }, + { + "InstanceName": "DefaultFillCompletely", + "SourceClassType": "FlatRedBall.TileCollisions.TileShapeCollection", + "Properties": [ + { + "Name": "AssociateWithFactory", + "Value": true, + "Type": "bool" + }, + { + "Name": "CollisionCreationOptions", + "Value": 1, + "Type": "int" + } + ], + "InstructionSaves": [], + "SourceType": 2, + "SourceFile": "TileShapeCollection", + "GenerateTimedEmit": true + }, + { + "InstanceName": "DefaultBorderOutline", + "SourceClassType": "FlatRedBall.TileCollisions.TileShapeCollection", + "Properties": [ + { + "Name": "AssociateWithFactory", + "Value": true, + "Type": "bool" + }, + { + "Name": "CollisionCreationOptions", + "Value": 2, + "Type": "int" + } + ], + "InstructionSaves": [], + "SourceType": 2, + "SourceFile": "TileShapeCollection", + "GenerateTimedEmit": true } ], "Name": "Screens\\TileShapeCollectionScreen",