1
0
mirror of https://github.com/demodude4u/Factorio-FBSR.git synced 2024-11-24 08:12:21 +02:00

Multiple warps from one logistic cell now possible

This commit is contained in:
Weston Rye (Demod) 2017-06-05 09:57:00 -04:00
parent e6ee288b4e
commit d251a55317
6 changed files with 41 additions and 44 deletions

View File

@ -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));
}
});
}

View File

@ -12,7 +12,7 @@ import java.util.TreeSet;
public class LogisticGridCell {
private Optional<Direction> move = Optional.empty();
private Optional<Direction> acceptFilter = Optional.empty();
private Optional<Point2D.Double> warp = Optional.empty();
private Optional<List<Point2D.Double>> warps = Optional.empty();
private Optional<Set<String>> inputs = Optional.empty();
private Optional<Set<String>> 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<Point2D.Double> getWarp() {
return warp;
}
public Optional<List<Point2D.Double>> getWarpedFrom() {
return warpedFrom;
}
public Optional<List<Point2D.Double>> 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<Direction> acceptFilter) {
@ -132,8 +139,4 @@ public class LogisticGridCell {
this.outputs = outputs;
}
public void setWarp(Optional<Point2D.Double> warp) {
this.warp = warp;
}
}

View File

@ -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));

View File

@ -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

View File

@ -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<Renderer> 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)));
}
}

View File

@ -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;
}
}