steamworks-rs-ugc.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --- a/src/ugc.rs 2026-09-18 16:42:37.405700424 +0000
  2. +++ b/src/ugc.rs 2026-09-18 16:42:37.406700437 +0000
  3. @@ -517,6 +517,14 @@
  4. pub timestamp: u32,
  5. }
  6. +#[derive(Clone, Copy, Debug)]
  7. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
  8. +pub struct UserItemVote {
  9. + pub voted_up: bool,
  10. + pub voted_down: bool,
  11. + pub vote_skipped: bool,
  12. +}
  13. +
  14. impl<Manager> UGC<Manager> {
  15. /// Suspends or resumes all workshop downloads
  16. pub fn suspend_downloads(&self, suspend: bool) {
  17. @@ -614,6 +622,63 @@
  18. })
  19. },
  20. );
  21. + }
  22. + }
  23. +
  24. + /// Sets the current user's vote (up or down) on a workshop item.
  25. + ///
  26. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#SetUserItemVote}
  27. + pub fn vote_up_item<F>(&self, published_file_id: PublishedFileId, vote_up: bool, cb: F)
  28. + where
  29. + F: FnOnce(Result<(), SteamError>) + 'static + Send,
  30. + {
  31. + unsafe {
  32. + let api_call =
  33. + sys::SteamAPI_ISteamUGC_SetUserItemVote(self.ugc, published_file_id.0, vote_up);
  34. + register_call_result::<sys::SetUserItemVoteResult_t, _, _>(
  35. + &self.inner,
  36. + api_call,
  37. + CALLBACK_BASE_ID + 8,
  38. + move |v, io_error| {
  39. + cb(if io_error {
  40. + Err(SteamError::IOFailure)
  41. + } else if v.m_eResult != sys::EResult::k_EResultOK {
  42. + Err(v.m_eResult.into())
  43. + } else {
  44. + Ok(())
  45. + })
  46. + },
  47. + );
  48. + }
  49. + }
  50. +
  51. + /// Gets the current user's existing vote (if any) on a workshop item.
  52. + ///
  53. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetUserItemVote}
  54. + pub fn user_item_vote<F>(&self, published_file_id: PublishedFileId, cb: F)
  55. + where
  56. + F: FnOnce(Result<UserItemVote, SteamError>) + 'static + Send,
  57. + {
  58. + unsafe {
  59. + let api_call = sys::SteamAPI_ISteamUGC_GetUserItemVote(self.ugc, published_file_id.0);
  60. + register_call_result::<sys::GetUserItemVoteResult_t, _, _>(
  61. + &self.inner,
  62. + api_call,
  63. + CALLBACK_BASE_ID + 9,
  64. + move |v, io_error| {
  65. + cb(if io_error {
  66. + Err(SteamError::IOFailure)
  67. + } else if v.m_eResult != sys::EResult::k_EResultOK {
  68. + Err(v.m_eResult.into())
  69. + } else {
  70. + Ok(UserItemVote {
  71. + voted_up: v.m_bVotedUp,
  72. + voted_down: v.m_bVotedDown,
  73. + vote_skipped: v.m_bVoteSkipped,
  74. + })
  75. + })
  76. + },
  77. + );
  78. }
  79. }