pub struct GameStringBuilder<'a> { /* private fields */ }
Expand description

Builds a string using an “enhanced sprintf”, which recognizes certain tags and replaces them with appropriate game values.

The output buffer is calculated to have a capacity of the input format string times 3 (or i32::MAX). Should that not be enough, you can use Self::output_buffer_size to override this.

See https://textbox.skytemple.org for a reference about message tags and a preview tool.

Implementations§

source§

impl<'a> GameStringBuilder<'a>

source

pub fn new() -> Self

source

pub fn set_flag_unknown0(&mut self, value: u16) -> &mut Self

Sets the unknown0 value of the preprocessor flags.

source

pub fn show_speaker(&mut self) -> &mut Self

Tells the game to show the speaker in the formatted message.

Sets the speaker value of the preprocessor flags to true.

If Self::set_speaker was not called, this will probably(…?) show the speech bubble icon as the speaker.

source

pub fn set_flag_unknown18(&mut self, value: u32) -> &mut Self

Sets the unknown18 value of the preprocessor flags.

source

pub fn set_speaker(&'a mut self, speaker: u32) -> &'a mut Self

Sets the speaker of the message to the given entity (probably actor or monster ID…?).

To actually also show the speaker, use Self::show_speaker.

source

pub fn set_flag_value(&'a mut self, flag_id: usize, value: u32) -> &'a mut Self

Sets flag values. Currently unknown what they do.

Max flag ID is 3.

source

pub fn set_id_value(&'a mut self, id_id: usize, value: u32) -> &'a mut Self

Sets an ID for a message placeholder. This is probably used by the \[name:id\], \[item:id\] etc. placeholders,

Max ID ID is 4.

source

pub fn set_number_value( &'a mut self, number_id: usize, value: i32 ) -> &'a mut Self

Sets a number for a message placeholder. This is probably used by the \[digits_c:0], etc. placeholders.

Max number ID is 4.

source

pub fn set_string( &'a mut self, string_id: usize, string: &'a CString ) -> &'a mut Self

Sets a string for message placeholders.

Replace all occurrences of \[string:<string_id>\] with the value of the string passed in.

Max string ID is 4.

source

pub fn output_buffer_size(&mut self, size: i32) -> &mut Self

Overwrites the size of the output buffer.

source

pub fn args(&self) -> &preprocessor_args

Returns a reference to the internal args. This will panic if Self::borrow_args was called before.

source

pub fn flags(&self) -> &preprocessor_flags

Returns a reference to the internal flags.

source

pub fn set_flags(&mut self, flags: &preprocessor_flags) -> &mut Self

Overwrite the internal flags with the specified ones.

This is useful if you want to re-use flags. You probably want to use Self::set_flag_unknown0, Self::show_speaker, Self::set_flag_unknown18 instead in most cases.

source

pub fn borrow_args( &'a mut self, args: &'a mut preprocessor_args ) -> &'a mut Self

Sets the internal arguments to use the arguments passed in.

This is useful if you want to re-use args.

Subsequent calls to Self::set_speaker, Self::set_flag_value, Self::set_id_value, Self::set_number_value,Self::set_string will manipulate the args passed in.

You probably don’t need to use this method in most cases, just use the above mentioned methods instead.

source

pub fn build<S: AsRef<str>>(self, format: S) -> String

Converts the format string to the formatted string.

Builds String from a str. The input is the format string to use.

source

pub fn build_from_cstr<S: AsRef<CStr>>(self, format: S) -> String

Converts the format string to the formatted string.

Builds String from a CStr. The input is the format string to use.

source

pub fn build_as_cstring<S: AsRef<str>>(self, format: S) -> CString

Converts the format string to the formatted string.

Builds CString from a str. The input is the format string to use.

source

pub fn build_from_cstr_as_cstring<S: AsRef<CStr>>(self, format: S) -> CString

Converts the format string to the formatted string.

Builds CString from a CStr. The input is the format string to use.

Trait Implementations§

source§

impl<'a> Default for GameStringBuilder<'a>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for GameStringBuilder<'a>

§

impl<'a> !Send for GameStringBuilder<'a>

§

impl<'a> !Sync for GameStringBuilder<'a>

§

impl<'a> Unpin for GameStringBuilder<'a>

§

impl<'a> !UnwindSafe for GameStringBuilder<'a>

Blanket Implementations§

§

impl<T> Any for Twhere T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
§

impl<T> Borrow<T> for Twhere T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.