1
0
mirror of https://github.com/demodude4u/Factorio-FBSR.git synced 2024-11-27 08:20:57 +02:00

Basic logistics and small improvements

This commit is contained in:
Weston Rye (Demod) 2017-06-01 14:00:34 -04:00
parent d70c046511
commit b0b88f9f70
47 changed files with 1091 additions and 365 deletions

View File

@ -2,77 +2,12 @@ package com.demod.fbsr;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
import org.json.JSONObject;
import com.demod.factorio.Utils;
public class BlueprintEntity {
public static enum Direction {
NORTH(0, -1), //
NORTHEAST(1, -1), //
EAST(1, 0), //
SOUTHEAST(1, 1), //
SOUTH(0, 1), //
SOUTHWEST(-1, 1), //
WEST(-1, 0), //
NORTHWEST(-1, -1);
public static Direction fromCardinal(int cardinal) {
return values()[cardinal * 2];
}
private final int dx;
private final int dy;
private Direction(int dx, int dy) {
this.dx = dx;
this.dy = dy;
}
public Direction back() {
return rotate(4);
}
public int cardinal() {
return ordinal() / 2;
}
public int getDx() {
return dx;
}
public int getDy() {
return dy;
}
public Direction left() {
return rotate(-2);
}
public Point2D.Double offset(Point2D.Double pos) {
return new Point2D.Double(pos.x + dx, pos.y + dy);
}
public Double offset(Point2D.Double pos, double distance) {
return new Point2D.Double(pos.x + distance * dx, pos.y + distance * dy);
}
public Rectangle2D.Double offset(Rectangle2D.Double rect, double distance) {
return new Rectangle2D.Double(rect.x + distance * dx, rect.y + distance * dy, rect.width, rect.height);
}
public Direction right() {
return rotate(2);
}
public Direction rotate(int deltaIndex) {
Direction[] values = values();
return values[(((ordinal() + deltaIndex) % values.length) + values.length) % values.length];
}
}
private final JSONObject json;
private final int id;

View File

@ -45,7 +45,7 @@ public class BlueprintStringData {
}
json = new JSONObject(jsonBuilder.toString());
}
System.out.println(json);
// System.out.println(json);
if (json.has("blueprint")) {
blueprints.add(new Blueprint(json));
} else {

View File

@ -0,0 +1,89 @@
package com.demod.fbsr;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
public enum Direction {
NORTH(0, -1), //
NORTHEAST(1, -1), //
EAST(1, 0), //
SOUTHEAST(1, 1), //
SOUTH(0, 1), //
SOUTHWEST(-1, 1), //
WEST(-1, 0), //
NORTHWEST(-1, -1);
public static Direction fromCardinal(int cardinal) {
return values()[cardinal * 2];
}
private final int dx;
private final int dy;
private Direction(int dx, int dy) {
this.dx = dx;
this.dy = dy;
}
public Direction back() {
return rotate(4);
}
public Direction backLeft() {
return rotate(-3);
}
public Direction backRight() {
return rotate(3);
}
public int cardinal() {
return ordinal() / 2;
}
public Direction frontLeft() {
return rotate(-1);
}
public Direction frontRight() {
return rotate(1);
}
public int getDx() {
return dx;
}
public int getDy() {
return dy;
}
public Direction left() {
return rotate(-2);
}
public Point2D.Double offset(Point2D.Double pos) {
return new Point2D.Double(pos.x + dx, pos.y + dy);
}
public Double offset(Point2D.Double pos, double distance) {
return new Point2D.Double(pos.x + distance * dx, pos.y + distance * dy);
}
public Rectangle2D.Double offset(Rectangle2D.Double rect, double distance) {
return new Rectangle2D.Double(rect.x + distance * dx, rect.y + distance * dy, rect.width, rect.height);
}
public Direction right() {
return rotate(2);
}
public Direction rotate(Direction dir) {
return rotate(dir.ordinal());
}
public Direction rotate(int deltaIndex) {
Direction[] values = values();
return values[(((ordinal() + deltaIndex) % values.length) + values.length) % values.length];
}
}

View File

@ -5,8 +5,10 @@ import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
@ -15,31 +17,36 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import org.json.JSONException;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.FactorioData;
import com.demod.factorio.ModInfo;
import com.demod.factorio.Utils;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.fbsr.render.Renderer;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.render.TypeRendererFactory;
import com.google.common.collect.LinkedHashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Table;
import javafx.util.Pair;
public class FBSR {
private static class RenderingTuple {
BlueprintEntity entity;
DataPrototype prototype;
EntityPrototype prototype;
TypeRendererFactory factory;
}
@ -54,6 +61,8 @@ public class FBSR {
private static volatile String version = null;
private static final Map<String, Color> itemColorCache = new HashMap<>();
private static void alignRenderingTuplesToGrid(List<RenderingTuple> renderingTuples) {
Multiset<Boolean> xAligned = LinkedHashMultiset.create();
Multiset<Boolean> yAligned = LinkedHashMultiset.create();
@ -63,10 +72,10 @@ public class FBSR {
continue; // XXX
}
Rectangle2D.Double bounds = Utils.parseRectangle(tuple.prototype.lua().get("selection_box"));
Rectangle2D.Double selectionBox = tuple.prototype.getSelectionBox();
Point2D.Double position = tuple.entity.getPosition();
bounds.x += position.x;
bounds.y += position.y;
Rectangle2D.Double bounds = new Rectangle2D.Double(selectionBox.x + position.x, selectionBox.y + position.y,
selectionBox.width, selectionBox.height);
// System.out.println(bounds);
// Everything is doubled and rounded to the closest original 0.5
@ -210,27 +219,38 @@ public class FBSR {
return image;
}
public static synchronized BufferedImage getModImage(LuaValue value) {
String path = value.toString();
if (path.isEmpty()) {
throw new IllegalArgumentException("Path is Empty!");
}
return modImageCache.computeIfAbsent(path, p -> {
String firstSegment = path.split("\\/")[0];
String mod = firstSegment.substring(2, firstSegment.length() - 2);
File modFolder = new File(FactorioData.factorio, "data/" + mod);
File file = new File(modFolder, path.replace(firstSegment, "").substring(1));
try {
return ImageIO.read(file);
} catch (IOException e) {
System.err.println(file.getAbsolutePath());
e.printStackTrace();
throw new RuntimeException(e);
private static void debugTracePath(Consumer<Renderer> register, DataTable table, WorldMap map, Point2D.Double pos,
String itemName) {
paintLogisticsAt(map, pos, itemName);
paintReverseLogisticsAt(map, pos, itemName);
drawDot(register, table, pos, itemName);
}
private static void drawDot(Consumer<Renderer> register, DataTable table, Point2D.Double pos, String itemName) {
register.accept(new Renderer(Layer.WIRE, pos) {
@Override
public void render(Graphics2D g) {
g.setColor(getItemLogisticColor(table, itemName));
g.fill(new Ellipse2D.Double(pos.x - 0.25, pos.y - 0.25, 0.5, 0.5));
}
});
}
private static String getVersion() throws JSONException, FileNotFoundException, IOException {
private static Color getItemLogisticColor(DataTable table, String itemName) {
return itemColorCache.computeIfAbsent(itemName, k -> {
DataPrototype prototype = table.getItem(k).get();
BufferedImage image = FactorioData.getModImage(prototype.lua().get("icon"));
Color color = Utils.getAverageColor(image);
// return new Color(color.getRGB() | 0xA0A0A0);
// return color.brighter().brighter();
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
return Color.getHSBColor(hsb[0], Math.max(0.25f, hsb[1]), Math.max(0.5f, hsb[2]));
// return Color.getHSBColor(hsb[0], Math.max(1f, hsb[1]),
// Math.max(0.75f, hsb[2]));
});
}
public static String getVersion() throws JSONException, FileNotFoundException, IOException {
if (version == null) {
ModInfo baseInfo = new ModInfo(Utils
.readJsonFromStream(new FileInputStream(new File(FactorioData.factorio, "data/base/info.json"))));
@ -239,19 +259,140 @@ public class FBSR {
return version;
}
private static void paintLogisticsAt(WorldMap map, Point2D.Double startPos, String itemName) {
ArrayDeque<Point2D.Double> work = new ArrayDeque<>();
work.add(startPos);
while (!work.isEmpty()) {
Point2D.Double pos = work.poll();
map.getLogisticGridCell(pos).ifPresent(c -> {
if (!c.getTransits().isPresent() || !c.getTransits().get().contains(itemName)) {
c.addTransit(itemName);
c.getMove().ifPresent(d -> {
work.add(d.offset(pos, 0.5));
});
c.getWarp().ifPresent(p -> {
work.add(p);
});
}
});
}
}
private static void paintReverseLogisticsAt(WorldMap map, Point2D.Double startPos, String itemName) {
ArrayDeque<Point2D.Double> work = new ArrayDeque<>();
map.getLogisticGridCell(startPos).ifPresent(c -> {
c.getMovedFrom().ifPresent(l -> {
l.forEach(d -> work.add(d.offset(startPos, 0.5)));
});
c.getWarpedFrom().ifPresent(l -> {
l.forEach(p -> work.add(p));
});
});
while (!work.isEmpty()) {
Point2D.Double pos = work.poll();
map.getLogisticGridCell(pos).ifPresent(c -> {
if (!c.getTransits().isPresent() || !c.getTransits().get().contains(itemName)) {
c.addTransit(itemName);
c.getMovedFrom().ifPresent(l -> {
l.forEach(d -> work.add(d.offset(pos, 0.5)));
});
c.getWarpedFrom().ifPresent(l -> {
l.forEach(p -> work.add(p));
});
}
});
}
}
private static void populateReverseLogistics(WorldMap map) {
Table<Integer, Integer, LogisticGridCell> logisticGrid = map.getLogisticGrid();
logisticGrid.cellSet().forEach(c -> {
Point2D.Double pos = new Point2D.Double(c.getRowKey() / 2.0 + 0.25, c.getColumnKey() / 2.0 + 0.25);
LogisticGridCell cell = c.getValue();
cell.getMove().ifPresent(d -> {
map.getLogisticGridCell(d.offset(pos, 0.5)).ifPresent(mc -> mc.addMovedFrom(d.back()));
});
cell.getWarp().ifPresent(p -> {
map.getLogisticGridCell(p).ifPresent(mc -> mc.addWarpedFrom(pos));
});
});
}
private static void populateTransitLogistics(WorldMap map) {
Table<Integer, Integer, LogisticGridCell> logisticGrid = map.getLogisticGrid();
ArrayDeque<Pair<Point2D.Double, LogisticGridCell>> work = new ArrayDeque<>();
logisticGrid.cellSet().stream().filter(c -> c.getValue().isTransitStart()).forEach(c -> {
Set<String> outputs = c.getValue().getOutputs().get();
for (String item : outputs) {
work.add(new Pair<>(map.getLogisticCellPosition(c), c.getValue()));
while (!work.isEmpty()) {
Pair<Point2D.Double, LogisticGridCell> pair = work.pop();
Point2D.Double cellPos = pair.getKey();
LogisticGridCell cell = pair.getValue();
if (cell.addTransit(item)) {
cell.getMove().ifPresent(d -> {
Point2D.Double nextCellPos = d.offset(cellPos, 0.5);
map.getLogisticGridCell(nextCellPos)
.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)));
});
}
}
}
});
// logisticGrid.cellSet().stream().filter(c ->
// c.getValue().isTransitEnd()).forEach(c -> {
// Set<String> inputs = c.getValue().getInputs().get();
// for (String item : inputs) {
// work.add(new Pair<>(map.getLogisticCellPosition(c), c.getValue()));
// while (!work.isEmpty()) {
// Pair<Point2D.Double, LogisticGridCell> pair = work.pop();
// Point2D.Double cellPos = pair.getKey();
// LogisticGridCell cell = pair.getValue();
// if (cell.addTransit(item)) {
// cell.getMovedFrom().ifPresent(l -> {
// for (Direction d : l) {
// Point2D.Double nextCellPos = d.offset(cellPos, 0.5);
// map.getLogisticGridCell(nextCellPos).filter(nc ->
// !nc.isBlockTransit())
// .ifPresent(next -> work.add(new Pair<>(nextCellPos, next)));
// }
// });
// cell.getWarpedFrom().ifPresent(l -> {
// for (Point2D.Double p : l) {
// map.getLogisticGridCell(p).filter(nc -> !nc.isBlockTransit())
// .ifPresent(next -> work.add(new Pair<>(p, next)));
// }
// });
// }
// }
// }
// });
}
public static BufferedImage renderBlueprint(Blueprint blueprint, BlueprintReporting reporting)
throws JSONException, IOException {
DataTable table = FactorioData.getTable();
WorldMap map = new WorldMap();
List<RenderingTuple> renderingTuples = new ArrayList<RenderingTuple>();
for (BlueprintEntity entity : blueprint.getEntities()) {
RenderingTuple tuple = new RenderingTuple();
tuple.entity = entity;
tuple.prototype = table.getEntities().get(entity.getName());
if (tuple.prototype == null) {
Optional<EntityPrototype> prototype = table.getEntity(entity.getName());
if (!prototype.isPresent()) {
reporting.addWarning("Cant find prototype for " + entity.getName());
continue;
}
tuple.prototype = prototype.get();
tuple.factory = TypeRendererFactory.forType(tuple.prototype.getType());
// System.out.println("\t" + entity.getName() + " -> " +
// tuple.factory.getClass().getSimpleName());
@ -259,20 +400,31 @@ public class FBSR {
}
alignRenderingTuplesToGrid(renderingTuples);
WorldMap worldMap = new WorldMap();
renderingTuples.forEach(t -> {
try {
t.factory.populateWorldMap(worldMap, table, t.entity, t.prototype);
t.factory.populateWorldMap(map, table, t.entity, t.prototype);
} catch (Exception e) {
reporting.addException(e);
}
});
renderingTuples.forEach(t -> {
try {
t.factory.populateLogistics(map, table, t.entity, t.prototype);
} catch (Exception e) {
reporting.addException(e);
}
});
populateReverseLogistics(map);
populateTransitLogistics(map);
List<Renderer> renderers = new ArrayList<>();
renderingTuples.forEach(t -> {
try {
t.factory.createRenderers(renderers::add, worldMap, table, t.entity, t.prototype);
t.factory.createRenderers(renderers::add, map, table, t.entity, t.prototype);
} catch (Exception e) {
reporting.addException(e);
}
@ -280,12 +432,75 @@ public class FBSR {
renderingTuples.forEach(t -> {
try {
t.factory.createWireConnections(renderers::add, worldMap, table, t.entity, t.prototype);
t.factory.createWireConnections(renderers::add, map, table, t.entity, t.prototype);
} catch (Exception e) {
reporting.addException(e);
}
});
// debugTracePath(renderers::add, table, map, new Point2D.Double(0.25,
// 0.25), "debug");
// debugTracePath(map, renderers, new Point2D.Double(-7.75, -7.75),
// Color.blue);
// debugTracePath(map, renderers, new Point2D.Double(7.75, -7.75),
// Color.green);
showLogisticGrid(renderers::add, table, map);
return applyRendering(reporting, (int) Math.round(TypeRendererFactory.tileSize), renderers);
}
private static void showLogisticGrid(Consumer<Renderer> register, DataTable table, WorldMap map) {
Table<Integer, Integer, LogisticGridCell> logisticGrid = map.getLogisticGrid();
logisticGrid.cellSet().forEach(c -> {
Point2D.Double pos = new Point2D.Double(c.getRowKey() / 2.0 + 0.25, c.getColumnKey() / 2.0 + 0.25);
LogisticGridCell cell = c.getValue();
cell.getTransits().ifPresent(s -> {
if (s.isEmpty()) {
return;
}
int i = 0;
float width = 0.3f / s.size();
for (String itemName : s) {
double shift = ((i + 1) / (double) (s.size() + 1) - 0.5) / 3.0; // -0.25..0.25
cell.getMove().filter(d -> map.getLogisticGridCell(d.offset(pos, 0.5))
.map(LogisticGridCell::isAccepting).orElse(false)).ifPresent(d -> {
register.accept(new Renderer(Layer.LOGISTICS_MOVE, pos) {
@Override
public void render(Graphics2D g) {
Stroke ps = g.getStroke();
g.setStroke(
new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.setColor(Utils.withAlpha(getItemLogisticColor(table, itemName), 128));
g.draw(new Line2D.Double(d.right().offset(pos, shift),
d.right().offset(d.offset(pos, 0.5), shift)));
g.setStroke(ps);
}
});
});
// cell.getWarp()
// .filter(p ->
// map.getLogisticGridCell(p).map(LogisticGridCell::isAccepting).orElse(false))
// .ifPresent(p -> {
// register.accept(new Renderer(Layer.LOGISTICS_WARP, pos) {
//
// @Override
// public void render(Graphics2D g) {
// Stroke ps = g.getStroke();
// g.setStroke(
// new BasicStroke(0.15f, BasicStroke.CAP_ROUND,
// BasicStroke.JOIN_ROUND));
// g.setColor(Utils.withAlpha(getItemLogisticColor(table,
// itemName), 128));
// g.draw(new Line2D.Double(pos, p));
// g.setStroke(ps);
// }
// });
// });
i++;
}
});
});
}
}

View File

@ -0,0 +1,127 @@
package com.demod.fbsr;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
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<Set<String>> inputs = Optional.empty();
private Optional<Set<String>> outputs = Optional.empty();
private Optional<SortedSet<String>> transits = Optional.empty();
private boolean blockTransit = false;
private Optional<List<Direction>> movedFrom = Optional.empty();
private Optional<List<Point2D.Double>> warpedFrom = Optional.empty();
public boolean acceptMoveFrom(Direction move) {
if (acceptFilter.isPresent()) {
return acceptFilter.get().ordinal() == move.ordinal();
}
return true;
}
public void addMovedFrom(Direction dir) {
if (acceptFilter.filter(a -> a.ordinal() != dir.ordinal()).isPresent()) {
return;
}
if (!movedFrom.isPresent()) {
movedFrom = Optional.of(new ArrayList<>());
}
movedFrom.get().add(dir);
}
public boolean addTransit(String itemName) {
if (!transits.isPresent()) {
transits = Optional.of(new TreeSet<>());
}
return transits.get().add(itemName);
}
public void addWarpedFrom(Point2D.Double pos) {
if (!warpedFrom.isPresent()) {
warpedFrom = Optional.of(new ArrayList<>());
}
warpedFrom.get().add(pos);
}
public Optional<Direction> getAcceptFilter() {
return acceptFilter;
}
public Optional<Set<String>> getInputs() {
return inputs;
}
public Optional<Direction> getMove() {
return move;
}
public Optional<List<Direction>> getMovedFrom() {
return movedFrom;
}
public Optional<Set<String>> getOutputs() {
return outputs;
}
public Optional<SortedSet<String>> getTransits() {
return transits;
}
public Optional<Point2D.Double> getWarp() {
return warp;
}
public Optional<List<Point2D.Double>> getWarpedFrom() {
return warpedFrom;
}
public boolean isAccepting() {
return move.isPresent() || warp.isPresent() || inputs.isPresent();
}
public boolean isBlockTransit() {
return blockTransit;
}
public boolean isTransitEnd() {
return getInputs().isPresent() && (getWarpedFrom().map(l -> !l.isEmpty()).isPresent()
|| getMovedFrom().map(l -> !l.isEmpty()).isPresent());
}
public boolean isTransitStart() {
return getOutputs().isPresent() && (getWarp().isPresent() || getMove().isPresent());
}
public void setAcceptFilter(Optional<Direction> acceptFilter) {
this.acceptFilter = acceptFilter;
}
public void setBlockTransit(boolean blockTransit) {
this.blockTransit = blockTransit;
}
public void setInputs(Optional<Set<String>> inputs) {
this.inputs = inputs;
}
public void setMove(Optional<Direction> move) {
this.move = move;
}
public void setOutputs(Optional<Set<String>> outputs) {
this.outputs = outputs;
}
public void setWarp(Optional<Point2D.Double> warp) {
this.warp = warp;
}
}

View File

@ -1,4 +1,4 @@
package com.demod.fbsr.render;
package com.demod.fbsr;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
@ -7,9 +7,11 @@ import java.awt.geom.Rectangle2D;
public abstract class Renderer {
public static enum Layer {
RAIL_STONE_BACKGROUND, RAIL_STONE, RAIL_TIES, RAIL_BACKPLATES, RAIL_METALS, //
ENTITY, ENTITY2, ENTITY3, //
ENTITY, LOGISTICS_MOVE, ENTITY2, ENTITY3, //
OVERLAY, OVERLAY2, OVERLAY3, OVERLAY4, //
WIRE;
LOGISTICS_WARP, //
WIRE,//
;
}
protected final Rectangle2D.Double bounds;

View File

@ -5,35 +5,125 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import com.google.common.collect.Table.Cell;
import javafx.util.Pair;
public class WorldMap {
public static enum BeltBend {
FROM_LEFT, NONE, FROM_RIGHT;
}
public static class BeltCell {
private final Direction facing;
private final boolean bendable;
private final boolean bendOthers;
public BeltCell(Direction facing, boolean bendable, boolean bendOthers) {
this.facing = facing;
this.bendable = bendable;
this.bendOthers = bendOthers;
}
public boolean canBendOthers() {
return bendOthers;
}
public Direction getFacing() {
return facing;
}
public boolean isBendable() {
return bendable;
}
}
// XXX Hash-based tables are not the most efficient here
// Row: X
// Column: Y
private final Table<Integer, Integer, Direction> belts = HashBasedTable.create();
private final Table<Integer, Integer, BeltCell> belts = HashBasedTable.create();
private final Table<Integer, Integer, Integer> pipes = HashBasedTable.create();
private final Table<Integer, Integer, Integer> heatPipes = HashBasedTable.create();
private final Table<Integer, Integer, Object> walls = HashBasedTable.create();
private final Table<Integer, Integer, Boolean> gates = HashBasedTable.create();
private final Table<Integer, Integer, Pair<String, Direction>> undergroundBeltEndings = HashBasedTable.create();
// Key: id1|id2|color
// Row: X*2
// Column: Y*2
private final Table<Integer, Integer, LogisticGridCell> logisticGrid = HashBasedTable.create();
// Key: "eid1|cid1|eid2|cid2|color"
private final Map<String, Pair<Point2D.Double, Point2D.Double>> wires = new LinkedHashMap<>();
private int flag(Direction facing) {
return 1 << facing.cardinal();
}
public Optional<Direction> getBelt(Point2D.Double pos) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
public Optional<BeltCell> getBelt(Point2D.Double pos) {
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return Optional.ofNullable(belts.get(kr, kc));
}
public Optional<BeltBend> getBeltBend(Point2D.Double pos) {
return getBelt(pos).map(b -> {
return getBeltBend(pos, b);
});
}
public BeltBend getBeltBend(Point2D.Double pos, BeltCell belt) {
if (!belt.bendable) {
return BeltBend.NONE;
}
boolean left = isBeltFacingMeFrom(pos, belt.facing.left());
boolean right = isBeltFacingMeFrom(pos, belt.facing.right());
boolean back = isBeltFacingMeFrom(pos, belt.facing.back());
if (back || (left && right)) {
return BeltBend.NONE;
} else if (left) {
return BeltBend.FROM_LEFT;
} else if (right) {
return BeltBend.FROM_RIGHT;
} else {
return BeltBend.NONE;
}
}
public Optional<Direction> getBeltFacing(Point2D.Double pos) {
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return Optional.ofNullable(belts.get(kr, kc)).map(BeltCell::getFacing);
}
public Point2D.Double getLogisticCellPosition(Cell<Integer, Integer, LogisticGridCell> c) {
return new Point2D.Double(c.getRowKey() / 2.0 + 0.25, c.getColumnKey() / 2.0 + 0.25);
}
public Table<Integer, Integer, LogisticGridCell> getLogisticGrid() {
return logisticGrid;
}
public Optional<LogisticGridCell> getLogisticGridCell(Point2D.Double pos) {
int kr = (int) Math.floor(pos.x * 2);
int kc = (int) Math.floor(pos.y * 2);
return Optional.ofNullable(logisticGrid.get(kr, kc));
}
public LogisticGridCell getOrCreateLogisticGridCell(Point2D.Double pos) {
int kr = (int) Math.floor(pos.x * 2);
int kc = (int) Math.floor(pos.y * 2);
LogisticGridCell ret = logisticGrid.get(kr, kc);
if (ret == null) {
logisticGrid.put(kr, kc, ret = new LogisticGridCell());
}
return ret;
}
public Pair<Point2D.Double, Point2D.Double> getWire(String key) {
return wires.get(key);
}
@ -42,49 +132,57 @@ public class WorldMap {
return wires.containsKey(key);
}
public boolean isBeltFacingMeFrom(Point2D.Double pos, Direction dir) {
return getBelt(dir.offset(pos)).filter(b -> b.bendOthers).map(b -> b.facing)
.map(d -> pos.distance(d.offset(dir.offset(pos))) < 0.1).orElse(false);
}
public boolean isHeatPipe(Point2D.Double pos, Direction facing) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return heatPipes.contains(kr, kc) && (heatPipes.get(kr, kc) & flag(facing)) > 0;
}
public boolean isHorizontalGate(Point2D.Double pos) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return gates.contains(kr, kc) && (gates.get(kr, kc) == false);
}
public boolean isMatchingUndergroundBeltEnding(String name, Point2D.Double pos, Direction dir) {
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return Optional.ofNullable(undergroundBeltEndings.get(kr, kc))
.filter(p -> p.getKey().equals(name) && p.getValue().ordinal() == dir.ordinal()).isPresent();
}
public boolean isPipe(Point2D.Double pos, Direction facing) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return pipes.contains(kr, kc) && (pipes.get(kr, kc) & flag(facing)) > 0;
}
public boolean isVerticalGate(Point2D.Double pos) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return gates.contains(kr, kc) && (gates.get(kr, kc) == true);
}
public boolean isWall(Point2D.Double pos) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
return walls.contains(kr, kc);
}
private int keyOf(double pos) {
return (int) Math.round(pos - 0.5);
}
public void setBelt(Point2D.Double pos, Direction direction) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
belts.put(kr, kc, direction);
public void setBelt(Point2D.Double pos, Direction facing, boolean bendable, boolean bendOthers) {
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
belts.put(kr, kc, new BeltCell(facing, bendable, bendOthers));
}
public void setHeatPipe(Point2D.Double pos, Direction... facings) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
int flags = 0;
if (facings.length == 0) {
flags = 0b1111;
@ -97,14 +195,14 @@ public class WorldMap {
}
public void setHorizontalGate(Point2D.Double pos) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
gates.put(kr, kc, false);
}
public void setPipe(Point2D.Double pos, Direction... facings) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
int flags = 0;
if (facings.length == 0) {
flags = 0b1111;
@ -116,15 +214,21 @@ public class WorldMap {
pipes.put(kr, kc, flags);
}
public void setUndergroundBeltEnding(String name, Point2D.Double pos, Direction dir) {
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
undergroundBeltEndings.put(kr, kc, new Pair<>(name, dir));
}
public void setVerticalGate(Point2D.Double pos) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
gates.put(kr, kc, true);
}
public void setWall(Point2D.Double pos) {
int kr = keyOf(pos.x);
int kc = keyOf(pos.y);
int kr = (int) Math.floor(pos.x);
int kc = (int) Math.floor(pos.y);
walls.put(kr, kc, pos);
}

View File

@ -1,34 +0,0 @@
package com.demod.fbsr.app;
public class BeltAnalysis {
// Identify the configurations of tile -> tile interactions and calculations
// LR -> LR
// LR -> L/R (Belt Side)
// L/R -> L/R (Under Start/End Side)
// I -> L/R
// LR -> I
// I -> C
// C -> I
// I -> I
// I -> LI/RI
// Belt -> Splitter
// Underground
public static class LogisticTile {
// Movement Tiles
// == Directional
// == Warp
// == Split
// Block Walls
// Inserter Grab/Drop
}
public static void main(String[] args) {
}
}

View File

@ -53,6 +53,7 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
private static final Pattern pastebinPattern = Pattern.compile("pastebin\\.com/([A-Za-z0-9]+)");
private static final Pattern hastebinPattern = Pattern.compile("hastebin\\.com/([A-Za-z0-9]+)");
private static final Pattern gistPattern = Pattern.compile("gist\\.github\\.com/([-a-zA-Z0-9@:%_\\+.~#?&//=]+)");
public static void main(String[] args) {
new BlueprintBotDiscordService().startAsync();
@ -152,6 +153,13 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
findBlueprintsInURL(event, reporting, "https://hastebin.com/raw/" + code);
}
}
{
Matcher matcher = gistPattern.matcher(content);
while (matcher.find()) {
String code = matcher.group(1);
findBlueprintsInURL(event, reporting, "https://gist.githubusercontent.com/" + code + "/raw/");
}
}
}
private byte[] generateDiscordFriendlyPNGImage(BufferedImage image) throws IOException {

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class AccumulatorRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("picture"));
register.accept(spriteRenderer(sprite, entity, prototype));
}

View File

@ -5,14 +5,15 @@ import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class AmmoTurretRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite baseSprite = getSpriteFromAnimation(prototype.lua().get("base_picture").get("layers").get(1));
register.accept(spriteRenderer(baseSprite, entity, prototype));
LuaValue turretLayers = prototype.lua().get("folded_animation").get("layers");

View File

@ -5,8 +5,9 @@ import java.util.Map;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class ArithmeticCombinatorRendering extends TypeRendererFactory {
@ -24,7 +25,7 @@ public class ArithmeticCombinatorRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
// prototype.debugPrint();
// entity.debugPrint();
Sprite sprite = getSpriteFromAnimation(

View File

@ -7,25 +7,28 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.FactorioData;
import com.demod.factorio.Utils;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.factorio.prototype.RecipePrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.FBSR;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
public class AssemblingMachineRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
List<Sprite> sprites = getSpritesFromAnimation(prototype.lua().get("animation"), entity.getDirection());
register.accept(spriteRenderer(sprites, entity, prototype));
@ -34,9 +37,10 @@ public class AssemblingMachineRendering extends TypeRendererFactory {
String recipe = entity.json().optString("recipe", null);
if (recipe != null) {
DataPrototype protoRecipe = dataTable.getRecipes().get(recipe);
if (protoRecipe.lua().get("icon") != LuaValue.NIL) {
spriteIcon.image = FBSR.getModImage(protoRecipe.lua().get("icon"));
RecipePrototype protoRecipe = dataTable.getRecipe(recipe).get();
LuaValue iconLua = protoRecipe.lua().get("icon");
if (!iconLua.isnil()) {
spriteIcon.image = FactorioData.getModImage(iconLua);
} else {
String name;
if (protoRecipe.lua().get("results") != LuaValue.NIL) {
@ -44,11 +48,11 @@ public class AssemblingMachineRendering extends TypeRendererFactory {
} else {
name = protoRecipe.lua().get("result").toString();
}
DataPrototype protoProduct = dataTable.getItems().get(name);
if (protoProduct == null) {
protoProduct = dataTable.getFluids().get(name);
Optional<DataPrototype> protoProduct = dataTable.getItem(name);
if (!protoProduct.isPresent()) {
protoProduct = dataTable.getFluid(name);
}
spriteIcon.image = FBSR.getModImage(protoProduct.lua().get("icon"));
spriteIcon.image = FactorioData.getModImage(protoProduct.get().lua().get("icon"));
}
spriteIcon.source = new Rectangle(0, 0, spriteIcon.image.getWidth(), spriteIcon.image.getHeight());
@ -63,15 +67,26 @@ public class AssemblingMachineRendering extends TypeRendererFactory {
delegate.render(g);
}
});
}
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
String recipe = entity.json().optString("recipe", null);
public void populateLogistics(WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
String recipeName = entity.json().optString("recipe", null);
if (recipeName != null) {
RecipePrototype protoRecipe = dataTable.getRecipe(recipeName).get();
setLogisticMachine(map, entity, prototype, protoRecipe);
}
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
String recipeName = entity.json().optString("recipe", null);
boolean hasFluid = false;
if (recipe != null) {
RecipePrototype protoRecipe = dataTable.getRecipes().get(recipe);
if (recipeName != null) {
RecipePrototype protoRecipe = dataTable.getRecipe(recipeName).get();
List<LuaValue> items = new ArrayList<>();
Utils.forEach(protoRecipe.lua().get("ingredients"), (Consumer<LuaValue>) items::add);

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class BeaconRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite baseSprite = getSpriteFromAnimation(prototype.lua().get("base_picture"));
Sprite antennaSpriteShadow = getSpriteFromAnimation(prototype.lua().get("animation_shadow"));
Sprite antennaSprite = getSpriteFromAnimation(prototype.lua().get("animation"));

View File

@ -5,16 +5,17 @@ import java.util.List;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class BoilerRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
List<Sprite> sprites = getSpritesFromAnimation(prototype.lua().get("structure"), entity.getDirection());
register.accept(spriteRenderer(sprites, entity, prototype));
}
@ -24,7 +25,7 @@ public class BoilerRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
Direction dir = entity.getDirection();
Point2D.Double position = dir.back().offset(entity.getPosition(), 0.5);
map.setPipe(dir.offset(position, 1), dir);

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class ConstantCombinatorRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(
prototype.lua().get("sprites").get(entity.getDirection().name().toLowerCase()));
register.accept(spriteRenderer(sprite, entity, prototype));

View File

@ -6,10 +6,11 @@ import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
import com.demod.fbsr.Renderer.Layer;
public class CurvedRailRendering extends TypeRendererFactory {
private static final String[] railNames = { //
@ -25,7 +26,7 @@ public class CurvedRailRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
String railName = railNames[entity.getDirection().ordinal()];
LuaValue pictureRailLua = prototype.lua().get("pictures").get(railName);
for (Entry<String, Layer> entry : StraightRailRendering.railLayers.entrySet()) {
@ -35,6 +36,6 @@ public class CurvedRailRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
}
}

View File

@ -5,8 +5,9 @@ import java.util.Map;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class DeciderCombinatorRendering extends TypeRendererFactory {
@ -22,7 +23,7 @@ public class DeciderCombinatorRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(
prototype.lua().get("sprites").get(entity.getDirection().name().toLowerCase()));
Sprite operatorSprite = getSpriteFromAnimation(prototype.lua()

View File

@ -3,20 +3,22 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
public class ElectricPoleRendering extends TypeRendererFactory {
private static final int SpriteIndex = 2;
// private static final int SpriteIndex = 2;
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("pictures"));
sprite.source.x = sprite.source.width * SpriteIndex;
// sprite.source.x = sprite.source.width * SpriteIndex;
sprite.source.x = sprite.source.width * entity.getDirection().cardinal();
register.accept(spriteRenderer(Layer.ENTITY3, sprite, entity, prototype));
}
}

View File

@ -5,14 +5,15 @@ import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class ElectricTurretRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite baseSprite = getSpriteFromAnimation(prototype.lua().get("base_picture").get("layers").get(1));
register.accept(spriteRenderer(baseSprite, entity, prototype));
LuaValue turretLayers = prototype.lua().get("folded_animation").get("layers");

View File

@ -5,15 +5,16 @@ import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class FluidTurretRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite baseSprite = getSpriteFromAnimation(prototype.lua().get("base_picture")
.get(entity.getDirection().name().toLowerCase()).get("layers").get(1));
register.accept(spriteRenderer(baseSprite, entity, prototype));
@ -24,7 +25,7 @@ public class FluidTurretRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
Direction dir = entity.getDirection();
map.setPipe(dir.right().offset(dir.back().offset(entity.getPosition()), 0.5), dir.right());
map.setPipe(dir.left().offset(dir.back().offset(entity.getPosition()), 0.5), dir.left());

View File

@ -5,15 +5,16 @@ import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class GateRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
boolean vertical = isVerticalGate(entity);
// Point2D.Double pos = entity.getPosition();
@ -104,7 +105,7 @@ public class GateRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
if (isVerticalGate(entity)) {
map.setVerticalGate(entity.getPosition());
} else {

View File

@ -5,22 +5,23 @@ import java.util.List;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class GeneratorRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
List<Sprite> sprites = getSpritesFromAnimation(prototype.lua()
.get((entity.getDirection().cardinal() % 2) == 0 ? "vertical_animation" : "horizontal_animation"));
register.accept(spriteRenderer(sprites, entity, prototype));
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
Direction dir = entity.getDirection();
Point2D.Double position = entity.getPosition();
map.setPipe(dir.offset(position, 2), dir);

View File

@ -3,9 +3,10 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class HeatPipeRendering extends TypeRendererFactory {
@ -32,7 +33,7 @@ public class HeatPipeRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
int adjCode = 0;
adjCode |= ((heatPipeFacingMeFrom(Direction.NORTH, map, entity) ? 1 : 0) << 0);
adjCode |= ((heatPipeFacingMeFrom(Direction.EAST, map, entity) ? 1 : 0) << 1);
@ -50,7 +51,7 @@ public class HeatPipeRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
map.setHeatPipe(entity.getPosition());
}
}

View File

@ -6,23 +6,37 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Optional;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
import com.demod.fbsr.WorldMap.BeltBend;
import com.demod.fbsr.WorldMap.BeltCell;
public class InserterRendering extends TypeRendererFactory {
private static final int[][] placeItemDir = //
new int[/* Cardinal */][/* Bend */] { //
{ -1, 1, 1 }, // North
{ 1, -1, -1 }, // East
{ -1, -1, 1 }, // South
{ 1, 1, -1 },// West
};
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Point2D.Double pos = entity.getPosition();
Direction dir = entity.getDirection();
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("platform_picture").get("sheet"));
sprite.source.x += sprite.source.width * (entity.getDirection().back().cardinal());
sprite.source.x += sprite.source.width * (dir.back().cardinal());
Sprite spriteArm1 = getSpriteFromAnimation(prototype.lua().get("hand_base_picture"));
Sprite spriteArm2 = getSpriteFromAnimation(prototype.lua().get("hand_open_picture"));
@ -40,7 +54,7 @@ public class InserterRendering extends TypeRendererFactory {
BufferedImage image = spriteArm2.image;
g.translate(pos.x, pos.y);
g.rotate(entity.getDirection().back().ordinal() * Math.PI / 4.0);
g.rotate(dir.back().ordinal() * Math.PI / 4.0);
g.translate(bounds.x, 0);
g.scale(bounds.width, armStretch);
g.drawImage(image, 0, 1, 1, 0, source.x, source.y, source.x + source.width,
@ -50,6 +64,57 @@ public class InserterRendering extends TypeRendererFactory {
g.setTransform(pat);
}
});
// register.accept(new Renderer(Layer.LOGISTICS_MOVE, sprite.bounds) {
// @Override
// public void render(Graphics2D g) {
// double armStretch =
// -prototype.lua().get("pickup_position").get(2).todouble();
// Point2D.Double inPos = dir.offset(pos, armStretch);
// Point2D.Double outPos = dir.offset(pos, -armStretch);
//
// map.getBelt(outPos).ifPresent(b -> {
// BeltBend bend = map.getBeltBend(outPos, b);
// Direction cellDir = dir.back().rotate(
// placeItemDir[b.getFacing().rotate(-dir.back().ordinal()).cardinal()][bend.ordinal()]);
//
// g.setColor(Color.cyan);
// g.draw(new Line2D.Double(pos, cellDir.offset(outPos, 0.25)));
// g.setColor(Color.magenta);
// g.drawString(dir.back().cardinal() + "|" + b.getFacing().cardinal() +
// "|" + bend.ordinal(),
// (float) outPos.x, (float) outPos.y);
// });
// }
// });
}
@Override
public void populateLogistics(WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
Point2D.Double pos = entity.getPosition();
Direction dir = entity.getDirection();
double armStretch = -prototype.lua().get("pickup_position").get(2).todouble();
Point2D.Double inPos = dir.offset(pos, armStretch);
Point2D.Double outPos = dir.offset(pos, -armStretch);
Optional<BeltCell> belt = map.getBelt(outPos);
belt.ifPresent(b -> {
BeltBend bend = map.getBeltBend(outPos, b);
Direction cellDir = dir.back()
.rotate(placeItemDir[b.getFacing().rotate(-dir.back().ordinal()).cardinal()][bend.ordinal()]);
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);
});
if (!belt.isPresent()) {
setLogisticWarp(map, inPos, dir.frontLeft(), outPos, dir.frontRight());
setLogisticWarp(map, inPos, dir.frontRight(), outPos, dir.frontRight());
setLogisticWarp(map, inPos, dir.backLeft(), outPos, dir.frontRight());
setLogisticWarp(map, inPos, dir.backRight(), outPos, dir.frontRight());
}
}
}

View File

@ -3,15 +3,16 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class LampRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("picture_off"));
register.accept(spriteRenderer(sprite, entity, prototype));
}

View File

@ -7,15 +7,16 @@ import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.Utils;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class MiningDrillRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
if (entity.getName().equals("pumpjack")) {
Sprite baseSprite = getSpriteFromAnimation(prototype.lua().get("base_picture").get("sheet"));
baseSprite.source.x = baseSprite.source.width * entity.getDirection().cardinal();
@ -30,7 +31,7 @@ public class MiningDrillRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
if (entity.getName().equals("pumpjack")) {
List<Point2D.Double> positions = new ArrayList<>();

View File

@ -3,22 +3,23 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class OffshorePumpRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(
prototype.lua().get("picture").get(entity.getDirection().name().toLowerCase()));
register.accept(spriteRenderer(sprite, entity, prototype));
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
map.setPipe(entity.getPosition(), entity.getDirection().back());
}
}

View File

@ -3,9 +3,10 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class PipeRendering extends TypeRendererFactory {
@ -32,7 +33,7 @@ public class PipeRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
int adjCode = 0;
adjCode |= ((pipeFacingMeFrom(Direction.NORTH, map, entity) ? 1 : 0) << 0);
adjCode |= ((pipeFacingMeFrom(Direction.EAST, map, entity) ? 1 : 0) << 1);
@ -50,7 +51,7 @@ public class PipeRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
map.setPipe(entity.getPosition());
}

View File

@ -3,8 +3,9 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class PipeToGroundRendering extends TypeRendererFactory {
@ -15,14 +16,14 @@ public class PipeToGroundRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(
prototype.lua().get("pictures").get(pipeToGroundCardinalNaming[entity.getDirection().cardinal()]));
register.accept(spriteRenderer(sprite, entity, prototype));
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
map.setPipe(entity.getPosition(), entity.getDirection());
}

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class PowerSwitchRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("power_on_animation"));
register.accept(spriteRenderer(sprite, entity, prototype));
}

View File

@ -3,21 +3,22 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class PumpRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(
prototype.lua().get("animations").get(entity.getDirection().name().toLowerCase()));
register.accept(spriteRenderer(sprite, entity, prototype));
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
map.setPipe(entity.getPosition(), entity.getDirection(), entity.getDirection().back());
}
}

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class RadarRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("pictures"));
register.accept(spriteRenderer(sprite, entity, prototype));
}

View File

@ -3,15 +3,16 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class RailChainSignalRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite railSprite = getSpriteFromAnimation(prototype.lua().get("rail_piece"));
railSprite.source.x += railSprite.source.width * (entity.getDirection().ordinal());

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class RailSignalRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite railSprite = getSpriteFromAnimation(prototype.lua().get("rail_piece"));
railSprite.source.x += railSprite.source.width * (entity.getDirection().ordinal());

View File

@ -3,15 +3,16 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class ReactorRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
register.accept(spriteRenderer(getSpritesFromAnimation(prototype.lua().get("picture"), entity.getDirection()),
entity, prototype));
register.accept(spriteRenderer(
@ -20,7 +21,7 @@ public class ReactorRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
for (Direction dir : Direction.values()) {
map.setHeatPipe(dir.offset(entity.getPosition(), 2));
}

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class RoboportRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
register.accept(spriteRenderer(getSpriteFromAnimation(prototype.lua().get("base")), entity, prototype));
register.accept(
spriteRenderer(getSpriteFromAnimation(prototype.lua().get("door_animation_down")), entity, prototype));

View File

@ -3,16 +3,17 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
import com.demod.fbsr.Renderer.Layer;
public class RocketSiloRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite baseSprite = getSpriteFromAnimation(prototype.lua().get("base_day_sprite"));
Sprite shadowSprite = getSpriteFromAnimation(prototype.lua().get("shadow_sprite"));
Sprite doorFrontSprite = getSpriteFromAnimation(prototype.lua().get("door_front_sprite"));

View File

@ -3,14 +3,15 @@ package com.demod.fbsr.render;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class SolarPanelRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("picture"));
register.accept(spriteRenderer(sprite, entity, prototype));
}

View File

@ -1,24 +1,34 @@
package com.demod.fbsr.render;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
public class SplitterRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
int[] beltSpriteMapping = TransportBeltRendering.transportBeltSpriteMapping[entity.getDirection()
.cardinal()][1];
Sprite belt1Sprite = getSpriteFromAnimation(prototype.lua().get("belt_horizontal"));
belt1Sprite.source.y = belt1Sprite.source.height * beltSpriteMapping[0];
if (beltSpriteMapping[1] == 1) {
belt1Sprite.source.x += belt1Sprite.source.width;
belt1Sprite.source.width *= -1;
}
if (beltSpriteMapping[2] == 1) {
belt1Sprite.source.y += belt1Sprite.source.height;
belt1Sprite.source.height *= -1;
}
Sprite belt2Sprite = new Sprite(belt1Sprite);
Point2D.Double beltShift = entity.getDirection().left().offset(new Point2D.Double(), 0.5);
@ -37,11 +47,34 @@ public class SplitterRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateLogistics(WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
Direction dir = entity.getDirection();
Double pos = entity.getPosition();
Point2D.Double leftPos = dir.left().offset(pos, 0.5);
Point2D.Double rightPos = dir.right().offset(pos, 0.5);
setLogisticMove(map, leftPos, dir.frontLeft(), dir);
setLogisticMove(map, leftPos, dir.frontRight(), dir);
setLogisticMove(map, leftPos, dir.backLeft(), dir);
setLogisticMove(map, leftPos, dir.backRight(), dir);
setLogisticMove(map, rightPos, dir.frontLeft(), dir);
setLogisticMove(map, rightPos, dir.frontRight(), dir);
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());
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
Direction direction = entity.getDirection();
Point2D.Double belt1Pos = direction.left().offset(entity.getPosition(), 0.5);
Point2D.Double belt2Pos = direction.right().offset(entity.getPosition(), 0.5);
map.setBelt(belt1Pos, direction);
map.setBelt(belt2Pos, direction);
map.setBelt(belt1Pos, direction, false, true);
map.setBelt(belt2Pos, direction, false, true);
}
}

