Added special skin category to include all skins except knives and gloves
This commit is contained in:
@@ -17,7 +17,7 @@ use tower_sessions_sqlx_store::sqlx::PgPool as SessionPgPool;
|
|||||||
mod error;
|
mod error;
|
||||||
mod skins;
|
mod skins;
|
||||||
mod users;
|
mod users;
|
||||||
use skins::{agent_info, skin_info, weapons, list_paint_index};
|
use skins::{agent_info, list_paint_index, skin_info, weapons};
|
||||||
use users::{login, logout, me, reload, update};
|
use users::{login, logout, me, reload, update};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
38
src/skins.rs
38
src/skins.rs
@@ -66,6 +66,7 @@ enum Categories {
|
|||||||
Pistols,
|
Pistols,
|
||||||
Heavy,
|
Heavy,
|
||||||
Equipment,
|
Equipment,
|
||||||
|
Weapons, // Special category to get all weapons except gloves and knives
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Categories {
|
impl Categories {
|
||||||
@@ -78,6 +79,7 @@ impl Categories {
|
|||||||
Categories::Pistols => "Pistols",
|
Categories::Pistols => "Pistols",
|
||||||
Categories::Heavy => "Heavy",
|
Categories::Heavy => "Heavy",
|
||||||
Categories::Equipment => "Equipment",
|
Categories::Equipment => "Equipment",
|
||||||
|
Categories::Weapons => "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,10 +107,19 @@ pub async fn skin_info(
|
|||||||
}
|
}
|
||||||
// Same with category
|
// Same with category
|
||||||
if let Some(category) = info_query.category {
|
if let Some(category) = info_query.category {
|
||||||
default_skins = default_skins
|
default_skins = match category {
|
||||||
|
Categories::Weapons => default_skins
|
||||||
|
.into_iter()
|
||||||
|
.filter(|x| {
|
||||||
|
![Categories::Gloves.as_str(), Categories::Knives.as_str()]
|
||||||
|
.contains(&x.category.as_str())
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
_ => default_skins
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|x| category.as_str() == x.category)
|
.filter(|x| category.as_str() == x.category)
|
||||||
.collect();
|
.collect(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// For each remaining default weapon, see if the user has set a skin
|
// For each remaining default weapon, see if the user has set a skin
|
||||||
// Secific cases for Knives and Gloves
|
// Secific cases for Knives and Gloves
|
||||||
@@ -261,7 +272,6 @@ pub struct PaintQuery {
|
|||||||
weapon: Uuid,
|
weapon: Uuid,
|
||||||
team: Teams,
|
team: Teams,
|
||||||
agent: Option<bool>,
|
agent: Option<bool>,
|
||||||
gloves: Option<bool>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_paint_index(
|
pub async fn list_paint_index(
|
||||||
@@ -270,24 +280,28 @@ pub async fn list_paint_index(
|
|||||||
) -> Result<Json<Vec<PaintIndexInfo>>, AppError> {
|
) -> Result<Json<Vec<PaintIndexInfo>>, AppError> {
|
||||||
let agent = match paint_query.agent {
|
let agent = match paint_query.agent {
|
||||||
Some(agent) => agent,
|
Some(agent) => agent,
|
||||||
None => false
|
None => false,
|
||||||
};
|
|
||||||
let gloves = match paint_query.gloves {
|
|
||||||
Some(gloves) => gloves,
|
|
||||||
None => false
|
|
||||||
};
|
};
|
||||||
let paints = if agent {
|
let paints = if agent {
|
||||||
let values = query!("SELECT a.name, a.def_index, a.display, r.color FROM agents a JOIN rarity r ON r.id = a.rarity WHERE a.team=$1", paint_query.team.as_i32()).fetch_all(&pool).await?;
|
let values = query!("SELECT a.name, a.def_index, a.display, r.color FROM agents a JOIN rarity r ON r.id = a.rarity WHERE a.team=$1", paint_query.team.as_i32()).fetch_all(&pool).await?;
|
||||||
values.into_iter().map(|x| PaintIndexInfo {
|
values
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| PaintIndexInfo {
|
||||||
name: x.name,
|
name: x.name,
|
||||||
paint_index: x.def_index,
|
paint_index: x.def_index,
|
||||||
display: x.display,
|
display: x.display,
|
||||||
color: x.color,
|
color: x.color,
|
||||||
min_float: 0.0,
|
min_float: 0.0,
|
||||||
max_float: 0.0
|
max_float: 0.0,
|
||||||
}).collect()
|
})
|
||||||
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
let category = query!("SELECT w.category FROM weapons w WHERE w.id=$1", paint_query.weapon).fetch_one(&pool).await?;
|
let category = query!(
|
||||||
|
"SELECT w.category FROM weapons w WHERE w.id=$1",
|
||||||
|
paint_query.weapon
|
||||||
|
)
|
||||||
|
.fetch_one(&pool)
|
||||||
|
.await?;
|
||||||
match category.category.as_str() {
|
match category.category.as_str() {
|
||||||
"Knives" | "Gloves" => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.category=$1", category.category).fetch_all(&pool).await?,
|
"Knives" | "Gloves" => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.category=$1", category.category).fetch_all(&pool).await?,
|
||||||
_ => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.id=$1", paint_query.weapon).fetch_all(&pool).await?
|
_ => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.id=$1", paint_query.weapon).fetch_all(&pool).await?
|
||||||
|
|||||||
Reference in New Issue
Block a user