1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 22:18:34 +01:00

Compare commits

..

2 commits

4 changed files with 19 additions and 3 deletions

View file

@ -22,6 +22,13 @@ Improvements
- Allow elements to auto-adjust their size even when their children are aligned oddly - Allow elements to auto-adjust their size even when their children are aligned oddly
- Close other dropdowns when opening a dropdown - Close other dropdowns when opening a dropdown
### MLEM.Data
Improvements
- Allow data texture atlas pivots and offsets to be negative
Fixes
- Fixed data texture atlases not allowing most characters in their region names
## 6.0.0 ## 6.0.0
### MLEM ### MLEM
Additions Additions

View file

@ -86,7 +86,7 @@ namespace MLEM.Data {
var atlas = new DataTextureAtlas(texture); var atlas = new DataTextureAtlas(texture);
// parse each texture region: "<names> loc <u> <v> <w> <h> [piv <px> <py>] [off <ox> <oy>]" // parse each texture region: "<names> loc <u> <v> <w> <h> [piv <px> <py>] [off <ox> <oy>]"
foreach (Match match in Regex.Matches(text, @"(.+)\W+loc\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W*(?:piv\W+([0-9.]+)\W+([0-9.]+))?\W*(?:off\W+([0-9.]+)\W+([0-9.]+))?")) { foreach (Match match in Regex.Matches(text, @"(.+)\s+loc\s+([0-9+]+)\s+([0-9+]+)\s+([0-9+]+)\s+([0-9+]+)\s*(?:piv\s+([0-9.+-]+)\s+([0-9.+-]+))?\s*(?:off\s+([0-9.+-]+)\s+([0-9.+-]+))?")) {
// offset // offset
var off = !match.Groups[8].Success ? Vector2.Zero : new Vector2( var off = !match.Groups[8].Success ? Vector2.Zero : new Vector2(
float.Parse(match.Groups[8].Value, CultureInfo.InvariantCulture), float.Parse(match.Groups[8].Value, CultureInfo.InvariantCulture),
@ -103,7 +103,7 @@ namespace MLEM.Data {
float.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X), float.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X),
float.Parse(match.Groups[7].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y)); float.Parse(match.Groups[7].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y));
foreach (var name in Regex.Split(match.Groups[1].Value, @"\W")) { foreach (var name in Regex.Split(match.Groups[1].Value, @"\s")) {
var trimmed = name.Trim(); var trimmed = name.Trim();
if (trimmed.Length <= 0) if (trimmed.Length <= 0)
continue; continue;

View file

@ -9,6 +9,10 @@ piv 80 16
Plant Plant
loc 96 0 16 32 loc 96 0 16 32
TestRegionNegativePivot
loc 0 32 +16 16
piv -32 +46
LongTableUp LongTableUp
loc 0 32 64 48 loc 0 32 64 48
piv 16 48 piv 16 48

View file

@ -13,7 +13,7 @@ namespace Tests {
using var game = TestGame.Create(); using var game = TestGame.Create();
using var texture = new Texture2D(game.GraphicsDevice, 1, 1); using var texture = new Texture2D(game.GraphicsDevice, 1, 1);
var atlas = DataTextureAtlas.LoadAtlasData(new TextureRegion(texture), game.RawContent, "Texture.atlas"); var atlas = DataTextureAtlas.LoadAtlasData(new TextureRegion(texture), game.RawContent, "Texture.atlas");
Assert.AreEqual(atlas.Regions.Count(), 7); Assert.AreEqual(atlas.Regions.Count(), 8);
// no added offset // no added offset
var table = atlas["LongTableUp"]; var table = atlas["LongTableUp"];
@ -24,6 +24,11 @@ namespace Tests {
var table2 = atlas["LongTableLeft"]; var table2 = atlas["LongTableLeft"];
Assert.AreEqual(table2.Area, new Rectangle(64, 32, 64, 48)); Assert.AreEqual(table2.Area, new Rectangle(64, 32, 64, 48));
Assert.AreEqual(table2.PivotPixels, new Vector2(112 - 64, 48 - 32)); Assert.AreEqual(table2.PivotPixels, new Vector2(112 - 64, 48 - 32));
// negative pivot
var negativePivot = atlas["TestRegionNegativePivot"];
Assert.AreEqual(negativePivot.Area, new Rectangle(0, 32, 16, 16));
Assert.AreEqual(negativePivot.PivotPixels, new Vector2(-32, 46 - 32));
} }
} }