From e7f5f393a5cf42c1f78d7711a23ec976e79e5889 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Thu, 1 Oct 2026 00:08:15 +0200 Subject: [PATCH] Added special skin category to include all skins except knives and gloves --- src/main.rs | 2 +- src/skins.rs | 52 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 299d121..734365d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use tower_sessions_sqlx_store::sqlx::PgPool as SessionPgPool; mod error; mod skins; 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}; #[tokio::main] diff --git a/src/skins.rs b/src/skins.rs index d152f5d..c34772e 100644 --- a/src/skins.rs +++ b/src/skins.rs @@ -66,6 +66,7 @@ enum Categories { Pistols, Heavy, Equipment, + Weapons, // Special category to get all weapons except gloves and knives } impl Categories { @@ -78,6 +79,7 @@ impl Categories { Categories::Pistols => "Pistols", Categories::Heavy => "Heavy", Categories::Equipment => "Equipment", + Categories::Weapons => "", } } } @@ -105,10 +107,19 @@ pub async fn skin_info( } // Same with category if let Some(category) = info_query.category { - default_skins = default_skins - .into_iter() - .filter(|x| category.as_str() == x.category) - .collect(); + 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() + .filter(|x| category.as_str() == x.category) + .collect(), + } } // For each remaining default weapon, see if the user has set a skin // Secific cases for Knives and Gloves @@ -261,7 +272,6 @@ pub struct PaintQuery { weapon: Uuid, team: Teams, agent: Option, - gloves: Option } pub async fn list_paint_index( @@ -270,24 +280,28 @@ pub async fn list_paint_index( ) -> Result>, AppError> { let agent = match paint_query.agent { Some(agent) => agent, - None => false - }; - let gloves = match paint_query.gloves { - Some(gloves) => gloves, - None => false + None => false, }; 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?; - values.into_iter().map(|x| PaintIndexInfo { - name: x.name, - paint_index: x.def_index, - display: x.display, - color: x.color, - min_float: 0.0, - max_float: 0.0 - }).collect() + values + .into_iter() + .map(|x| PaintIndexInfo { + name: x.name, + paint_index: x.def_index, + display: x.display, + color: x.color, + min_float: 0.0, + max_float: 0.0, + }) + .collect() } 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() { "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?