From 2d38774341d3c028341c060bae15a68ec09287f4 Mon Sep 17 00:00:00 2001 From: rogo Date: Sun, 25 Aug 2024 18:45:54 +0200 Subject: [PATCH] fixed elements crossing chunk borders --- Scripts/Chunk.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Scripts/Chunk.cs b/Scripts/Chunk.cs index f1042cf..b9207b9 100644 --- a/Scripts/Chunk.cs +++ b/Scripts/Chunk.cs @@ -111,21 +111,19 @@ public class Chunk { } private void Swap(Element what, Element swapTo) { - Element swap = new Element(what); - - GD.Print($"Swap: {what} -> {swapTo}"); - if (swapTo.Position.Y == 0) GD.Print($""); - - if (what == null || swapTo == null) return; + if (what == null || swapTo == null) { + GD.PrintErr("Trying to swap null"); + return; + } + Element temp = new Element(what); what.Position = swapTo.Position; what.Chunk = swapTo.Chunk; - Elements[swapTo.Position.X, swapTo.Position.Y] = what; - - swapTo.Position = swap.Position; - swapTo.Chunk = swap.Chunk; - Elements[swap.Position.X, swap.Position.Y] = swapTo; + what.Chunk.Elements[what.Position.X, what.Position.Y] = what; + swapTo.Position = temp.Position; + swapTo.Chunk = temp.Chunk; + swapTo.Chunk.Elements[swapTo.Position.X, swapTo.Position.Y] = swapTo; what.Active = true; swapTo.Active = true;