Skip to content

Steam (planned)

Note: Not built yet. This page is a design note for a planned feature. The API below is a proposal, not part of the current engine. Names may change before release.

  • Implement the engine-side Steam layer.
  • Expose it to the C# Kolpa.Engine API.
  • Replace the proposed calls below with the real signatures.
  • Regenerate reference/ so the new types appear.

Achievements, stats, rich presence, and cloud saves, all from C#. Check that Steam is on before you call anything else. When Steam is off, the other calls do nothing.

using Kolpa.Engine;
if (Steam.IsInitialized)
{
string player = Steam.PersonaName;
string id = Steam.SteamId;
}

Steam.SteamId would return the id as a string.

Steam stays off until the game has an app id. In the project settings:

[Core]
steam_app_id = 0
title = Kolpa Game

0 leaves Steam off. That is what you want for a build that is not on Steam. Set steam_app_id to your Steam app id when you ship. If the player did not start the game from the Steam client, the engine asks Steam to relaunch it, then exits.

Note: A file named steam_appid.txt next to the executable would override steam_app_id and skip that relaunch. Use it for a local test. Leave the setting at 0.

The name is the API name from your Steam app. Unlocking would store immediately:

if (Steam.IsInitialized && !Steam.IsAchievementUnlocked("WIN_THE_GAME"))
{
Steam.SetAchievement("WIN_THE_GAME");
}

Steam.ClearAchievement("WIN_THE_GAME") would clear it, also storing at once.

Stats wait until you store them. Set the value, then call Steam.StoreStats():

if (Steam.IsInitialized)
{
int wins = Steam.GetStatInt("WINS");
Steam.SetStatInt("WINS", wins + 1);
Steam.StoreStats();
}

A wrong name or the wrong number type would be rejected, with the log naming the failed stat or achievement.

This is the line friends see. The key and value are the ones you set up for your Steam app.

if (Steam.IsInitialized)
{
Steam.SetRichPresence("status", "Playing");
}

Steam.ClearRichPresence() would clear it. The engine would also clear it on shutdown.

Cloud sync would use one folder:

Platform Saves folder
Windows Documents/My Games/<title>/game/saves/
Linux ~/.<title>/game/saves/

<title> is the title value in the project settings. title = Kolpa Game puts the folder at Documents/My Games/Kolpa Game, and saves at Documents/My Games/Kolpa Game/game/saves/.

string userRoot = AppPaths.SettingsUserPath;
string savePath = System.IO.Path.Combine(userRoot, "game", "saves", "slot_01.json");
System.IO.File.WriteAllText(savePath, json);
Steam.SyncSaves();

Steam.SyncSaves() would upload and download files in that folder. The newer file wins. The engine would also sync when Steam starts and again on shutdown.

Steam.DeleteSaveFile would take a name relative to that folder, not a full path. A subfolder would be allowed: "chapter/slot_01.json".

Note: Steam.SyncSaves() would return false when Steam is off or cloud is disabled for the app. Steam.DeleteSaveFile would still delete the local file.

Opening the Steam overlay would pause the game. Closing it resumes only if the overlay was what paused. A pause you already had stays paused.

Previous: In-game UI: HUD and menus.

Next: Debug draw: one-frame wireframes, planned.