Skip to content
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
2 changes: 1 addition & 1 deletion CommandLineToolExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Main(string[] args)
// Empty project path loads default project (with one empty page).
// Project is irrelevant if you just need data, but you need it to perform sheet calculations
// Set to not render any icons
project = FactorioDataSource.Parse(factorioPath, "", "", false, new ConsoleProgressReport(), errorCollector, "en", false);
project = FactorioDataSource.Parse(factorioPath, "", "", false, false, new ConsoleProgressReport(), errorCollector, "en", false);
}
catch (Exception ex)
{
Expand Down
5 changes: 3 additions & 2 deletions YAFC/Utils/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public void Save()
public string language { get; set; } = "en";
public string overrideFont { get; set; }

public void AddProject(string path, string dataPath, string modsPath, bool expensiveRecipes)
public void AddProject(string path, string dataPath, string modsPath, bool expensiveRecipes, bool netProduction)
{
recentProjects = recentProjects.Where(x => string.Compare(path, x.path, StringComparison.InvariantCultureIgnoreCase) != 0)
.Prepend(new RecentProject {path = path, modsPath = modsPath, dataPath = dataPath, expensive = expensiveRecipes}).ToArray();
.Prepend(new RecentProject {path = path, modsPath = modsPath, dataPath = dataPath, expensive = expensiveRecipes, netProduction = netProduction}).ToArray();
Save();
}
}
Expand All @@ -66,5 +66,6 @@ public struct RecentProject
public string dataPath { get; set; }
public string modsPath { get; set; }
public bool expensive { get; set; }
public bool netProduction { get; set; }
}
}
2 changes: 1 addition & 1 deletion YAFC/Windows/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private async Task<bool> SaveProjectAs()
if (path != null)
{
project.Save(path);
Preferences.Instance.AddProject(path, DataUtils.dataPath, DataUtils.modsPath, DataUtils.expensiveRecipes);
Preferences.Instance.AddProject(path, DataUtils.dataPath, DataUtils.modsPath, DataUtils.expensiveRecipes, DataUtils.netProduction);
return true;
}

Expand Down
9 changes: 7 additions & 2 deletions YAFC/Windows/WelcomeScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class WelcomeScreen : WindowUtility, IProgress<(string, string)>
private string currentLoad1, currentLoad2;
private string path = "", dataPath = "", modsPath = "";
private bool expensive;
private bool netProduction;
private string createText;
private bool canCreate;
private readonly VerticalScrollCustom errorScroll;
Expand Down Expand Up @@ -134,6 +135,9 @@ protected override void BuildContents(ImGui gui)
gui.BuildText("In-game objects language:");
}

using (gui.EnterRow())
gui.BuildCheckBox("Use net production/consumption when analyzing recipes", netProduction, out netProduction);

