From a4f9518d1e33b1f8ca73227e0c584b2b0281182c Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 18 Dec 2020 09:42:57 -0500 Subject: [PATCH] testing winMM --- core/src/mindustry/input/InputHandler.java | 38 ++---------------- core/src/mindustry/world/Block.java | 7 ++++ .../world/blocks/power/PowerNode.java | 40 ++++++++++++++++++- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 2fed50a715..65147fda5d 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -48,7 +48,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ /** Maximum line length. */ final static int maxLength = 100; final static Rect r1 = new Rect(), r2 = new Rect(); - final static Seq tmpPoints = new Seq<>(), tmpPoints2 = new Seq<>(); public final OverlayFragment frag = new OverlayFragment(); @@ -1144,7 +1143,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ diagonal = !diagonal; } - if(block instanceof PowerNode){ + if(block != null && block.swapDiagonalPlacement){ diagonal = !diagonal; } @@ -1161,39 +1160,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ points = Placement.normalizeLine(startX, startY, endX, endY); } - if(block instanceof PowerNode node){ - var base = tmpPoints2; - var result = tmpPoints.clear(); - - base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(block, player.team(), p.x, p.y, rotation, false)); - boolean addedLast = false; - - outer: - for(int i = 0; i < base.size;){ - var point = base.get(i); - result.add(point); - if(i == base.size - 1) addedLast = true; - - //find the furthest node that overlaps this one - for(int j = base.size - 1; j > i; j--){ - var other = base.get(j); - boolean over = node.overlaps(world.tile(point.x, point.y), world.tile(other.x, other.y)); - - if(over){ - //add node to list and start searching for node that overlaps the next one - i = j; - continue outer; - } - } - - //if it got here, that means nothing was found. try to proceed to the next node anyway - i ++; - } - - if(!addedLast) result.add(base.peek()); - - points.clear(); - points.addAll(result); + if(block != null){ + block.changePlacementPath(points, rotation); } float angle = Angles.angle(startX, startY, endX, endY); diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 09546b6b27..b82a1ddb1a 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -143,6 +143,8 @@ public class Block extends UnlockableContent{ public boolean sync; /** Whether this block uses conveyor-type placement mode. */ public boolean conveyorPlacement; + /** Whether to swap the diagonal placement modes. */ + public boolean swapDiagonalPlacement; /** * The color of this block when displayed on the minimap or map preview. * Do not set manually! This is overridden when loading for most blocks. @@ -386,6 +388,11 @@ public class Block extends UnlockableContent{ return this; } + /** Mutates the given list of points used during line placement. */ + public void changePlacementPath(Seq points, int rotation){ + + } + public Object nextConfig(){ if(saveConfig && lastConfig != null){ return lastConfig; diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index f744dbe0b5..ab265dbf09 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -25,7 +25,8 @@ public class PowerNode extends PowerBlock{ protected static boolean returnValue = false; protected static BuildPlan otherReq; - protected final ObjectSet graphs = new ObjectSet<>(); + protected final static ObjectSet graphs = new ObjectSet<>(); + protected final static Seq tmpPoints = new Seq<>(), tmpPoints2 = new Seq<>(); public @Load("laser") TextureRegion laser; public @Load("laser-end") TextureRegion laserEnd; @@ -40,6 +41,7 @@ public class PowerNode extends PowerBlock{ consumesPower = false; outputsPower = false; canOverdrive = false; + swapDiagonalPlacement = true; config(Integer.class, (entity, value) -> { PowerModule power = entity.power; @@ -149,6 +151,42 @@ public class PowerNode extends PowerBlock{ Draw.reset(); } + @Override + public void changePlacementPath(Seq points, int rotation){ + var base = tmpPoints2; + var result = tmpPoints.clear(); + + base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(this, player.team(), p.x, p.y, rotation, false)); + boolean addedLast = false; + + outer: + for(int i = 0; i < base.size;){ + var point = base.get(i); + result.add(point); + if(i == base.size - 1) addedLast = true; + + //find the furthest node that overlaps this one + for(int j = base.size - 1; j > i; j--){ + var other = base.get(j); + boolean over = overlaps(world.tile(point.x, point.y), world.tile(other.x, other.y)); + + if(over){ + //add node to list and start searching for node that overlaps the next one + i = j; + continue outer; + } + } + + //if it got here, that means nothing was found. try to proceed to the next node anyway + i ++; + } + + if(!addedLast) result.add(base.peek()); + + points.clear(); + points.addAll(result); + } + protected void setupColor(float satisfaction){ float fract = 1f - satisfaction;