mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 13:38:34 +01:00
Compare commits
No commits in common. "9a0b8ef846abbba4a8d87b22f4e06e098f38833c" and "ee2b0b82fe8e1fde44f7bde9163b0f72218ac79d" have entirely different histories.
9a0b8ef846
...
ee2b0b82fe
4 changed files with 18 additions and 31 deletions
|
@ -24,10 +24,6 @@ Additions
|
|||
Fixes
|
||||
- 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
|
||||
### MLEM
|
||||
Additions
|
||||
|
|
|
@ -56,30 +56,32 @@ namespace MLEM.Data {
|
|||
text = reader.ReadToEnd();
|
||||
var atlas = new DataTextureAtlas(texture);
|
||||
|
||||
// parse each texture region: "<name> 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.]+))?")) {
|
||||
// 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+(\w+)\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),
|
||||
float.Parse(match.Groups[9].Value, CultureInfo.InvariantCulture));
|
||||
|
||||
// location
|
||||
var loc = new Rectangle(
|
||||
int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value),
|
||||
int.Parse(match.Groups[4].Value), int.Parse(match.Groups[5].Value));
|
||||
loc.Offset(off);
|
||||
|
||||
// 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[7].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y));
|
||||
piv += off;
|
||||
|
||||
}
|
||||
var region = new TextureRegion(texture, loc) {
|
||||
PivotPixels = piv,
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
SimpleDeskUp
|
||||
loc 0 0 48 32
|
||||
piv 16 16
|
||||
|
||||
SimpleDeskRight
|
||||
loc 48 0 48 32
|
||||
piv 80 16
|
||||
|
||||
Plant
|
||||
loc 96 0 16 32
|
||||
|
||||
LongTableUp
|
||||
loc 0 32 64 48
|
||||
piv 16 48
|
||||
|
||||
LongTableRight
|
||||
loc 32 30 64 48
|
||||
piv 80 46
|
||||
off 32 2
|
||||
loc 64 32 64 48
|
||||
piv 112 48
|
|
@ -15,15 +15,9 @@ namespace Tests {
|
|||
var atlas = DataTextureAtlas.LoadAtlasData(new TextureRegion(texture), game.RawContent, "Texture.atlas");
|
||||
Assert.AreEqual(atlas.Regions.Count(), 5);
|
||||
|
||||
// no added offset
|
||||
var table = atlas["LongTableUp"];
|
||||
Assert.AreEqual(table.Area, new Rectangle(0, 32, 64, 48));
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue