Browse Source

Add support for primitive to factory enum conversion

tags/v0.5.1
NGnius 3 years ago
parent
commit
fadafc5bb8
3 changed files with 35 additions and 0 deletions
  1. +1
    -0
      Cargo.toml
  2. +21
    -0
      src/robocraft/factory_request_builder.rs
  3. +13
    -0
      src/robocraft_simple/factory_request_builder.rs

+ 1
- 0
Cargo.toml View File

@@ -14,6 +14,7 @@ reqwest = { version = "^0.11", features = ["json"]}
url = "^2.2"
ureq = { version = "^2", features = ["json"], optional = true}
base64 = "^0.13"
num_enum = "^0.5"

[dev-dependencies]
tokio = { version = "1.4.0", features = ["macros"]}


+ 21
- 0
src/robocraft/factory_request_builder.rs View File

@@ -1,8 +1,11 @@
use reqwest::{RequestBuilder, Error};
use num_enum::{TryFromPrimitive};

use crate::robocraft::{FactoryInfo, RoboShopItemsInfo};
use crate::robocraft::factory_json::ListPayload;

#[derive(Eq, PartialEq, TryFromPrimitive)]
#[repr(u8)]
pub enum FactoryOrderType {
Suggested = 0,
CombatRating = 1,
@@ -12,6 +15,8 @@ pub enum FactoryOrderType {
MostBought = 5,
}

#[derive(Eq, PartialEq, TryFromPrimitive)]
#[repr(u32)]
pub enum FactoryMovementType {
Wheels = 100000,
Hovers = 200000,
@@ -27,6 +32,8 @@ pub enum FactoryMovementType {
Propellers=1200000
}

#[derive(Eq, PartialEq, TryFromPrimitive)]
#[repr(u32)]
pub enum FactoryWeaponType {
Laser=10000000,
PlasmaLauncher=20000000,
@@ -40,6 +47,8 @@ pub enum FactoryWeaponType {
ChainShredder=75000000,
}

#[derive(Eq, PartialEq, TryFromPrimitive)]
#[repr(u8)]
pub enum FactoryTextSearchType {
All=0,
Player=1,
@@ -94,6 +103,12 @@ impl FactorySearchBuilder {
self
}
pub fn movement_raw(mut self, filter: String) -> Self {
self.payload.movement_filter = filter.clone();
self.payload.movement_category_filter = filter.clone();
self
}
pub fn weapon_or(mut self, weapon_type: FactoryWeaponType) -> Self {
if self.payload.weapon_filter == "" {
self.payload.weapon_filter = format!("{},{}", &self.payload.weapon_filter, weapon_type as isize);
@@ -104,6 +119,12 @@ impl FactorySearchBuilder {
self
}
pub fn weapon_raw(mut self, filter: String) -> Self {
self.payload.weapon_filter = filter.clone();
self.payload.weapon_category_filter = filter.clone();
self
}
pub fn cpu_range(mut self, min: isize, max: isize) -> Self {
self.payload.minimum_cpu = min;
self.payload.maximum_cpu = max;


+ 13
- 0
src/robocraft_simple/factory_request_builder.rs View File

@@ -3,6 +3,7 @@ use ureq::{Request, Response, Error};
use crate::robocraft::{FactoryInfo, RoboShopItemsInfo, FactoryTextSearchType, FactoryWeaponType, FactoryMovementType, FactoryOrderType};
use crate::robocraft::{ListPayload};

#[derive(Clone)]
pub struct FactorySearchBuilder {
reqwest_builder: Request,
payload: ListPayload,
@@ -41,6 +42,12 @@ impl FactorySearchBuilder {
}
*/
pub fn movement_raw(mut self, filter: String) -> Self {
self.payload.movement_filter = filter.clone();
self.payload.movement_category_filter = filter.clone();
self
}
pub fn movement_or(mut self, movement_type: FactoryMovementType) -> Self {
if self.payload.movement_filter == "" {
self.payload.movement_filter = format!("{},{}", &self.payload.movement_filter, movement_type as isize);
@@ -51,6 +58,12 @@ impl FactorySearchBuilder {
self
}
pub fn weapon_raw(mut self, filter: String) -> Self {
self.payload.weapon_filter = filter.clone();
self.payload.weapon_category_filter = filter.clone();
self
}
pub fn weapon_or(mut self, weapon_type: FactoryWeaponType) -> Self {
if self.payload.weapon_filter == "" {
self.payload.weapon_filter = format!("{},{}", &self.payload.weapon_filter, weapon_type as isize);


Loading…
Cancel
Save