steamworks-js-workshop.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. diff --git a/src/api/workshop.rs b/src/api/workshop.rs
  2. index c8482ca..3046cbe 100644
  3. --- a/src/api/workshop.rs
  4. +++ b/src/api/workshop.rs
  5. @@ -7,7 +7,7 @@ pub mod workshop {
  6. use napi::threadsafe_function::ThreadsafeFunction;
  7. use napi::threadsafe_function::ThreadsafeFunctionCallMode;
  8. use std::path::Path;
  9. - use steamworks::{ClientManager, FileType, PublishedFileId, UpdateHandle};
  10. + use steamworks::{AppId, ClientManager, FileType, PublishedFileId, UpdateHandle};
  11. use tokio::sync::oneshot;
  12. #[napi(object)]
  13. @@ -108,6 +108,13 @@ pub mod workshop {
  14. pub total: BigInt,
  15. }
  16. + #[napi(object)]
  17. + pub struct UserItemVote {
  18. + pub voted_up: bool,
  19. + pub voted_down: bool,
  20. + pub vote_skipped: bool,
  21. + }
  22. +
  23. #[derive(Debug)]
  24. #[napi]
  25. pub enum UpdateStatus {
  26. @@ -320,6 +327,90 @@ pub mod workshop {
  27. }
  28. }
  29. + /// Sets the current user's vote (up or down) on a workshop item.
  30. + ///
  31. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#SetUserItemVote}
  32. + #[napi]
  33. + pub async fn vote_item(item_id: BigInt, vote_up: bool) -> Result<(), Error> {
  34. + let client = crate::client::get_client();
  35. + let (tx, rx) = oneshot::channel();
  36. +
  37. + client
  38. + .ugc()
  39. + .vote_up_item(PublishedFileId(item_id.get_u64().1), vote_up, |result| {
  40. + tx.send(result).unwrap();
  41. + });
  42. +
  43. + let result = rx.await.unwrap();
  44. + match result {
  45. + Ok(()) => Ok(()),
  46. + Err(e) => Err(Error::from_reason(e.to_string())),
  47. + }
  48. + }
  49. +
  50. + /// Adds a workshop item to the current user's favorites list.
  51. + ///
  52. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#AddItemToFavorites}
  53. + #[napi]
  54. + pub async fn add_favorite(app_id: u32, item_id: BigInt) -> Result<(), Error> {
  55. + let client = crate::client::get_client();
  56. + let (tx, rx) = oneshot::channel();
  57. +
  58. + client.ugc().add_item_to_favorites(
  59. + AppId(app_id),
  60. + PublishedFileId(item_id.get_u64().1),
  61. + |result| {
  62. + tx.send(result).unwrap();
  63. + },
  64. + );
  65. +
  66. + rx.await.unwrap().map_err(|e| Error::from_reason(e.to_string()))
  67. + }
  68. +
  69. + /// Removes a workshop item from the current user's favorites list.
  70. + ///
  71. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#RemoveItemFromFavorites}
  72. + #[napi]
  73. + pub async fn remove_favorite(app_id: u32, item_id: BigInt) -> Result<(), Error> {
  74. + let client = crate::client::get_client();
  75. + let (tx, rx) = oneshot::channel();
  76. +
  77. + client.ugc().remove_item_from_favorites(
  78. + AppId(app_id),
  79. + PublishedFileId(item_id.get_u64().1),
  80. + |result| {
  81. + tx.send(result).unwrap();
  82. + },
  83. + );
  84. +
  85. + rx.await.unwrap().map_err(|e| Error::from_reason(e.to_string()))
  86. + }
  87. +
  88. + /// Gets the current user's existing vote (if any) on a workshop item.
  89. + ///
  90. + /// {@link https://partner.steamgames.com/doc/api/ISteamUGC#GetUserItemVote}
  91. + #[napi]
  92. + pub async fn get_user_vote(item_id: BigInt) -> Result<UserItemVote, Error> {
  93. + let client = crate::client::get_client();
  94. + let (tx, rx) = oneshot::channel();
  95. +
  96. + client
  97. + .ugc()
  98. + .user_item_vote(PublishedFileId(item_id.get_u64().1), |result| {
  99. + tx.send(result).unwrap();
  100. + });
  101. +
  102. + let result = rx.await.unwrap();
  103. + match result {
  104. + Ok(v) => Ok(UserItemVote {
  105. + voted_up: v.voted_up,
  106. + voted_down: v.voted_down,
  107. + vote_skipped: v.vote_skipped,
  108. + }),
  109. + Err(e) => Err(Error::from_reason(e.to_string())),
  110. + }
  111. + }
  112. +
  113. /// Gets the current state of a workshop item on this client. States can be combined.
  114. ///
  115. /// @returns a number with the current item state, e.g. 9