Skip to content

Commit

Permalink
Add Fluff::PlaceBlockGeneric emitted by tool uses.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Oct 17, 2023
1 parent 3bd17ad commit fdcf85d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
8 changes: 8 additions & 0 deletions all-is-cubes/src/fluff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
/// Each [`Fluff`] value represents the beginning of such an effect. It does not specify
/// anything about the exact duration; the intent is that they should all be negligibly
/// short.
///
/// Currently, all `Fluff` is an item from a fixed list. In the future, it will be able
/// to refer to audio and visual assets defined in a `Universe`.
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
#[non_exhaustive]
pub enum Fluff {
/// A standard beep/“bell” sound, as might be used for a notification or error.
Beep,

/// A sound suitable for “something was activated or done”, e.g. a button was clicked.
Happened,

/// Sound and visual effect from a block having been placed in the game world
/// by player action, without any more specific overriding styling.
PlaceBlockGeneric,
}
14 changes: 9 additions & 5 deletions all-is-cubes/src/inv/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ impl ToolInput {
old_block: Block,
new_block: Block,
) -> Result<UniverseTransaction, ToolError> {
let affected_cube = cursor.cube() + cursor.face_selected().normal_vector();
let rotation = match new_block
.evaluate()
.map_err(|e| ToolError::Internal(e.to_string()))? // TODO: better error typing here
Expand All @@ -375,11 +376,14 @@ impl ToolInput {
.unwrap_or(GridRotation::IDENTITY)
}
};
self.set_cube(
cursor.cube() + cursor.face_selected().normal_vector(),
old_block,
new_block.rotate(rotation),
)
let txn = self.set_cube(affected_cube, old_block, new_block.rotate(rotation))?;
let txn = txn
.merge(
SpaceTransaction::fluff(affected_cube, Fluff::PlaceBlockGeneric)
.bind(self.cursor()?.space().clone()),
)
.expect("fluff never fails to merge");
Ok(txn)
}

/// Returns a [`Cursor`] indicating what blocks the tool should act on, if it is
Expand Down
12 changes: 11 additions & 1 deletion all-is-cubes/src/space/space_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,20 @@ impl SpaceTransaction {
/// transaction is committed, in addition to other effects of the transaction.
///
/// TODO: will eventually need rotation.
pub fn add_fluff(&mut self, cube: Cube, fluff: crate::fluff::Fluff) {
pub fn add_fluff(&mut self, cube: Cube, fluff: Fluff) {
self.at(cube).fluff.push(fluff);
}

/// Emit [`Fluff`] (sound/particle effects) located at the given cube when this
/// transaction is committed.
///
/// TODO: will eventually need rotation.
pub fn fluff(cube: Cube, fluff: Fluff) -> Self {
let mut txn = Self::default();
txn.at(cube).fluff.push(fluff);
txn
}

/// Computes the region of cubes directly affected by this transaction.
/// Ignores behaviors.
///
Expand Down

0 comments on commit fdcf85d

Please sign in to comment.