1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-24 21:48:35 +01:00

Compare commits

..

No commits in common. "9a0b8ef846abbba4a8d87b22f4e06e098f38833c" and "ee2b0b82fe8e1fde44f7bde9163b0f72218ac79d" have entirely different histories.

4 changed files with 18 additions and 31 deletions

View file

@ -24,10 +24,6 @@ Additions
Fixes Fixes
- Fixed a crash if a paragraph has a link formatting code, but no font - Fixed a crash if a paragraph has a link formatting code, but no font
### MLEM.Data
Additions
- Added the ability to specify a coordinate offset in data texture atlases
## 5.0.0 ## 5.0.0
### MLEM ### MLEM
Additions Additions

View file

@ -56,30 +56,32 @@ namespace MLEM.Data {
text = reader.ReadToEnd(); text = reader.ReadToEnd();
var atlas = new DataTextureAtlas(texture); 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: "<name> loc <u> <v> <w> <h> piv <px> <py>" followed by extra data in the form "key <x> <y>"
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, @"(.+)\W+loc\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)\W+([0-9]+)(?:\W+piv\W+([0-9.]+)\W+([0-9.]+))?(?:\W+(\w+)\W+([0-9.]+)\W+([0-9.]+))*")) {
var name = match.Groups[1].Value.Trim(); 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),
float.Parse(match.Groups[9].Value, CultureInfo.InvariantCulture));
// location // location
var loc = new Rectangle( var loc = new Rectangle(
int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value), int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value),
int.Parse(match.Groups[4].Value), int.Parse(match.Groups[5].Value)); int.Parse(match.Groups[4].Value), int.Parse(match.Groups[5].Value));
loc.Offset(off);
// pivot // pivot
var piv = !match.Groups[6].Success ? Vector2.Zero : new Vector2( var piv = Vector2.Zero;
if (match.Groups[6].Success) {
piv = new Vector2(
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));
piv += off; }
var region = new TextureRegion(texture, loc) { var region = new TextureRegion(texture, loc) {
PivotPixels = piv, PivotPixels = piv,
Name = name Name = name
}; };
// additional data
if (match.Groups[8].Success) {
for (var i = 0; i < match.Groups[8].Captures.Count; i++) {
region.SetData(match.Groups[8].Captures[i].Value, new Vector2(
float.Parse(match.Groups[9].Captures[i].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X),
float.Parse(match.Groups[10].Captures[i].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y)));
}
}
atlas.regions.Add(name, region); atlas.regions.Add(name, region);
} }

View file

@ -1,19 +1,14 @@
SimpleDeskUp SimpleDeskUp
loc 0 0 48 32 loc 0 0 48 32
piv 16 16 piv 16 16
SimpleDeskRight SimpleDeskRight
loc 48 0 48 32 loc 48 0 48 32
piv 80 16 piv 80 16
Plant Plant
loc 96 0 16 32 loc 96 0 16 32
LongTableUp LongTableUp
loc 0 32 64 48 loc 0 32 64 48
piv 16 48 piv 16 48
LongTableRight LongTableRight
loc 32 30 64 48 loc 64 32 64 48
piv 80 46 piv 112 48
off 32 2

View file

@ -15,15 +15,9 @@ namespace Tests {
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(), 5); Assert.AreEqual(atlas.Regions.Count(), 5);
// no added offset
var table = atlas["LongTableUp"]; var table = atlas["LongTableUp"];
Assert.AreEqual(table.Area, new Rectangle(0, 32, 64, 48)); Assert.AreEqual(table.Area, new Rectangle(0, 32, 64, 48));
Assert.AreEqual(table.PivotPixels, new Vector2(16, 48 - 32)); Assert.AreEqual(table.PivotPixels, new Vector2(16, 48 - 32));
// added offset
var table2 = atlas["LongTableRight"];
Assert.AreEqual(table2.Area, new Rectangle(64, 32, 64, 48));
Assert.AreEqual(table2.PivotPixels, new Vector2(112 - 64, 48 - 32));
} }
} }