#How do i make a crafting system?

1 messages · Page 1 of 1 (latest)

serene thistle
#

I wanna make a crafting system where you just pick what you wanna craft
I have tried my own code but it was uhhh too messy. Anyone got any tips or ideas? gddeadinside <@&1349109171240439858>

rigid bloom
#

Whats the basic idea of your system?
I'd do it like that: have a global node that has an array of Recipe class instances. The Recipe class has an Array of ingredients and their quantities, as well as an Array of output items and their quantities. I'd then add Dictionaries while implementing UI for crafting so I can perform search for recipes without going through the whole array. Recipes will be fixed and initialized in-code in _ready() function of said global node.

wary brook
serene thistle
rigid bloom
#

Good question. Does player inventory have limited slots?

sharp turret
#

You could index a folder with resource files recursively where each file is a recipie, then just put them all in an array or dictionary

sharp turret
#

If you have a resource file type you make for your recipe you can save each file in a folder, go through every file in the folder and add them to an autoload dictionary

#

holup, I'll see if i can find some code where i did this for items

sharp turret
#
func load_recipes(_path: String, _tempfiletree: Dictionary = {}) -> Dictionary:
    # Print files/directories into console window (only if GoDot is running Debug Mode)
    var _printDebug = false
    # Open path so we can view contents
    var _dir = DirAccess.open(_path)
    # Check if we gained access to the path
    if _dir:
        # Make sure we have a key to append files into
        if not _tempfiletree.has(_path):
            _tempfiletree[_path] = []
        # Begin iterating
        _dir.list_dir_begin()
        # Get first file or directory
        var _filename = _dir.get_next()
        # Loop as long as we have a name for something
        while _filename != "":
            if _dir.current_is_dir():
                if OS.is_debug_build() and _printDebug:
                    print("Dir: " + _filename)
                # Call self for subdirectory
                _tempfiletree = _buildPathContents(_path.path_join(_filename), _tempfiletree)
            else:
                # Add file to array
                                # IT*S HERE YOU WOULD USE A RESOURCE LOADER TO DESERIALIZE YOUR FILE
    _tempfiletree[_dir.get_current_dir()].append(_filename)
                if OS.is_debug_build() and _printDebug:
                    print("File: " + _filename)
            # Get next file or directory
            _filename = _dir.get_next()
        # End iterating
        _dir.list_dir_end()
    return _tempfiletree
serene thistle
#

also

#

How do i check for a folder in my res

sharp turret
#

It goes through a folder and all subfolders and adds the files to a dictionary, you can also load your stuff using an asset loader

serene thistle
#

nvm

rigid bloom
# serene thistle Yes?

in that case, for fast access, I would, aside from already existing Array, make a Dictionary[Item, Array] that maps an ingredient to an array of recipes.
that way recipes that player doesnt have at least one item for wont even be processed