31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
/**
|
|
* CraftingSystem — thin wrapper around ContentLoader for recipe definitions.
|
|
*/
|
|
class CraftingSystem {
|
|
constructor(contentLoader) {
|
|
this.loader = contentLoader;
|
|
this.playerCrafting = new Map();
|
|
}
|
|
|
|
getAllRecipes() { return this.loader.getAllRecipes(); }
|
|
getRecipe(id) { return this.loader.getRecipe(id); }
|
|
getRecipesByType(type) { return this.loader.getRecipesByType(type); }
|
|
getCraftingTabs() { return this.loader.getCraftingTabs(); }
|
|
|
|
initializePlayerData(userId) {
|
|
if (this.playerCrafting.has(userId)) return this.playerCrafting.get(userId);
|
|
const data = { skill: 1, experience: 0, knownRecipes: new Set(), totalCrafted: 0 };
|
|
this.playerCrafting.set(userId, data);
|
|
return data;
|
|
}
|
|
|
|
getPlayerCrafting(userId) { return this.initializePlayerData(userId); }
|
|
|
|
recordCraft(userId, recipeId) {
|
|
const pd = this.initializePlayerData(userId);
|
|
pd.totalCrafted++;
|
|
pd.knownRecipes.add(recipeId);
|
|
}
|
|
}
|
|
module.exports = CraftingSystem;
|