Merge branch 'master' of git.clkl.de:agp8x/satisfactory
commit
25b4444a73
10
build.gradle
10
build.gradle
|
|
@ -10,13 +10,13 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.2'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
|
||||
implementation 'org.jgrapht:jgrapht-io:1.5.1'
|
||||
implementation 'guru.nidi:graphviz-java:0.18.1'
|
||||
implementation 'org.graalvm.js:js:20.0.0'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.13.0'
|
||||
implementation 'org.graalvm.js:js:22.1.0.1'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.2'
|
||||
}
|
||||
|
||||
test {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class Database {
|
|||
public static final Map<Item, Recipe> preferences = new HashMap<>();
|
||||
|
||||
// Items & recipes
|
||||
public static final Item IronOre = add(new Ore("Iron Ore"));
|
||||
public static final Item IronOre = new Ore("Iron Ore");
|
||||
public static final Item IronIngot = new Ingot("Iron Ingot");
|
||||
public static final Item CopperOre = new Ore("Copper Ore");
|
||||
public static final Item CopperIngot = new Ingot("Copper Ingot");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import org.jgrapht.event.ConnectedComponentTraversalEvent;
|
|||
import org.jgrapht.event.EdgeTraversalEvent;
|
||||
import org.jgrapht.event.TraversalListener;
|
||||
import org.jgrapht.event.VertexTraversalEvent;
|
||||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||
import org.jgrapht.graph.EdgeReversedGraph;
|
||||
import org.jgrapht.nio.Attribute;
|
||||
|
|
@ -15,11 +14,9 @@ import org.jgrapht.traverse.DepthFirstIterator;
|
|||
import org.jgrapht.traverse.GraphIterator;
|
||||
import satisfactory.items.Item;
|
||||
import satisfactory.items.ProductionEdge;
|
||||
import satisfactory.items.SumResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -30,7 +27,7 @@ public class Utils {
|
|||
|
||||
public static Map<Item, Integer> getRawOnly(Map<Item, Integer> totals) {
|
||||
Map<Item, Integer> raws = new HashMap<>();
|
||||
for (Item item : totals.keySet().stream().filter(Item::isRaw).collect(Collectors.toList())) {
|
||||
for (Item item : totals.keySet().stream().filter(Item::isRaw).toList()) {
|
||||
raws.put(item, totals.get(item));
|
||||
}
|
||||
return raws;
|
||||
|
|
@ -53,7 +50,7 @@ public class Utils {
|
|||
EdgeReversedGraph<Item, DefaultWeightedEdge> inverse = new EdgeReversedGraph<>(graph);
|
||||
|
||||
GraphIterator<Item, DefaultWeightedEdge> iterator = new DepthFirstIterator<>(inverse, target);
|
||||
iterator.addTraversalListener(new TraversalListener<Item, DefaultWeightedEdge>() {
|
||||
iterator.addTraversalListener(new TraversalListener<>() {
|
||||
@Override
|
||||
public void connectedComponentFinished(ConnectedComponentTraversalEvent e) {
|
||||
System.out.println("\tconnectedComponentFinished: " + e);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import java.util.*;
|
|||
|
||||
public abstract class Item {
|
||||
protected boolean isRaw = false;
|
||||
private String name;
|
||||
private Set<Recipe> recipes;
|
||||
private final String name;
|
||||
private final Set<Recipe> recipes;
|
||||
private Recipe preference = null;
|
||||
public int sum = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package satisfactory.items;
|
|||
|
||||
public class Production {
|
||||
private final Item item;
|
||||
private final int amount;
|
||||
private final double amount;
|
||||
|
||||
public Production(Item item, int amount) {
|
||||
public Production(Item item, double amount) {
|
||||
this.item = item;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ public class Production {
|
|||
return item;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import org.jgrapht.Graphs;
|
|||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||
import satisfactory.buildings.Building;
|
||||
import satisfactory.buildings.production.Assembler;
|
||||
import satisfactory.items.requirements.RateAccumulator;
|
||||
import satisfactory.items.requirements.TotalAccumulator;
|
||||
|
||||
|
|
@ -128,6 +127,7 @@ public class Recipe {
|
|||
}
|
||||
return outputs.entrySet().stream().filter(itemIntegerEntry -> isByProduct(reference, itemIntegerEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
public boolean isByProduct(Item reference, Item test) {
|
||||
return !reference.equals(test) && outputs.containsKey(reference) && outputs.containsKey(test);
|
||||
}
|
||||
|
|
@ -174,13 +174,13 @@ public class Recipe {
|
|||
return product.getRecipe().outputs.get(product) * runs;
|
||||
}
|
||||
|
||||
public SumResult sum(Item target, int prodPerMinute) {
|
||||
public SumResult sum(Item target, double prodPerMinute) {
|
||||
Graph<Item, DefaultWeightedEdge> buildGraph = buildGraph(target);
|
||||
Graph<Item, ProductionEdge> production = new DefaultDirectedWeightedGraph<>(ProductionEdge.class);
|
||||
Map<Item, Double> map = new HashMap<>();
|
||||
Queue<Item> queue = new LinkedList<>();
|
||||
queue.add(target);
|
||||
map.put(target, (double) prodPerMinute);
|
||||
map.put(target, prodPerMinute);
|
||||
production.addVertex(target);
|
||||
production.addEdge(target, target, new ProductionEdge(target, target, prodPerMinute, processesNeeded(target, prodPerMinute)));
|
||||
Set<Item> visited = new HashSet<>();
|
||||
|
|
@ -235,9 +235,7 @@ public class Recipe {
|
|||
}
|
||||
visited.add(item);
|
||||
}
|
||||
map.forEach((item, aDouble) -> {
|
||||
System.out.println(item.getName() + ": " + aDouble);
|
||||
});
|
||||
map.forEach((item, aDouble) -> System.out.println(item.getName() + ": " + aDouble));
|
||||
return new SumResult(production, map);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class SumResult {
|
|||
|
||||
public SumResult merge(SumResult other) {
|
||||
HashMap<Item, Double> map = new HashMap<>();
|
||||
this.map.forEach(map::put);
|
||||
map.putAll(this.map);
|
||||
other.map.forEach((item, aDouble) -> map.merge(item, aDouble, Double::sum));
|
||||
return new SumResult(merge(production, other.getProduction()), map);
|
||||
}
|
||||
|
|
@ -58,8 +58,7 @@ public class SumResult {
|
|||
graph1.vertexSet().forEach(result::addVertex);
|
||||
graph1.edgeSet().forEach(productionEdge -> {
|
||||
List<ProductionEdge> collect = result.edgeSet().stream()
|
||||
.filter(productionEdge1 -> productionEdge1.hasSource(productionEdge.getSource()))
|
||||
.collect(Collectors.toList());
|
||||
.filter(productionEdge1 -> productionEdge1.hasSource(productionEdge.getSource())).toList();
|
||||
collect.forEach(edge -> {
|
||||
Item src = result.getEdgeSource(edge);
|
||||
Item target = result.getEdgeTarget(edge);
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class RateAccumulator extends Accumulator<Double> {
|
||||
private Item item;
|
||||
private final Item item;
|
||||
|
||||
public RateAccumulator(Recipe recipe, Item item) {
|
||||
super(new HashMap<>());
|
||||
recipe.getInputs().forEach((item1, integer) -> inputs.put(item1, integer));
|
||||
inputs.putAll(recipe.getInputs());
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package satisfactory.items;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import satisfactory.Database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DatabaseTest {
|
||||
|
|
@ -9,7 +10,7 @@ public class DatabaseTest {
|
|||
void testWaterPreference() {
|
||||
Item i = Database.Water;
|
||||
assertSame(i.getPreference(), i.getRecipe());
|
||||
assertTrue(i.getPreference() == i.getRecipe());
|
||||
assertSame(i.getPreference(), i.getRecipe());
|
||||
assertTrue(i.getRecipe().toString().contains("water pump thingy"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue