add jackson, format, calculate resources

master
agp8x 2021-03-19 00:07:22 +01:00
parent 84f4526dbe
commit 5343d26b12
9 changed files with 84 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
.idea/
out/
*.iml

14
satisfactory.iml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.fasterxml.jackson.core:jackson-annotations:2.12.2" level="project" />
<orderEntry type="library" name="com.fasterxml.jackson.core:jackson-core:2.12.2" level="project" />
<orderEntry type="library" name="com.fasterxml.jackson.core:jackson-databind:2.12.2" level="project" />
</component>
</module>

View File

@ -64,7 +64,7 @@ public class Database {
public static final Item VersatileFrameWork = new Part("Versatile Framework");
public static final Item Nobelisk = new Part("Nobelisk");
public static final Item Water = new RawFluid("Water");
public static final Item CrudeOil = new RawFluid("Water");
public static final Item CrudeOil = new RawFluid("Crude Oil");
public static final Item HeavyOilResidue = new ProcessedFluid("Heavy Oil Residue");
public static final Item Fuel = new ProcessedFluid("Fuel");
public static final Item LiquidBiofuel = new ProcessedFluid("Liquid Biofuel");

View File

@ -1,8 +1,28 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import items.Item;
import items.Recipe;
import java.util.Map;
public class Test {
public static void main(String[] args) {
public static void main(String[] args) throws JsonProcessingException {
//System.out.println(Database.AdaptiveControlUnit);
System.out.println(Database.HeavyModularFrame.getRecipes().stream().findFirst().get().getTotalRequirements());
Map<Item, Integer> totalRequirements = Database.HeavyModularFrame.getRecipes().stream().findFirst().get().getTotalRequirements();
System.out.println(totalRequirements);
ObjectMapper om = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
String json = om.writeValueAsString(totalRequirements);
System.out.println(json);
Map<Item, Integer> rawOnly = Database.HeavyModularFrame.getRecipes().iterator().next().getRawOnly();
String json2 = om.writeValueAsString(rawOnly);
String json3 = om.writeValueAsString(Recipe.getInputs(rawOnly));
System.out.println(json2);
System.out.println(json3);
System.out.println(om.writeValueAsString(Database.AdaptiveControlUnit.getRecipes().iterator().next().getRawOnly()));
}
}

View File

@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.Set;
public class Item {
protected boolean isRaw = false;
private String name;
private Set<Recipe> recipes;
@ -24,9 +25,10 @@ public class Item {
}
public void add(Recipe recipe) {
add(recipe,1);
add(recipe, 1);
}
public void add(Recipe recipe, int amount){
public void add(Recipe recipe, int amount) {
recipes.add(recipe);
recipe.checkOutput(this, amount);
}
@ -35,10 +37,14 @@ public class Item {
return name;
}
public Set<Recipe> getRecipes(){
public Set<Recipe> getRecipes() {
return recipes;
}
public boolean isRaw() {
return isRaw;
}
@Override
public String toString() {
return "Item{" +

View File

@ -2,6 +2,7 @@ package items;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class Recipe {
private Map<Item, Integer> inputs;
@ -37,6 +38,14 @@ public class Recipe {
this.isHandCraftable = isHandCraftable;
}
public static Map<String, Integer> getInputs(Map<Item, Integer> values) {
Map<String, Integer> names = new HashMap<>();
for (Item item : values.keySet()) {
names.put(item.getName(), values.get(item));
}
return names;
}
public void addInput(Item item, int amount) {
inputs.put(item, amount);
}
@ -78,20 +87,29 @@ public class Recipe {
for (Item i : inputs.keySet()) {
queue.put(i, inputs.get(i));
}
while (!queue.isEmpty()){
while (!queue.isEmpty()) {
Item i = queue.keySet().iterator().next();
int amount = queue.remove(i);
total.put(i, total.getOrDefault(i,0)+ amount);
if (i.getRecipes().isEmpty()){
total.put(i, total.getOrDefault(i, 0) + amount);
if (i.getRecipes().isEmpty()) {
continue;
}
Recipe r = i.getRecipes().iterator().next();
Map<Item, Integer> subRequirements = r.getTotalRequirements();
for (Item subItem : subRequirements.keySet()) {
int subAmount = subRequirements.get(subItem);
total.put(subItem, total.getOrDefault(subItem, 0) + subAmount*amount);
total.put(subItem, total.getOrDefault(subItem, 0) + subAmount * amount);
}
}
return total;
}
public Map<Item, Integer> getRawOnly() {
Map<Item, Integer> totals = getTotalRequirements();
Map<Item, Integer> raws = new HashMap<>();
for (Item item : totals.keySet().stream().filter(Item::isRaw).collect(Collectors.toList())) {
raws.put(item, totals.get(item));
}
return raws;
}
}

View File

@ -8,13 +8,20 @@ import java.util.Set;
public class Ore extends Item {
public Ore(String name, Set<Recipe> recipes) {
super(name, recipes);
setIsRaw();
}
public Ore(String name, Recipe... recipes) {
super(name, recipes);
setIsRaw();
}
public Ore(String name) {
super(name);
setIsRaw();
}
private void setIsRaw() {
isRaw = true;
}
}

View File

@ -4,7 +4,7 @@ import items.Recipe;
import java.util.Set;
public class ProcessedFluid extends Fluid{
public class ProcessedFluid extends Fluid {
public ProcessedFluid(String name, Set<Recipe> recipes) {
super(name, recipes);
}

View File

@ -4,16 +4,23 @@ import items.Recipe;
import java.util.Set;
public class RawFluid extends Fluid{
public class RawFluid extends Fluid {
public RawFluid(String name, Set<Recipe> recipes) {
super(name, recipes);
setIsRaw();
}
public RawFluid(String name, Recipe... recipes) {
super(name, recipes);
setIsRaw();
}
public RawFluid(String name) {
super(name);
setIsRaw();
}
private void setIsRaw() {
isRaw = true;
}
}