Inventory & Crafting

Introduction

This page breaks down how the system evolved throughout development, showing the different versions, challenges I faced, and what I learned during the process.

Result

For my specialization I chose to create an Inventory system, which quickly evolved to include crafting functionality. Inventories and crafting have always interested me from minecraft to potion making in skyrim


Where it begun

In the beginning I put in time to research on inventory systems. It was a bit hard considering the time limit, so after finding a bit information I begun to plan the different parts that would be needed.

After that I begun looking on how I could implement the inventorygrid. I wanted to test around with its size, so I focused on making a where I can easily customize its size. I went through several different methods until I found one I could work with.

Version 1

Version1: One sprite with drawn cells. From knowing the amount of cells and the sprites size I could calculate theirs size and position.

Version 2

Version2: Focused on deciding amount of cells from the background size and the size of the cell. Problem was uneven sizes and some cells not rendering.

Final Version

Final Version: Ended with deciding the background size, cellsize and then the amount row, columns and gapsize.


Resize Grid and ItemFactory

The struggle to build a grid that position cells from the amount of rows, column and gapsize.

Changing the amount of columns and gapsize between cells.

When that step was finished it was time to createitems and additems to the grid.

From my group project 7, I got to learn working with factories when working with weapons, and I did want to continue training using it. So I adapted similair logic to the ItemFactory as in WeaponFactory.
The difference that here I create the ItemPureData in engine instead of getting it from Unity.

std::unordered_map<eName, std::unique_ptr<ItemPureData>> myItemData2;


Moving, adding, UI feedback

And with that it was time to addItem into the inventorygrid move it around, adding to the Craftinggrid and remove items.

That was a big process on its own, with sprite rendering while hovering, while holding, follow the mouse , showing information from its puredata , keep track on cellindexes and so on.

Moving items around the grid

An item sprite follows the mouse and items can be removed


Crafting & Recipes

Crafting was something I aimed towards from the beginning, for an Inventory always come hand in hand with a crafting system. I had a clear vision from the start that I was going to use a map where the first is the item that are created and the second is the items needed for it.

//mapping crafted item to its required ingredienses
std::unordered_map<eName, std::vector<std::string>> myCraftingRecipies;

I begun with a map with only string, but later choose to use enum instead for the “key”. I will probably shift over to only enums for making sure no spelling mistake can cause an error


What more I wanted to implement

  • Finish stacking

  • Max Weight in the Inventory

  • Selling Items

  • Create recipes during runtime

  • Create Items during runtime

Stacking:

As of now you can stack and decrease stack, each itemtype has a flag if they can stack or not and what their maxstack is.

I wanted to implement that if you move a stack of 2 over a stack of 4 for example, the one you drop it on shall take what stack it can, and the rest go back to its former position.

And that if you right click over an Item, you pick up one after another of the stack, with a small time delay.

Also that some recipes require more of one stack of an item.

Unfortunately time was not on my side, hence why I could not finish stacking functionality

Max Weight:

Will be implemented soon, and it will hinder from adding more items to inventorygrid, even draging and item from craftgrid or resultcell to inventorygrid.

Selling Items:

This will also be implemented soon.

Create recipes & Items during runtime:

This one can be tricky depending on how I implement it. For creation uses with imgui is possible, but for an “in game” feature, that will be hard. Would require more that Im making a game instead of an inventory with alot of extra feature


What could I have done different?

The Inventory and Crafting systems share a lot of logic and layout behavior. I could have designed a common base class or system to reduce code duplication and simplify future changes.

  1. Both InventoryGrid and CraftingGrid had very similar behaviors—handling cells, layout, drag-and-drop—which could’ve been unified into a generic GridBase or templated system.

  2. I focused more on functionality than architecture early on. In future projects, I’d like to experiment with patterns like Model-View-Controller (MVC) which was recommened to me, to separate logic (model), visuals (view), and input/control flow (controller). This could make the system more modular, testable, and reusable.

  3. While the current system works well inside TGA’s engine, making it more engine-agnostic from the beginning could have made it easier to reuse across projects.


Conclusion

This project taught me a lot about system structure, planning UI interactions, and how to adapt functionality across different gameplay elements. While not as modular as I initially envisioned, building an inventory and crafting system from scratch helped me understand how interconnected systems can be designed, tested, and iterated on.

I would do this again I would implement the things states above, which is easier now with the knowledge I have now.

Overall, this specialization project was a great opportunity to experiment, learn, and push my technical and design skills in game development.