Howdy folks, you may have escaped me last week, but I am back, and I've been messing around with more crafting experiments!
I've ditched the drag-and-drop behavior seeing as when I actually need to put this into my game, I'll need to control it with keyboard/gamepad. So now, you have a set of items on the left side of the screen, two crafting slots, a result slot and some buttons to trigger crafting. It should be noted that I am using assets from the fabulous Kenney, and you should definitely check out his stuff if you haven't already!
When you click on an item, it'll be assigned to one of the crafting slots. Then you can either click the green button to see if you can craft something, or the red button to clear your selection. When you assign an item to a crafting slot, both its UID and ItemID are registered to a global variable. So, when you click craft the project checks whether the values in the two Ingredient global variables match any of the recipes in a JSON project file. If they do, the results slot changes its frame to match the new item and you've "crafted" something.
Granted, I've not gotten to the point of being able to add the created item to your "inventory" but that's my next step. Currently, the "inventory" is purely the objects on the screen, it's not tracked anywhere. So, I think the next thing to do is build in the inventory as an array so we can track which items the player has, and remove/create them as needed.
It's been quite interesting making these crafting experiments in steps like this. Starting with something quite basic, then slowly building on it to not only refine the existing mechanics but to develop new ones is a nice way to work.
Also, I mentioned to Tom that it might be helpful to be able to attach files to blog posts – so at some point soon, I may be able to share these mini projects with you more easily. Wouldn't that be nice?
Have a nice weekend!