Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Nikola-Milovic |
So basically to keep this readable and understandable. I have a JSON file with all of my item data. The items are dictionaries, and they are saved in an array inside a JSON file.
So JSON contains an array of dictionaries. Which I load up into my singleton that holds this data in a variable (it’s passed by reference so I use it across my game and change the values of the stuff the amount of items and such), and after loading i split that array(not really split just append to different arrays items based on rarity). And when the game exists I save variable that held the items back into JSON. It seemed like a great solution, but now thinking about is, is having a variable with 100 dictionaries a smart idea? It works great but idk how performant is it.
So array of dictionaries inside JSON → loaded up into a variable called inventory → from here another singleton splits the items based on rarity into different arrays (common rare epic etc). I use these arrays for my drop system, reward system, inventory and so on.
func seperate_items():
for item in all_items:
match(item["type"]):
"plush":
all_plush_items.append(item)
"wood":
all_wood_items.append(item)
"plastic":
all_plastic_items.append(item)
match(item["rarity"]):
"common":
common.append(item)
"uncommon":
uncommon.append(item)
"rare":
rare.append(item)
"epic":
epic.append(item)
all_items is a variable that is set equal to the actual variable that holds all values. (so it should be pointing to the same thing)