mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +01:00
Allow specifying multiple names for a DataTextureAtlas region
This commit is contained in:
parent
08e28cb95b
commit
ba1058748e
7 changed files with 21 additions and 19 deletions
|
@ -80,6 +80,7 @@ Improvements
|
|||
- Allow enumerating all region names of a DataTextureAtlas
|
||||
- Cache RuntimeTexturePacker texture data while packing to improve performance
|
||||
- Greatly improved RuntimeTexturePacker performance
|
||||
- Allow specifying multiple names for a DataTextureAtlas region
|
||||
|
||||
Fixes
|
||||
- Fixed SoundEffectReader incorrectly claiming it could read ogg and mp3 files
|
||||
|
|
2
FNA
2
FNA
|
@ -1 +1 @@
|
|||
Subproject commit 62cbf1c3180c31de0265b267a7ed080efd20150c
|
||||
Subproject commit 700a6f096ad359cc12634eeb5608ee9c8d29798c
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
@ -5,7 +6,6 @@ using System.Text.RegularExpressions;
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Extensions;
|
||||
using MLEM.Textures;
|
||||
|
||||
namespace MLEM.Data {
|
||||
|
@ -84,9 +84,8 @@ namespace MLEM.Data {
|
|||
}
|
||||
var atlas = new DataTextureAtlas(texture);
|
||||
|
||||
// parse each texture region: "<name> 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.]+))?")) {
|
||||
var name = match.Groups[1].Value.Trim();
|
||||
// offset
|
||||
var off = !match.Groups[8].Success ? Vector2.Zero : new Vector2(
|
||||
float.Parse(match.Groups[8].Value, CultureInfo.InvariantCulture),
|
||||
|
@ -103,11 +102,16 @@ namespace MLEM.Data {
|
|||
float.Parse(match.Groups[6].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X),
|
||||
float.Parse(match.Groups[7].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y));
|
||||
|
||||
foreach (var name in Regex.Split(match.Groups[1].Value, @"\W")) {
|
||||
var trimmed = name.Trim();
|
||||
if (trimmed.Length <= 0)
|
||||
continue;
|
||||
var region = new TextureRegion(texture, loc) {
|
||||
PivotPixels = piv,
|
||||
Name = name
|
||||
Name = trimmed
|
||||
};
|
||||
atlas.regions.Add(name, region);
|
||||
atlas.regions.Add(trimmed, region);
|
||||
}
|
||||
}
|
||||
|
||||
return atlas;
|
||||
|
|
|
@ -13,6 +13,6 @@ LongTableUp
|
|||
loc 0 32 64 48
|
||||
piv 16 48
|
||||
|
||||
LongTableRight
|
||||
LongTableRight LongTableDown LongTableLeft
|
||||
loc 64 32 64 48
|
||||
piv 112 48
|
|
@ -169,11 +169,8 @@ namespace Sandbox {
|
|||
var region2 = new TextureRegion(round);
|
||||
|
||||
var atlas = this.Content.LoadTextureAtlas("Textures/Furniture");
|
||||
foreach (var r in atlas.Regions) {
|
||||
foreach (var r in atlas.Regions)
|
||||
Console.WriteLine(r.Name + ": " + r.U + " " + r.V + " " + r.Width + " " + r.Height + " " + r.PivotPixels);
|
||||
foreach (var key in r.GetDataKeys())
|
||||
Console.WriteLine(key + " " + r.GetData<Vector2>(key));
|
||||
}
|
||||
|
||||
this.OnDraw += (g, time) => {
|
||||
this.SpriteBatch.Begin(samplerState: SamplerState.PointClamp);
|
||||
|
|
|
@ -13,7 +13,7 @@ LongTableUp
|
|||
loc 0 32 64 48
|
||||
piv 16 48
|
||||
|
||||
LongTableRight
|
||||
LongTableRight LongTableDown LongTableLeft
|
||||
loc 32 30 64 48
|
||||
piv 80 46
|
||||
off 32 2
|
|
@ -13,7 +13,7 @@ namespace Tests {
|
|||
using var game = TestGame.Create();
|
||||
using var texture = new Texture2D(game.GraphicsDevice, 1, 1);
|
||||
var atlas = DataTextureAtlas.LoadAtlasData(new TextureRegion(texture), game.RawContent, "Texture.atlas");
|
||||
Assert.AreEqual(atlas.Regions.Count(), 5);
|
||||
Assert.AreEqual(atlas.Regions.Count(), 7);
|
||||
|
||||
// no added offset
|
||||
var table = atlas["LongTableUp"];
|
||||
|
@ -21,7 +21,7 @@ namespace Tests {
|
|||
Assert.AreEqual(table.PivotPixels, new Vector2(16, 48 - 32));
|
||||
|
||||
// added offset
|
||||
var table2 = atlas["LongTableRight"];
|
||||
var table2 = atlas["LongTableLeft"];
|
||||
Assert.AreEqual(table2.Area, new Rectangle(64, 32, 64, 48));
|
||||
Assert.AreEqual(table2.PivotPixels, new Vector2(112 - 64, 48 - 32));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue