Add optional argument to select a specific style
This commit is contained in:
1 parent
473d5d0173
commit
5dda54ecd4
2 files changed
+12
-5
No files matched your search
+10
-3
@@ -12,20 +12,27 @@ struct Args {
|
||||
/// Text to display in the speech bubble
|
||||
text: String,
|
||||
|
||||
/// Style of the Miku art. Random is chosen if not specified.
|
||||
#[arg(short, long)]
|
||||
style: Option<i32>,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args = Args::parse();
|
||||
|
||||
let text = args.text;
|
||||
draw_miku_says(&text)?;
|
||||
let style = match args.style {
|
||||
Some(s) => s,
|
||||
None => -1 // Default to -1 to select a random style
|
||||
};
|
||||
draw_miku_says(&text, style)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw_miku_says(text: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn draw_miku_says(text: &str, style: i32) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let speech_bubble_lines = get_speech_bubble_lines(text);
|
||||
let miku_art = get_miku_art();
|
||||
let miku_art = get_miku_art(style);
|
||||
|
||||
let (window_width, window_height) = size()?;
|
||||
let available_width = window_width as usize;
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
pub fn get_miku_art() -> Vec<&'static str> {
|
||||
pub fn get_miku_art(style: i32) -> Vec<&'static str> {
|
||||
let mut rng = rand::rng();
|
||||
let styles = vec![
|
||||
//MARK: small art
|
||||
@@ -504,6 +504,6 @@ pub fn get_miku_art() -> Vec<&'static str> {
|
||||
],
|
||||
];
|
||||
|
||||
let selected_style = rng.random_range(0..styles.len());
|
||||
let selected_style = if style < 0 { rng.random_range(0..styles.len()) } else { style as usize };
|
||||
styles[selected_style].clone()
|
||||
}
|
||||
Reference in new issue
Block a user