From 892af98003c1f6b15c5d7230d97fa02c1ed45566 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Mon, 19 Aug 2024 20:55:14 -0700 Subject: [PATCH] inv: Implement `Tool::PushPull` using `Operation::Alt`. --- all-is-cubes/src/inv/tool.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/all-is-cubes/src/inv/tool.rs b/all-is-cubes/src/inv/tool.rs index a028160fc..d85d30edc 100644 --- a/all-is-cubes/src/inv/tool.rs +++ b/all-is-cubes/src/inv/tool.rs @@ -182,22 +182,27 @@ impl Tool { } } Self::PushPull => { + // TODO: this tool is just a demonstration piece, and so we should + // make it possible to express as just a `Tool::Custom`. + let cursor = input.cursor()?; - let mut direction: Face6 = cursor + let direction: Face6 = cursor .face_selected() .opposite() .try_into() .map_err(|_| ToolError::NotUsable)?; - // If we can't push, then try pulling. - // TODO: Tool should have user-controllable modes - if cursor.space().read().unwrap()[cursor.cube() + direction.normal_vector()] != AIR - { - direction = direction.opposite(); - } + // TODO: Tool should have user-controllable modes for push vs. pull when the + // choice is free let velocity = 8; - let op = Operation::StartMove(block::Move::new(direction, 0, velocity)); + let op = Operation::Alt( + [ + Operation::StartMove(block::Move::new(direction, 0, velocity)), + Operation::StartMove(block::Move::new(direction.opposite(), 0, velocity)), + ] + .into(), + ); input.apply_operation(self.clone(), &op) }