Character

Struct Character 

Source
pub struct Character {
    pub body: Body,
    pub space: Handle<Space>,
    /* private fields */
}
Expand description

A Character:

  • knows what Space it is looking at, by Handle,
  • knows where it is located and how it collides via a Body which it owns and steps, and
  • handles the parts of input management that are associated with universe state (controlling velocity, holding tools).

§Serialization stability warning

This type implements serde::Serialize and serde::Deserialize, but serialization support is still experimental (as is the game data model in general). We do not guarantee that future versions of all-is-cubes will be able to deserialize data which is serialized by this version.

Additionally, the serialization schema is designed with serde_json in mind. It is not guaranteed that using a different data format crate, which may use a different subset of the information exposed via serde::Serialize, will produce stable results.

Fields§

§body: Body

Position, collision, and look direction.

§space: Handle<Space>

Refers to the Space to be viewed and collided with.

Implementations§

Source§

impl Character

Source

pub fn spawn(spawn: &Spawn, space: Handle<Space>) -> Self

Constructs a Character within/looking at the given space with the initial state specified by spawn.

Source

pub fn spawn_default( read_ticket: ReadTicket<'_>, space: Handle<Space>, ) -> Result<Self, HandleError>

Constructs a Character within/looking at the given space with the initial state specified by Space::spawn.

Source

pub fn view<'t>( handle: &Handle<Self>, read_ticket: ReadTicket<'t>, ) -> Result<(&'t Handle<Space>, ViewTransform, f32), HandleError>

Computes the view transform for this character’s eye; translation and rotation from the camera coordinate system (whose look direction is the -Z axis) to the Space’s coordinate system.

See the documentation for [ViewTransform] for the interpretation of this transform.

In addition to the transform it also returns the Space to be viewed and the automatic exposure value.

TODO: This return value should really be a struct, but we are somewhat in the middle of refactoring how Character is built and this particular tuple is an interim measure.

Source

pub fn inventory(&self) -> &Inventory

Returns the character’s current inventory.

Source

pub fn selected_slots(&self) -> [Ix; 3]

Returns the character’s currently selected inventory slots.

The indices of this array are buttons (e.g. mouse buttons), and the values are inventory slot indices.

Source

pub fn set_selected_slot(&mut self, which_selection: usize, slot: Ix)

Changes which inventory slot is currently selected.

Source

pub fn click( read_ticket: ReadTicket<'_>, this: Handle<Character>, cursor: Option<&Cursor>, button: usize, ) -> Result<UniverseTransaction, ToolError>

Use this character’s selected tool on the given cursor.

Return an error if:

  • The tool is not usable.
  • The cursor does not refer to the same space as this character occupies.

Trait Implementations§

Source§

impl Debug for Character

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Character

Available on crate feature save only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Listen for Character

Registers a listener for mutations of this character.

Source§

type Msg = CharacterChange

The type of message which may be obtained from this source. Read more
Source§

type Listener = <Notifier<<Character as Listen>::Msg, Arc<dyn Listener<<Character as Listen>::Msg> + Sync + Send>> as Listen>::Listener

The type which all added listeners must be convertible to.
Source§

fn listen_raw(&self, listener: Self::Listener)

Subscribe the given Listener to this source of messages. Read more
Source§

fn listen<L>(&self, listener: L)
where L: IntoListener<Self::Listener, Self::Msg>, Self: Sized,

Subscribe the given Listener to this source of messages. Read more
Source§

impl Serialize for Character

Available on crate feature save only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Transactional for Character

Source§

type Transaction = CharacterTransaction

The type of transaction which should be used with Self.
Source§

fn transact<'c, F, O>( &mut self, f: F, ) -> Result<O, ExecuteError<Self::Transaction>>
where F: FnOnce(&mut Self::Transaction, &Self) -> Result<O, <Self::Transaction as Merge>::Conflict>, Self::Transaction: Transaction<Target = Self, Context<'c> = (), Output = NoOutput> + Default,

Convenience method for building and then applying a transaction to self, equivalent to the following steps: Read more
Source§

impl UTransactional for Character

Source§

fn bind( target: Handle<Self>, transaction: Self::Transaction, ) -> UniverseTransaction

Specify the target of the transaction as a Handle, and erase its type, so that it can be combined with other transactions in the same universe. Read more
Source§

impl UniverseMember for Character

Source§

type Read<'ticket> = Read<'ticket>

Type returned by Handle::<T>::read() which is the way to read the T value after it has been inserted into the Universe.
Source§

impl VisitHandles for Character

Source§

fn visit_handles(&self, visitor: &mut dyn HandleVisitor)

For each Handle contained within self that is reachable without traversing another Handle, call visitor with a reference to it.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

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

Casts the value.
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where 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 Dst
where Src: CheckedCast<Dst>,

Source§

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

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 Dst
where Src: OverflowingCast<Dst>,

Source§

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

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

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

Casts the value.
Source§

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

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where 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) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

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

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,