Enum all_is_cubes::inv::Tool
source · #[non_exhaustive]pub enum Tool {
Activate,
RemoveBlock {
keep: bool,
},
Block(Block),
InfiniteBlocks(Block),
CopyFromSpace,
EditBlock,
PushPull,
Jetpack {
active: bool,
},
Custom {
op: Operation,
icon: Block,
},
ExternalAction {
function: EphemeralOpaque<dyn Fn(&ToolInput) + Send + Sync>,
icon: Block,
},
}
Expand description
A Tool
is an object which a character can use to have some effect in the game,
such as placing or removing a block. In particular, a tool use usually corresponds
to a click.
Currently, Tool
s also play the role of “inventory items”. This may change in the
future.
§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.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Activate
“Click”, or “push button”, or generally “activate the function of this” as opposed to editing it.
This can activate an ActivatableRegion
.
It may have more functions in the future.
RemoveBlock
Delete any targeted block from the space.
Block(Block)
Move the given block out of inventory (consuming this tool) into the targeted empty space.
InfiniteBlocks(Block)
Places copies of the given block in targeted empty space. Infinite uses.
CopyFromSpace
Copy block from space to inventory.
EditBlock
Teleport into a block’s space for editing.
TODO: This is not yet actually implemented.
PushPull
Push targeted block into adjacent cube.
Jetpack
Allows flight.
TODO: This should probably be a feature a tool can have rather than a single-purpose item, but we don’t yet have a plan for programmable items.
Custom
A tool which performs an arbitrary Operation
.
ExternalAction
Fields
A tool which calls an arbitrary function.
TODO: This is not used and should perhaps be folded into Custom
Implementations§
source§impl Tool
impl Tool
sourcepub fn use_tool(
self,
input: &ToolInput
) -> Result<(Option<Self>, UniverseTransaction), ToolError>
pub fn use_tool( self, input: &ToolInput ) -> Result<(Option<Self>, UniverseTransaction), ToolError>
Computes the effect of using the tool.
The effect consists of both mutations to self
and a UniverseTransaction
.
If the result is None
then the tool is deleted.
If the transaction does not succeed, the original Tool
value should be kept.
TODO: Return type is inelegant
sourcepub fn use_immutable_tool(
&self,
input: &ToolInput
) -> Result<UniverseTransaction, ToolError>
pub fn use_immutable_tool( &self, input: &ToolInput ) -> Result<UniverseTransaction, ToolError>
As Self::use_tool
, except that it does not allow the tool to modify itself.
This operation is used for special cases where an action is expressed by a tool but the tool is not a “game item”.
sourcepub fn icon<'a>(
&'a self,
predefined: &'a BlockProvider<Icons>
) -> Cow<'a, Block>
pub fn icon<'a>( &'a self, predefined: &'a BlockProvider<Icons> ) -> Cow<'a, Block>
Return a block to use as an icon for this tool. For tools that place blocks, has the same appearance as the block to be placed. The display name of the block should be the display name of the tool.
TODO (API instability): Eventually we will probably want additional decorations that probably should not need to be painted into the block itself.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Tool
impl<'de> Deserialize<'de> for Tool
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 PartialEq for Tool
impl PartialEq for Tool
source§impl VisitRefs for Tool
impl VisitRefs for Tool
source§fn visit_refs(&self, visitor: &mut dyn RefVisitor)
fn visit_refs(&self, visitor: &mut dyn RefVisitor)
impl Eq for Tool
impl StructuralEq for Tool
impl StructuralPartialEq for Tool
Auto Trait Implementations§
impl !RefUnwindSafe for Tool
impl Send for Tool
impl Sync for Tool
impl Unpin for Tool
impl !UnwindSafe for Tool
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.