1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

fixed new cpy instruction yielding incorrect pivots

This commit is contained in:
Ell 2022-09-14 11:20:55 +02:00
parent 4918a72760
commit 740c65a887
2 changed files with 15 additions and 13 deletions

View file

@ -167,24 +167,26 @@ namespace MLEM.Data {
// the location is the only mandatory instruction, which is why we check it here // the location is the only mandatory instruction, which is why we check it here
if (location == Rectangle.Empty || namesOffsets.Count <= 0) if (location == Rectangle.Empty || namesOffsets.Count <= 0)
return; return;
foreach (var (name, addedOff) in namesOffsets) {
var loc = location;
var piv = pivot;
var off = offset + addedOff;
location.Offset(offset.ToPoint()); loc.Offset(off);
if (pivot != Vector2.Zero) { if (piv != Vector2.Zero) {
pivot += offset; piv += off;
if (!pivotRelative) if (!pivotRelative)
pivot -= location.Location.ToVector2(); piv -= loc.Location.ToVector2();
} }
foreach (var (name, off) in namesOffsets) { var region = new TextureRegion(texture, loc) {
var region = new TextureRegion(texture, location.OffsetCopy(off.ToPoint())) { PivotPixels = piv,
PivotPixels = pivot + off,
Name = name Name = name
}; };
foreach (var kv in customData) foreach (var kv in customData)
region.SetData(kv.Key, kv.Value); region.SetData(kv.Key, kv.Value);
atlas.regions.Add(name, region); atlas.regions.Add(name, region);
} }
// we only clear names offsets if the location was valid, otherwise we ignore multiple names for a region // we only clear names offsets if the location was valid, otherwise we ignore multiple names for a region
namesOffsets.Clear(); namesOffsets.Clear();
} }

View file

@ -35,13 +35,13 @@ namespace Tests {
Assert.AreEqual(negativePivot.Area, new Rectangle(0, 32, 16, 16)); Assert.AreEqual(negativePivot.Area, new Rectangle(0, 32, 16, 16));
Assert.AreEqual(negativePivot.PivotPixels, new Vector2(-32, 46 - 32)); Assert.AreEqual(negativePivot.PivotPixels, new Vector2(-32, 46 - 32));
// copies // copies (pivot pixels should be identical to LongTableUp because they're region-internal)
var copy1 = atlas["Copy1"]; var copy1 = atlas["Copy1"];
Assert.AreEqual(copy1.Area, new Rectangle(0 + 16, 32, 64, 48)); Assert.AreEqual(copy1.Area, new Rectangle(0 + 16, 32, 64, 48));
Assert.AreEqual(copy1.PivotPixels, new Vector2(16 + 16, 48 - 32)); Assert.AreEqual(copy1.PivotPixels, new Vector2(16, 48 - 32));
var copy2 = atlas["Copy2"]; var copy2 = atlas["Copy2"];
Assert.AreEqual(copy2.Area, new Rectangle(0 + 32, 32 + 4, 64, 48)); Assert.AreEqual(copy2.Area, new Rectangle(0 + 32, 32 + 4, 64, 48));
Assert.AreEqual(copy2.PivotPixels, new Vector2(16 + 32, 48 - 32 + 4)); Assert.AreEqual(copy2.PivotPixels, new Vector2(16, 48 - 32));
// data // data
var data = atlas["DataTest"]; var data = atlas["DataTest"];