I’m trying to decide the best way to go about this issue… I’m making a platformer game that will soon have an inventory. My engine is within the package called PlatformerEngine, and the actual implementation is within the package PlatformerImplementation. I created a DataParser class which reads a save file, and stores the data in multiple HashMaps. Later, you may call flush() in order to save changes made to DataParser. For instance…
// Blah blah blah, arbitrarily accessing the singleton class DataParser…
DataParser parser = getDataParser();
// Dynamically sets a property
parser.setProperty(“Settings”, “fullscreen”, “true”);
// Saves said property to an output file
parser.flush();
The data parser can basically be considered the save file itself, and is rather abstract.
I also plan to make an Inventory system which, of course, will store items acquired. The inventory will refer to particular parts of the DataParser to determine what is stored in the inventory.
I was thinking that I could convert String names from the DataParser (essentially the save file) to a particular object extending a class called Item. For instance, lets say the save file stored a name “Apple”. When the inventory wants to add apple from the save file, it would need to convert the String name to a particular instance of the class Item, and store it within the inventory.
My second idea was to simply have the Inventory class only point to the string data located in DataParser and leave it at that. When displaying the inventory to the Player, Images will be generated representing the names of the items that the Inventory points to. The advantage here is that what is stored is more centralized. The disadvantage is that whenever the inventory is loaded, it must parse through the inventory each time and determine what should be displayed and how the particular item behaves rather than already having the Items with image data and behaviors stored before hand.
What do you think I should do here? I’m kind of stuck until I come up with a solution…