View File

@ -4,8 +4,9 @@ import java.awt.geom.Point2D;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class StorageTankRendering extends TypeRendererFactory {
@ -20,14 +21,14 @@ public class StorageTankRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("pictures").get("picture").get("sheet"));
sprite.source.x = sprite.source.width * (entity.getDirection().cardinal() % 2);
register.accept(spriteRenderer(sprite, entity, prototype));
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
// FIXME maybe should use the fluid box
Point2D.Double position = entity.getPosition();

View File

@ -7,10 +7,11 @@ import java.util.function.Consumer;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
import com.demod.fbsr.Renderer.Layer;
public class StraightRailRendering extends TypeRendererFactory {
@ -36,7 +37,7 @@ public class StraightRailRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
String railName = railNames[entity.getDirection().ordinal()];
LuaValue pictureRailLua = prototype.lua().get("pictures").get(railName);
@ -47,6 +48,6 @@ public class StraightRailRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
}
}

View File

@ -4,15 +4,16 @@ import java.util.List;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
import com.demod.fbsr.Renderer.Layer;
public class TrainStopRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
List<Sprite> railSprites = getSpritesFromAnimation(prototype.lua().get("rail_overlay_animations"),
entity.getDirection());
List<Sprite> sprites = getSpritesFromAnimation(prototype.lua().get("animations"), entity.getDirection());

