Package com.csse3200.game.services
Class ProfileService
java.lang.Object
com.csse3200.game.services.ProfileService
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the current profile.void
createProfile
(String profileName, int slot) Creates a new profile with the specified name and slot.Gets all available savefiles organized by slot.int
Gets the current slot number.Gets the current active profile.getSaveFromSlot
(int slot) Gets a specific savefile from a slot.int
Gets the number of used slots.boolean
isActive()
Checks if a profile is currently loaded.boolean
isSlotEmpty
(int slot) Checks if a slot is empty.void
loadProfile
(Savefile savefile) Loads a profile from the specified savefile.void
Saves the current profile to the current slot.void
saveProfileToSlot
(int slot) Saves the current profile to a specific slot.
-
Constructor Details
-
ProfileService
public ProfileService()Creates a new ProfileService instance.
-
-
Method Details
-
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
Creates a new profile with the specified name and slot.- Parameters:
profileName
- the name for the new profileslot
- the slot to save the profile to (1-3)
-
loadProfile
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 loadedIllegalArgumentException
- if slot is not between 1 and 3
-
getAllSaves
Gets all available savefiles organized by slot.- Returns:
- a list of savefiles (null entries indicate empty slots)
-
getSaveFromSlot
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
-