Skip to content

Commit

Permalink
Improved recipes sorting, added hover tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
andev0 committed Aug 17, 2024
1 parent ecbd5ea commit 13d9e3e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Tools/SatisfactoryRecipeExporter/DocsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ type DocsDescriptor = {
mDescription: string;

mPersistentBigIcon: string;

mResourceSinkPoints: string;
};

type DocsRecipe = {
ClassName: string;

mDisplayName: string;

mManufacturingMenuPriority: string;

mIngredients: string;
mProduct: string;

Expand Down
5 changes: 4 additions & 1 deletion src/Tools/SatisfactoryRecipeExporter/ExportedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type Descriptor = {

// Set if the resource is used in parsed recipes.
isResourceInUse: boolean;

// For resolving recipe complexity.
resourceSinkPoints: number;
};

type Resource = Omit<Descriptor, "isResourceInUse">;
type Resource = Omit<Descriptor, "isResourceInUse" | "resourceSinkPoints">;
33 changes: 27 additions & 6 deletions src/Tools/SatisfactoryRecipeExporter/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ let descriptorsMap = new Map<string, Descriptor>(satisfactory
displayName: docsDescriptor.mDisplayName,
description: docsDescriptor.mDescription.replaceAll("\r\n", "\n"),
iconPath: `${iconPath}${iconName}.png`,
isResourceInUse: false // Will be set after parsing recipes.
isResourceInUse: false, // Will be set after parsing recipes.
resourceSinkPoints: +docsDescriptor.mResourceSinkPoints,
};
})
.map(descriptor => [descriptor.id, descriptor]));
Expand All @@ -149,13 +150,33 @@ let recipes: Recipe[] = satisfactory
return name.startsWith("Build_") && !blacklistedMachines.includes(name);
});

let ingredients = parseResourcesList(docsRecipe.mIngredients);
let products = parseResourcesList(docsRecipe.mProduct);

let ingredientsComplexity = 0;
let productsComplexity = 0;

for (const ingredient of ingredients)
{
let resource = descriptorsMap.get(ingredient.id);

ingredientsComplexity = Math.max(ingredientsComplexity, resource?.resourceSinkPoints ?? 0);
}

for (const product of products)
{
let resource = descriptorsMap.get(product.id);

productsComplexity = Math.max(productsComplexity, resource?.resourceSinkPoints ?? 0);
}

return {
id: docsRecipe.ClassName,
displayName: docsRecipe.mDisplayName,
isAlternate: docsRecipe.ClassName.startsWith("Recipe_Alternate_"),
complexity: +docsRecipe.mManufacturingMenuPriority,
ingredients: parseResourcesList(docsRecipe.mIngredients),
products: parseResourcesList(docsRecipe.mProduct),
isAlternate: docsRecipe.mDisplayName.startsWith("Alternate:"),
complexity: Math.max(ingredientsComplexity, productsComplexity),
ingredients: ingredients,
products: products,
producedIn: machines,
manufacturingDuration: +docsRecipe.mManufactoringDuration
};
Expand Down Expand Up @@ -284,7 +305,7 @@ fs.writeFileSync(
.filter(descriptor => descriptor.isResourceInUse)
.map<Resource>(descriptor =>
{
let { isResourceInUse, ...resource } = descriptor;
let { isResourceInUse, resourceSinkPoints, ...resource } = descriptor;
return resource;
})
})
Expand Down
13 changes: 8 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MouseHandler } from "./MouseHandler";
// Ignore import error as the file only appears on launch of the exporting tool.
// @ts-ignore
import satisfactoryData from '../dist/GameData/Satisfactory.json';
import { GameRecipe, GameRecipeEvent } from "./GameData/GameRecipe";
import { GameRecipeEvent } from "./GameData/GameRecipe";

async function main()
{
Expand Down Expand Up @@ -144,14 +144,14 @@ async function main()
nodeCreationContainer?.classList.add("hidden");
});

nodeCreationContainer!.addEventListener("click", () =>
let tabSelectors = document.querySelector("div#tab-selectors")!;
let recipeTabs = document.querySelector("div#recipe-tabs")!;

recipeTabs.addEventListener("click", () =>
{
document.dispatchEvent(new GameRecipeEvent(undefined, undefined, "recipe-selected"));
});

let tabSelectors = document.querySelector("div#tab-selectors")!;
let recipeTabs = document.querySelector("div#recipe-tabs")!;

for (const machine of satisfactoryData.machines)
{
let tabSelector = document.createElement("div");
Expand Down Expand Up @@ -189,6 +189,7 @@ async function main()
{
let recipeNode = document.createElement("div");
recipeNode.classList.add("recipe");
recipeNode.title = recipe.displayName;

for (const product of recipe.products)
{
Expand Down Expand Up @@ -301,6 +302,7 @@ async function main()
icon.loading = "lazy";
icon.alt = resource!.displayName;
icon.src = `GameData/SatisfactoryIcons/${resource!.iconPath}`;
icon.title = resource!.displayName;

let amount = document.createElement("p");
amount.classList.add("amount");
Expand Down Expand Up @@ -328,6 +330,7 @@ async function main()

let selectedRecipeMachine = document.querySelector("#selected-recipe-machine>div.machine>img.icon") as HTMLImageElement;
selectedRecipeMachine.src = `GameData/SatisfactoryIcons/${machine.iconPath}`;
selectedRecipeMachine.title = machine.displayName;

document.querySelectorAll("#selected-recipe-input>div.resource").forEach(div => div.remove());
let selectedRecipeInput = document.querySelector("#selected-recipe-input") as HTMLDivElement;
Expand Down

0 comments on commit 13d9e3e

Please sign in to comment.