From 5317f13d6faabd7c17219853e2f9d83b1d21e6b4 Mon Sep 17 00:00:00 2001
From: Dale McCoy <21223975+DaleStan@users.noreply.github.com>
Date: Sat, 18 May 2024 13:42:44 -0400
Subject: [PATCH] Before failing to add a recipe, look for special recipes too.
This allows you to use ctrl+click to produce or consume filled barrels, stacked items, or similar.
---
Yafc.Model/Data/DataUtils.cs | 73 ++++++++++++++++++++----------------
1 file changed, 40 insertions(+), 33 deletions(-)
diff --git a/Yafc.Model/Data/DataUtils.cs b/Yafc.Model/Data/DataUtils.cs
index 8ff39883..3eef19c8 100644
--- a/Yafc.Model/Data/DataUtils.cs
+++ b/Yafc.Model/Data/DataUtils.cs
@@ -109,48 +109,55 @@ public static Bits GetMilestoneOrder(FactorioId id) {
///
/// - The only normal item in .
/// - The only normal user favorite in .
+ /// - The only item in , considering both normal and special items.
+ /// - The only user favorite in , considering both normal and special items.
/// - If no previous options are applicable, .
///
public static T? SelectSingle(this T[] list, out string recipeHint) where T : FactorioObject {
- var userFavorites = Project.current.preferences.favorites;
- bool acceptOnlyFavorites = false;
- T? element = null;
- if (list.Any(t => t.IsAccessible())) {
- recipeHint = "Hint: Complete milestones to enable ctrl+click";
- }
- else {
- recipeHint = "Hint: Mark a recipe as accessible to enable ctrl+click";
- }
- foreach (var elem in list) {
- if (!elem.IsAccessibleWithCurrentMilestones() || elem.specialType != FactorioObjectSpecialType.Normal) {
- continue;
+ return @internal(list, true, out recipeHint) ?? @internal(list, false, out recipeHint);
+
+ static T? @internal(T[] list, bool excludeSpecial, out string recipeHint) {
+ HashSet userFavorites = Project.current.preferences.favorites;
+ bool acceptOnlyFavorites = false;
+ T? element = null;
+ if (list.Any(t => t.IsAccessible())) {
+ recipeHint = "Hint: Complete milestones to enable ctrl+click";
}
-
- if (userFavorites.Contains(elem)) {
- if (!acceptOnlyFavorites || element == null) {
- element = elem;
- recipeHint = "Hint: ctrl+click to add your favorited recipe";
- acceptOnlyFavorites = true;
- }
- else {
- recipeHint = "Hint: Cannot ctrl+click with multiple favorited recipes";
- return null;
- }
+ else {
+ recipeHint = "Hint: Mark a recipe as accessible to enable ctrl+click";
}
- else if (!acceptOnlyFavorites) {
- if (element == null) {
- element = elem;
- recipeHint = "Hint: ctrl+click to add the accessible recipe";
+ foreach (T elem in list) {
+ // Always consider normal entries. A list with two normals and one special should select nothing, rather than selecting the only special item.
+ if (!elem.IsAccessibleWithCurrentMilestones() || (elem.specialType != FactorioObjectSpecialType.Normal && excludeSpecial)) {
+ continue;
}
- else {
- element = null;
- recipeHint = "Hint: Set a favorite recipe to add it with ctrl+click";
- acceptOnlyFavorites = true;
+
+ if (userFavorites.Contains(elem)) {
+ if (!acceptOnlyFavorites || element == null) {
+ element = elem;
+ recipeHint = "Hint: ctrl+click to add your favorited recipe";
+ acceptOnlyFavorites = true;
+ }
+ else {
+ recipeHint = "Hint: Cannot ctrl+click with multiple favorited recipes";
+ return null;
+ }
+ }
+ else if (!acceptOnlyFavorites) {
+ if (element == null) {
+ element = elem;
+ recipeHint = excludeSpecial ? "Hint: ctrl+click to add the accessible normal recipe" : "Hint: ctrl+click to add the accessible recipe";
+ }
+ else {
+ element = null;
+ recipeHint = "Hint: Set a favorite recipe to add it with ctrl+click";
+ acceptOnlyFavorites = true;
+ }
}
}
- }
- return element;
+ return element;
+ }
}
public static void SetupForProject(Project project) {