An unofficial collection of APIs used in FreeJam games and mods
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

257 lines
8.5KB

  1. use serde::{Deserialize, Serialize};
  2. // list endpoint
  3. #[derive(Deserialize, Serialize, Clone)]
  4. pub(crate) struct ListPayload {
  5. #[serde(rename = "page")]
  6. pub page: isize,
  7. #[serde(rename = "pageSize")]
  8. pub page_size: isize,
  9. #[serde(rename = "order")]
  10. pub order: isize,
  11. #[serde(rename = "playerFilter")]
  12. pub player_filter: bool,
  13. #[serde(rename = "movementFilter")]
  14. pub movement_filter: String, // csv int enums as str
  15. #[serde(rename = "movementCategoryFilter")]
  16. pub movement_category_filter: String, // csv int enums as str
  17. #[serde(rename = "weaponFilter")]
  18. pub weapon_filter: String, // csv int enums as str
  19. #[serde(rename = "weaponCategoryFilter")]
  20. pub weapon_category_filter: String, // csv int enums as str
  21. #[serde(rename = "minimumCpu")]
  22. pub minimum_cpu: isize,
  23. #[serde(rename = "maximumCpu")]
  24. pub maximum_cpu: isize,
  25. #[serde(rename = "textFilter")]
  26. pub text_filter: String,
  27. #[serde(rename = "textSearchField")]
  28. pub text_search_field: isize, // ???
  29. #[serde(rename = "buyable")]
  30. pub buyable: bool,
  31. #[serde(rename = "prependFeaturedRobot")]
  32. pub prepend_featured_robot: bool,
  33. #[serde(rename = "featuredOnly")]
  34. pub featured_only: bool,
  35. #[serde(rename = "defaultPage")]
  36. pub default_page: bool,
  37. }
  38. impl ListPayload {
  39. pub fn default() -> ListPayload {
  40. ListPayload {
  41. page: 1,
  42. page_size: 100,
  43. order: 0,
  44. player_filter: false,
  45. movement_filter: "100000,200000,300000,400000,500000,600000,700000,800000,900000,1000000,1100000,1200000".to_string(),
  46. movement_category_filter: "100000,200000,300000,400000,500000,600000,700000,800000,900000,1000000,1100000,1200000".to_string(),
  47. weapon_filter: "10000000,20000000,25000000,30000000,40000000,50000000,60000000,65000000,70100000,75000000".to_string(),
  48. weapon_category_filter: "10000000,20000000,25000000,30000000,40000000,50000000,60000000,65000000,70100000,75000000".to_string(),
  49. minimum_cpu: -1,
  50. maximum_cpu: -1,
  51. text_filter: "".to_string(),
  52. text_search_field: 0,
  53. buyable: true,
  54. prepend_featured_robot: false,
  55. featured_only: false,
  56. default_page: true,
  57. }
  58. }
  59. pub fn empty() -> ListPayload {
  60. ListPayload {
  61. page: 1,
  62. page_size: 100,
  63. order: 0,
  64. player_filter: false,
  65. movement_filter: "".to_string(),
  66. movement_category_filter: "".to_string(),
  67. weapon_filter: "".to_string(),
  68. weapon_category_filter: "".to_string(),
  69. minimum_cpu: -1,
  70. maximum_cpu: -1,
  71. text_filter: "".to_string(),
  72. text_search_field: 0,
  73. buyable: true,
  74. prepend_featured_robot: false,
  75. featured_only: false,
  76. default_page: false,
  77. }
  78. }
  79. }
  80. /// Standard factory response format.
  81. #[derive(Deserialize, Serialize, Clone)]
  82. pub struct FactoryInfo<T> {
  83. #[serde(rename = "response")]
  84. /// The response data
  85. pub response: T,
  86. #[serde(rename = "statusCode")]
  87. /// HTTP status code for the query
  88. pub status_code: usize,
  89. }
  90. /// Collection of robots in response to a list query.
  91. #[derive(Deserialize, Serialize, Clone)]
  92. pub struct RoboShopItemsInfo {
  93. #[serde(rename = "roboShopItems")]
  94. /// Robot items
  95. pub roboshop_items: Vec<FactoryRobotListInfo>,
  96. }
  97. /// Information about a single robot in response to a list query.
  98. ///
  99. /// This does not include robot block data since it is not returned by this API endpoint.
  100. /// Use `FactoryAPI.get(data.item_id)` to retrieve all info for a single robot.
  101. #[derive(Deserialize, Serialize, Clone)]
  102. pub struct FactoryRobotListInfo {
  103. /// Item ID
  104. #[serde(rename = "itemId")]
  105. pub item_id: usize,
  106. /// Robot name
  107. #[serde(rename = "itemName")]
  108. pub item_name: String,
  109. /// Robot description
  110. #[serde(rename = "itemDescription")]
  111. pub item_description: String,
  112. /// Thumbnail URL, as displayed to preview the robot.
  113. #[serde(rename = "thumbnail")]
  114. pub thumbnail: String, // url
  115. /// Robot author's username or UUID
  116. #[serde(rename = "addedBy")]
  117. pub added_by: String,
  118. /// Robot author's display name
  119. #[serde(rename = "addedByDisplayName")]
  120. pub added_by_display_name: String,
  121. /// Date added, in standard ISO format
  122. #[serde(rename = "addedDate")]
  123. pub added_date: String, // ISO date
  124. /// Expiry date, in standard ISO format
  125. #[serde(rename = "expiryDate")]
  126. pub expiry_date: String, // ISO date
  127. /// Robot CPU value
  128. #[serde(rename = "cpu")]
  129. pub cpu: usize,
  130. /// Robot RR
  131. #[serde(rename = "totalRobotRanking")]
  132. pub total_robot_ranking: usize,
  133. /// Robot's rentals
  134. #[serde(rename = "rentCount")]
  135. pub rent_count: usize,
  136. /// Robot's purchases
  137. #[serde(rename = "buyCount")]
  138. pub buy_count: usize,
  139. /// Is this robot buyable? (probably yes, unless you're a mod/admin or missing parts)
  140. #[serde(rename = "buyable")]
  141. pub buyable: bool,
  142. /// Removed date, in standard ISO format (probably None, unless authenticated as a mod/admin)
  143. #[serde(rename = "removedDate")]
  144. pub removed_date: Option<String>,
  145. /// Author ban date, in standard ISO format (probable None)
  146. #[serde(rename = "banDate")]
  147. pub ban_date: Option<String>,
  148. /// Is this robot featured?
  149. #[serde(rename = "featured")]
  150. pub featured: bool,
  151. /// CRF Banner message
  152. #[serde(rename = "bannerMessage")]
  153. pub banner_message: Option<String>,
  154. /// Robot's combat rating, out of 5
  155. #[serde(rename = "combatRating")]
  156. pub combat_rating: f32,
  157. /// Robot's cosmetic rating, out of 5
  158. #[serde(rename = "cosmeticRating")]
  159. pub cosmetic_rating: f32,
  160. /// Robot's count of (some?) blocks it uses
  161. #[serde(rename = "cubeAmounts")]
  162. pub cube_amounts: String, // JSON as str
  163. }
  164. impl std::string::ToString for FactoryRobotListInfo {
  165. fn to_string(&self) -> String {
  166. format!("{} by {} ({})", &self.item_name, &self.added_by_display_name, &self.item_id)
  167. }
  168. }
  169. // get/<item_id> endpoint
  170. /// Complete information about a single robot in response to a get query.
  171. /// Please refer to FactoryRobotListInfo for more in-depth documentation of fields.
  172. #[derive(Deserialize, Serialize, Clone)]
  173. pub struct FactoryRobotGetInfo {
  174. /// Item ID
  175. #[serde(rename = "id")]
  176. pub item_id: usize,
  177. /// Robot name
  178. #[serde(rename = "name")]
  179. pub item_name: String,
  180. /// Robot description
  181. #[serde(rename = "description")]
  182. pub item_description: String,
  183. /// Robot thumbnail URL
  184. #[serde(rename = "thumbnail")]
  185. pub thumbnail: String, // url
  186. /// Robot author's username or UUID
  187. #[serde(rename = "addedBy")]
  188. pub added_by: String,
  189. /// Robot author's display name
  190. #[serde(rename = "addedByDisplayName")]
  191. pub added_by_display_name: String,
  192. /// ISO date added
  193. #[serde(rename = "addedDate")]
  194. pub added_date: String, // ISO date
  195. /// ISO date expiring
  196. #[serde(rename = "expiryDate")]
  197. pub expiry_date: String, // ISO date
  198. /// CPU
  199. #[serde(rename = "cpu")]
  200. pub cpu: usize,
  201. /// RR
  202. #[serde(rename = "totalRobotRanking")]
  203. pub total_robot_ranking: usize,
  204. /// Robot rent count
  205. #[serde(rename = "rentCount")]
  206. pub rent_count: usize,
  207. /// Robot buy count
  208. #[serde(rename = "buyCount")]
  209. pub buy_count: usize,
  210. /// Robot is buyable?
  211. #[serde(rename = "buyable")]
  212. pub buyable: bool,
  213. /// ISO date removed
  214. #[serde(rename = "removedDate")]
  215. pub removed_date: Option<String>,
  216. /// ISO date banned
  217. #[serde(rename = "banDate")]
  218. pub ban_date: Option<String>,
  219. /// Robot is featured?
  220. #[serde(rename = "featured")]
  221. pub featured: bool,
  222. /// CRF banner message
  223. #[serde(rename = "bannerMessage")]
  224. pub banner_message: Option<String>,
  225. /// Robot's combat rating, out of 5
  226. #[serde(rename = "combatRating")]
  227. pub combat_rating: f32,
  228. /// Robot's cosmetic rating, out of 5
  229. #[serde(rename = "cosmeticRating")]
  230. pub cosmetic_rating: f32,
  231. /// Robot block cube and position data
  232. #[serde(rename = "cubeData")]
  233. pub cube_data: String,
  234. /// Robot block colour data
  235. #[serde(rename = "colourData")]
  236. pub colour_data: String,
  237. /// Cube counts
  238. #[serde(rename = "cubeAmounts")]
  239. pub cube_amounts: String, // JSON as str
  240. }
  241. impl std::string::ToString for FactoryRobotGetInfo {
  242. fn to_string(&self) -> String {
  243. format!("{} by {} ({})", &self.item_name, &self.added_by_display_name, &self.item_id)
  244. }
  245. }