Added special skin category to include all skins except knives and gloves

This commit is contained in:
2026-10-01 00:08:15 +02:00
parent 746b01000c
commit e7f5f393a5
2 changed files with 34 additions and 20 deletions

View File

@@ -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]

View File

@@ -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
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();
.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<bool>,
gloves: Option<bool>
}
pub async fn list_paint_index(
@@ -270,24 +280,28 @@ pub async fn list_paint_index(
) -> Result<Json<Vec<PaintIndexInfo>>, 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 {
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()
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?