Browse Source

Address comments

- Make ``MiiSelectorReturn`` ``non_exhaustive``
- Remove ``checksum`` from ``MiiSelectorReturn``
- Change ``From`` impl for ``MiiSelectorReturn``
- Rename ``OriginConsole`` members
- Fix ranges
pull/78/head
TechiePi 2 years ago
parent
commit
16f8de4376
  1. 1
      ctru-rs/examples/mii-selector.rs
  2. 10
      ctru-rs/src/applets/mii_selector.rs
  3. 107
      ctru-rs/src/mii.rs

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

@ -18,7 +18,6 @@ fn main() {
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!("Mii checksum: {:?}", result.checksum);
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!(

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

@ -52,12 +52,12 @@ pub struct MiiSelector {
} }
/// Return value from a MiiSelector's launch /// Return value from a MiiSelector's launch
#[non_exhaustive]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MiiSelectorReturn { pub struct MiiSelectorReturn {
pub mii_data: MiiData, pub mii_data: MiiData,
pub is_mii_selected: bool, pub is_mii_selected: bool,
pub mii_type: MiiType, pub mii_type: MiiType,
pub checksum: u16,
} }
/// Error type for the Mii selector /// Error type for the Mii selector
@ -148,16 +148,15 @@ impl MiiSelector {
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 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 {
Err(MiiLaunchError::InvalidChecksum) Err(MiiLaunchError::InvalidChecksum)
} }
} }
} }
impl From<Box<ctru_sys::MiiSelectorReturn>> for MiiSelectorReturn { impl From<ctru_sys::MiiSelectorReturn> for MiiSelectorReturn {
fn from(ret: Box<ctru_sys::MiiSelectorReturn>) -> Self { fn from(ret: ctru_sys::MiiSelectorReturn) -> Self {
let checksum = ret.checksum;
let raw_mii_data = ret.mii; let raw_mii_data = ret.mii;
let no_mii_selected = ret.no_mii_selected; let no_mii_selected = ret.no_mii_selected;
let guest_mii_index_clone = ret.guest_mii_index; let guest_mii_index_clone = ret.guest_mii_index;
@ -178,7 +177,6 @@ impl From<Box<ctru_sys::MiiSelectorReturn>> for MiiSelectorReturn {
} else { } else {
MiiType::User MiiType::User
}, },
checksum,
} }
} }
} }

107
ctru-rs/src/mii.rs

