#How do i make a crafting system?
1 messages · Page 1 of 1 (latest)
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.
check nodes (-=)(+1)-> modify nodes -> update crafting menu -> |Save
what
brb chat
How would i display the recipies you can craft? Go trough the file system?
Good question. Does player inventory have limited slots?
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
Yes?
elaborate
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
hm alr ig
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
GoDot 4.4.1 Stable # # Call / Execute function with: # var mylist = _buildPathContents("C:/my/path/to/some/directory") # # [ Example Output ] # for _key in mylist : # print(_key) # for i in range(mylist[_key].size()): # print("\t" + mylist[_key][i]) # func _buildPathContents(_path: String, _tempfiletree: Dictionary = {}) -> Dictionary: #...
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
uh
#1430204815455162388 message
nvm
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
<@&1349109171240439858>