From 51e990a3a0a956bd2aa2dc7e01fa66dbcb752b33 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Fri, 8 Mar 2024 10:24:37 -0800 Subject: [PATCH] Remove unused `Tool::ExternalAction`. It's unused, will probably be replaced in its purpose with `Tool::Custom`, and gets in the way of deriving on the `Tool` enum. --- all-is-cubes/src/inv/tool.rs | 55 ----------------------------- all-is-cubes/src/save/conversion.rs | 10 +----- all-is-cubes/src/save/schema.rs | 3 -- 3 files changed, 1 insertion(+), 67 deletions(-) diff --git a/all-is-cubes/src/inv/tool.rs b/all-is-cubes/src/inv/tool.rs index 2a8256904..13ab5c601 100644 --- a/all-is-cubes/src/inv/tool.rs +++ b/all-is-cubes/src/inv/tool.rs @@ -79,31 +79,9 @@ pub enum Tool { /// Icon for the tool. icon: Block, }, - - /// A tool which calls an arbitrary function. - /// TODO: This is not used and should perhaps be folded into `Custom` - ExternalAction { - // TODO: Rework this so that the external component gets to update the icon. - // (Perhaps that's "a block defined by an external source"?) - /// Function that will be called when the tool is activated. - function: EphemeralOpaque, - /// Icon for the tool. - icon: Block, - }, } impl Tool { - #[allow(dead_code)] // TODO: This is going to be used for UI interactions but got delayed, so hide the warning - pub(crate) fn external_action( - icon: Block, - function: F, - ) -> Self { - Tool::ExternalAction { - icon, - function: EphemeralOpaque::new(Arc::new(function)), - } - } - /// Computes the effect of using the tool. /// /// The effect consists of both mutations to `self` and a [`UniverseTransaction`]. @@ -259,14 +237,6 @@ impl Tool { } Ok((Some(self), txn)) } - Self::ExternalAction { ref function, .. } => { - if let Some(f) = function.try_ref() { - f(input); - Ok((Some(self), UniverseTransaction::default())) - } else { - Err(ToolError::NotUsable) // TODO: communicate permanent error - } - } } } @@ -309,7 +279,6 @@ impl Tool { Cow::Borrowed(&predefined[Icons::Jetpack { active: *active }]) } Self::Custom { icon, op: _ } => Cow::Borrowed(icon), - Self::ExternalAction { icon, .. } => Cow::Borrowed(icon), } } @@ -327,7 +296,6 @@ impl Tool { Tool::PushPull => One, Tool::Jetpack { .. } => One, Tool::Custom { .. } => One, // TODO: let tool specify - Tool::ExternalAction { .. } => One, } } } @@ -347,9 +315,6 @@ impl VisitHandles for Tool { op.visit_handles(visitor); icon.visit_handles(visitor); } - Tool::ExternalAction { function: _, icon } => { - icon.visit_handles(visitor); - } } } } @@ -988,24 +953,4 @@ mod tests { .bind(tester.space_handle.clone()) ); } - - #[test] - fn use_external_action() { - use core::sync::atomic::{AtomicU32, Ordering}; - - let called = Arc::new(AtomicU32::new(0)); - let tool = Tool::external_action(AIR, { - let called = called.clone(); - move |_: &ToolInput| { - called.fetch_add(1, Ordering::Relaxed); - } - }); - - let tester = ToolTester::new(|_space| {}); - assert_eq!( - tester.equip_and_use_tool(tool), - Ok(UniverseTransaction::default()) - ); - assert_eq!(called.load(Ordering::Relaxed), 1); - } } diff --git a/all-is-cubes/src/save/conversion.rs b/all-is-cubes/src/save/conversion.rs index 9a55e717e..4eb4eaadd 100644 --- a/all-is-cubes/src/save/conversion.rs +++ b/all-is-cubes/src/save/conversion.rs @@ -571,7 +571,7 @@ mod math { mod inv { use super::*; - use crate::inv::{EphemeralOpaque, Inventory, Slot, Tool}; + use crate::inv::{Inventory, Slot, Tool}; impl Serialize for Inventory { fn serialize(&self, serializer: S) -> Result @@ -641,10 +641,6 @@ mod inv { op: op.clone(), icon: icon.clone(), }, - Tool::ExternalAction { - function: _, - ref icon, - } => schema::ToolSer::ExternalActionV1 { icon: icon.clone() }, } .serialize(serializer) } @@ -665,10 +661,6 @@ mod inv { schema::ToolSer::PushPullV1 {} => Tool::PushPull, schema::ToolSer::JetpackV1 { active } => Tool::Jetpack { active }, schema::ToolSer::CustomV1 { op, icon } => Tool::Custom { op, icon }, - schema::ToolSer::ExternalActionV1 { icon } => Tool::ExternalAction { - function: EphemeralOpaque(None), - icon, - }, }) } } diff --git a/all-is-cubes/src/save/schema.rs b/all-is-cubes/src/save/schema.rs index f5536120d..f512b102f 100644 --- a/all-is-cubes/src/save/schema.rs +++ b/all-is-cubes/src/save/schema.rs @@ -321,9 +321,6 @@ pub(crate) enum ToolSer { op: crate::op::Operation, icon: Block, }, - ExternalActionV1 { - icon: Block, - }, } //------------------------------------------------------------------------------------------------//