Skip to content

Commit

Permalink
Clipboard Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
enigmaquip committed Dec 7, 2016
1 parent d87e242 commit 15d2416
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
11 changes: 4 additions & 7 deletions TEditXna/Editor/Clipboard/ClipboardBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,20 @@ public ObservableCollection<TileEntity> TileEntities
{
get { return _tileEntities; }
}

// since we are using these functions to add chests into the world we don't need to check all spots, only the anchor spot
public Chest GetChestAtTile(int x, int y, int tileType)
{
if (tileType == 88)
return Chests.FirstOrDefault(c => (c.X == x || c.X == x - 1 || c.X == x - 2) && (c.Y == y || c.Y == y - 1));
else
return Chests.FirstOrDefault(c => (c.X == x || c.X == x - 1) && (c.Y == y || c.Y == y - 1));
return Chests.FirstOrDefault(c => (c.X == x) && (c.Y == y));
}

public Sign GetSignAtTile(int x, int y)
{
return Signs.FirstOrDefault(c => (c.X == x || c.X == x - 1) && (c.Y == y || c.Y == y - 1));
return Signs.FirstOrDefault(c => (c.X == x) && (c.Y == y));
}

public TileEntity GetTileEntityAtTile(int x, int y)
{
return TileEntities.FirstOrDefault(c => (c.PosX == x || c.PosX == x - 1) && (c.PosY == y || c.PosY == y - 1));
return TileEntities.FirstOrDefault(c => (c.PosX == x) && (c.PosY == y));
}

public void RenderBuffer()
Expand Down
9 changes: 0 additions & 9 deletions TEditXna/Editor/Clipboard/ClipboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,6 @@ public void PasteBufferIntoWorld(Vector2Int32 anchor)
newChest.Y = y + anchor.Y;
world.Chests.Add(newChest);
}
else
{
// Empty chest
world.Chests.Add(new Chest(x + anchor.X, y + anchor.Y));
}
}
}

Expand All @@ -302,10 +297,6 @@ public void PasteBufferIntoWorld(Vector2Int32 anchor)
newSign.Y = y + anchor.Y;
world.Signs.Add(newSign);
}
else
{
world.Signs.Add(new Sign(x + anchor.X, y + anchor.Y, string.Empty));
}
}
}

Expand Down
50 changes: 14 additions & 36 deletions TEditXna/Terraria/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,20 @@ public bool ValidTileLocation(int x, int y)

public Chest GetChestAtTile(int x, int y)
{
Tile tile = Tiles[x, y];
if (tile.Type == 88)
return Chests.FirstOrDefault(c => (c.X == x || c.X == x - 1 || c.X == x - 2) && (c.Y == y || c.Y == y - 1));
else
return Chests.FirstOrDefault(c => (c.X == x || c.X == x - 1) && (c.Y == y || c.Y == y - 1));
Vector2Int32 anchor = GetAnchor(x,y);
return Chests.FirstOrDefault(c => (c.X == anchor.X) && (c.Y == anchor.Y));
}

public Sign GetSignAtTile(int x, int y)
{
return Signs.FirstOrDefault(c => (c.X == x || c.X == x - 1) && (c.Y == y || c.Y == y - 1));
Vector2Int32 anchor = GetAnchor(x,y);
return Signs.FirstOrDefault(c => (c.X == anchor.X) && (c.Y == anchor.Y));
}

public TileEntity GetTileEntityAtTile(int x, int y)
{
Tile tile = Tiles[x, y];
if (tile.Type == (int)TileType.Dummy)
return TileEntities.FirstOrDefault(c => (c.PosX == x || c.PosX == x - 1) && (c.PosY == y || c.PosY == y - 1 || c.PosY == y - 2));
else if (tile.Type == (int)TileType.ItemFrame)
return TileEntities.FirstOrDefault(c => (c.PosX == x || c.PosX == x - 1) && (c.PosY == y || c.PosY == y - 1));
else
return TileEntities.FirstOrDefault(c => (c.PosX == x) && (c.PosY == y));
Vector2Int32 anchor = GetAnchor(x,y);
return TileEntities.FirstOrDefault(c => (c.PosX == anchor.X) && (c.PosY == anchor.Y));
}

public Vector2Int32 GetMannequin(int x, int y)
Expand All @@ -218,34 +211,19 @@ public Vector2Int32 GetRack(int x, int y)
return new Vector2Int32(x, y);
}

public Vector2Int32 GetChestAnchor(int x, int y)
// find upper left corner of sprites
public Vector2Int32 GetAnchor(int x, int y)
{
Tile tile = Tiles[x, y];
int xShift = 0;
int yShift = 0;

if (tile.Type == 88)
TileProperty tileprop = TileProperties[tile.Type];
if (tileprop.IsFramed && (tileprop.FrameSize.X > 1 || tileprop.FrameSize.Y > 1))
{
xShift = tile.U % 54 / 18;
yShift = tile.V % 36 / 18;
int xShift = tile.U % ((tileprop.TextureGrid.X + 2) * tileprop.FrameSize.X) / (tileprop.TextureGrid.X + 2);
int yShift = tile.V % ((tileprop.TextureGrid.Y + 2) * tileprop.FrameSize.Y) / (tileprop.TextureGrid.Y + 2);
return new Vector2Int32(x - xShift, y - yShift);
}
else
{
xShift = tile.U % 36 / 18;
yShift = tile.V % 36 / 18;
}

return new Vector2Int32(x - xShift, y - yShift);
}

public Vector2Int32 GetSignAnchor(int x, int y)
{
Tile tile = Tiles[x, y];

int xShift = tile.U % 36 / 18;
int yShift = tile.V % 36 / 18;

return new Vector2Int32(x - xShift, y - yShift);
return new Vector2Int32(x, y);
}

public void Validate()
Expand Down

0 comments on commit 15d2416

Please sign in to comment.