Skip to content

Commit

Permalink
Version 4.0.3 (#953)
Browse files Browse the repository at this point in the history
* fix(Matrix3x2): decompose method (#941)

* Fix bug when using `NinePatch` with `Texture2DRegion`. (#945)

Resolves #943

* BitmapFont now always loads from TitleContainer. (#946)

Fixes KNI web builds when using BitmapFont (#944)

* Fix bug when creating a NinePatch using the Texture2DRegion extension method (#948)

* Revert UV code (#951)

* [Weekly] Version 4.0.3 (#952)

* Starting 4.0.2 release prep

* Update changelog

* Bump version number to 4.0.3

* Updated workflows to use dotnet 8

---------

Co-authored-by: Ilia Bahrebar <150489740+Std-Enigma@users.noreply.github.com>
Co-authored-by: Dwergi <sebastian.nordgren@gmail.com>
Co-authored-by: Joseph Newman <greenstack@users.noreply.github.com>
Co-authored-by: Jeremy Swartwood <jeremy.swartwood@gmail.com>
  • Loading branch information
5 people authored Sep 30, 2024
1 parent c814a65 commit e22c2cc
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup Dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Build MonoGame.Extended
run: dotnet build MonoGame.Extended.sln --nologo --verbosity minimal --configuration Release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup DotNet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Test MonoGame.Extended
run: dotnet test MonoGame.Extended.sln --nologo --verbosity minimal --configuration Release
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
> Unreleased changes exist in the current `develop` branch but have not been pushed as either a stable or prerelease NuGet package.
>
## [4.0.3]
## Fixed
- Resoled issue where `Matrix3x2.Decompose` returned incorrect values for transformation [@Std-Enigma](https://github.com/Std-Enigma) [#941](https://github.com/craftworkgames/MonoGame.Extended/pull/941)
- Resolved bug in NinePatch where padding calculations were incorrect [@Dwergi](https://github.com/Dwergi) [#945](https://github.com/craftworkgames/MonoGame.Extended/pull/945)
- Resoled bug in `Texture2DExtensions.CreateNinePatch` where source rectangles were calculated that overlapped. [@greenstack](https://github.com/greenstack) [#948](https://github.com/craftworkgames/MonoGame.Extended/pull/948)

## Changed
- `BitmapFont` uses `TitleContainer` to load stream of file [@Dwergi](https://github.com/Dwergi) [#946](https://github.com/craftworkgames/MonoGame.Extended/pull/946)
- Revert UV code for `Sprite.OriginNormalize`, resolving incorrect calculations [@kaltinril](https://github.com/kaltinril) [#951](https://github.com/craftworkgames/MonoGame.Extended/pull/951)


## [4.0.2]
### Fixed
- Resolved issue when reading .particle files for a ParticleEffect that cause a recursion loop bug creating a stack overflow exception [@AristurtleDev](https://github.com/AristurtleDev) [#938](https://github.com/craftworkgames/MonoGame.Extended/pull/938)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<MonoGameExtendedVersion>4.0.2</MonoGameExtendedVersion>
<MonoGameExtendedVersion>4.0.3</MonoGameExtendedVersion>
<IsPrerelease Condition="'$(IS_PRERELEASE)' != ''">-prerelease</IsPrerelease>
<BuildNumber Condition="'$(BUILD_NUMBER)' != ''">.$(BUILD_NUMBER)</BuildNumber>
<Version>$(MonoGameExtendedVersion)$(IsPrerelease)$(BuildNumber)</Version>
Expand Down
14 changes: 10 additions & 4 deletions source/MonoGame.Extended/BitmapFonts/BitmapFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,19 @@ public void Reset()

public static BitmapFont FromFile(GraphicsDevice graphicsDevice, string path)
{
using FileStream stream = File.OpenRead(path);
return FromStream(graphicsDevice, stream);
using Stream stream = TitleContainer.OpenStream(path);
return FromStream(graphicsDevice, stream, path);
}

[Obsolete("Use the FromStream() overload that takes an explicit name.")]
public static BitmapFont FromStream(GraphicsDevice graphicsDevice, FileStream stream)
{
var bmfFile = BitmapFontFileReader.Read(stream);
return FromStream(graphicsDevice, stream, stream.Name);
}

public static BitmapFont FromStream(GraphicsDevice graphicsDevice, Stream stream, string name)
{
var bmfFile = BitmapFontFileReader.Read(stream, name);

// Load page textures
Dictionary<string, Texture2D> pages = new Dictionary<string, Texture2D>();
Expand All @@ -379,7 +385,7 @@ public static BitmapFont FromStream(GraphicsDevice graphicsDevice, FileStream st
if (!pages.ContainsKey(bmfFile.Pages[i]))
{
string texturePath = Path.Combine(Path.GetDirectoryName(bmfFile.Path), bmfFile.Pages[i]);
using (Stream textureStream = File.OpenRead(texturePath))
using (Stream textureStream = TitleContainer.OpenStream(texturePath))
{
Texture2D texture = Texture2D.FromStream(graphicsDevice, textureStream);
pages.Add(bmfFile.Pages[i], texture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,33 @@ public static class BitmapFontFileReader
public static BitmapFontFileContent Read(string path)
{
using var stream = File.OpenRead(path);
return Read(stream);
return Read(stream, path);
}

/// <summary>
/// Reads the content of the font file at the path specified.
/// </summary>
/// <param name="stream">A <see cref="FileStream"/> containing the font file contents to read.</param>
/// <param name="stream">A <see cref="Stream"/> containing the font file contents to read.</param>
/// <returns>A <see cref="BitmapFontFileContent"/> instance containing the results of the read operation.</returns>
/// <exception cref="InvalidOperationException">
/// Thrown if the header for the file contents does not match a known header format.
/// </exception>
[Obsolete("Use the overload that takes an explicit name parameter.")]
public static BitmapFontFileContent Read(FileStream stream)
{
return Read(stream, stream.Name);
}

/// <summary>
/// Reads the content of the font file at the path specified.
/// </summary>
/// <param name="stream">A <see cref="Stream"/> containing the font file contents to read.</param>
/// <param name="name">The name or path that uniquely identifies this <see cref="BitmapFontFileContent"/>.</param>
/// <returns>A <see cref="BitmapFontFileContent"/> instance containing the results of the read operation.</returns>
/// <exception cref="InvalidOperationException">
/// Thrown if the header for the file contents does not match a known header format.
/// </exception>
public static BitmapFontFileContent Read(Stream stream, string name)
{
long position = stream.Position;
var sig = stream.ReadByte();
Expand All @@ -60,7 +75,7 @@ public static BitmapFontFileContent Read(FileStream stream)
_ => throw new InvalidOperationException("This does not appear to be a valid BMFont file!")
};

bmfFile.Path = stream.Name;
bmfFile.Path = name;

return bmfFile;
}
Expand Down
16 changes: 13 additions & 3 deletions source/MonoGame.Extended/Graphics/NinePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class NinePatch
/// </summary>
public string Name { get; }

/// <summary>
/// The size of the border patches around the middle patch.
/// </summary>
public Thickness Padding { get; }

/// <summary>
Expand Down Expand Up @@ -90,7 +93,11 @@ public NinePatch(Texture2DRegion[] patches) : this(patches, null) { }
/// <summary>
/// Initializes a new instance of the <see cref="NinePatch"/> class with the specified patches and name.
/// </summary>
/// <param name="patches">An array of nine <see cref="Texture2DRegion"/> objects.</param>
/// <param name="patches">
/// An array of nine <see cref="Texture2DRegion"/> objects.
/// The top, left, bottom and right regions must to be of exactly the same size.
/// Mid patches can be as small as 1x1.
/// </param>
/// <param name="name">
/// The name of the nine-patch. If null or empty, a default name will be generated based on the texture name of the
/// top-left patch.
Expand All @@ -113,8 +120,11 @@ public NinePatch(Texture2DRegion[] patches, string name)
}

_patches = patches;
Rectangle mid = patches[NinePatch.Middle].Bounds;
Padding = new Thickness(mid.Left, mid.Top, mid.Right, mid.Bottom);

Size topLeft = patches[NinePatch.TopLeft].Size;
Size bottomRight = patches[NinePatch.BottomRight].Size;
Padding = new Thickness(topLeft.Width, topLeft.Height, bottomRight.Width, bottomRight.Height);

Name = name;
}
}
14 changes: 2 additions & 12 deletions source/MonoGame.Extended/Graphics/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,8 @@ public class Sprite : IColorable
/// </remarks>
public Vector2 OriginNormalized
{
get
{
float normalizedX = (Origin.X - TextureRegion.LeftUV) / (TextureRegion.RightUV - TextureRegion.LeftUV);
float normalizedY = (Origin.Y - TextureRegion.TopUV) / (TextureRegion.BottomUV - TextureRegion.TopUV);
return new Vector2(normalizedX, normalizedY);
}
set
{
float actualX = value.X * (TextureRegion.RightUV - TextureRegion.LeftUV) + TextureRegion.LeftUV;
float actualY = value.Y * (TextureRegion.BottomUV - TextureRegion.TopUV) + TextureRegion.TopUV;
Origin = new Vector2(actualX, actualY);
}
get { return new Vector2(Origin.X / TextureRegion.Width, Origin.Y / TextureRegion.Height); }
set { Origin = new Vector2(value.X * TextureRegion.Width, value.Y * TextureRegion.Height); }
}

/// <summary>
Expand Down
12 changes: 7 additions & 5 deletions source/MonoGame.Extended/Graphics/Texture2DRegion.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,20 @@ public static NinePatch CreateNinePatch(this Texture2DRegion textureRegion, int

int middleWidth = textureRegion.Width - leftPadding - rightPadding;
int middleHeight = textureRegion.Height - topPadding - bottomPadding;
int rightX = textureRegion.Width - rightPadding;
int bottomY = textureRegion.Height - bottomPadding;

patches[NinePatch.TopLeft] = textureRegion.GetSubregion(0, 0, leftPadding, topPadding);
patches[NinePatch.TopMiddle] = textureRegion.GetSubregion(leftPadding, 0, middleWidth, topPadding);
patches[NinePatch.TopRight] = textureRegion.GetSubregion(middleWidth, 0, rightPadding, topPadding);
patches[NinePatch.TopRight] = textureRegion.GetSubregion(rightX, 0, rightPadding, topPadding);

patches[NinePatch.MiddleLeft] = textureRegion.GetSubregion(0, topPadding, leftPadding, middleHeight);
patches[NinePatch.Middle] = textureRegion.GetSubregion(leftPadding, topPadding, middleWidth, middleHeight);
patches[NinePatch.MiddleRight] = textureRegion.GetSubregion(middleWidth, topPadding, rightPadding, middleHeight);
patches[NinePatch.MiddleRight] = textureRegion.GetSubregion(rightX, topPadding, rightPadding, middleHeight);

patches[NinePatch.BottomLeft] = textureRegion.GetSubregion(0, middleHeight, leftPadding, bottomPadding);
patches[NinePatch.BottomMiddle] = textureRegion.GetSubregion(leftPadding, middleHeight, middleWidth, bottomPadding);
patches[NinePatch.BottomRight] = textureRegion.GetSubregion(middleWidth, middleHeight, rightPadding, bottomPadding);
patches[NinePatch.BottomLeft] = textureRegion.GetSubregion(0, bottomY, leftPadding, bottomPadding);
patches[NinePatch.BottomMiddle] = textureRegion.GetSubregion(leftPadding, bottomY, middleWidth, bottomPadding);
patches[NinePatch.BottomRight] = textureRegion.GetSubregion(rightX, bottomY, rightPadding, bottomPadding);

return new NinePatch(patches);
}
Expand Down
2 changes: 1 addition & 1 deletion source/MonoGame.Extended/Math/Matrix3x2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void Transform(in float x, in float y, ref Vector3 result)
public void Decompose(out Vector2 translation, out float rotation, out Vector2 scale)
{
translation.X = M31;
translation.Y = M31;
translation.Y = M32;

rotation = (float)Math.Atan2(M21, M11);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ private static BitmapFontFileContent CreateExpected()
[Fact]
public void Read_BinaryFile_Test()
{
using FileStream stream = File.OpenRead("BitmapFonts/files/bmfont/test-font-binary.fnt");
var actual = BitmapFontFileReader.Read(stream);
string path = "BitmapFonts/files/bmfont/test-font-binary.fnt";
using FileStream stream = File.OpenRead(path);
var actual = BitmapFontFileReader.Read(stream, path);
Assert.Equal(_expected.Header, actual.Header);
Assert.Equal(_expected.Info, actual.Info);
Assert.Equal(_expected.Common, actual.Common);
Expand All @@ -116,8 +117,9 @@ public void Read_BinaryFile_Test()
[Fact]
public void Read_XmlFile_Test()
{
using FileStream stream = File.OpenRead("BitmapFonts/files/bmfont/test-font-xml.fnt");
var actual = BitmapFontFileReader.Read(stream);
string path = "BitmapFonts/files/bmfont/test-font-xml.fnt";
using FileStream stream = File.OpenRead(path);
var actual = BitmapFontFileReader.Read(stream, path);
Assert.Equal(_expected.Header, actual.Header);
Assert.Equal(_expected.Info, actual.Info);
Assert.Equal(_expected.Common, actual.Common);
Expand All @@ -130,8 +132,9 @@ public void Read_XmlFile_Test()
[Fact]
public void Read_Text_Test()
{
using FileStream stream = File.OpenRead("BitmapFonts/files/bmfont/test-font-text.fnt");
var actual = BitmapFontFileReader.Read(stream);
string path = "BitmapFonts/files/bmfont/test-font-text.fnt";
using FileStream stream = File.OpenRead(path);
var actual = BitmapFontFileReader.Read(stream, path);
Assert.Equal(_expected.Header, actual.Header);
Assert.Equal(_expected.Info, actual.Info);
Assert.Equal(_expected.Common, actual.Common);
Expand Down

0 comments on commit e22c2cc

Please sign in to comment.