Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot placeable is accessible #191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions YAFC/Workspace/ProductionTable/ProductionTableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,12 @@ private void BuildShoppngList(RecipeRow recipeRoot)
{
if (recipe.entity != null)
{
shopList.TryGetValue(recipe.entity, out var prev);
FactorioObject shopItem = recipe.entity.itemsToPlace?.FirstOrDefault();
if (shopItem is null)
shopItem = recipe.entity;
shopList.TryGetValue(shopItem, out var prev);
var count = MathUtils.Ceil(recipe.buildingCount);
shopList[recipe.entity] = prev + count;
shopList[shopItem] = prev + count;
if (recipe.parameters.modules.modules != null)
{
foreach (var module in recipe.parameters.modules.modules)
Expand Down
2 changes: 1 addition & 1 deletion YAFCparser/Data/FactorioDataDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private void DeserializeItem(LuaTable table)
var item = DeserializeCommon<Item>(table, "item");

if (table.Get("place_result", out string placeResult) && !String.IsNullOrEmpty(placeResult))
placeResults[item] = placeResult;
placeResults[item] = new List<string>() { placeResult };
item.stackSize = table.Get("stack_size", 1);
if (item.locName == null && table.Get("placed_as_equipment_result", out string result))
{
Expand Down
11 changes: 7 additions & 4 deletions YAFCparser/Data/FactorioDataDeserializer_Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal partial class FactorioDataDeserializer
private readonly DataBucket<string, RecipeOrTechnology> recipeCategories = new DataBucket<string, RecipeOrTechnology>();
private readonly DataBucket<EntityCrafter, string> recipeCrafters = new DataBucket<EntityCrafter, string>();
private readonly DataBucket<Recipe, Item> recipeModules = new DataBucket<Recipe, Item>();
private readonly Dictionary<Item, string> placeResults = new Dictionary<Item, string>();
private readonly Dictionary<Item, List<string>> placeResults = new Dictionary<Item, List<string>>();
private readonly List<Item> universalModules = new List<Item>();
private Item[] allModules;
private readonly HashSet<Item> sciencePacks = new HashSet<Item>();
Expand Down Expand Up @@ -227,10 +227,13 @@ private void CalculateMaps()
allMechanics.Add(mechanics);
break;
case Item item:
if (placeResults.TryGetValue(item, out var placeResultStr))
if (placeResults.TryGetValue(item, out var placeResultNames))
{
item.placeResult = GetObject<Entity>(placeResultStr);
entityPlacers.Add(item.placeResult, item);
item.placeResult = GetObject<Entity>(placeResultNames.First());
foreach (var name in placeResultNames)
{
entityPlacers.Add(GetObject<Entity>(name), item);
}
}
if (item.fuelResult != null)
miscSources.Add(item.fuelResult, item);
Expand Down
11 changes: 10 additions & 1 deletion YAFCparser/Data/FactorioDataDeserializer_Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ private void DeserializeEntity(LuaTable table)
var name = table.Get("name", "");
string usesPower;
var defaultDrain = 0f;

if (table.Get("placeable_by", out LuaTable placeableBy) && placeableBy.Get("item", out string itemName))
{
var item = GetObject<Item>(itemName);
if (!placeResults.TryGetValue(item, out var resultNames))
resultNames = placeResults[item] = new List<string>();
resultNames.Add(name);
}

switch (factorioType)
{
case "transport-belt":
Expand Down Expand Up @@ -282,7 +291,7 @@ private void DeserializeEntity(LuaTable table)
{
if (possibleRecipe is Recipe rec)
CreateLaunchRecipe(crafter, rec, partsRequired, outputCount);
}
}
}
}
}
Expand Down