steamworks-rs-ugc.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. diff --git a/src/ugc.rs b/src/ugc.rs
  2. index 653ab11..bb93239 100644
  3. --- a/src/ugc.rs
  4. +++ b/src/ugc.rs
  5. @@ -517,6 +517,14 @@ pub struct InstallInfo {
  6. pub timestamp: u32,
  7. }
  8. +#[derive(Clone, Copy, Debug)]
  9. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
  10. +pub struct UserItemVote {
  11. + pub voted_up: bool,
  12. + pub voted_down: bool,
  13. + pub vote_skipped: bool,
  14. +}
  15. +
  16. impl<Manager> UGC<Manager> {
  17. /// Suspends or resumes all workshop downloads
  18. pub fn suspend_downloads(&self, suspend: bool) {
  19. @@ -617,6 +625,114 @@ impl<Manager> UGC<Manager> {
  20. }
  21. }
  22. + /// Sets the current user's vote (up or down) on a workshop item.
  23. + ///
  24. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#SetUserItemVote}
  25. + pub fn vote_up_item<F>(&self, published_file_id: PublishedFileId, vote_up: bool, cb: F)
  26. + where
  27. + F: FnOnce(Result<(), SteamError>) + 'static + Send,
  28. + {
  29. + unsafe {
  30. + let api_call =
  31. + sys::SteamAPI_ISteamUGC_SetUserItemVote(self.ugc, published_file_id.0, vote_up);
  32. + register_call_result::<sys::SetUserItemVoteResult_t, _, _>(
  33. + &self.inner,
  34. + api_call,
  35. + CALLBACK_BASE_ID + 8,
  36. + move |v, io_error| {
  37. + cb(if io_error {
  38. + Err(SteamError::IOFailure)
  39. + } else if v.m_eResult != sys::EResult::k_EResultOK {
  40. + Err(v.m_eResult.into())
  41. + } else {
  42. + Ok(())
  43. + })
  44. + },
  45. + );
  46. + }
  47. + }
  48. +
  49. + /// Adds a workshop item to the current user's favorites list.
  50. + ///
  51. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#AddItemToFavorites}
  52. + pub fn add_item_to_favorites<F>(&self, app_id: AppId, published_file_id: PublishedFileId, cb: F)
  53. + where
  54. + F: FnOnce(Result<(), SteamError>) + 'static + Send,
  55. + {
  56. + unsafe {
  57. + let api_call =
  58. + sys::SteamAPI_ISteamUGC_AddItemToFavorites(self.ugc, app_id.0, published_file_id.0);
  59. + self.register_favorites_result(api_call, cb);
  60. + }
  61. + }
  62. +
  63. + /// Removes a workshop item from the current user's favorites list.
  64. + ///
  65. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#RemoveItemFromFavorites}
  66. + pub fn remove_item_from_favorites<F>(&self, app_id: AppId, published_file_id: PublishedFileId, cb: F)
  67. + where
  68. + F: FnOnce(Result<(), SteamError>) + 'static + Send,
  69. + {
  70. + unsafe {
  71. + let api_call = sys::SteamAPI_ISteamUGC_RemoveItemFromFavorites(
  72. + self.ugc,
  73. + app_id.0,
  74. + published_file_id.0,
  75. + );
  76. + self.register_favorites_result(api_call, cb);
  77. + }
  78. + }
  79. +
  80. + unsafe fn register_favorites_result<F>(&self, api_call: sys::SteamAPICall_t, cb: F)
  81. + where
  82. + F: FnOnce(Result<(), SteamError>) + 'static + Send,
  83. + {
  84. + register_call_result::<sys::UserFavoriteItemsListChanged_t, _, _>(
  85. + &self.inner,
  86. + api_call,
  87. + CALLBACK_BASE_ID + 7,
  88. + move |v, io_error| {
  89. + cb(if io_error {
  90. + Err(SteamError::IOFailure)
  91. + } else if v.m_eResult != sys::EResult::k_EResultOK {
  92. + Err(v.m_eResult.into())
  93. + } else {
  94. + Ok(())
  95. + })
  96. + },
  97. + );
  98. + }
  99. +
  100. + /// Gets the current user's existing vote (if any) on a workshop item.
  101. + ///
  102. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetUserItemVote}
  103. + pub fn user_item_vote<F>(&self, published_file_id: PublishedFileId, cb: F)
  104. + where
  105. + F: FnOnce(Result<UserItemVote, SteamError>) + 'static + Send,
  106. + {
  107. + unsafe {
  108. + let api_call = sys::SteamAPI_ISteamUGC_GetUserItemVote(self.ugc, published_file_id.0);
  109. + register_call_result::<sys::GetUserItemVoteResult_t, _, _>(
  110. + &self.inner,
  111. + api_call,
  112. + CALLBACK_BASE_ID + 9,
  113. + move |v, io_error| {
  114. + cb(if io_error {
  115. + Err(SteamError::IOFailure)
  116. + } else if v.m_eResult != sys::EResult::k_EResultOK {
  117. + Err(v.m_eResult.into())
  118. + } else {
  119. + Ok(UserItemVote {
  120. + voted_up: v.m_bVotedUp,
  121. + voted_down: v.m_bVotedDown,
  122. + vote_skipped: v.m_bVoteSkipped,
  123. + })
  124. + })
  125. + },
  126. + );
  127. + }
  128. + }
  129. +
  130. /// Gets the publisher file IDs of all currently subscribed items.
  131. pub fn subscribed_items(&self) -> Vec<PublishedFileId> {
  132. unsafe {