diff options
| author | William Venner <[email protected]> | 2021-04-21 20:41:06 +0100 |
|---|---|---|
| committer | William Venner <[email protected]> | 2021-04-21 20:41:06 +0100 |
| commit | deb807d5c163c42f17540451b0189044352bea7d (patch) | |
| tree | c01ce69abbbac3c26110dfe6a10d975a03f5de25 | |
| parent | Merge pull request #45 from WilliamVenner/fix/macos_builds (diff) | |
| download | steamworks-rs-deb807d5c163c42f17540451b0189044352bea7d.tar.xz steamworks-rs-deb807d5c163c42f17540451b0189044352bea7d.zip | |
Add `Client::init_app()` which removes the need for `steam_appid.txt`
| -rw-r--r-- | src/app.rs | 5 | ||||
| -rw-r--r-- | src/lib.rs | 22 |
2 files changed, 26 insertions, 1 deletions
@@ -4,6 +4,11 @@ use super::*; #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct AppId(pub u32); +impl From<u32> for AppId { + fn from(id: u32) -> Self { + AppId(id) + } +} /// Access to the steam apps interface pub struct Apps<Manager> { @@ -119,7 +119,8 @@ impl Client<ClientManager> { /// /// If the game isn't being run through steam this can be provided by /// placing a `steam_appid.txt` with the ID inside in the current - /// working directory + /// working directory. Alternatively, you can use `Client::init_app(<app_id>)` + /// to force a specific app ID. /// * The game isn't running on the same user/level as the steam client /// * The user doesn't own a license for the game. /// * The app ID isn't completely set up. @@ -147,6 +148,25 @@ impl Client<ClientManager> { })) } } + + /// Attempts to initialize the steamworks api **for a specified app ID** + /// and returns a client to access the rest of the api. + /// + /// This should only ever have one instance per a program. + /// + /// # Errors + /// + /// This can fail if: + /// * The steam client isn't running + /// * The game isn't running on the same user/level as the steam client + /// * The user doesn't own a license for the game. + /// * The app ID isn't completely set up. + pub fn init_app<ID: Into<AppId>>(app_id: ID) -> SResult<(Client<ClientManager>, SingleClient<ClientManager>)> { + let app_id = app_id.into().0.to_string(); + std::env::set_var("SteamAppId", &app_id); + std::env::set_var("SteamGameId", app_id); + Client::init() + } } impl <M> SingleClient<M> where M: Manager { /// Runs any currently pending callbacks |