Skip to main content

PieceTrait

Trait PieceTrait 

Source
pub trait PieceTrait:
    PieceBaseTrait
    + Downcast
    + Send
    + Debug
    + 'static
    + Serialize
    + Deserialize {
Show 14 methods // Required methods fn svg_piece( &self, f: &mut Html, gpc: &GPiece, gs: &GameState, id: VisiblePieceId, ) -> Result<(), InternalError>; fn describe_html( &self, gpc: &GPiece, _goccults: &GOccults, ) -> Result<Html, InternalError>; // Provided methods fn add_ui_operations( &self, _y: ShowUnocculted, _upd: &mut Vec<UoDescription>, _gs: &GameState, _gpc: &GPiece, ) -> Result<(), InternalError> { ... } fn ui_operation( &self, _y: ShowUnocculted, _a: ApiPieceOpArgs<'_>, _opname: &str, _wrc: WhatResponseToClientOp, ) -> Result<OpOutcomeThunkGeneric<(PlayerId, PieceId), (PieceUpdate, Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>>), ApiPieceOpError>, ApiPieceOpError> { ... } fn ui_permit_flip(&self, _gpc: &GPiece) -> Result<bool, ApiPieceOpError> { ... } fn held_change_hook( &self, _ig: &InstanceRef, _gplayers: &DenseSlotMap<PlayerId, GPlayer>, _ipieces: &IPieces, _goccults: &GOccults, _gpieces: &mut GPieces, _tpiece: PieceId, _was_held: Option<PlayerId>, ) -> Result<OpOutcomeThunkGeneric<(PlayerId,), Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>>, InternalError>, InternalError> { ... } fn save_reloaded_hook( &self, _piece: PieceId, _gs: &mut GameState, _ig: &InstanceRef, ) -> Result<(), InternalError> { ... } fn loaded_hook_preview( &self, _gpc: &mut GPiece, ) -> Result<(), InternalError> { ... } fn bbox_preview(&self) -> Result<RectC<i32>, InternalError> { ... } fn delete_hook( &self, _p: &GPiece, _gs: &mut GameState, ) -> ExecuteGameChangeUpdates { ... } fn sortkey(&self) -> Option<&str> { ... } fn occultation_notify_hook( &self, _piece: PieceId, ) -> Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>> { ... } fn op_multigrab( &self, _a: ApiPieceOpArgs<'_>, _show: ShowUnocculted, _qty: u32, _new_z: ShouldSetZLevel, ) -> Result<OpOutcomeThunkGeneric<(PlayerId, PieceId), (PieceUpdate, Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>>), ApiPieceOpError>, ApiPieceOpError> { ... } fn abs_bbox(&self, p: &GPiece) -> Result<RectC<i32>, InternalError> { ... }
}

Required Methods§

Source

fn svg_piece( &self, f: &mut Html, gpc: &GPiece, gs: &GameState, id: VisiblePieceId, ) -> Result<(), InternalError>

Source

fn describe_html( &self, gpc: &GPiece, _goccults: &GOccults, ) -> Result<Html, InternalError>

Provided Methods§

Source

fn add_ui_operations( &self, _y: ShowUnocculted, _upd: &mut Vec<UoDescription>, _gs: &GameState, _gpc: &GPiece, ) -> Result<(), InternalError>

Source

fn ui_operation( &self, _y: ShowUnocculted, _a: ApiPieceOpArgs<'_>, _opname: &str, _wrc: WhatResponseToClientOp, ) -> Result<OpOutcomeThunkGeneric<(PlayerId, PieceId), (PieceUpdate, Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>>), ApiPieceOpError>, ApiPieceOpError>

Source

fn ui_permit_flip(&self, _gpc: &GPiece) -> Result<bool, ApiPieceOpError>

Can return false to mean “I will handle it in ui_operation”

Source

fn held_change_hook( &self, _ig: &InstanceRef, _gplayers: &DenseSlotMap<PlayerId, GPlayer>, _ipieces: &IPieces, _goccults: &GOccults, _gpieces: &mut GPieces, _tpiece: PieceId, _was_held: Option<PlayerId>, ) -> Result<OpOutcomeThunkGeneric<(PlayerId,), Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>>, InternalError>, InternalError>

Piece is responsible for dealing with the possibility that they may be occulted!

Source

fn save_reloaded_hook( &self, _piece: PieceId, _gs: &mut GameState, _ig: &InstanceRef, ) -> Result<(), InternalError>

Source

fn loaded_hook_preview(&self, _gpc: &mut GPiece) -> Result<(), InternalError>

Source

fn bbox_preview(&self) -> Result<RectC<i32>, InternalError>

Source

fn delete_hook( &self, _p: &GPiece, _gs: &mut GameState, ) -> ExecuteGameChangeUpdates

Not called if the whole game is destroyed. You can use Drop of course but it’s not usually much use since you don’t have a reference to the game or anything.

Source

fn sortkey(&self) -> Option<&str>

Source

fn occultation_notify_hook( &self, _piece: PieceId, ) -> Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>>

Source

fn op_multigrab( &self, _a: ApiPieceOpArgs<'_>, _show: ShowUnocculted, _qty: u32, _new_z: ShouldSetZLevel, ) -> Result<OpOutcomeThunkGeneric<(PlayerId, PieceId), (PieceUpdate, Vec<Box<dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer<'_>)>>), ApiPieceOpError>, ApiPieceOpError>

Source

fn abs_bbox(&self, p: &GPiece) -> Result<RectC<i32>, InternalError>

Implementations§

Source§

impl dyn PieceTrait

Source

pub fn is<__T>(&self) -> bool
where __T: PieceTrait,

Returns true if the trait object wraps an object of type __T.

Source

pub fn downcast<__T>( self: Box<dyn PieceTrait>, ) -> Result<Box<__T>, Box<dyn PieceTrait>>
where __T: PieceTrait,

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

Source

pub fn downcast_rc<__T>( self: Rc<dyn PieceTrait>, ) -> Result<Rc<__T>, Rc<dyn PieceTrait>>
where __T: PieceTrait,

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

Source

pub fn downcast_ref<__T>(&self) -> Option<&__T>
where __T: PieceTrait,

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

Source

pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>
where __T: PieceTrait,

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for Box<dyn PieceTrait>

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Box<dyn PieceTrait>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl<'de> Deserialize<'de> for Box<dyn PieceTrait + Send>

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Box<dyn PieceTrait + Send>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl<'r> RefTraitObjectPieceTraitExt<'r> for &'r (dyn PieceTrait + 'static)

Source§

impl<'r> RefTraitObjectPieceTraitExt<'r> for &'r (dyn PieceTrait + 'static)

Source§

impl<'typetag> Serialize for dyn PieceTrait + 'typetag

Source§

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

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

impl<'typetag> Serialize for dyn PieceTrait + Send + 'typetag

Source§

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

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

impl<'typetag> Serialize for dyn PieceTrait + Send + Sync + 'typetag

Source§

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

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

impl<'typetag> Serialize for dyn PieceTrait + Sync + 'typetag

Source§

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

Serialize this value into the given Serde serializer. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§