| 09-06-2011, 10:06 AM | #1 |
Right now, I am deciding between two different approaches. The first is the standard one with methods for adding items to the recipe: call ItemRecipe.create(result).add(item1).add(item2).addCharges(item3, 60) However, I also had an idea for a second approach where I abuse the [] operators. This results in much less verbose recipe creations, however due to the operator abuse you can't simply prefix all your recipe creations with "call": set i = ItemRecipe.create(result)[item1][item2] set ItemRecipe.create(result)[item1][item2][item3]=60 The brackets at the end look nice but the start of the line is just bad, especially since it's different for recipes that contain a charges requirement. Which of the two do you think is better? Can you think of an alternative that is better than both? Keep in mind that the API needs to support both adding item count requirements and item charges requirements. |
| 09-06-2011, 11:00 AM | #2 |
Keep it with operators, people who don't like the "set ItemRecipe.create(result)" API should do this: local ItemRecipe recipe = ItemRecipe.create(result) set recipe[item1][item2][item3] = 60 |
| 09-06-2011, 11:53 AM | #3 |
"Abusing" operators in such way brings way too much abstraction to the code. I'd stick with the first API. |
| 09-08-2011, 05:53 AM | #4 |
Thanks to share your ideas! :) |
| 09-14-2011, 05:10 AM | #5 |
I like both pretty equally the first one seems a bit easier to understand what exactly is happening for a new user the second one seems like it'd be easier for people who just want it to work and aren't very programming savvy. then again, the sytax (on API 2) for a charged item might be too weird for some people. |
| 09-16-2011, 05:56 PM | #6 |
I decided to use the first API after I started writing the documentation. I could find no simple way of explaining all those syntax exceptions that come with the operator approach. If I require multiple paragraphs and examples to describe my API, then it's a bad API. New question: what's the preferable approach for charged-item-stacking-on-pickup-even-if-inventory-is-full? There are two options:
|
| 09-16-2011, 10:25 PM | #7 |
RecipeAddItem minority reporting in. |
| 09-17-2011, 01:10 AM | #8 | |
Quote:
|
| 09-17-2011, 03:42 AM | #9 |
^This. The first option won't bother the user if they don't want to implement it. |
| 09-17-2011, 07:03 PM | #10 |
I like option 1 much, much more duplicate dummy items aren't that much of a big deal considering how rarely charge items are used anyways. in most rpg's its pretty much only potions and those are bought (are bought charged items handled as well?) in anything else there aren't usually enough items (much less charged ones) for this to be a hassle. |
| 09-17-2011, 10:56 PM | #11 | |
Quote:
|
| 09-18-2011, 10:36 PM | #12 | |
Quote:
|
| 09-22-2011, 04:27 PM | #13 |
Thank you all for your feedback. If anyone's interested, this is what I've come up with so far. |
| 09-23-2011, 09:18 PM | #14 | |
this is awesome it actually makes me want to do an rpg style game just so i can play with item recipes Quote:
the first time i read it as: this recipe will now be based on charged items only when i reread it, i understood what you were going for but i still think the wording is confusing. howbout something like: //* The .addCharges method functions similarly to .add, however it requires that the given //* item (ingredientItemId) have at least a certain amount of charges (chargeCount) also this next recommendation might make you cry tears of blood, so i apologize in advanced. it might be better to have the AUTOMATICALLY_MERGE_ITEMS bool be part of the recipe rather than a global for the entire system. I've seen a lot of maps (and see there being a lot more) that auto merge basic items, but require a trip to, as a generic example, a forge for the more advanced stuff. a step further would be to add a way to differentiate which items combine at what "forge". for example say you want a forge and a factory recipe 1 combines only at the forge and recipe 2 only at the factory as is, you'd call .checkUnitItems(u) and everything would come together, regardless of the unit being at forge or factory. but even though I think this would be cool to have as a feature, its use would probably be seldom and it might very well cause some ugly code. I guess a way around the first part (global vs member auto-combine) would be to add every item in a non-auto-combine recipe to the item filter but it feels like the member example would be much prettier I'll add some more once I throw all this stuff in a test map (or you upload yours :D) when i get home later on |
| 09-24-2011, 08:32 AM | #15 | ||
Quote:
Quote:
However, if some items are shared by both forge recipes and auto recipes, none of that would help. I could add the boolean to individual recipes to not make them auto-combine, but that still leaves the problem of forges being able to combine non-forge recipes when you use their forge ability. The simplest solution I see to this problem is to simply paste an additional copy of the entire system into the map, rename the struct into ForgeRecipe, change its unit filter so it only works with forges, and create all your forge recipes there. You can then copy it again for the factory recipes and so on. I could still merge the two filters so that you can use a single copy of the system for multiple units when there's no overlap in ingredients, though. |
