1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

Allow data texture atlas pivots and offsets to be negative

This commit is contained in:
Ell 2022-08-02 23:56:18 +02:00
parent 72647a2edf
commit b012c65990
4 changed files with 14 additions and 2 deletions

View file

@ -23,6 +23,9 @@ Improvements
- Close other dropdowns when opening a dropdown - Close other dropdowns when opening a dropdown
### MLEM.Data ### MLEM.Data
Improvements
- Allow data texture atlas pivots and offsets to be negative
Fixes Fixes
- Fixed data texture atlases not allowing most characters in their region names - Fixed data texture atlases not allowing most characters in their region names

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, @"(.+)\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.]+))?")) { 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),

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));
} }
} }