Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ napi = { version = "2.16.8", features = ["tokio_rt", "napi6", "serde-json"] }
napi-derive = "2.16.9"
lazy_static = "1"
tokio = { version = "1", features = ["sync", "time"] }
steamworks = { git = "https://github.com/Noxime/steamworks-rs/", rev = "40a457a61f5ef714d93804e51e0c5e3d405145a3", features = ["serde"] }
steamworks = { path = "../steamworks-rs", features = ["serde"] }
serde = "1"
serde_json = "1"

Expand Down
34 changes: 34 additions & 0 deletions client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,38 @@ export declare namespace workshop {
export function getItems(items: Array<bigint>, queryConfig?: WorkshopItemQueryConfig | undefined | null): Promise<WorkshopItemsResult>
export function getAllItems(page: number, queryType: UGCQueryType, itemType: UGCType, creatorAppId: number, consumerAppId: number, queryConfig?: WorkshopItemQueryConfig | undefined | null): Promise<WorkshopPaginatedResult>
export function getUserItems(page: number, accountId: number, listType: UserListType, itemType: UGCType, sortOrder: UserListOrder, appIds: AppIDs, queryConfig?: WorkshopItemQueryConfig | undefined | null): Promise<WorkshopPaginatedResult>
/**
* Start tracking playtime on a set of workshop items.
*
* When your app shuts down, playtime tracking will automatically stop.
*
* @param itemIds - The array of workshop items you want to start tracking. (Maximum of 100 items.)
* @returns Promise that resolves when the operation completes
*
* {@link https://partner.steamgames.com/doc/api/ISteamUGC#StartPlaytimeTracking}
*/
export function startPlaytimeTracking(itemIds: Array<bigint>): Promise<void>
/**
* Stop tracking playtime on a set of workshop items.
*
* This will increment the number of "playtime" sessions for those items by one.
* When your app shuts down, playtime tracking will automatically stop.
*
* @param itemIds - The array of workshop items you want to stop tracking. (Maximum of 100 items.)
* @returns Promise that resolves when the operation completes
*
* {@link https://partner.steamgames.com/doc/api/ISteamUGC#StopPlaytimeTracking}
*/
export function stopPlaytimeTracking(itemIds: Array<bigint>): Promise<void>
/**
* Stop tracking playtime of all workshop items.
*
* When your app shuts down, playtime tracking will automatically stop.
* This will increment the number of "playtime" sessions for all items that were being tracked by one.
*
* @returns Promise that resolves when the operation completes
*
* {@link https://partner.steamgames.com/doc/api/ISteamUGC#StopPlaytimeTrackingForAllItems}
*/
export function stopPlaytimeTrackingForAllItems(): Promise<void>
}
1 change: 1 addition & 0 deletions src/api/friends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub mod friends {
steamworks::FriendState::Snooze => PersonaState::Snooze,
steamworks::FriendState::LookingToTrade => PersonaState::LookingToTrade,
steamworks::FriendState::LookingToPlay => PersonaState::LookingToPlay,
steamworks::FriendState::Invisible => PersonaState::Invisible,
},
game_played: f.game_played().map(|g| FriendGameInfo {
game_id: BigInt::from(g.game.raw()),
Expand Down
227 changes: 110 additions & 117 deletions src/api/workshop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,121 +424,114 @@ pub mod workshop {
}
}

// TODO: Uncomment these methods once the steamworks-rs PR is merged
// PR: https://github.com/Noxime/steamworks-rs/pull/297
// These methods require start_playtime_tracking, stop_playtime_tracking, and
// stop_playtime_tracking_for_all_items to be added to the steamworks-rs UGC API

// /// Start tracking playtime on a set of workshop items.
// ///
// /// When your app shuts down, playtime tracking will automatically stop.
// ///
// /// @param itemIds - The array of workshop items you want to start tracking. (Maximum of 100 items.)
// /// @returns Promise that resolves when the operation completes
// ///
// /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#StartPlaytimeTracking}
// #[napi]
// pub async fn start_playtime_tracking(item_ids: Vec<BigInt>) -> Result<(), Error> {
// if item_ids.is_empty() {
// return Err(Error::from_reason(
// "item_ids must contain at least 1 item".to_string(),
// ));
// }
//
// if item_ids.len() > 100 {
// return Err(Error::from_reason(
// "item_ids must not contain more than 100 items".to_string(),
// ));
// }
//
// let client = crate::client::get_client();
// let (tx, rx) = oneshot::channel();
//
// let published_file_ids: Vec<PublishedFileId> = item_ids
// .iter()
// .map(|id| PublishedFileId(id.get_u64().1))
// .collect();
//
// client
// .ugc()
// .start_playtime_tracking(&published_file_ids, |result| {
// tx.send(result).unwrap();
// });
//
// let result = rx.await.unwrap();
// match result {
// Ok(()) => Ok(()),
// Err(e) => Err(Error::from_reason(e.to_string())),
// }
// }

// /// Stop tracking playtime on a set of workshop items.
// ///
// /// This will increment the number of "playtime" sessions for those items by one.
// /// When your app shuts down, playtime tracking will automatically stop.
// ///
// /// @param itemIds - The array of workshop items you want to stop tracking. (Maximum of 100 items.)
// /// @returns Promise that resolves when the operation completes
// ///
// /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#StopPlaytimeTracking}
// #[napi]
// pub async fn stop_playtime_tracking(item_ids: Vec<BigInt>) -> Result<(), Error> {
// if item_ids.is_empty() {
// return Err(Error::from_reason(
// "item_ids must contain at least 1 item".to_string(),
// ));
// }
//
// if item_ids.len() > 100 {
// return Err(Error::from_reason(
// "item_ids must not contain more than 100 items".to_string(),
// ));
// }
//
// let client = crate::client::get_client();
// let (tx, rx) = oneshot::channel();
//
// let published_file_ids: Vec<PublishedFileId> = item_ids
// .iter()
// .map(|id| PublishedFileId(id.get_u64().1))
// .collect();
//
// client
// .ugc()
// .stop_playtime_tracking(&published_file_ids, |result| {
// tx.send(result).unwrap();
// });
//
// let result = rx.await.unwrap();
// match result {
// Ok(()) => Ok(()),
// Err(e) => Err(Error::from_reason(e.to_string())),
// }
// }

// /// Stop tracking playtime of all workshop items.
// ///
// /// When your app shuts down, playtime tracking will automatically stop.
// /// This will increment the number of "playtime" sessions for all items that were being tracked by one.
// ///
// /// @returns Promise that resolves when the operation completes
// ///
// /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#StopPlaytimeTrackingForAllItems}
// #[napi]
// pub async fn stop_playtime_tracking_for_all_items() -> Result<(), Error> {
// let client = crate::client::get_client();
// let (tx, rx) = oneshot::channel();
//
// client
// .ugc()
// .stop_playtime_tracking_for_all_items(|result| {
// tx.send(result).unwrap();
// });
//
// let result = rx.await.unwrap();
// match result {
// Ok(()) => Ok(()),
// Err(e) => Err(Error::from_reason(e.to_string())),
// }
// }
/// Start tracking playtime on a set of workshop items.
///
/// When your app shuts down, playtime tracking will automatically stop.
///
/// @param itemIds - The array of workshop items you want to start tracking. (Maximum of 100 items.)
/// @returns Promise that resolves when the operation completes
///
/// {@link https://partner.steamgames.com/doc/api/ISteamUGC#StartPlaytimeTracking}
#[napi]
pub async fn start_playtime_tracking(item_ids: Vec<BigInt>) -> Result<(), Error> {
if item_ids.is_empty() {
return Err(Error::from_reason(
"item_ids must contain at least 1 item".to_string(),
));
}

if item_ids.len() > 100 {
return Err(Error::from_reason(
"item_ids must not contain more than 100 items".to_string(),
));
}

let client = crate::client::get_client();
let (tx, rx) = oneshot::channel();

let published_file_ids: Vec<PublishedFileId> = item_ids
.iter()
.map(|id| PublishedFileId(id.get_u64().1))
.collect();

client
.ugc()
.start_playtime_tracking(&published_file_ids, |result| {
tx.send(result).unwrap();
});

let result = rx.await.unwrap();
match result {
Ok(()) => Ok(()),
Err(e) => Err(Error::from_reason(e.to_string())),
}
}

/// Stop tracking playtime on a set of workshop items.
///
/// This will increment the number of "playtime" sessions for those items by one.
/// When your app shuts down, playtime tracking will automatically stop.
///
/// @param itemIds - The array of workshop items you want to stop tracking. (Maximum of 100 items.)
/// @returns Promise that resolves when the operation completes
///
/// {@link https://partner.steamgames.com/doc/api/ISteamUGC#StopPlaytimeTracking}
#[napi]
pub async fn stop_playtime_tracking(item_ids: Vec<BigInt>) -> Result<(), Error> {
if item_ids.is_empty() {
return Err(Error::from_reason(
"item_ids must contain at least 1 item".to_string(),
));
}

if item_ids.len() > 100 {
return Err(Error::from_reason(
"item_ids must not contain more than 100 items".to_string(),
));
}

let client = crate::client::get_client();
let (tx, rx) = oneshot::channel();

let published_file_ids: Vec<PublishedFileId> = item_ids
.iter()
.map(|id| PublishedFileId(id.get_u64().1))
.collect();

client
.ugc()
.stop_playtime_tracking(&published_file_ids, |result| {
tx.send(result).unwrap();
});

let result = rx.await.unwrap();
match result {
Ok(()) => Ok(()),
Err(e) => Err(Error::from_reason(e.to_string())),
}
}

/// Stop tracking playtime of all workshop items.
///
/// When your app shuts down, playtime tracking will automatically stop.
/// This will increment the number of "playtime" sessions for all items that were being tracked by one.
///
/// @returns Promise that resolves when the operation completes
///
/// {@link https://partner.steamgames.com/doc/api/ISteamUGC#StopPlaytimeTrackingForAllItems}
#[napi]
pub async fn stop_playtime_tracking_for_all_items() -> Result<(), Error> {
let client = crate::client::get_client();
let (tx, rx) = oneshot::channel();

client.ugc().stop_playtime_tracking_for_all_items(|result| {
tx.send(result).unwrap();
});

let result = rx.await.unwrap();
match result {
Ok(()) => Ok(()),
Err(e) => Err(Error::from_reason(e.to_string())),
}
}
}
Loading