'Fluent API' Recipe Builder syntax
See original GitHub issueDescription
An extension coupled with a RecipeBuilder class, allowing for easier recipe building. The current implementation is in my library and works fine, although I assume it would need some adjusting to fit tML standards.
What does this proposal attempt to solve or improve?
The way recipes are added right now is not exactly the most pleasant, albeit not atrocious. This syntax aims to solve the issue by providing some kind of ‘natural language’ implementation to recipes added in AddRecipes.
Which (other) solutions should be considered?
I am unaware of any other solutions such as this one, other than Mirsario’s.
Examples
Here are two examples that show what the syntax could be. The first example instantiates a new RecipeBuilder manually.
The second example uses both the extension method and multiple crafting stations
The current implementation has several other methods which I’ve not included in this issue, but are as follows:
SetResult
: callsSetResult
for the recipeSetResultStack
: changes only the amount produced, useful in case of multiple recipes producing the same item but not the same quantity- Several instances of
New
, which take different parameters.New
will automatically callFinish
on an old recipe if its not been added to the game Clear
: effectively callsNew
with the existing information. Not namedNew
since it only works if you already have an existing product in the builder- The different constructors for
RecipeBuilder
(which all follow the differentSetResult
forModRecipe
)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (6 by maintainers)
Yeah that’s not how the builder pattern works When you call ‘Build()’, that’s the final step. Any other step is possible at any moment before building. In case you’re wondering, the fluent API pattern is almost always used alongside the builder pattern, and it makes perfect sense. In short, you should be able to construct the recipe in any order.
One recipe builder instance should build one recipe. 1 <-> 1 relation
So ModRecipeBuilder.Build() should return a ModRecipe If you want to make a new recipe, you then go again:
new ModRecipeBuilder().Requires(..)..At(...).Build();
Anywhere
sounds quite redundant since you don’t require a tile, what does that even do?