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.EngineAPI. - Replace the proposed calls below with the real signatures.
- Regenerate
reference/so the new types appear.
What it would cover
Section titled “What it would cover”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.
App id
Section titled “App id”Steam stays off until the game has an app id. In the project settings:
[Core]steam_app_id = 0title = Kolpa Game0 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.txtnext to the executable would overridesteam_app_idand skip that relaunch. Use it for a local test. Leave the setting at0.
Achievements and stats
Section titled “Achievements and stats”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.
Rich presence
Section titled “Rich presence”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 saves
Section titled “Cloud saves”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.DeleteSaveFilewould still delete the local file.
Overlay
Section titled “Overlay”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.
Continue reading
Section titled “Continue reading”Previous: In-game UI: HUD and menus.
Next: Debug draw: one-frame wireframes, planned.
