Skip to content

Commit

Permalink
fix advanced issues in builds without it
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover authored May 15, 2024
1 parent 7e78055 commit 99b39ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
27 changes: 24 additions & 3 deletions src/func.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{lists::*, GamepadInjector};
use crate::lists::*;
#[cfg(feature = "advanced")]
use crate::GamepadInjector;
use cgisf_lib::{gen_sentence, SentenceConfigBuilder};
use chrono::{prelude::*, DateTime};
use enigo::*;
Expand Down Expand Up @@ -265,14 +267,13 @@ fn screenshot(tts: &mut Tts) {
}
}

pub async fn main_logic(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut Enigo, gamepadobj: &mut Option<GamepadInjector>) {
pub async fn main_logic(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut Enigo) {
let mut rng: rand::prelude::ThreadRng = thread_rng();

let index: WeightedIndex<usize> =
WeightedIndex::new(options.iter().map(|item| item.1)).unwrap();
match options[index.sample(&mut rng)].0 {
"keyboard" => keyboard(enigo, &mut rng),
"gamepad" => gamepad(&mut gamepadobj.unwrap().as_mut(), &mut rng),
"mouse" => mouse(enigo, &mut rng),
"quote" => quote(tts, &mut rng),
"screenshot" => screenshot(tts),
Expand All @@ -283,3 +284,23 @@ pub async fn main_logic(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut En

sleep(Duration::from_millis(1500)).await;
}

#[cfg(feature = "advanced")]
pub async fn main_logic_adv(options: &[(&str, usize)], tts: &mut Tts, enigo: &mut Enigo, gamepadobj: &mut GamepadInjector) {
let mut rng: rand::prelude::ThreadRng = thread_rng();

let index: WeightedIndex<usize> =
WeightedIndex::new(options.iter().map(|item| item.1)).unwrap();
match options[index.sample(&mut rng)].0 {
"keyboard" => keyboard(enigo, &mut rng),
"gamepad" => gamepad(gamepadobj, &mut rng),
"mouse" => mouse(enigo, &mut rng),
"quote" => quote(tts, &mut rng),
"screenshot" => screenshot(tts),
"quote_gen" => quote_gen(tts),
"quote_gen_ext" => quote_gen_ext(tts).await,
_ => println!("idk what you did but fix it"),
}

sleep(Duration::from_millis(1500)).await;
}
15 changes: 9 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use model::*;
use std::fs::*;
use enigo::*;
use config::*;
use func::main_logic;
use func::*;
use tts::*;

#[tokio::main]
Expand All @@ -31,12 +31,15 @@ async fn main() {
};

let mut enigo: Enigo = Enigo::new(&Settings::default()).unwrap();
let mut gamepad = None;
if cfg!(feature = "advanced") {
gamepad = Some(GamepadInjector::new());
}
#[cfg(feature = "advanced")]
let mut gamepad = GamepadInjector::new();

#[cfg(feature = "advanced")]
loop {
main_logic(&options, &mut tts, &mut enigo).await;
}
#[not(cfg(feature = "advanced"))]
loop {
main_logic(&options, &mut tts, &mut enigo, &mut gamepad).await;
main_logic_adv(&options, &mut tts, &mut enigo, &mut gamepad).await;
}
}

0 comments on commit 99b39ee

Please sign in to comment.