@ -40,10 +40,11 @@ pub struct SelectorPosition {
/// Represents the kind of origin console /// Represents the kind of origin console
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum OriginConsole { pub enum OriginConsole {
ConsoleWii, Wii,
ConsoleDSi, DSi,
Console3DS, /// Both New 3DS and Old 3DS
ConsoleWiiUSwitch, N3DS,
WiiUSwitch,
} }
/// Represents the identity of the origin console /// Represents the identity of the origin console
@ -291,17 +292,17 @@ impl From<ctru_sys::MiiData> for MiiData {
}; };
let position = SelectorPosition { let position = SelectorPosition {
page_index: partial_u8_bits_to_u8(&raw_position[0..3]), page_index: partial_u8_bits_to_u8(&raw_position[0..=3]),
slot_index: partial_u8_bits_to_u8(&raw_position[4..7]), slot_index: partial_u8_bits_to_u8(&raw_position[4..=7]),
}; };
let device = ConsoleIdentity { let device = ConsoleIdentity {
origin_console: { origin_console: {
match (raw_device[6], raw_device[5], raw_device[4]) { match (raw_device[6], raw_device[5], raw_device[4]) {
(false, false, true) => OriginConsole::ConsoleWii, (false, false, true) => OriginConsole::Wii,
(false, true, false) => OriginConsole::ConsoleDSi, (false, true, false) => OriginConsole::DSi,
(false, true, true) => OriginConsole::Console3DS, (false, true, true) => OriginConsole::N3DS,
_ => OriginConsole::ConsoleWiiUSwitch, _ => OriginConsole::WiiUSwitch,
} }
}, },
}; };
@ -313,85 +314,85 @@ impl From<ctru_sys::MiiData> for MiiData {
false => MiiSex::Male, false => MiiSex::Male,
} }
}, },
birthday_month: partial_u8_bits_to_u8(&raw_details[1..4]), birthday_month: partial_u8_bits_to_u8(&raw_details[1..=4]),
birthday_day: partial_u8_bits_to_u8(&raw_details[5..9]), birthday_day: partial_u8_bits_to_u8(&raw_details[5..=9]),
shirt_color: partial_u8_bits_to_u8(&raw_details[10..13]), shirt_color: partial_u8_bits_to_u8(&raw_details[10..=13]),
is_favorite: raw_details[14], is_favorite: raw_details[14],
}; };
let face_details = FaceDetails { let face_details = FaceDetails {
style: FaceStyle { style: FaceStyle {
is_sharing_enabled: !raw_face_style[1], is_sharing_enabled: !raw_face_style[0],
shape: partial_u8_bits_to_u8(&raw_face_style[1..4]), shape: partial_u8_bits_to_u8(&raw_face_style[1..=4]),
skin_color: partial_u8_bits_to_u8(&raw_face_style[5..7]), skin_color: partial_u8_bits_to_u8(&raw_face_style[5..=7]),
}, },
wrinkles: partial_u8_bits_to_u8(&raw_face_details[0..3]), wrinkles: partial_u8_bits_to_u8(&raw_face_details[0..=3]),
makeup: partial_u8_bits_to_u8(&raw_face_details[4..7]), makeup: partial_u8_bits_to_u8(&raw_face_details[4..=7]),
}; };
let hair_details = HairDetails { let hair_details = HairDetails {
style: raw_mii_data[0x32], style: raw_mii_data[0x32],
color: partial_u8_bits_to_u8(&raw_hair_details[0..2]), color: partial_u8_bits_to_u8(&raw_hair_details[0..=2]),
is_flipped: raw_hair_details[3], is_flipped: raw_hair_details[3],
}; };
let eye_details = EyeDetails { let eye_details = EyeDetails {
style: partial_u8_bits_to_u8(&raw_eye_details[0..5]), style: partial_u8_bits_to_u8(&raw_eye_details[0..=5]),
color: partial_u8_bits_to_u8(&raw_eye_details[6..8]), color: partial_u8_bits_to_u8(&raw_eye_details[6..=8]),
scale: partial_u8_bits_to_u8(&raw_eye_details[9..12]), scale: partial_u8_bits_to_u8(&raw_eye_details[9..=12]),
y_scale: partial_u8_bits_to_u8(&raw_eye_details[13..15]), y_scale: partial_u8_bits_to_u8(&raw_eye_details[13..=15]),
rotation: partial_u8_bits_to_u8(&raw_eye_details[16..20]), rotation: partial_u8_bits_to_u8(&raw_eye_details[16..=20]),
x_spacing: partial_u8_bits_to_u8(&raw_eye_details[21..24]), x_spacing: partial_u8_bits_to_u8(&raw_eye_details[21..=24]),
y_position: partial_u8_bits_to_u8(&raw_eye_details[25..29]), y_position: partial_u8_bits_to_u8(&raw_eye_details[25..=29]),
}; };
let eyebrow_details = EyebrowDetails { let eyebrow_details = EyebrowDetails {
style: partial_u8_bits_to_u8(&raw_eyebrow_details[0..4]), style: partial_u8_bits_to_u8(&raw_eyebrow_details[0..=4]),
color: partial_u8_bits_to_u8(&raw_eyebrow_details[5..7]), color: partial_u8_bits_to_u8(&raw_eyebrow_details[5..=7]),
scale: partial_u8_bits_to_u8(&raw_eyebrow_details[8..11]), scale: partial_u8_bits_to_u8(&raw_eyebrow_details[8..=11]),
y_scale: partial_u8_bits_to_u8(&raw_eyebrow_details[12..14]), y_scale: partial_u8_bits_to_u8(&raw_eyebrow_details[12..=14]),
rotation: partial_u8_bits_to_u8(&raw_eyebrow_details[16..19]), rotation: partial_u8_bits_to_u8(&raw_eyebrow_details[16..=19]),
x_spacing: partial_u8_bits_to_u8(&raw_eyebrow_details[21..24]), x_spacing: partial_u8_bits_to_u8(&raw_eyebrow_details[21..=24]),
y_position: partial_u8_bits_to_u8(&raw_eyebrow_details[25..29]), y_position: partial_u8_bits_to_u8(&raw_eyebrow_details[25..=29]),
}; };
let nose_details = NoseDetails { let nose_details = NoseDetails {
style: partial_u8_bits_to_u8(&raw_nose_details[0..4]), style: partial_u8_bits_to_u8(&raw_nose_details[0..=4]),
scale: partial_u8_bits_to_u8(&raw_nose_details[5..8]), scale: partial_u8_bits_to_u8(&raw_nose_details[5..=8]),
y_position: partial_u8_bits_to_u8(&raw_nose_details[9..13]), y_position: partial_u8_bits_to_u8(&raw_nose_details[9..=13]),
}; };
let mouth_details = MouthDetails { let mouth_details = MouthDetails {
style: partial_u8_bits_to_u8(&raw_mouth_details[0..5]), style: partial_u8_bits_to_u8(&raw_mouth_details[0..=5]),
color: partial_u8_bits_to_u8(&raw_mouth_details[6..8]), color: partial_u8_bits_to_u8(&raw_mouth_details[6..=8]),
scale: partial_u8_bits_to_u8(&raw_mouth_details[9..12]), scale: partial_u8_bits_to_u8(&raw_mouth_details[9..=12]),
y_scale: partial_u8_bits_to_u8(&raw_mouth_details[13..15]), y_scale: partial_u8_bits_to_u8(&raw_mouth_details[13..=15]),
}; };
let mustache_details = MustacheDetails { let mustache_details = MustacheDetails {
mouth_y_position: partial_u8_bits_to_u8(&raw_mustache_details[0..4]), mouth_y_position: partial_u8_bits_to_u8(&raw_mustache_details[0..=4]),
mustache_style: partial_u8_bits_to_u8(&raw_mustache_details[5..7]), mustache_style: partial_u8_bits_to_u8(&raw_mustache_details[5..=7]),
}; };
let beard_details = BeardDetails { let beard_details = BeardDetails {
style: partial_u8_bits_to_u8(&raw_beard_details[0..2]), style: partial_u8_bits_to_u8(&raw_beard_details[0..=2]),
color: partial_u8_bits_to_u8(&raw_beard_details[3..5]), color: partial_u8_bits_to_u8(&raw_beard_details[3..=5]),
scale: partial_u8_bits_to_u8(&raw_beard_details[6..9]), scale: partial_u8_bits_to_u8(&raw_beard_details[6..=9]),
y_position: partial_u8_bits_to_u8(&raw_beard_details[10..14]), y_position: partial_u8_bits_to_u8(&raw_beard_details[10..=14]),
}; };
let glass_details = GlassDetails { let glass_details = GlassDetails {
style: partial_u8_bits_to_u8(&raw_glass_details[0..3]), style: partial_u8_bits_to_u8(&raw_glass_details[0..=3]),
color: partial_u8_bits_to_u8(&raw_glass_details[4..6]), color: partial_u8_bits_to_u8(&raw_glass_details[4..=6]),
scale: partial_u8_bits_to_u8(&raw_glass_details[7..10]), scale: partial_u8_bits_to_u8(&raw_glass_details[7..=10]),
y_position: partial_u8_bits_to_u8(&raw_glass_details[11..15]), y_position: partial_u8_bits_to_u8(&raw_glass_details[11..=15]),
}; };
let mole_details = MoleDetails { let mole_details = MoleDetails {
is_enabled: raw_mole_details[0], is_enabled: raw_mole_details[0],
scale: partial_u8_bits_to_u8(&raw_mole_details[1..4]), scale: partial_u8_bits_to_u8(&raw_mole_details[1..=4]),
x_position: partial_u8_bits_to_u8(&raw_mole_details[5..9]), x_position: partial_u8_bits_to_u8(&raw_mole_details[5..=9]),
y_position: partial_u8_bits_to_u8(&raw_mole_details[10..14]), y_position: partial_u8_bits_to_u8(&raw_mole_details[10..=14]),
}; };
MiiData { MiiData {

Loading…
Cancel
Save