add jackson, format, calculate resources
parent
84f4526dbe
commit
5343d26b12
|
|
@ -1,3 +1,2 @@
|
||||||
.idea/
|
.idea/
|
||||||
out/
|
out/
|
||||||
*.iml
|
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -64,7 +64,7 @@ public class Database {
|
||||||
public static final Item VersatileFrameWork = new Part("Versatile Framework");
|
public static final Item VersatileFrameWork = new Part("Versatile Framework");
|
||||||
public static final Item Nobelisk = new Part("Nobelisk");
|
public static final Item Nobelisk = new Part("Nobelisk");
|
||||||
public static final Item Water = new RawFluid("Water");
|
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 HeavyOilResidue = new ProcessedFluid("Heavy Oil Residue");
|
||||||
public static final Item Fuel = new ProcessedFluid("Fuel");
|
public static final Item Fuel = new ProcessedFluid("Fuel");
|
||||||
public static final Item LiquidBiofuel = new ProcessedFluid("Liquid Biofuel");
|
public static final Item LiquidBiofuel = new ProcessedFluid("Liquid Biofuel");
|
||||||
|
|
|
||||||
|
|
@ -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;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Test {
|
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.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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
|
protected boolean isRaw = false;
|
||||||
private String name;
|
private String name;
|
||||||
private Set<Recipe> recipes;
|
private Set<Recipe> recipes;
|
||||||
|
|
||||||
|
|
@ -24,9 +25,10 @@ public class Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Recipe recipe) {
|
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);
|
recipes.add(recipe);
|
||||||
recipe.checkOutput(this, amount);
|
recipe.checkOutput(this, amount);
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +37,14 @@ public class Item {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Recipe> getRecipes(){
|
public Set<Recipe> getRecipes() {
|
||||||
return recipes;
|
return recipes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRaw() {
|
||||||
|
return isRaw;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Item{" +
|
return "Item{" +
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package items;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Recipe {
|
public class Recipe {
|
||||||
private Map<Item, Integer> inputs;
|
private Map<Item, Integer> inputs;
|
||||||
|
|
@ -37,6 +38,14 @@ public class Recipe {
|
||||||
this.isHandCraftable = isHandCraftable;
|
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) {
|
public void addInput(Item item, int amount) {
|
||||||
inputs.put(item, amount);
|
inputs.put(item, amount);
|
||||||
}
|
}
|
||||||
|
|
@ -78,20 +87,29 @@ public class Recipe {
|
||||||
for (Item i : inputs.keySet()) {
|
for (Item i : inputs.keySet()) {
|
||||||
queue.put(i, inputs.get(i));
|
queue.put(i, inputs.get(i));
|
||||||
}
|
}
|
||||||
while (!queue.isEmpty()){
|
while (!queue.isEmpty()) {
|
||||||
Item i = queue.keySet().iterator().next();
|
Item i = queue.keySet().iterator().next();
|
||||||
int amount = queue.remove(i);
|
int amount = queue.remove(i);
|
||||||
total.put(i, total.getOrDefault(i,0)+ amount);
|
total.put(i, total.getOrDefault(i, 0) + amount);
|
||||||
if (i.getRecipes().isEmpty()){
|
if (i.getRecipes().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Recipe r = i.getRecipes().iterator().next();
|
Recipe r = i.getRecipes().iterator().next();
|
||||||
Map<Item, Integer> subRequirements = r.getTotalRequirements();
|
Map<Item, Integer> subRequirements = r.getTotalRequirements();
|
||||||
for (Item subItem : subRequirements.keySet()) {
|
for (Item subItem : subRequirements.keySet()) {
|
||||||
int subAmount = subRequirements.get(subItem);
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,20 @@ import java.util.Set;
|
||||||
public class Ore extends Item {
|
public class Ore extends Item {
|
||||||
public Ore(String name, Set<Recipe> recipes) {
|
public Ore(String name, Set<Recipe> recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ore(String name, Recipe... recipes) {
|
public Ore(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ore(String name) {
|
public Ore(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
setIsRaw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setIsRaw() {
|
||||||
|
isRaw = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import items.Recipe;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ProcessedFluid extends Fluid{
|
public class ProcessedFluid extends Fluid {
|
||||||
public ProcessedFluid(String name, Set<Recipe> recipes) {
|
public ProcessedFluid(String name, Set<Recipe> recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,23 @@ import items.Recipe;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RawFluid extends Fluid{
|
public class RawFluid extends Fluid {
|
||||||
public RawFluid(String name, Set<Recipe> recipes) {
|
public RawFluid(String name, Set<Recipe> recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawFluid(String name, Recipe... recipes) {
|
public RawFluid(String name, Recipe... recipes) {
|
||||||
super(name, recipes);
|
super(name, recipes);
|
||||||
|
setIsRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawFluid(String name) {
|
public RawFluid(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
setIsRaw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setIsRaw() {
|
||||||
|
isRaw = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue