Class ProfileService

java.lang.Object
com.csse3200.game.services.ProfileService

public class ProfileService extends Object
Service for managing user profiles.

This service provides a centralized way to manage profile operations including creating, loading, saving, and deleting profiles. It acts as a wrapper around the existing Persistence class to provide a service-based interface.

  • Constructor Details

    • ProfileService

      public ProfileService()
      Creates a new ProfileService instance.
  • Method Details

    • getProfile

      public Profile getProfile()
      Gets the current active profile.
      Returns:
      the current profile
    • getCurrentSlot

      public int getCurrentSlot()
      Gets the current slot number.
      Returns:
      the current slot (1-3), or 0 if no slot is active
    • isActive

      public boolean isActive()
      Checks if a profile is currently loaded.
      Returns:
      true if a profile is loaded, false otherwise
    • createProfile

      public void createProfile(String profileName, int slot)
      Creates a new profile with the specified name and slot.
      Parameters:
      profileName - the name for the new profile
      slot - the slot to save the profile to (1-3)
    • loadProfile

      public void loadProfile(Savefile savefile)
      Loads a profile from the specified savefile.
      Parameters:
      savefile - the savefile to load
    • saveCurrentProfile

      public void saveCurrentProfile()
      Saves the current profile to the current slot.
      Throws:
      IllegalStateException - if no profile is currently loaded
    • saveProfileToSlot

      public void saveProfileToSlot(int slot)
      Saves the current profile to a specific slot.
      Parameters:
      slot - the slot to save to (1-3)
      Throws:
      IllegalStateException - if no profile is currently loaded
      IllegalArgumentException - if slot is not between 1 and 3
    • getAllSaves

      public List<Savefile> getAllSaves()
      Gets all available savefiles organized by slot.
      Returns:
      a list of savefiles (null entries indicate empty slots)
    • getSaveFromSlot

      public Savefile getSaveFromSlot(int slot)
      Gets a specific savefile from a slot.
      Parameters:
      slot - the slot to get the savefile from (1-3)
      Returns:
      the savefile in that slot, or null if the slot is empty
      Throws:
      IllegalArgumentException - if slot is not between 1 and 3
    • clear

      public void clear()
      Clears the current profile.
    • isSlotEmpty

      public boolean isSlotEmpty(int slot)
      Checks if a slot is empty.
      Parameters:
      slot - the slot to check (1-3)
      Returns:
      true if the slot is empty, false otherwise
      Throws:
      IllegalArgumentException - if slot is not between 1 and 3
    • getUsedSlotCount

      public int getUsedSlotCount()
      Gets the number of used slots.
      Returns:
      the number of slots that contain savefiles