Struct sharecart1000::Sharecart [−][src]
This is your Sharecart data, in a rusty form.
Fields
map_x: u16
This should be 0-1023 (10 bits).
- Saving: Ignores the high bits (eg:
cart.map_x % 1024
) - Loading: Attempts to parse a
u16
(0 on failure), and then truncates to 10 bits.
map_y: u16
This should be 0-1023 (10 bits).
- Saving: Ignores the high bits (eg:
cart.map_y % 1024
) - Loading: Attempts to parse a
u16
(0 on failure), and then truncates to 10 bits.
misc: [u16; 4]
Misc data.
- Saving: The full range is supported
- Loading: Attempts to parse a
u16
, uses 0 on failure.
player_name: String
The player’s name, or something like it.
The definition of “1023chars” is slightly fuzzy when you get into the fact
that there’s multi-byte characters, but that some languages assume all
chars are 1 byte. While we’re working with it in memory, we just act like
it’s a normal String
value. If you’re just using this field for 1,023 or
fewer ASCII characters (without line endings), you’ll be totally fine.
Otherwise there’s some edge cases to worry about.
- Saving: Filters out any
'\r'
, and'\n'
, takes the first 1023 bytes of what’s left, lossy re-parses as utf-8 to make sure there was no partial byte sequences at the end, and then strips any'\u{0FFFD}'
. - Loading: Same as with saving.
switch: [bool; 8]
The eight switches.
- Saving: Always outputs as “TRUE” or “FALSE”.
- Loading: Ignores case, so that “True” and “TrUe” and such are also
allowed as
true
. Any value that isn’t read astrue
becomesfalse
.
Implementations
impl Sharecart
[src]
pub fn from_str<S: AsRef<str>>(buf: S) -> Self
[src]
Parses the string given into a Sharecart
value.
You will always get a Sharecart
of some sort back. If any individual
field is missing, then you’ll get the Default
value in that field. If
the “[Main]” section is missing then you’ll get the default value in every
field. If the string somehow can’t even be parsed at all then you’ll get
the default value in every field. Field names ignore capitalization
differences.
Note: the contents of the o_o.ini
file might not be valid utf-8, so
as you read it from disk to pass into this function you’ll have to decide
how you want to handle that possibility. I’d suggest you use
String::from_utf8_lossy
, but it’s up to you.
use sharecart1000::Sharecart; let mut sc = Sharecart::default(); assert_eq!(sc, Sharecart::from_str("")); assert_eq!(sc, Sharecart::from_str("[Main]")); sc.map_x = 73; sc.map_y = 1023; assert_eq!(sc, Sharecart::from_str(r#"[Main] MapX=73 MapY=1023"#)); sc.misc[0] = 54; sc.misc[1] = 540; sc.misc[2] = 999; sc.misc[3] = ::std::u16::MAX; sc.player_name = "Fearless Concurrency".to_string(); let mut foo = true; for i in 0 .. 8 { sc.switch[i] = foo; foo = !foo; } assert_eq!(sc, Sharecart::from_str(sc.to_string()));
pub fn to_string(&self) -> String
[src]
Gives you a String
that you can write into the o_o.ini
file.
The string includes the “[Main]” section tag and other proper ini
formatting, so that you can completely replace the current o_o.ini
contents with this new string when saving the game.
Lines are always separated by the '\n'
character, even on Windows.
If you would like to use the “\r\n” windows-style line break sequence
instead, please use the replace
method on the output string (eg:
sc.to_string().replace("\n", "\r\n")
).
use sharecart1000::Sharecart; assert_eq!(Sharecart::default().to_string(), r#"[Main] MapX=0 MapY=0 Misc0=0 Misc1=0 Misc2=0 Misc3=0 PlayerName= Switch0=FALSE Switch1=FALSE Switch2=FALSE Switch3=FALSE Switch4=FALSE Switch5=FALSE Switch6=FALSE Switch7=FALSE "#);
Trait Implementations
impl Clone for Sharecart
[src]
impl Debug for Sharecart
[src]
impl Default for Sharecart
[src]
impl Eq for Sharecart
[src]
impl Hash for Sharecart
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Sharecart
[src]
fn cmp(&self, other: &Sharecart) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Sharecart> for Sharecart
[src]
impl PartialOrd<Sharecart> for Sharecart
[src]
fn partial_cmp(&self, other: &Sharecart) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for Sharecart
[src]
impl StructuralPartialEq for Sharecart
[src]
Auto Trait Implementations
impl RefUnwindSafe for Sharecart
impl Send for Sharecart
impl Sync for Sharecart
impl Unpin for Sharecart
impl UnwindSafe for Sharecart
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,