pub fn use_tool(
        &self,
        cursor: &Cursor,
        character: URef<Character>,
        slot_index: Option<usize>,
    ) -> Result<UniverseTransaction, ToolError> {
        let activate = Tool::Activate;
        let tool = if let Some(slot_index) = slot_index {
            if let Some(tool) = self.slots.get(slot_index) {
                tool
            } else {
                return Err(ToolError::NotUsable);
            }
        } else {
            &activate
        };

        let input = ToolInput {
            cursor: cursor.clone(),
            character: Some(character.clone()),
        };
        let (new_tool, mut transaction) = tool.clone().use_tool(&input)?;

        if &new_tool != tool {
            if let Some(slot_index) = slot_index {
                transaction = transaction
                    .merge(
                        CharacterTransaction::inventory(InventoryTransaction::replace(
                            slot_index,
                            tool.clone(),
                            new_tool,
                        ))
                        .bind(character),
                    )
                    .expect("failed to merge tool self-update");
            } else {
                panic!("shouldn't happen: no slot but tool mutated");
            }
        }

        Ok(transaction)
    }
/// Apply a tool to the cursor location.
///
/// If `slot_index` is [`None`], uses a [`Tool::Activate`] that does not exist in the inventory.
/// TODO: Bad API, have a more coherent overall design.
///
/// `character` must be the character containing the inventory. TODO: Bad API
Apply a tool to the cursor location.

`character` must be the character containing the inventory. TODO: Bad API
Apply a tool to the cursor location . ` character ` must be the character containing the inventory . TODO : Bad API
pub fn use_tool(
        &self,
        cursor: &Cursor,
        character: URef<Character>,
        slot_index: Option<usize>,
    ) -> Result<UniverseTransaction, ToolError> {
        let activate = Tool::Activate;
        let tool = if let Some(slot_index) = slot_index {
            if let Some(tool) = self.slots.get(slot_index) {
                tool
            } else {
                return Err(ToolError::NotUsable);
            }
        } else {
            &activate
        };
        let input = ToolInput {
            cursor: cursor.clone(),
            character: Some(character.clone()),
        };
        let (new_tool, mut transaction) = tool.clone().use_tool(&input)?;
        if &new_tool != tool {
            if let Some(slot_index) = slot_index {
                transaction = transaction
                    .merge(
                        CharacterTransaction::inventory(InventoryTransaction::replace(
                            slot_index,
                            tool.clone(),
                            new_tool,
                        ))
                        .bind(character),
                    )
                    .expect("failed to merge tool self-update");
            } else {
                panic!("shouldn't happen: no slot but tool mutated");
            }
        }
        Ok(transaction)
    }
pub fn use_tool ( & self , cursor : & Cursor , character : URef < Character > , slot_index : Option < usize > , ) -> Result < UniverseTransaction , ToolError > { let activate = Tool :: Activate ; let tool = if let Some ( slot_index ) = slot_index { if let Some ( tool ) = self . slots . get ( slot_index ) { tool } else { return Err ( ToolError :: NotUsable ) ; } } else { & activate } ; let input = ToolInput { cursor : cursor . clone ( ) , character : Some ( character . clone ( ) ) , } ; let ( new_tool , mut transaction ) = tool . clone ( ) . use_tool ( & input ) ? ; if & new_tool != tool { if let Some ( slot_index ) = slot_index { transaction = transaction . merge ( CharacterTransaction :: inventory ( InventoryTransaction :: replace ( slot_index , tool . clone ( ) , new_tool , ) ) . bind ( character ) , ) . expect ( " " ) ; } else { panic ! ( " " ) ; } } Ok ( transaction ) }
Apply a tool to the cursor location.
Apply a tool to the cursor location .
&self
cursor
&Cursor
character
URef<Character>
slot_index
Option<usize>