forked from Bitcoindefi/OpenAO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmeltingRecipeData.ts
More file actions
31 lines (24 loc) · 1.16 KB
/
Copy pathsmeltingRecipeData.ts
File metadata and controls
31 lines (24 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import fs from "node:fs";
import path from "node:path";
import type { SmeltingRecipe } from "./smeltingRecipes";
const DEFAULT_SMELTING_RECIPES_JSON_PATH = path.resolve(__dirname, "../jsons/smeltingRecipes.json");
function normalizeSmeltingRecipe(recipe: SmeltingRecipe): SmeltingRecipe {
return {
id: Number(recipe.id ?? 0),
mineralItemId: Number(recipe.mineralItemId ?? 0),
ingotItemId: Number(recipe.ingotItemId ?? 0),
requiredSkill: Number(recipe.requiredSkill ?? 0),
mineralsPerIngot: Number(recipe.mineralsPerIngot ?? 0),
};
}
export function normalizeSmeltingRecipesData(recipes: SmeltingRecipe[]): SmeltingRecipe[] {
return recipes.map(normalizeSmeltingRecipe).filter((recipe) => recipe.id > 0);
}
export function loadSmeltingRecipesDataFromJsonFile(filePath: string): SmeltingRecipe[] {
const raw = fs.readFileSync(filePath, "utf8");
return normalizeSmeltingRecipesData(JSON.parse(raw) as SmeltingRecipe[]);
}
export function loadDefaultSmeltingRecipesData(): SmeltingRecipe[] {
return loadSmeltingRecipesDataFromJsonFile(DEFAULT_SMELTING_RECIPES_JSON_PATH);
}
export { DEFAULT_SMELTING_RECIPES_JSON_PATH };