Package com.csse3200.game.files
Class FileLoader
java.lang.Object
com.csse3200.game.files.FileLoader
Wrapper for reading Java objects from JSON files.
A generic method is provided already, but methods for reading specific classes can be added for more control.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
Read generic Java classes from a JSON file.static <T> T
readClass
(Class<T> type, String filename, FileLoader.Location location) Read generic Java classes from a JSON file.static InventoryComponent
readInventory
(List<String> inventory, int CPU) Reads Inventory component of a save file json - currently a placeholder for refacotring end sprint 2 / into sprint 3static <T> T
readPlayer
(Class<SaveLoadService.PlayerInfo> player, String filename, FileLoader.Location location) Read playerinfo from a JSON file and write into class.static void
writeClass
(SaveLoadService.PlayerInfo playerInfo, String filename, FileLoader.Location location) Write specific player instance to a JSON file.static void
writeClass
(Object object, String filename) Write generic Java classes to a JSON file.static void
writeClass
(Object object, String filename, FileLoader.Location location) Write generic Java classes to a JSON file.
-
Field Details
-
jsonSave
public static com.badlogic.gdx.utils.Json jsonSave
-
-
Constructor Details
-
FileLoader
public FileLoader()
-
-
Method Details
-
readClass
Read generic Java classes from a JSON file. Properties in the JSON file will override class defaults.- Type Parameters:
T
- Class type to read JSON into- Parameters:
type
- class typefilename
- file to read from- Returns:
- instance of class, may be null
-
readClass
Read generic Java classes from a JSON file. Properties in the JSON file will override class defaults.- Type Parameters:
T
- Class type to read JSON into- Parameters:
type
- class typefilename
- file to read fromlocation
- File storage type. See https://github.com/libgdx/libgdx/wiki/File-handling#file-storage-types- Returns:
- instance of class, may be null
-
readPlayer
public static <T> T readPlayer(Class<SaveLoadService.PlayerInfo> player, String filename, FileLoader.Location location) Read playerinfo from a JSON file and write into class.- Type Parameters:
T
- Class type to read JSON into- Parameters:
player
- class typefilename
- file to read fromlocation
- File storage type. See- Returns:
- instance of class, may be null
-
readInventory
Reads Inventory component of a save file json - currently a placeholder for refacotring end sprint 2 / into sprint 3- Parameters:
inventory
- string representation of the itemsCPU
- processor count to be loaded in
-
writeClass
Write generic Java classes to a JSON file.- Parameters:
object
- Java object to write.filename
- File to write to.
-
writeClass
Write generic Java classes to a JSON file.- Parameters:
object
- Java object to write.filename
- File to write to.location
- File storage type. See https://github.com/libgdx/libgdx/wiki/File-handling#file-storage-types
-
writeClass
public static void writeClass(SaveLoadService.PlayerInfo playerInfo, String filename, FileLoader.Location location) Write specific player instance to a JSON file.- Parameters:
playerInfo
- information required to load the player back infilename
- File to write to.location
- File storage type. See https://github.com/libgdx/libgdx/wiki/File-handling#file-storage-types
-