View File

@ -1,51 +1,42 @@
package com.demod.fbsr.render;
import java.awt.geom.Point2D;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.WorldMap.BeltBend;
public class TransportBeltRendering extends TypeRendererFactory {
public static final int[][][] transportBeltSpriteMapping = //
new int[/* NESW */][/* LNR */][/* SXY */] { //
new int[/* Cardinal */][/* Bend */][/* SXY */] { //
{ { 8, 1, 0 }, { 1, 0, 0 }, { 8, 0, 0 } }, // North
{ { 9, 0, 0 }, { 0, 0, 0 }, { 11, 0, 0 } }, // East
{ { 10, 1, 0 }, { 1, 0, 1 }, { 10, 0, 0 } }, // South
{ { 11, 1, 0 }, { 0, 1, 0 }, { 9, 1, 0 } }, // West
};
public boolean beltFacingMeFrom(UnaryOperator<Direction> rotateFunction, WorldMap map, BlueprintEntity entity) {
Point2D.Double adjacentPosition = rotateFunction.apply(entity.getDirection()).offset(entity.getPosition());
Optional<Direction> adjacentDirection = map.getBelt(adjacentPosition);
return adjacentDirection.map(d -> entity.getPosition().distance(d.offset(adjacentPosition)) < 0.1)
.orElse(false);
}
// XXX I'm not using horizontal or vertical frames
public static final String[][] transportBeltConnectorFrameMapping = //
new String[/* Cardinal */][/* Bend */] { //
{ "nw", "x", "ne" }, // North
{ "ne", "x", "se" }, // East
{ "se", "x", "sw" }, // South
{ "sw", "x", "nw" }, // West
};
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
boolean left = beltFacingMeFrom(Direction::left, map, entity);
boolean right = beltFacingMeFrom(Direction::right, map, entity);
boolean back = beltFacingMeFrom(Direction::back, map, entity);
int bend;
if (back || (left && right)) {
bend = 1; // none
} else if (left) {
bend = 0; // from the left
} else if (right) {
bend = 2; // from the right
} else {
bend = 1; // none
}
int[] spriteMapping = transportBeltSpriteMapping[entity.getDirection().cardinal()][bend];
EntityPrototype prototype) {
BeltBend bend = map.getBeltBend(entity.getPosition()).get();
int[] spriteMapping = transportBeltSpriteMapping[entity.getDirection().cardinal()][bend.ordinal()];
Sprite sprite = getSpriteFromAnimation(prototype.lua().get("animations"));
sprite.source.y = sprite.source.height * spriteMapping[0];
@ -59,11 +50,51 @@ public class TransportBeltRendering extends TypeRendererFactory {
}
register.accept(spriteRenderer(sprite, entity, prototype));
if (entity.json().has("connections")) {
String connectorFrameMapping = transportBeltConnectorFrameMapping[entity.getDirection().cardinal()][bend
.ordinal()];
LuaValue connectorFrameSpritesLua = prototype.lua().get("connector_frame_sprites");
Sprite connectorShadow = getSpriteFromAnimation(
connectorFrameSpritesLua.get("frame_shadow_" + connectorFrameMapping));
Sprite connectorSprite = getSpriteFromAnimation(
connectorFrameSpritesLua.get("frame_main_" + connectorFrameMapping));
register.accept(spriteRenderer(connectorShadow, entity, prototype));
register.accept(spriteRenderer(connectorSprite, entity, prototype));
}
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
map.setBelt(entity.getPosition(), entity.getDirection());
public void populateLogistics(WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
Direction dir = entity.getDirection();
Point2D.Double pos = entity.getPosition();
setLogisticMove(map, pos, dir.frontLeft(), dir);
setLogisticMove(map, pos, dir.frontRight(), dir);
BeltBend bend = map.getBeltBend(pos).get();
switch (bend) {
case FROM_LEFT:
setLogisticMove(map, pos, dir.backLeft(), dir.right());
setLogisticMove(map, pos, dir.backRight(), dir);
break;
case FROM_RIGHT:
setLogisticMove(map, pos, dir.backLeft(), dir);
setLogisticMove(map, pos, dir.backRight(), dir.left());
break;
case NONE:
setLogisticMove(map, pos, dir.backLeft(), dir);
setLogisticMove(map, pos, dir.backRight(), dir);
break;
}
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
map.setBelt(entity.getPosition(), entity.getDirection(), true, true);
}
}

View File

@ -28,13 +28,16 @@ import org.json.JSONObject;
import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.FactorioData;
import com.demod.factorio.Utils;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.factorio.prototype.RecipePrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.FBSR;
import com.demod.fbsr.Direction;
import com.demod.fbsr.LogisticGridCell;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
import com.google.common.collect.ImmutableList;
import javafx.util.Pair;
@ -62,7 +65,7 @@ public class TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable,
BlueprintEntity entity, DataPrototype prototype) {
BlueprintEntity entity, EntityPrototype prototype) {
super.createRenderers(register, map, dataTable, entity, prototype);
register.accept(new Renderer(Layer.OVERLAY3, entity.getPosition()) {
@Override
@ -86,7 +89,7 @@ public class TypeRendererFactory {
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
super.populateWorldMap(map, dataTable, entity, prototype);
if (!defaultedTypes.isEmpty()) {
@ -172,7 +175,14 @@ public class TypeRendererFactory {
protected static Sprite getSpriteFromAnimation(LuaValue lua) {
Sprite ret = new Sprite();
ret.image = FBSR.getModImage(lua.get("filename"));
LuaValue filenameLua = lua.get("filename");
boolean drawAsShadow = lua.get("draw_as_shadow").optboolean(false);
drawAsShadow = false;// FIXME shadows need a special mask layer
if (drawAsShadow) {
ret.image = FactorioData.getModImage(filenameLua, new Color(255, 255, 255, 128));
} else {
ret.image = FactorioData.getModImage(filenameLua);
}
int srcX = lua.get("x").optint(0);
int srcY = lua.get("y").optint(0);
int srcWidth = lua.get("width").checkint();
@ -209,7 +219,7 @@ public class TypeRendererFactory {
}
protected static Renderer spriteRenderer(Layer layer, List<Sprite> sprites, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Point2D.Double pos = entity.getPosition();
for (Sprite sprite : sprites) {
sprite.bounds.x += pos.x;
@ -255,20 +265,20 @@ public class TypeRendererFactory {
}
protected static Renderer spriteRenderer(Layer layer, Sprite sprite, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
return spriteRenderer(layer, ImmutableList.of(sprite), entity, prototype);
}
protected static Renderer spriteRenderer(List<Sprite> sprites, BlueprintEntity entity, DataPrototype prototype) {
protected static Renderer spriteRenderer(List<Sprite> sprites, BlueprintEntity entity, EntityPrototype prototype) {
return spriteRenderer(Layer.ENTITY, sprites, entity, prototype);
}
protected static Renderer spriteRenderer(Sprite sprite, BlueprintEntity entity, DataPrototype prototype) {
protected static Renderer spriteRenderer(Sprite sprite, BlueprintEntity entity, EntityPrototype prototype) {
return spriteRenderer(Layer.ENTITY, sprite, entity, prototype);
}
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
try {
List<Sprite> sprites;
@ -286,9 +296,9 @@ public class TypeRendererFactory {
sprites = getSpritesFromAnimation(spriteLua, entity.getDirection());
} else {
Sprite sprite = new Sprite();
sprite.image = FBSR.getModImage(prototype.lua().get("icon"));
sprite.image = FactorioData.getModImage(prototype.lua().get("icon"));
sprite.source = new Rectangle(0, 0, sprite.image.getWidth(), sprite.image.getHeight());
sprite.bounds = Utils.parseRectangle(prototype.lua().get("selection_box"));
sprite.bounds = (Rectangle2D.Double) prototype.getSelectionBox().clone();
sprites = ImmutableList.of(sprite);
}
@ -300,7 +310,7 @@ public class TypeRendererFactory {
}
public void createWireConnections(Consumer<Renderer> register, WorldMap map, DataTable table,
BlueprintEntity entity, DataPrototype prototype) {
BlueprintEntity entity, EntityPrototype prototype) {
int entityId = entity.getId();
JSONObject connectionsJson = entity.json().optJSONObject("connections");
@ -332,9 +342,6 @@ public class TypeRendererFactory {
Double p2 = pair.getValue();
p2.setLocation(getWirePositionFor(entity, prototype, colorName, circuitId));
Rectangle2D.Double bounds = new Rectangle2D.Double();
bounds.setFrameFromDiagonal(p1, p2);
Color color;
switch (colorName) {
case "red":
@ -349,25 +356,7 @@ public class TypeRendererFactory {
break;
}
register.accept(new Renderer(Layer.WIRE, bounds) {
final double drop = 0.6;
@Override
public void render(Graphics2D g) {
Stroke ps = g.getStroke();
g.setStroke(new BasicStroke(1f / 32f));
g.setColor(color);
Path2D.Double path = new Path2D.Double();
path.moveTo(p1.x, p1.y);
Point2D.Double mid = new Point2D.Double((p1.x + p2.x) / 2,
(p1.y + p2.y) / 2 + drop);
path.curveTo(mid.x, mid.y, mid.x, mid.y, p2.x, p2.y);
g.draw(path);
g.setStroke(ps);
}
});
register.accept(createWireRenderer(p1, p2, color));
}
});
});
@ -375,7 +364,31 @@ public class TypeRendererFactory {
}
}
protected void debugPrintContext(BlueprintEntity entity, DataPrototype prototype) {
protected Renderer createWireRenderer(Point2D.Double p1, Point2D.Double p2, Color color) {
Rectangle2D.Double bounds = new Rectangle2D.Double();
bounds.setFrameFromDiagonal(p1, p2);
return new Renderer(Layer.WIRE, bounds) {
final double drop = 0.6;
@Override
public void render(Graphics2D g) {
Stroke ps = g.getStroke();
g.setStroke(new BasicStroke(1f / 32f));
g.setColor(color);
Path2D.Double path = new Path2D.Double();
path.moveTo(p1.x, p1.y);
Point2D.Double mid = new Point2D.Double((p1.x + p2.x) / 2, (p1.y + p2.y) / 2 + drop);
path.curveTo(mid.x, mid.y, mid.x, mid.y, p2.x, p2.y);
g.draw(path);
g.setStroke(ps);
}
};
}
protected void debugPrintContext(BlueprintEntity entity, EntityPrototype prototype) {
System.out.println("=================================================================");
System.out.println("=========================== PROTOTYPE ===========================");
System.out.println("=================================================================");
@ -386,7 +399,7 @@ public class TypeRendererFactory {
Utils.debugPrintJson(entity.json());
}
protected Point2D.Double getWirePositionFor(BlueprintEntity entity, DataPrototype prototype, String colorName,
protected Point2D.Double getWirePositionFor(BlueprintEntity entity, EntityPrototype prototype, String colorName,
int circuitId) {
LuaValue connectionPointLua = wireConnectionCircuitId.entrySet().stream().filter(e -> e.getValue() == circuitId)
.map(e -> prototype.lua().get(e.getKey())).filter(l -> !l.isnil()).findAny().get();
@ -402,8 +415,59 @@ public class TypeRendererFactory {
return new Point2D.Double(pos.x + offset.x, pos.y + offset.y);
}
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateLogistics(WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
// default do nothing
}
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
// default do nothing
}
protected void setLogisticMachine(WorldMap map, BlueprintEntity entity, EntityPrototype prototype,
RecipePrototype recipe) {
Point2D.Double entityPos = entity.getPosition();
Rectangle2D.Double box = prototype.getSelectionBox();
double xStart = entityPos.x + box.x;
double yStart = entityPos.y + box.y;
double xEnd = xStart + box.width;
double yEnd = yStart + box.height;
Set<String> inputs = recipe.getInputs().keySet();
Set<String> outputs = recipe.getOutputs().keySet();
Point2D.Double cellPos = new Point2D.Double();
for (cellPos.x = xStart + 0.25; cellPos.x < xEnd; cellPos.x += 0.5) {
for (cellPos.y = yStart + 0.25; cellPos.y < yEnd; cellPos.y += 0.5) {
LogisticGridCell cell = map.getOrCreateLogisticGridCell(cellPos);
cell.setInputs(Optional.of(inputs));
cell.setOutputs(Optional.of(outputs));
cell.setBlockTransit(true);
}
}
}
protected void setLogisticMove(WorldMap map, Point2D.Double gridPos, Direction cellDir, Direction moveDir) {
map.getOrCreateLogisticGridCell(cellDir.offset(gridPos, 0.25)).setMove(Optional.of(moveDir));
}
protected void setLogisticMoveAndAcceptFilter(WorldMap map, Point2D.Double gridPos, Direction cellDir, Direction moveDir,
Direction acceptFilter) {
LogisticGridCell cell = map.getOrCreateLogisticGridCell(cellDir.offset(gridPos, 0.25));
cell.setMove(Optional.of(moveDir));
cell.setAcceptFilter(Optional.of(acceptFilter));
}
protected void setLogisticAcceptFilter(WorldMap map, Point2D.Double gridPos, Direction cellDir,
Direction acceptFilter) {
LogisticGridCell cell = map.getOrCreateLogisticGridCell(cellDir.offset(gridPos, 0.25));
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

@ -1,19 +1,21 @@
package com.demod.fbsr.render;
import java.awt.geom.Point2D;
import java.util.function.Consumer;
import com.demod.factorio.DataTable;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.Renderer.Layer;
import com.demod.fbsr.WorldMap;
import com.demod.fbsr.render.Renderer.Layer;
public class UndergroundBeltRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
// LuaUtils.debugPrintTable("", prototype.lua());
// System.exit(1);
@ -62,10 +64,47 @@ public class UndergroundBeltRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateLogistics(WorldMap map, DataTable dataTable, BlueprintEntity entity,
EntityPrototype prototype) {
Direction dir = entity.getDirection();
Point2D.Double pos = entity.getPosition();
boolean input = entity.json().getString("type").equals("input");
if (!input) {
map.setBelt(entity.getPosition(), entity.getDirection());
if (input) {
setLogisticMove(map, pos, dir.backLeft(), dir);
setLogisticMove(map, pos, dir.backRight(), dir);
setLogisticAcceptFilter(map, pos, dir.frontLeft(), dir);
setLogisticAcceptFilter(map, pos, dir.frontRight(), dir);
} else {
// XXX really should be a filter that accepts no direction
setLogisticMoveAndAcceptFilter(map, pos, dir.backLeft(), dir, dir.back());
setLogisticMoveAndAcceptFilter(map, pos, dir.backRight(), dir, dir.back());
setLogisticMove(map, pos, dir.frontLeft(), dir);
setLogisticMove(map, pos, dir.frontRight(), dir);
}
if (input) {
int maxDistance = prototype.lua().get("max_distance").toint();
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());
break;
}
}
}
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
boolean input = entity.json().getString("type").equals("input");
if (input) {
map.setBelt(entity.getPosition(), entity.getDirection(), false, false);
} else {
map.setBelt(entity.getPosition(), entity.getDirection(), false, true);
map.setUndergroundBeltEnding(entity.getName(), entity.getPosition(), entity.getDirection());
}
}
}

View File

@ -9,9 +9,10 @@ import org.luaj.vm2.LuaValue;
import com.demod.factorio.DataTable;
import com.demod.factorio.Utils;
import com.demod.factorio.prototype.DataPrototype;
import com.demod.factorio.prototype.EntityPrototype;
import com.demod.fbsr.BlueprintEntity;
import com.demod.fbsr.BlueprintEntity.Direction;
import com.demod.fbsr.Direction;
import com.demod.fbsr.Renderer;
import com.demod.fbsr.WorldMap;
public class WallRendering extends TypeRendererFactory {
@ -38,7 +39,7 @@ public class WallRendering extends TypeRendererFactory {
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity,
DataPrototype prototype) {
EntityPrototype prototype) {
Point2D.Double pos = entity.getPosition();
boolean northGate = map.isVerticalGate(Direction.NORTH.offset(pos));
@ -77,7 +78,7 @@ public class WallRendering extends TypeRendererFactory {
}
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, DataPrototype prototype) {
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
map.setWall(entity.getPosition());
}
}