Package com.misc

Class SaveControls


  • public class SaveControls
    extends java.lang.Object
    A class to store the functions required to save objects in the main game.
    Since:
    6/03/2020
    • Constructor Detail

      • SaveControls

        public SaveControls()
        Creates a new Gson instance and creates a fresh save file setting the current save to 0
    • Method Detail

      • saveGame

        public void saveGame​(int saveNumber,
                             int score,
                             int time,
                             int difficulty,
                             Firestation firestation,
                             java.util.ArrayList<ETFortress> ETFortresses)
        The one function to save the entire game in a selected file.
        Parameters:
        saveNumber - The number of the save file to store the JSON in
        score - The game score to be converted
        time - The game time to be converted
        difficulty - The game difficulty to be converted
        firestation - The firestation to be converted
        ETFortresses - The ETFortresses to be converted
      • loadFromSave

        public void loadFromSave​(int saveNumber)
        Attempts to load a save file. If it fails to open/find a save file it defaults to a new save file
        Parameters:
        saveNumber - The index of the save file to load
      • deleteSave

        public void deleteSave​(int saveNumber)
        Attempts to delete a save file. If deleting the save file in use, set the currentSaveNumber to 0 to start a new game on reload
        Parameters:
        saveNumber - The index of the save file to delete
      • getCurrentSaveNumber

        public int getCurrentSaveNumber()
        Gets the index of the save file currently used. Will be 0 if no save is loaded.
        Returns:
        The index of the save file currently loaded
      • setCurrentSaveNumber

        public void setCurrentSaveNumber​(int saveNumber)
        Sets the index of the save file currently used.
        Parameters:
        saveNumber - The index of the save file currently loaded
      • checkIfSaveEmpty

        public boolean checkIfSaveEmpty​(int saveNumber)
        Checks if a save file contains any data
        Parameters:
        saveNumber - The save number to check
        Returns:
        Whether the save file is empty (true) or not (false)
      • getSaveName

        public java.lang.String getSaveName​(int saveNumber)
        Gets the name of a save file
        Parameters:
        saveNumber - The save number to check
        Returns:
        The name of the savefile
      • setSaveName

        public void setSaveName​(int saveNumber,
                                java.lang.String name)
        Sets the name of a save file
        Parameters:
        saveNumber - The save number to change
        name - The name of the savefile
      • getSaveFile

        public SaveControls.SaveFile getSaveFile()
        Gets the current loaded save file
        Returns:
        The current savefile
      • getSavedDifficulty

        public int getSavedDifficulty()
        Gets the saved game difficulty
        Returns:
        The saved difficulty