2021-03-18 17:28:08 +01:00
|
|
|
using System.Linq;
|
|
|
|
using Microsoft.Xna.Framework;
|
2021-04-02 17:12:27 +02:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2021-03-18 17:28:08 +01:00
|
|
|
using MLEM.Data;
|
2021-04-02 17:12:27 +02:00
|
|
|
using MLEM.Textures;
|
2021-03-18 17:28:08 +01:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace Tests {
|
|
|
|
public class TestDataTextureAtlas {
|
|
|
|
|
|
|
|
[Test]
|
2022-09-14 12:19:05 +02:00
|
|
|
public void Test([Values(0, 4)] int regionX, [Values(0, 4)] int regionY) {
|
2021-04-02 17:12:27 +02:00
|
|
|
using var game = TestGame.Create();
|
|
|
|
using var texture = new Texture2D(game.GraphicsDevice, 1, 1);
|
2022-09-14 12:19:05 +02:00
|
|
|
var region = new TextureRegion(texture, regionX, regionY, 1, 1);
|
|
|
|
var atlas = DataTextureAtlas.LoadAtlasData(region, game.RawContent, "Texture.atlas");
|
2022-09-14 11:59:28 +02:00
|
|
|
Assert.AreEqual(12, atlas.Regions.Count());
|
2021-03-18 17:28:08 +01:00
|
|
|
|
2022-09-14 11:04:51 +02:00
|
|
|
// no pivot
|
|
|
|
var plant = atlas["Plant"];
|
2022-09-14 12:19:05 +02:00
|
|
|
Assert.AreEqual(plant.Area, new Rectangle(96 + regionX, 0 + regionY, 16, 32));
|
2022-09-14 11:04:51 +02:00
|
|
|
Assert.AreEqual(plant.PivotPixels, Vector2.Zero);
|
|
|
|
|
2021-07-12 03:14:05 +02:00
|
|
|
// no added offset
|
2021-03-18 17:28:08 +01:00
|
|
|
var table = atlas["LongTableUp"];
|
2022-09-14 12:19:05 +02:00
|
|
|
Assert.AreEqual(table.Area, new Rectangle(0 + regionX, 32 + regionY, 64, 48));
|
2021-03-18 17:28:08 +01:00
|
|
|
Assert.AreEqual(table.PivotPixels, new Vector2(16, 48 - 32));
|
2021-07-12 03:14:05 +02:00
|
|
|
|
|
|
|
// added offset
|
2022-09-14 11:04:51 +02:00
|
|
|
var table2 = atlas["LongTableDown"];
|
2022-09-14 12:19:05 +02:00
|
|
|
Assert.AreEqual(table2.Area, new Rectangle(64 + regionX, 32 + regionY, 64, 48));
|
2021-07-12 03:14:05 +02:00
|
|
|
Assert.AreEqual(table2.PivotPixels, new Vector2(112 - 64, 48 - 32));
|
2022-08-02 23:56:18 +02:00
|
|
|
|
|
|
|
// negative pivot
|
|
|
|
var negativePivot = atlas["TestRegionNegativePivot"];
|
2022-09-14 12:19:05 +02:00
|
|
|
Assert.AreEqual(negativePivot.Area, new Rectangle(0 + regionX, 32 + regionY, 16, 16));
|
2022-08-02 23:56:18 +02:00
|
|
|
Assert.AreEqual(negativePivot.PivotPixels, new Vector2(-32, 46 - 32));
|
2022-09-14 10:40:52 +02:00
|
|
|
|
2022-09-14 11:59:28 +02:00
|
|
|
// cpy (pivot pixels should be identical to LongTableUp because they're region-internal)
|
2022-09-14 10:40:52 +02:00
|
|
|
var copy1 = atlas["Copy1"];
|
2022-09-14 12:19:05 +02:00
|
|
|
Assert.AreEqual(copy1.Area, new Rectangle(0 + 16 + regionX, 32 + regionY, 64, 48));
|
2022-09-14 11:20:55 +02:00
|
|
|
Assert.AreEqual(copy1.PivotPixels, new Vector2(16, 48 - 32));
|
2022-09-14 10:40:52 +02:00
|
|
|
var copy2 = atlas["Copy2"];
|
2022-09-14 12:19:05 +02:00
|
|
|
Assert.AreEqual(copy2.Area, new Rectangle(0 + 32 + regionX, 32 + 4 + regionY, 64, 48));
|
2022-09-14 11:20:55 +02:00
|
|
|
Assert.AreEqual(copy2.PivotPixels, new Vector2(16, 48 - 32));
|
2022-09-14 10:40:52 +02:00
|
|
|
|
2022-09-14 11:59:28 +02:00
|
|
|
// frm
|
|
|
|
var copy3 = atlas["Copy3"];
|
2022-09-14 12:19:05 +02:00
|
|
|
Assert.AreEqual(copy3.Area, new Rectangle(0 + 2 + regionX, 32 + 4 + regionY, 64, 48));
|
2022-09-14 11:59:28 +02:00
|
|
|
Assert.AreEqual(copy3.PivotPixels, new Vector2(16, 48 - 32));
|
|
|
|
|
2022-09-14 10:40:52 +02:00
|
|
|
// data
|
|
|
|
var data = atlas["DataTest"];
|
|
|
|
Assert.AreEqual("ThisIsSomeData", data.GetData<string>("DataPoint1"));
|
|
|
|
Assert.AreEqual("3.5", data.GetData<string>("DataPoint2"));
|
|
|
|
Assert.AreEqual("---", data.GetData<string>("DataPoint3"));
|
2021-03-18 17:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-06-17 18:23:47 +02:00
|
|
|
}
|