Package me.nabdev.pathfinding.utilities
Class PathSerializer
java.lang.Object
me.nabdev.pathfinding.utilities.PathSerializer
Serializes and deserializes paths to and from JSON
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe current JSON format version, used to ensure that the JSON is compatible. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathfromDeployFolder(String displayName) Load a path from the deploy folder via its display name.static PathLoad a path from the deploy folder by its filenamestatic PathLoad a path from diskstatic PathfromJSON(org.json.JSONObject jsonObject) Load a path from a JSON objectstatic voidtoDeployFolder(Path path, String displayName) Save a path to the deploy folderstatic voidtoDeployFolder(Path path, String displayName, String fileName) Save a path to the deploy folderstatic voidSave a path to diskstatic org.json.JSONObjectSave a path to a JSON object
-
Field Details
-
VERSION
public static final int VERSIONThe current JSON format version, used to ensure that the JSON is compatible.- See Also:
-
-
Constructor Details
-
PathSerializer
public PathSerializer()
-
-
Method Details
-
fromDisk
Load a path from disk- Parameters:
path- The path of the JSON file to load- Returns:
- The path
- Throws:
FileNotFoundException- If the file does not exist
-
fromDeployFolderByFilename
public static Path fromDeployFolderByFilename(String path) throws FileNotFoundException, IOException Load a path from the deploy folder by its filename- Parameters:
path- The path of the JSON file to load, relative to deploy/oxplorer/paths- Returns:
- The path
- Throws:
FileNotFoundException- If the file does not existIOException
-
fromDeployFolder
Load a path from the deploy folder via its display name. Spaces and other non-alphanumeric characters will be replaced with underscores when searching.- Parameters:
displayName- The name of the path to load (without the .json extension)- Returns:
- The path
- Throws:
FileNotFoundException- If the file could not be foundIOException
-
toDisk
Save a path to disk- Parameters:
filePath- The file location to save topath- The path to savedisplayName- The display name of the path- Throws:
IOException- If the file cannot be written to
-
toDeployFolder
Save a path to the deploy folder- Parameters:
path- The path to savedisplayName- The display name of the path (will be used as the file name)- Throws:
IOException- If the file cannot be written to
-
toDeployFolder
public static void toDeployFolder(Path path, String displayName, String fileName) throws IOException Save a path to the deploy folder- Parameters:
path- The path to savedisplayName- The display name of the path (will be used as the file name)fileName- The name of the file to save to- Throws:
IOException- If the file cannot be written to
-
fromJSON
Load a path from a JSON object- Parameters:
jsonObject- The JSON object to load from- Returns:
- The path
-
toJSON
Save a path to a JSON object- Parameters:
path- The path to savedisplayName- The display name of the path- Returns:
- The JSON object
-