From d251a55317fa62625bce248212ae76aa67174a98 Mon Sep 17 00:00:00 2001 From: "Weston Rye (Demod)" Date: Mon, 5 Jun 2017 09:57:00 -0400 Subject: [PATCH] Multiple warps from one logistic cell now possible --- .../src/com/demod/fbsr/FBSR.java | 25 +++++++--------- .../src/com/demod/fbsr/LogisticGridCell.java | 29 ++++++++++--------- .../demod/fbsr/render/InserterRendering.java | 8 ++--- .../demod/fbsr/render/SplitterRendering.java | 8 ++--- .../fbsr/render/TypeRendererFactory.java | 11 ++++--- .../fbsr/render/UndergroundBeltRendering.java | 4 +-- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/FBSR.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/FBSR.java index 8187fb6..ed9d96a 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/FBSR.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/FBSR.java @@ -274,8 +274,10 @@ public class FBSR { map.getLogisticGridCell(d.offset(pos, 0.5)).filter(mc -> mc.acceptMoveFrom(d)) .ifPresent(mc -> mc.addMovedFrom(d.back())); }); - cell.getWarp().ifPresent(p -> { - map.getLogisticGridCell(p).ifPresent(mc -> mc.addWarpedFrom(pos)); + cell.getWarps().ifPresent(l -> { + for (Point2D.Double p : l) { + map.getLogisticGridCell(p).ifPresent(mc -> mc.addWarpedFrom(pos)); + } }); }); } @@ -299,9 +301,11 @@ public class FBSR { .filter(nc -> !nc.isBlockTransit() && nc.acceptMoveFrom(d)) .ifPresent(next -> work.add(new Pair<>(nextCellPos, next))); }); - cell.getWarp().ifPresent(p -> { - map.getLogisticGridCell(p).filter(nc -> !nc.isBlockTransit()) - .ifPresent(next -> work.add(new Pair<>(p, next))); + cell.getWarps().ifPresent(l -> { + for (Point2D.Double p : l) { + map.getLogisticGridCell(p).filter(nc -> !nc.isBlockTransit()) + .ifPresent(next -> work.add(new Pair<>(p, next))); + } }); } } @@ -455,16 +459,7 @@ public class FBSR { }); cell.getWarpedFrom().ifPresent(l -> { for (Point2D.Double p : l) { - register.accept(new Renderer(Layer.DEBUG_LA2, p) { - @Override - public void render(Graphics2D g) { - Stroke ps = g.getStroke(); - g.setStroke(new BasicStroke(2 / 32f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - g.setColor(Color.magenta); - g.draw(new Line2D.Double(pos, p)); - g.setStroke(ps); - } - }); + register.accept(RenderUtils.createWireRenderer(p, pos, Color.MAGENTA)); } }); } diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/LogisticGridCell.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/LogisticGridCell.java index ff4e4b8..aa6d1b6 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/LogisticGridCell.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/LogisticGridCell.java @@ -12,7 +12,7 @@ import java.util.TreeSet; public class LogisticGridCell { private Optional move = Optional.empty(); private Optional acceptFilter = Optional.empty(); - private Optional warp = Optional.empty(); + private Optional> warps = Optional.empty(); private Optional> inputs = Optional.empty(); private Optional> outputs = Optional.empty(); @@ -56,6 +56,13 @@ public class LogisticGridCell { return transits.get().add(itemName); } + public void addWarp(Point2D.Double warp) { + if (!warps.isPresent()) { + warps = Optional.of(new ArrayList<>()); + } + this.warps.get().add(warp); + } + public void addWarpedFrom(Point2D.Double pos) { if (!warpedFrom.isPresent()) { warpedFrom = Optional.of(new ArrayList<>()); @@ -87,16 +94,16 @@ public class LogisticGridCell { return transits; } - public Optional getWarp() { - return warp; - } - public Optional> getWarpedFrom() { return warpedFrom; } + public Optional> getWarps() { + return warps; + } + public boolean isAccepting() { - return move.isPresent() || warp.isPresent() || inputs.isPresent(); + return move.isPresent() || warps.isPresent() || inputs.isPresent(); } public boolean isBlockTransit() { @@ -104,12 +111,12 @@ public class LogisticGridCell { } public boolean isTransitEnd() { - return getInputs().isPresent() && (getWarpedFrom().map(l -> !l.isEmpty()).isPresent() - || getMovedFrom().map(l -> !l.isEmpty()).isPresent()); + return inputs.isPresent() + && (warpedFrom.map(l -> !l.isEmpty()).isPresent() || movedFrom.map(l -> !l.isEmpty()).isPresent()); } public boolean isTransitStart() { - return getOutputs().isPresent() && (getWarp().isPresent() || getMove().isPresent()); + return outputs.isPresent() && (warps.isPresent() || move.isPresent()); } public void setAcceptFilter(Optional acceptFilter) { @@ -132,8 +139,4 @@ public class LogisticGridCell { this.outputs = outputs; } - public void setWarp(Optional warp) { - this.warp = warp; - } - } diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/InserterRendering.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/InserterRendering.java index c9654c4..9856b0d 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/InserterRendering.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/InserterRendering.java @@ -122,10 +122,10 @@ public class InserterRendering extends TypeRendererFactory { cellDir = dir.frontRight(); } - setLogisticWarp(map, inPos, dir.frontLeft(), outPos, cellDir); - setLogisticWarp(map, inPos, dir.frontRight(), outPos, cellDir); - setLogisticWarp(map, inPos, dir.backLeft(), outPos, cellDir); - setLogisticWarp(map, inPos, dir.backRight(), outPos, cellDir); + addLogisticWarp(map, inPos, dir.frontLeft(), outPos, cellDir); + addLogisticWarp(map, inPos, dir.frontRight(), outPos, cellDir); + addLogisticWarp(map, inPos, dir.backLeft(), outPos, cellDir); + addLogisticWarp(map, inPos, dir.backRight(), outPos, cellDir); if (entity.json().has("filters")) { LogisticGridCell cell = map.getOrCreateLogisticGridCell(cellDir.offset(outPos, 0.25)); diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/SplitterRendering.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/SplitterRendering.java index 0561f70..de0e2b8 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/SplitterRendering.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/SplitterRendering.java @@ -64,10 +64,10 @@ public class SplitterRendering extends TypeRendererFactory { setLogisticMove(map, rightPos, dir.backLeft(), dir); setLogisticMove(map, rightPos, dir.backRight(), dir); - setLogisticWarp(map, leftPos, dir.backLeft(), rightPos, dir.frontLeft()); - setLogisticWarp(map, leftPos, dir.backRight(), rightPos, dir.frontRight()); - setLogisticWarp(map, rightPos, dir.backLeft(), leftPos, dir.frontLeft()); - setLogisticWarp(map, rightPos, dir.backRight(), leftPos, dir.frontRight()); + addLogisticWarp(map, leftPos, dir.backLeft(), rightPos, dir.frontLeft()); + addLogisticWarp(map, leftPos, dir.backRight(), rightPos, dir.frontRight()); + addLogisticWarp(map, rightPos, dir.backLeft(), leftPos, dir.frontLeft()); + addLogisticWarp(map, rightPos, dir.backRight(), leftPos, dir.frontRight()); } @Override diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/TypeRendererFactory.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/TypeRendererFactory.java index b97c47d..ce18409 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/TypeRendererFactory.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/TypeRendererFactory.java @@ -140,6 +140,11 @@ public class TypeRendererFactory { return byType.getOrDefault(type, DEFAULT); } + protected void addLogisticWarp(WorldMap map, Double gridPos1, Direction cellDir1, Double gridPos2, + Direction cellDir2) { + map.getOrCreateLogisticGridCell(cellDir1.offset(gridPos1, 0.25)).addWarp(cellDir2.offset(gridPos2, 0.25)); + } + public void createRenderers(Consumer register, WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) { try { @@ -305,10 +310,4 @@ public class TypeRendererFactory { cell.setAcceptFilter(Optional.of(acceptFilter)); } - protected void setLogisticWarp(WorldMap map, Double gridPos1, Direction cellDir1, Double gridPos2, - Direction cellDir2) { - map.getOrCreateLogisticGridCell(cellDir1.offset(gridPos1, 0.25)) - .setWarp(Optional.of(cellDir2.offset(gridPos2, 0.25))); - } - } diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/UndergroundBeltRendering.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/UndergroundBeltRendering.java index 4c16baa..825109d 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/UndergroundBeltRendering.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/render/UndergroundBeltRendering.java @@ -89,8 +89,8 @@ public class UndergroundBeltRendering extends TypeRendererFactory { for (int offset = 1; offset <= maxDistance; offset++) { Point2D.Double targetPos = dir.offset(pos, offset); if (map.isMatchingUndergroundBeltEnding(entity.getName(), targetPos, dir)) { - setLogisticWarp(map, pos, dir.frontLeft(), targetPos, dir.backLeft()); - setLogisticWarp(map, pos, dir.frontRight(), targetPos, dir.backRight()); + addLogisticWarp(map, pos, dir.frontLeft(), targetPos, dir.backLeft()); + addLogisticWarp(map, pos, dir.frontRight(), targetPos, dir.backRight()); break; } }