Class GameServices
java.lang.Object
com.codename1.gaming.GameServices
The gaming platform the application runs under: achievements, stats, cloud saves, the signed in player and their presence.
One API for every platform. The first backend is Steam (the steam build
target); others plug in behind the same calls. Everything here is safe to
call everywhere: with no platform, or one that has not connected,
#isAvailable() is false and every call does nothing and answers its
default, so a game needs no platform checks around it.
GameServices.unlockAchievement("FIRST_WIN");
GameServices.setStat("wins", GameServices.getStatInt("wins", 0) + 1);
GameServices.commit();
Identifiers are the ones configured with the platform (on Steam, the API names entered in the Steamworks partner site).
Pausing. Register a GameServicesListener to hear when the platform's
own interface (the Steam overlay) opens over the game; pause while it is up.
Call from the EDT.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidRegisters a listener.static booleanClears every presence value.static booleancommit()Sends achievement and stat changes to the platform.static booleandeleteSave(String name) Deletes a cloud save.static voidfirePlatformUIChanged(boolean shown) Tells listeners the platform's interface opened or closed.static StringThe language the player chose for the game on the platform, as the platform names it (Steam:"english","german"...), or an empty string.static StringThe platform name ("steam"), or an empty string when there is none.static StringThe player's stable platform id (a Steam id, for instance), or an empty string.static StringThe player's display name, or an empty string.static floatgetStatFloat(String id, float def) A float stat, ordefwhen unknown.static intgetStatInt(String id, int def) An integer stat, ordefwhen unknown.static booleanWhether a cloud save exists.static booleanWhether an achievement is unlocked.static booleanTrue when a gaming platform is connected and a player signed in.static booleanWhether saves are synced through the platform for this player.static booleanTrue when the player is on a controller-first interface (a Steam Deck, Steam's Big Picture / Gaming Mode): size touch targets and text for it and expect no mouse.static booleanopenPlatformUI(String target) Opens the platform's own interface over the game.static booleanownsContent(String id) Whether the player owns an add-on (on Steam, a DLC app id).static byte[]Reads a cloud save, or null when there is none.static voidUnregisters a listener.static booleanLocks an achievement again, for testing; platforms may refuse it outside development builds.static voidInstalls the platform backend.static booleansetPresence(String key, String value) Sets what friends see the player doing.static booleanSets a float stat.static booleanSets an integer stat.static booleanUnlocks an achievement.static booleanWrites a cloud save, replacing one with the same name.
-
Method Details
-
setBackend
Installs the platform backend. Called by ports. -
getPlatformName
The platform name ("steam"), or an empty string when there is none. -
isAvailable
public static boolean isAvailable()True when a gaming platform is connected and a player signed in. -
getPlayerId
The player's stable platform id (a Steam id, for instance), or an empty string. -
getPlayerName
The player's display name, or an empty string. -
unlockAchievement
Unlocks an achievement. Platforms show their own notification. Persisted by#commit(). -
resetAchievement
Locks an achievement again, for testing; platforms may refuse it outside development builds. -
isAchievementUnlocked
Whether an achievement is unlocked. -
getStatInt
An integer stat, ordefwhen unknown. -
setStat
Sets an integer stat. Persisted by#commit(). -
getStatFloat
A float stat, ordefwhen unknown. -
setStat
Sets a float stat. Persisted by#commit(). -
commit
public static boolean commit()Sends achievement and stat changes to the platform. Call it at natural points (end of a level), not every frame: platforms rate limit it. -
isCloudSaveAvailable
public static boolean isCloudSaveAvailable()Whether saves are synced through the platform for this player. -
writeSave
Writes a cloud save, replacing one with the same name. -
readSave
Reads a cloud save, or null when there is none. -
hasSave
Whether a cloud save exists. -
deleteSave
Deletes a cloud save. -
setPresence
-
clearPresence
public static boolean clearPresence()Clears every presence value. -
ownsContent
Whether the player owns an add-on (on Steam, a DLC app id). -
openPlatformUI
Opens the platform's own interface over the game.targetnames a page: on Steam one of the overlay dialogs ("friends","achievements","stats","community","settings") or anhttps://URL. Answers false when the platform has no such interface. -
isControllerFirst
public static boolean isControllerFirst()True when the player is on a controller-first interface (a Steam Deck, Steam's Big Picture / Gaming Mode): size touch targets and text for it and expect no mouse. -
getLanguage
The language the player chose for the game on the platform, as the platform names it (Steam:"english","german"...), or an empty string. -
addListener
Registers a listener. -
removeListener
Unregisters a listener. -
firePlatformUIChanged
public static void firePlatformUIChanged(boolean shown) Tells listeners the platform's interface opened or closed. Called by backends, on the EDT.
-