Input/Output (IO)¶
IO¶
-
class
CommonIOUtils
¶ Bases:
object
Utilities for reading/writing to and from files.
-
static
delete_directory
(directory_path, ignore_errors=False)¶ Delete a directory.
Parameters: - directory_path (str) – The folder to delete.
- ignore_errors (bool, optional) – If True, any exceptions thrown will be ignored (Useful in preventing infinite loops)
Returns: True if successful. False if not.
Return type: bool
-
static
delete_file
(file_path, ignore_errors=False)¶ Delete a file.
Parameters: - file_path (str) – The file to delete.
- ignore_errors (bool, optional) – If True, any exceptions thrown will be ignored (Useful in preventing infinite loops)
Returns: True if successful. False if not.
Return type: bool
-
static
load_from_file
(file_path, buffering=1, encoding='utf-8')¶ Load string data from a file.
Parameters: - file_path (str) – The file to read from.
- buffering (int, optional) – See the built-in python
open()
function documentation for more details. - encoding (str, optional) – See the built-in python
open()
function documentation for more details.
Returns: The contents of the file as a string or None if an error occurred.
Return type: Union[str, None]
-
static
write_to_file
(file_path, data, buffering=1, encoding='utf-8', ignore_errors=False, remove_if_exists=False)¶ Write string data to a file.
Parameters: - file_path (str) – The file to write to.
- data (str) – The data to write.
- buffering (int, optional) – See the built-in python
open()
function documentation for more details. - encoding (str, optional) – See the built-in python
open()
function documentation for more details. - ignore_errors (bool, optional) – If True, any exceptions thrown will be ignored (Useful in preventing infinite loops)
- remove_if_exists (bool, optional) – If True and the File exists already, it will be deleted before writing the data. If False and the File exists already, the data will be appended to the end of it. Default is False.
Returns: True if successful. False if not.
Return type: bool
-
static
JSON IO¶
-
class
CommonJSONIOUtils
¶ Bases:
object
Utilities for reading/writing JSON data to and from files.
-
static
load_from_file
(file_path, buffering=1, encoding='utf-8', decoder_class=None, object_hook=None)¶ Deserialize an object from a JSON file.
Parameters: - file_path – The file to read from.
- buffering (int, optional) – See the built-in python
open()
function documentation for more details. - encoding (str, optional) – See the built-in python
open()
function documentation for more details. - decoder_class (Type[JSONDecoder], optional) – Specify a custom JSON decoder class to use in place of the default deserialization. Default is None.
- object_hook (Callable[[Dict[str, Any]], Any], optional) – A callable that will be called whenever a dictionary appears while decoding JSON. It can be used to create custom objects from data. Default is None.
Type: file_path: str
Returns: The contents of the file as an object or None if an error occurred.
Return type: Union[Any, None]
-
static
load_from_folder
(folder_path, skip_file_names=(), buffering=1, encoding='utf-8', decoder_class=None, object_hook=None, on_file_read_failure=lambda *_, **__: True)¶ Deserialize objects from a folder containing JSON files.
Parameters: - folder_path – The folder to read from.
- skip_file_names (Iterator[str], optional) – A collection of file names to ignore. Default is an empty collection.
- buffering (int, optional) – See the built-in python
open()
function documentation for more details. - encoding (str, optional) – See the built-in python
open()
function documentation for more details. - decoder_class (Type[JSONDecoder], optional) – Specify a custom JSON decoder class to use in place of the default deserialization. Default is None.
- object_hook (Callable[[Dict[str, Any]], Any], optional) – A callable that will be called whenever a dictionary appears while decoding JSON. It can be used to create custom objects from data. Default is None.
- on_file_read_failure (Callable[[str, Exception], bool], optional) – When a file fails to read due to an exception, this callback will be called. If the callback returns False, no more files will be read. If the callback returns True, the rest of the files will continue to be read. Default is a callback that returns True.
Type: folder_path: str
Returns: A dictionary of the contents of each file within the specified folder organized by file name or None if the folder path does not exist.
Return type: Union[Dict[str, Any], None]
-
static
write_to_file
(file_path, obj, buffering=1, encoding='utf-8', encoder_class=None)¶ Serialize an object to a file as JSON.
Parameters: - file_path (str) – The file to write to.
- obj (Any) – The object to write as JSON.
- buffering (int, optional) – See the built-in python
open()
function documentation for more details. - encoding (str, optional) – See the built-in python
open()
function documentation for more details. - encoder_class (Type[JSONEncoder], optional) – Specify a custom JSON encoder class to use in place of the default serialization. Default is None.
Returns: True if successful. False if not.
Return type: bool
-
static
Save/Load¶
Save¶
-
class
CommonSaveUtils
¶ Bases:
object
Utilities for managing save files.
-
static
get_save_account
()¶ Retrieve the current save account.
Returns: The current save account. Returns: Any
-
static
get_save_slot
()¶ Retrieve the current save slot.
Returns: The current save slot. Returns: Any
-
static
get_save_slot_guid
()¶ Retrieve the guid identifier for the current save slot.
Returns: The GUID identifier for the current save slot. Returns: int
-
static
get_save_slot_id
()¶ Retrieve the identifier for the current save slot.
Returns: The identifier for the current save slot. Returns: int
-
static