mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
fixed new cpy instruction yielding incorrect pivots
This commit is contained in:
parent
4918a72760
commit
740c65a887
2 changed files with 15 additions and 13 deletions
|
@ -167,24 +167,26 @@ namespace MLEM.Data {
|
|||
// the location is the only mandatory instruction, which is why we check it here
|
||||
if (location == Rectangle.Empty || namesOffsets.Count <= 0)
|
||||
return;
|
||||
foreach (var (name, addedOff) in namesOffsets) {
|
||||
var loc = location;
|
||||
var piv = pivot;
|
||||
var off = offset + addedOff;
|
||||
|
||||
location.Offset(offset.ToPoint());
|
||||
if (pivot != Vector2.Zero) {
|
||||
pivot += offset;
|
||||
if (!pivotRelative)
|
||||
pivot -= location.Location.ToVector2();
|
||||
}
|
||||
loc.Offset(off);
|
||||
if (piv != Vector2.Zero) {
|
||||
piv += off;
|
||||
if (!pivotRelative)
|
||||
piv -= loc.Location.ToVector2();
|
||||
}
|
||||
|
||||
foreach (var (name, off) in namesOffsets) {
|
||||
var region = new TextureRegion(texture, location.OffsetCopy(off.ToPoint())) {
|
||||
PivotPixels = pivot + off,
|
||||
var region = new TextureRegion(texture, loc) {
|
||||
PivotPixels = piv,
|
||||
Name = name
|
||||
};
|
||||
foreach (var kv in customData)
|
||||
region.SetData(kv.Key, kv.Value);
|
||||
atlas.regions.Add(name, region);
|
||||
}
|
||||
|
||||
// we only clear names offsets if the location was valid, otherwise we ignore multiple names for a region
|
||||
namesOffsets.Clear();
|
||||
}
|
||||
|
|
|
@ -35,13 +35,13 @@ namespace Tests {
|
|||
Assert.AreEqual(negativePivot.Area, new Rectangle(0, 32, 16, 16));
|
||||
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"];
|
||||
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"];
|
||||
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
|
||||
var data = atlas["DataTest"];
|
||||
|
|
Loading…
Reference in a new issue