Class TCastleSteam

Unit

Declaration

type TCastleSteam = class(TObject)

Description

Integration with Steam. See Steam and Castle Game Engine documentation for usage. Create an instance of this class (passing to the constructor the Steam application id), observe properties like Enabled and UserStatsReceived, and call methods like SetAchievement to interact with Steam API.

Hierarchy

  • TObject
  • TCastleSteam

Overview

Methods

Public constructor Create(const AAppId: TAppId);
Public destructor Destroy; override;
Public procedure SetAchievement(const AchievementId: String);
Public function GetAchievement(const AchievementId: String): Boolean;
Public procedure ClearAchievement(const AchievementId: String);
Public procedure ClearAllAchievements;
Public procedure IndicateAchievementProgress(const AchievementId: String; const CurrentProgress, MaxProgress: UInt32);
Public function Country: String;
Public function OverlayEnabled: Boolean;
Public function RunningInVR: Boolean;
Public function RunningOnSteamDeck: Boolean;
Public function BuildId: Integer;
Public function DlcInstalled(const DlcAppID: TAppId): Boolean;
Public function Language: String;

Properties

Public property AppId: TAppId read FAppId;
Public property Enabled: Boolean read FEnabled;
Public property Achievements: TStrings read FAchievements;
Public property UserStatsReceived: Boolean read FUserStatsReceived;
Public property OnUserStatsReceived: TNotifyEvent read FOnUserStatsReceived write FOnUserStatsReceived;

Description

Methods

Public constructor Create(const AAppId: TAppId);

Connect to Steam and initialize everything.

  1. It tries to connect to Steam API and checks if the game was run through Steam or through exe file.

    In the latter case the game will automatically restart through Steam. See Steam and Castle Game Engine documentation for a description how does the Steam integration behave, when it restarts the game.

  2. Will request user stats from Steam.

    Only once user stats are received, you can use achievements. Observe UserStatsReceived or use event OnUserStatsReceived to know when it happens.

Public destructor Destroy; override;

This item has no description.

Public procedure SetAchievement(const AchievementId: String);

Set achievement as "achieved", Steam will automatically show a small overlay indicating that the achievement is obtained.

Public function GetAchievement(const AchievementId: String): Boolean;

Is this achievement "achieved".

Public procedure ClearAchievement(const AchievementId: String);

Set achievement as "not achieved". Should not be necessary for normal usage (the convention is that once users achieve something, it stays achieved forever). But this is useful for testing purposes – you may want to clear own achievements during testing.

Public procedure ClearAllAchievements;

Clears all achievements from the connected user.

See also
ClearAchievement
Set achievement as "not achieved".
Public procedure IndicateAchievementProgress(const AchievementId: String; const CurrentProgress, MaxProgress: UInt32);

Show Steam overlay "progress towards achievement" e.g. "Wins 33/100".

Don't use this when achievement is already achieved. Doing so will only result in an error from Steam, visible as a warning in logs: "Failed to SteamAPI_ISteamUserStats_IndicateAchievementProgress".

Calling this with CurrentProgress >= MaxProgress does not mark the achievement as achieved. It only shows the progress in the overlay. You still have to call SetAchievement to make it achieved.

Public function Country: String;

2 digit ISO 3166-1-alpha-2 format country code this client is running in (as looked up via an IP-to-location database) e.g "US" or "UK".

Public function OverlayEnabled: Boolean;

Is the Steam overlay running and the user can access it. The overlay process could take a few seconds to start & hook the game process, so this function will initially return false while the overlay is loading.

Public function RunningInVR: Boolean;

Is Steam running in VR mode.

Public function RunningOnSteamDeck: Boolean;

Is currently running on the Steam Deck device.

Public function BuildId: Integer;

Build id of this app.

Public function DlcInstalled(const DlcAppID: TAppId): Boolean;

Checks if the user owns the DLC and if the DLC is installed.

Public function Language: String;

Current game language.

Properties

Public property AppId: TAppId read FAppId;

Steam application id, given when creating this.

Public property Enabled: Boolean read FEnabled;

Do we have Steam integration available.

If True, this means that Steam dynamic library was found, and we don't need to restart the application. See https://castle-engine.io/steam for more information.

This is the normal state of things when the game is run through Steam. It means that all features of this class work as they should.

Public property Achievements: TStrings read FAchievements;

Achievement names for this game (read-only). These are IDs of achievements, can be used in other calls like SetAchievement or GetAchievement. This field is initialized when UserStatsReceived becomes True, it is Nil before.

Public property UserStatsReceived: Boolean read FUserStatsReceived;

Have we received user stats from Steam. Before this is True, methods of this class dealing with user stats (like achievements) don't do anything.

Public property OnUserStatsReceived: TNotifyEvent read FOnUserStatsReceived write FOnUserStatsReceived;

We have received user stats from Steam. Right before calling this event, UserStatsReceived changed to True and Achievements have been filled with achievement names. From now on you can use Steam features that depend on it, like Achievements.


Generated by PasDoc 0.16.0-snapshot.