using (gui.EnterRow())
{
if (Preferences.Instance.recentProjects.Length > 1)
Expand Down Expand Up @@ -270,6 +274,7 @@ private void BuildPathSelect(ImGui gui, ref string path, string description, str

private void SetProject(RecentProject project)
{
netProduction = project.netProduction;
expensive = project.expensive;
modsPath = project.modsPath ?? "";
path = project.path ?? "";
Expand All @@ -290,7 +295,7 @@ private async void LoadProject()
try
{
var (dataPath, modsPath, projectPath, expensiveRecipes) = (this.dataPath, this.modsPath, path, expensive);
Preferences.Instance.AddProject(projectPath, dataPath, modsPath, expensiveRecipes);
Preferences.Instance.AddProject(projectPath, dataPath, modsPath, expensiveRecipes, netProduction);
Preferences.Instance.Save();
tip = tips.Length > 0 ? tips[DataUtils.random.Next(tips.Length)] : "";

Expand All @@ -299,7 +304,7 @@ private async void LoadProject()

await Ui.ExitMainThread();
var collector = new ErrorCollector();
var project = FactorioDataSource.Parse(dataPath, modsPath, projectPath, expensiveRecipes, this, collector, Preferences.Instance.language);
var project = FactorioDataSource.Parse(dataPath, modsPath, projectPath, expensiveRecipes, netProduction, this, collector, Preferences.Instance.language);
await Ui.EnterMainThread();
Console.WriteLine("Opening main screen");
new MainScreen(displayIndex, project);
Expand Down
2 changes: 2 additions & 0 deletions YAFCmodel/Data/DataUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public static ulong GetMilestoneOrder(FactorioId id)
public static string dataPath { get; internal set; }
public static string modsPath { get; internal set; }
public static bool expensiveRecipes { get; internal set; }
public static bool netProduction { get; internal set; }
public static string[] allMods { get; internal set; }

public static readonly Random random = new Random();

public static bool SelectSingle<T>(this T[] list, out T element) where T:FactorioObject
Expand Down
4 changes: 2 additions & 2 deletions YAFCparser/Data/FactorioDataDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void AddTemperatureToFluidIcon(Fluid fluid)
fluid.iconSpec = fluid.iconSpec.Concat(iconStr.Take(4).Select((x, n) => new FactorioIconPart {path = "__.__/"+x, y=-16, x = n*7-12, scale = 0.28f})).ToArray();
}

public Project LoadData(string projectPath, LuaTable data, LuaTable prototypes, IProgress<(string, string)> progress, ErrorCollector errorCollector, bool renderIcons)
public Project LoadData(string projectPath, LuaTable data, LuaTable prototypes, bool netProduction, IProgress<(string, string)> progress, ErrorCollector errorCollector, bool renderIcons)
{
progress.Report(("Loading", "Loading items"));
raw = (LuaTable)data["raw"];
Expand Down Expand Up @@ -107,7 +107,7 @@ public Project LoadData(string projectPath, LuaTable data, LuaTable prototypes,
var iconRenderTask = renderIcons ? Task.Run(RenderIcons) : Task.CompletedTask;
UpdateRecipeIngredientFluids();
UpdateRecipeCatalysts();
CalculateMaps();
CalculateMaps(netProduction);
ExportBuiltData();
progress.Report(("Post-processing", "Calculating dependencies"));
Dependencies.Calculate();
Expand Down
14 changes: 10 additions & 4 deletions YAFCparser/Data/FactorioDataDeserializer_Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private bool IsBarrelingRecipe(Recipe barreling, Recipe unbarreling)
return true;
}

private void CalculateMaps()
private void CalculateMaps(bool netProduction)
{
var itemUsages = new DataBucket<Goods, Recipe>();
var itemProduction = new DataBucket<Goods, Recipe>();
Expand All @@ -208,15 +208,21 @@ private void CalculateMaps()
allRecipes.Add(recipe);
foreach (var product in recipe.products)
{
if (product.amount > 0)
float inputAmount = netProduction ? (recipe.ingredients.FirstOrDefault(i => i.goods == product.goods)?.amount ?? 0) : 0;
float outputAmount = ((IFactorioObjectWrapper)product).amount;
if (outputAmount > inputAmount)
itemProduction.Add(product.goods, recipe);
}

foreach (var ingredient in recipe.ingredients)
{
if (ingredient.variants == null)
float inputAmount = ingredient.amount;
IFactorioObjectWrapper outputData = recipe.products.FirstOrDefault(p => p.goods == ingredient.goods || p.goods == ingredient.variants?[0]);
float outputAmount = netProduction ? (outputData?.amount ?? 0) : 0;

if (ingredient.variants == null && inputAmount > outputAmount)
itemUsages.Add(ingredient.goods, recipe);
else
else if (ingredient.variants != null)
{
ingredient.goods = ingredient.variants[0];
foreach (var variant in ingredient.variants)
Expand Down
5 changes: 3 additions & 2 deletions YAFCparser/FactorioDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void FindMods(string directory, IProgress<(string, string)> progr
}
}

public static Project Parse(string factorioPath, string modPath, string projectPath, bool expensive, IProgress<(string, string)> progress, ErrorCollector errorCollector, string locale, bool renderIcons = true)
public static Project Parse(string factorioPath, string modPath, string projectPath, bool expensive, bool netProduction, IProgress<(string, string)> progress, ErrorCollector errorCollector, string locale, bool renderIcons = true)
{
LuaContext dataContext = null;
try
Expand Down Expand Up @@ -261,6 +261,7 @@ public static Project Parse(string factorioPath, string modPath, string projectP
DataUtils.dataPath = factorioPath;
DataUtils.modsPath = modPath;
DataUtils.expensiveRecipes = expensive;
DataUtils.netProduction = netProduction;


dataContext = new LuaContext();
Expand All @@ -287,7 +288,7 @@ public static Project Parse(string factorioPath, string modPath, string projectP
currentLoadingMod = null;

var deserializer = new FactorioDataDeserializer(expensive, factorioVersion ?? defaultFactorioVersion);
var project = deserializer.LoadData(projectPath, dataContext.data, dataContext.defines["prototypes"] as LuaTable, progress, errorCollector, renderIcons);
var project = deserializer.LoadData(projectPath, dataContext.data, dataContext.defines["prototypes"] as LuaTable, netProduction, progress, errorCollector, renderIcons);
Console.WriteLine("Completed!");
progress.Report(("Completed!", ""));
return project;
Expand Down