selectcar class amount in preset
This commit is contained in:
parent
4d0d4e6fee
commit
5e7c10e92a
1 changed files with 34 additions and 7 deletions
|
|
@ -11,13 +11,28 @@ use crate::user_grade::License;
|
|||
macro_rules! make_car_class {
|
||||
($parent_pc:expr, $car_classes_list:expr, $($n:expr),*) => {
|
||||
$(
|
||||
let mut sub_pc = Collection::new(concat!("Car Class ", $n).to_string());
|
||||
let mut pc = Collection::new(concat!("Car Class ", $n).to_string());
|
||||
|
||||
// collection enabled dependency
|
||||
let enabled_values: Vec<String>;
|
||||
if $n == 1 {
|
||||
enabled_values = vec!["1".to_string(), "2".to_string(), "3".to_string(), "4".to_string()];
|
||||
} else if $n == 2 {
|
||||
enabled_values = vec!["2".to_string(), "3".to_string(), "4".to_string()];
|
||||
} else if $n == 3 {
|
||||
enabled_values = vec!["3".to_string(), "4".to_string()];
|
||||
} else if $n == 4 {
|
||||
enabled_values = vec!["4".to_string()];
|
||||
} else {
|
||||
unimplemented!("The macro is only implemented up to $n=4");
|
||||
}
|
||||
pc.enable_at_other_values("classes_count".to_string(), enabled_values);
|
||||
|
||||
// car class
|
||||
let mut p = ParamCarClasses::new(concat!("carclass", $n), $car_classes_list.clone()).await;
|
||||
p.meta_mut().label = "Car Class".to_string();
|
||||
p.meta_mut().description = Some("Select here a car class to drive".to_string());
|
||||
sub_pc.add_parameter(p);
|
||||
pc.add_parameter(p);
|
||||
|
||||
// license min
|
||||
let mut p = ParamEnumSingle::new(concat!("CarClass", $n, "LicenseMin"));
|
||||
|
|
@ -26,7 +41,7 @@ macro_rules! make_car_class {
|
|||
}
|
||||
p.meta_mut().label = "Minim License".to_string();
|
||||
p.meta_mut().description = Some("This defines the minimum license level for drivers to use drive class".to_string());
|
||||
sub_pc.add_parameter(p);
|
||||
pc.add_parameter(p);
|
||||
|
||||
// license max
|
||||
let mut p = ParamEnumSingle::new(concat!("CarClass", $n, "LicenseMax"));
|
||||
|
|
@ -37,7 +52,7 @@ macro_rules! make_car_class {
|
|||
}
|
||||
p.meta_mut().label = "Maximum License".to_string();
|
||||
p.meta_mut().description = Some("This defines the maximum license level of drivers to use drive class".to_string());
|
||||
sub_pc.add_parameter(p);
|
||||
pc.add_parameter(p);
|
||||
|
||||
// registration
|
||||
let mut p = ParamEnumSingle::new(concat!("CarClass", $n, "Registration"));
|
||||
|
|
@ -46,7 +61,7 @@ macro_rules! make_car_class {
|
|||
p.add_enum_item("RegQuali", "Registration: qualify in free practice");
|
||||
p.meta_mut().label = "Registration".to_string();
|
||||
p.meta_mut().description = Some("No registration means that drivers cannot register at all (only spontaneous joining\nRegistration allows drivers to occupy seats (and preserve skins)\nIf more drivers register than pits are available, it is possible to use the free practice as qualification".to_string());
|
||||
sub_pc.add_parameter(p);
|
||||
pc.add_parameter(p);
|
||||
|
||||
// free cars
|
||||
let mut p = ParamEnumSingle::new(concat!("CarClass", $n, "FreeCars"));
|
||||
|
|
@ -54,9 +69,9 @@ macro_rules! make_car_class {
|
|||
p.add_enum_item("no", "No");
|
||||
p.meta_mut().label = "Free Cars".to_string();
|
||||
p.meta_mut().description = Some("If activated, the server will provide free, unoccupied cars in this class for spontaneously joining drivers".to_string());
|
||||
sub_pc.add_parameter(p);
|
||||
pc.add_parameter(p);
|
||||
|
||||
$parent_pc.add_collection(sub_pc);
|
||||
$parent_pc.add_collection(pc);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
|
@ -186,11 +201,23 @@ pub async fn get(db: Option<DatabaseManager>) -> Collection {
|
|||
|
||||
async fn get_car_classes(db: Option<DatabaseManager>) -> Collection {
|
||||
let mut pc = Collection::new("Car Classes".to_string());
|
||||
|
||||
// count
|
||||
let mut p = ParamEnumSingle::new("classes_count");
|
||||
p.add_enum_item("1", "1 Class");
|
||||
p.add_enum_item("2", "2 Classes");
|
||||
p.add_enum_item("3", "3 Classes");
|
||||
p.add_enum_item("4", "4 Classes");
|
||||
p.meta_mut().label = "Car Class Count".to_string();
|
||||
p.meta_mut().description = Some("How many car classes shall be available".to_string());
|
||||
pc.add_parameter(p);
|
||||
|
||||
let ccl = match db {
|
||||
None => CarClassList::new_empty(),
|
||||
Some(db) => CarClassList::new(db.db_content().await.tbl_classes().await).await,
|
||||
};
|
||||
make_car_class!(&mut pc, ccl, 1,2,3,4);
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue