From c6f5d0d40d75c12ef88acd58822387055990827c Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 20 Feb 2024 21:50:46 -0700 Subject: [PATCH] added comments to Gamerandom Improved newline wrapping with dialog box. Added new properties to ITopDownEntity. --- .../FlatRedBall/Utilities/GameRandom.cs | 25 ++++++++++++++++--- .../Controls/Games/DialogBox.cs | 15 ++++++----- .../CodeGenerators/EntityCodeGenerator.cs | 5 +++- .../CodeGenerators/InterfacesFileGenerator.cs | 2 ++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Engines/FlatRedBallXNA/FlatRedBall/Utilities/GameRandom.cs b/Engines/FlatRedBallXNA/FlatRedBall/Utilities/GameRandom.cs index 34efe96c6..bb44fe78d 100644 --- a/Engines/FlatRedBallXNA/FlatRedBall/Utilities/GameRandom.cs +++ b/Engines/FlatRedBallXNA/FlatRedBall/Utilities/GameRandom.cs @@ -75,16 +75,27 @@ public IList MultipleIn(IList list, int numberToReturn) } /// - /// Returns a random number within the specified range (inclusive). + /// Returns a random float within the specified range (inclusive). For example, calling Between(5,10) will return any number between 5 and 10, including 5 and 10. /// /// The inclusive lower bound. /// The inclusive upper bound /// The random float between the bounds. public float Between(float lowerBound, float upperBound) => lowerBound + (float)NextDouble() * (upperBound - lowerBound); + /// + /// Returns a random double within the specified range (inclusive). For example, calling Between(5,10) will return any number between 5 and 10, including 5 and 10. + /// + /// The inclusive lower bound. + /// The inclusive upper bound. + /// The random double between the bounds. public double Between(double lowerBound, double upperBound) => lowerBound + NextDouble() * (upperBound - lowerBound); - + /// + /// Returns a random decimal within the specified range (inclusive). For example, calling Between(5,10) will return any number between 5 and 10, including 5 and 10. + /// + /// The inclusive lower bound. + /// The inclusive upper bound. + /// A random decimal between the bounds. public decimal Between(decimal lowerBound, decimal upperBound) => lowerBound + (decimal)NextDouble() * (upperBound - lowerBound); @@ -198,15 +209,21 @@ class CumulativeAreaRectangle public float CumulativeSize; } + /// + /// Returns a random point inside any of the shapes in the argument ShapeCollection. + /// + /// The ShapeCollection containing the shapes to search. + /// A random point in the shapes. + /// Currently circles and polygons are not supported. Please ask in discord if this is affecting you. public Vector2 PointIn(ShapeCollection shapeCollection) { if (shapeCollection.Circles.Count > 0) { - throw new NotImplementedException("PointIn with Circles not implemented - bug Vic"); + throw new NotImplementedException("PointIn with Circles not implemented - please ask in discord if this is affecting you"); } if(shapeCollection.Polygons.Count > 0) { - throw new NotImplementedException("PointIn with Polygons not implemented - bug Vic"); + throw new NotImplementedException("PointIn with Polygons not implemented - please ask in discord if this is affecting you"); } var rectangles = new List(); diff --git a/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/DialogBox.cs b/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/DialogBox.cs index 3afcecab4..9e1e0ac09 100644 --- a/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/DialogBox.cs +++ b/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/DialogBox.cs @@ -396,9 +396,12 @@ private string[] ConvertToPages(string text) } else { - var foundTags = BbCodeParser.Parse(text, CustomSetPropertyOnRenderable.Tags); - - var withRemovedTags = BbCodeParser.RemoveTags(text, foundTags); + // To remove the tags, we must keep newlines in since since that's how the tags are removed... + var foundTagsWithNewlines = BbCodeParser.Parse(text, CustomSetPropertyOnRenderable.Tags); + // ...but when we add the tags back in, we do it without counting newlines, so we need to remove newlines for + // the tags that are added back in: + var foundTagsWithoutNewlines = BbCodeParser.Parse(text.Replace("\n", ""), CustomSetPropertyOnRenderable.Tags); + var withRemovedTags = BbCodeParser.RemoveTags(text, foundTagsWithNewlines); var unlimitedLines = new List(); var oldVerticalMode = this.coreTextObject.TextOverflowVerticalMode; @@ -435,12 +438,12 @@ private string[] ConvertToPages(string text) { var toAppend = unlimitedLines[absoluteLineNumber]; var sizeBeforeTags = toAppend.Length; - if(foundTags.Count > 0) + if(foundTagsWithoutNewlines.Count > 0) { - toAppend = BbCodeParser.AddTags(toAppend, foundTags, strippedTextCount); + toAppend = BbCodeParser.AddTags(toAppend, foundTagsWithoutNewlines, strippedTextCount); } strippedTextCount += sizeBeforeTags; - stringBuilder.Append(toAppend); + stringBuilder.Append(toAppend + "\n"); absoluteLineNumber++; } pages.Add(stringBuilder.ToString()); diff --git a/FRBDK/Glue/TopDownPlugin/CodeGenerators/EntityCodeGenerator.cs b/FRBDK/Glue/TopDownPlugin/CodeGenerators/EntityCodeGenerator.cs index 2fbd0cda7..6d950039a 100644 --- a/FRBDK/Glue/TopDownPlugin/CodeGenerators/EntityCodeGenerator.cs +++ b/FRBDK/Glue/TopDownPlugin/CodeGenerators/EntityCodeGenerator.cs @@ -90,6 +90,9 @@ private void GenerateTopDownElementSave(IElement element, ICodeBlock codeBlock) .Set("private") .Line("mCurrentMovement = value;"); + codeBlock.Line("public string CurrentMovementName => CurrentMovement?.Name;"); + codeBlock.Line("public float MaxSpeed => CurrentMovement?.MaxSpeed ?? 0;"); + codeBlock.Property("public FlatRedBall.Input.IInputDevice", "InputDevice") .Line("get;") @@ -113,7 +116,7 @@ private void GenerateTopDownElementSave(IElement element, ICodeBlock codeBlock) .AutoSet(); codeBlock.Line("/// "); - codeBlock.Line("/// The input object which controls the horizontal movement of the character."); + codeBlock.Line("/// The input object which controls the movement of the character."); codeBlock.Line("/// Common examples include a d-pad, analog stick, or keyboard keys."); codeBlock.Line("/// "); codeBlock.AutoProperty("public FlatRedBall.Input.I2DInput", "MovementInput"); diff --git a/FRBDK/Glue/TopDownPlugin/CodeGenerators/InterfacesFileGenerator.cs b/FRBDK/Glue/TopDownPlugin/CodeGenerators/InterfacesFileGenerator.cs index d6026b6cd..b4050d863 100644 --- a/FRBDK/Glue/TopDownPlugin/CodeGenerators/InterfacesFileGenerator.cs +++ b/FRBDK/Glue/TopDownPlugin/CodeGenerators/InterfacesFileGenerator.cs @@ -42,6 +42,8 @@ public interface ITopDownEntity DataTypes.TopDownValues CurrentMovement {{ get; }} Entities.TopDownDirection DirectionFacing {{ get; }} System.Collections.Generic.List AnimationSets {{ get; }} + FlatRedBall.Input.I2DInput MovementInput {{ get; set; }} + float MaxSpeed {{ get; }} float XVelocity {{ get; set; }} float YVelocity {{ get; set; }}