pub struct Character {
pub body: Body,
pub space: Handle<Space>,
/* private fields */
}Expand description
A Character:
- knows what
Spaceit is looking at, byHandle, - knows where it is located and how it collides via a
Bodywhich 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: BodyPosition, collision, and look direction.
space: Handle<Space>Refers to the Space to be viewed and collided with.
Implementations§
Source§impl Character
impl Character
Sourcepub fn spawn(spawn: &Spawn, space: Handle<Space>) -> Self
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.
Sourcepub fn spawn_default(
read_ticket: ReadTicket<'_>,
space: Handle<Space>,
) -> Result<Self, HandleError>
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.
Sourcepub fn view<'t>(
handle: &Handle<Self>,
read_ticket: ReadTicket<'t>,
) -> Result<(&'t Handle<Space>, ViewTransform, f32), HandleError>
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.
Sourcepub fn selected_slots(&self) -> [Ix; 3]
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.
Sourcepub fn set_selected_slot(&mut self, which_selection: usize, slot: Ix)
pub fn set_selected_slot(&mut self, which_selection: usize, slot: Ix)
Changes which inventory slot is currently selected.
Sourcepub fn click(
read_ticket: ReadTicket<'_>,
this: Handle<Character>,
cursor: Option<&Cursor>,
button: usize,
) -> Result<UniverseTransaction, ToolError>
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<'de> Deserialize<'de> for Character
Available on crate feature save only.
impl<'de> Deserialize<'de> for Character
save only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Listen for Character
Registers a listener for mutations of this character.
impl Listen for Character
Registers a listener for mutations of this character.
Source§type Msg = CharacterChange
type Msg = CharacterChange
Source§type Listener = <Notifier<<Character as Listen>::Msg, Arc<dyn Listener<<Character as Listen>::Msg> + Sync + Send>> as Listen>::Listener
type Listener = <Notifier<<Character as Listen>::Msg, Arc<dyn Listener<<Character as Listen>::Msg> + Sync + Send>> as Listen>::Listener
Source§fn listen_raw(&self, listener: Self::Listener)
fn listen_raw(&self, listener: Self::Listener)
Source§impl Transactional for Character
impl Transactional for Character
Source§type Transaction = CharacterTransaction
type Transaction = CharacterTransaction
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,
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,
self,
equivalent to the following steps: Read moreSource§impl UTransactional for Character
impl UTransactional for Character
Source§fn bind(
target: Handle<Self>,
transaction: Self::Transaction,
) -> UniverseTransaction
fn bind( target: Handle<Self>, transaction: Self::Transaction, ) -> UniverseTransaction
Source§impl UniverseMember for Character
impl UniverseMember for Character
Source§impl VisitHandles for Character
impl VisitHandles for Character
Source§fn visit_handles(&self, visitor: &mut dyn HandleVisitor)
fn visit_handles(&self, visitor: &mut dyn HandleVisitor)
Auto Trait Implementations§
impl !Freeze for Character
impl !RefUnwindSafe for Character
impl Send for Character
impl Sync for Character
impl Unpin for Character
impl !UnwindSafe for Character
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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