Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions FactorioDataWrapper/src/com/demod/factorio/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class DataTable {
private final Map<String, ItemSubGroupPrototype> itemSubGroups = new LinkedHashMap<>();

private final Map<String, List<EntityPrototype>> craftingCategories = new LinkedHashMap<>();
private final Set<String> characterCraftingCategories = new LinkedHashSet<>();

private final ListMultimap<String, RecipePrototype> recipesByInput = MultimapBuilder.hashKeys().arrayListValues()
.build();
Expand Down Expand Up @@ -117,6 +118,12 @@ public DataTable(TypeHierarchy typeHierarchy, LuaTable rawLua, JSONObject exclud
});
});

LuaValue characterCraftingCategoriesLua = entities.get("character").lua().get("crafting_categories");
if (!characterCraftingCategoriesLua.isnil()) {
Utils.forEach(characterCraftingCategoriesLua.checktable(),
categoryLua -> characterCraftingCategories.add(categoryLua.tojstring()));
}

for (Map<String, ? extends DataPrototype> protos : Arrays.asList(items, recipes, entities, fluids, technologies,
equipments, tiles, achievements, itemGroups, itemSubGroups)) {
protos.values().forEach(p -> {
Expand Down Expand Up @@ -249,6 +256,10 @@ public Map<String, List<EntityPrototype>> getCraftingCategories() {
return craftingCategories;
}

public Set<String> getCharacterCraftingCategories() {
return characterCraftingCategories;
}

public FactorioData getData() {
return data;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.demod.factorio.prototype;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import org.json.JSONArray;

import com.demod.factorio.DataTable;
import com.demod.factorio.Utils;
import com.demod.factorio.fakelua.LuaTable;
import com.demod.factorio.fakelua.LuaValue;

public class RecipePrototype extends DataPrototype {

private final String category;
private final Set<String> categories = new LinkedHashSet<>();
private final Map<String, Integer> inputs = new LinkedHashMap<>();
private final Map<String, Double> outputs = new LinkedHashMap<>();
private final double energyRequired;
private final boolean handCraftable;
private boolean handCraftable;
private final boolean recycling;

public RecipePrototype(LuaTable lua) {
Expand Down Expand Up @@ -47,12 +51,14 @@ public RecipePrototype(LuaTable lua) {
}

energyRequired = lua.get("energy_required").optdouble(0.5);
category = lua.get("category").optjstring("crafting");
// FIXME get these from the character prototype
handCraftable = category.equals("crafting") || category.equals("electronics") || category.equals("pressing")
|| category.equals("recycling-or-hand-crafing") || category.equals("organic-or-hand-crafing")
|| category.equals("organic-or-assembling");
recycling = category.equals("recycling");
LuaValue categoriesLua = lua.get("categories");
if (categoriesLua.isnil()) {
categories.add(lua.get("category").optjstring("crafting"));
} else {
Utils.forEach(categoriesLua.checktable(), categoryLua -> categories.add(categoryLua.tojstring()));
}
category = categories.iterator().next();
recycling = categories.contains("recycling");
}

public String getCategory() {
Expand All @@ -79,6 +85,12 @@ public boolean isRecycling() {
return recycling;
}

@Override
public void setTable(DataTable table) {
super.setTable(table);
handCraftable = categories.stream().anyMatch(table.getCharacterCraftingCategories()::contains);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down