Steam
Steamworks from Balaur Script: the steam modules in every desktop build, a game that runs without Steam, balaur export --steam, and callbacks.
Every desktop build of the engine has Steam in it, and so does the editor.
Valve's Steamworks SDK is loaded at run time, from the steam_api library
beside the game, when the Steam client runs it.
- Without that library or the client, the game runs as before. Every
steam_*call answers nil, and a call that answers later answersunsupported. steam::is_loaded()says which case you are in.- Where Steam is loaded,
platform::sign_inandplatform::identityanswer through it. Platform services says what answers each call elsewhere.
The modules
Each Steamworks interface is a module: Valve's method names in snake case.
SteamUser()->GetSteamID() is steam_user::get_steam_id(), and
SteamUserStats()->GetAchievement is steam_user_stats::get_achievement.
The script modules reference lists every one.
steamholdsis_loaded, Valve's enums and constants under their own names, and theEVENT_*kinds.- A call Valve answers later returns an id.
task::waiton it answers a map whosekindis anEVENT_*constant, with the callback's fields andfailed. - Callbacks nobody asked for arrive as the
steam_eventevent, on a node that calledevents::listen(node, "steam_event").
// scripts/steam_hooks.bs
pub class SteamHooks {
node: Node,
}
impl SteamHooks {
pub async fn init() {
if !steam::is_loaded() {
log::info("no Steam here; the game plays on without it");
return;
}
events::listen(self.node, "steam_event");
let name = steam_friends::get_persona_name().or("player");
log::info("playing as {name}");
let first = steam_user_stats::get_achievement("ACH_FIRST_RUN");
if first != nil && !first.unwrap().achieved {
steam_user_stats::set_achievement("ACH_FIRST_RUN");
steam_user_stats::set_stat_int32("runs", 1);
steam_user_stats::store_stats();
}
let count = await task::wait(steam_user_stats::get_number_of_current_players());
if count["kind"].as_str() == steam::EVENT_NUMBER_OF_CURRENT_PLAYERS {
log::info("{count["players"]} playing now");
}
}
pub fn on_steam_event(e: any) {
if e["kind"].as_str() == steam::EVENT_USER_STATS_STORED {
log::info("stats stored");
}
}
}
Exporting for Steam
A plain export ships no Valve file. A Steam build is the same export with one flag:
balaur export . --target windows-x64 --steam
-
--steamcopies Valve'ssteam_apibeside the game, insideContents/MacOSin a.app, signed there with the game's identity. -
It needs the AppID Steamworks gave the game, in
project.toml:[steam] app_id = 480 -
--steam --devalso writes the AppID tosteam_appid.txtbeside the game, so it starts without the Steam client. A release leaves it out: the client names the app.
Steam takes 64-bit Windows, macOS and 64-bit Linux. Forge builds the Steam build beside the plain one and uploads it to your depots; see the Forge Steam guide.