Skip to content

Commit

Permalink
added comments to Gamerandom
Browse files Browse the repository at this point in the history
Improved newline wrapping with dialog box.
Added new properties to ITopDownEntity.
  • Loading branch information
vchelaru committed Feb 21, 2024
1 parent 4e11f2d commit c6f5d0d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
25 changes: 21 additions & 4 deletions Engines/FlatRedBallXNA/FlatRedBall/Utilities/GameRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,27 @@ public IList<T> MultipleIn<T>(IList<T> list, int numberToReturn)
}

/// <summary>
/// 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.
/// </summary>
/// <param name="lowerBound">The inclusive lower bound.</param>
/// <param name="upperBound">The inclusive upper bound</param>
/// <returns>The random float between the bounds.</returns>
public float Between(float lowerBound, float upperBound) => lowerBound + (float)NextDouble() * (upperBound - lowerBound);

/// <summary>
/// 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.
/// </summary>
/// <param name="lowerBound">The inclusive lower bound.</param>
/// <param name="upperBound">The inclusive upper bound.</param>
/// <returns>The random double between the bounds.</returns>
public double Between(double lowerBound, double upperBound) => lowerBound + NextDouble() * (upperBound - lowerBound);


/// <summary>
/// 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.
/// </summary>
/// <param name="lowerBound">The inclusive lower bound.</param>
/// <param name="upperBound">The inclusive upper bound.</param>
/// <returns>A random decimal between the bounds.</returns>
public decimal Between(decimal lowerBound, decimal upperBound) => lowerBound + (decimal)NextDouble() * (upperBound - lowerBound);


Expand Down Expand Up @@ -198,15 +209,21 @@ class CumulativeAreaRectangle
public float CumulativeSize;
}

/// <summary>
/// Returns a random point inside any of the shapes in the argument ShapeCollection.
/// </summary>
/// <param name="shapeCollection">The ShapeCollection containing the shapes to search.</param>
/// <returns>A random point in the shapes.</returns>
/// <exception cref="NotImplementedException">Currently circles and polygons are not supported. Please ask in discord if this is affecting you.</exception>
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<CumulativeAreaRectangle>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
var oldVerticalMode = this.coreTextObject.TextOverflowVerticalMode;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
Expand All @@ -113,7 +116,7 @@ private void GenerateTopDownElementSave(IElement element, ICodeBlock codeBlock)
.AutoSet();

codeBlock.Line("/// <summary>");
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("/// </summary>");
codeBlock.AutoProperty("public FlatRedBall.Input.I2DInput", "MovementInput");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface ITopDownEntity
DataTypes.TopDownValues CurrentMovement {{ get; }}
Entities.TopDownDirection DirectionFacing {{ get; }}
System.Collections.Generic.List<TopDown.AnimationSet> AnimationSets {{ get; }}
FlatRedBall.Input.I2DInput MovementInput {{ get; set; }}
float MaxSpeed {{ get; }}
float XVelocity {{ get; set; }}
float YVelocity {{ get; set; }}
Expand Down

0 comments on commit c6f5d0d

Please sign in to comment.