Browse Source

Add an error code for when Mii selection is cancelled

pull/122/head
DeltaF1 2 years ago
parent
commit
070de964be
  1. 26
      ctru-rs/examples/mii-selector.rs
  2. 7
      ctru-rs/src/applets/mii_selector.rs

26
ctru-rs/examples/mii-selector.rs

@ -1,4 +1,4 @@
use ctru::applets::mii_selector::MiiSelector; use ctru::applets::mii_selector::{LaunchError, MiiSelector};
use ctru::prelude::*; use ctru::prelude::*;
fn main() { fn main() {
@ -14,16 +14,20 @@ fn main() {
mii_selector.blacklist_user_mii(0.into()); mii_selector.blacklist_user_mii(0.into());
mii_selector.set_title("Great Mii Selector!"); mii_selector.set_title("Great Mii Selector!");
let result = mii_selector.launch().unwrap(); match mii_selector.launch() {
Ok(result) => {
println!("Is Mii selected?: {:?}", result.is_mii_selected); println!("Is Mii selected?: {:?}", result.is_mii_selected);
println!("Mii type: {:?}", result.mii_type); println!("Mii type: {:?}", result.mii_type);
println!("Name: {:?}", result.mii_data.name); println!("Name: {:?}", result.mii_data.name);
println!("Author: {:?}", result.mii_data.author_name); println!("Author: {:?}", result.mii_data.author_name);
println!( println!(
"Does the Mii have moles?: {:?}", "Does the Mii have moles?: {:?}",
result.mii_data.mole_details.is_enabled result.mii_data.mole_details.is_enabled
); );
}
Err(LaunchError::InvalidChecksum) => println!("Corrupt Mii selected"),
Err(LaunchError::NoMiiSelected) => println!("No Mii selected"),
}
// Main loop // Main loop
while apt.main_loop() { while apt.main_loop() {

7
ctru-rs/src/applets/mii_selector.rs

@ -56,6 +56,8 @@ pub struct MiiSelector {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SelectionResult { pub struct SelectionResult {
pub mii_data: MiiData, pub mii_data: MiiData,
#[deprecated]
pub is_mii_selected: bool, pub is_mii_selected: bool,
pub mii_type: MiiType, pub mii_type: MiiType,
} }
@ -64,6 +66,7 @@ pub struct SelectionResult {
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum LaunchError { pub enum LaunchError {
InvalidChecksum, InvalidChecksum,
NoMiiSelected,
} }
impl MiiSelector { impl MiiSelector {
@ -147,6 +150,10 @@ impl MiiSelector {
let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default(); let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default();
unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) } unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) }
if return_val.no_mii_selected != 0 {
return Err(LaunchError::NoMiiSelected);
}
if unsafe { ctru_sys::miiSelectorChecksumIsValid(return_val.as_mut()) } { if unsafe { ctru_sys::miiSelectorChecksumIsValid(return_val.as_mut()) } {
Ok((*return_val).into()) Ok((*return_val).into())
} else { } else {

Loading…
Cancel
Save