From 82d32f96551479cac850884e47a12e3698c48129 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Tue, 21 Nov 2023 19:35:03 -0800 Subject: [PATCH] Remove `SpaceTransaction::set()`. The majority of its uses were replaced with `SpaceTransaction::filling()`. --- all-is-cubes-ui/src/vui/widgets/toolbar.rs | 14 +++--- all-is-cubes/src/space/space_txn.rs | 54 +--------------------- 2 files changed, 9 insertions(+), 59 deletions(-) diff --git a/all-is-cubes-ui/src/vui/widgets/toolbar.rs b/all-is-cubes-ui/src/vui/widgets/toolbar.rs index 58dd72d7d..fe9a8e10b 100644 --- a/all-is-cubes-ui/src/vui/widgets/toolbar.rs +++ b/all-is-cubes-ui/src/vui/widgets/toolbar.rs @@ -14,7 +14,7 @@ use all_is_cubes::drawing::embedded_graphics::{ use all_is_cubes::inv::{Slot, TOOL_SELECTIONS}; use all_is_cubes::listen::{DirtyFlag, Gate, Listen as _, ListenableSource, Listener}; use all_is_cubes::math::{Cube, FaceMap, GridAab, GridCoordinate, GridPoint, GridVector, Gridgid}; -use all_is_cubes::space::{Space, SpacePhysics, SpaceTransaction}; +use all_is_cubes::space::{CubeTransaction, Space, SpacePhysics, SpaceTransaction}; use all_is_cubes::time::Duration; use all_is_cubes::transaction::Merge as _; use all_is_cubes::universe::{URef, Universe}; @@ -196,12 +196,14 @@ impl ToolbarController { break; } - let position = self.slot_position(index); + let cube = self.slot_position(index); // Draw icon - txn.set( - position, - None, - Some(stack.icon(&self.definition.hud_blocks.icons).into_owned()), + txn.merge_from( + CubeTransaction::replacing( + None, + Some(stack.icon(&self.definition.hud_blocks.icons).into_owned()), + ) + .at(cube), )?; } diff --git a/all-is-cubes/src/space/space_txn.rs b/all-is-cubes/src/space/space_txn.rs index 6b2736a6c..af03e9735 100644 --- a/all-is-cubes/src/space/space_txn.rs +++ b/all-is-cubes/src/space/space_txn.rs @@ -66,29 +66,11 @@ impl SpaceTransaction { /// transaction will fail. /// If `new` is not [`None`], replaces the existing block with `new`. /// - /// TODO: This name is a poor name now that [`Self::set`] exists. + /// TODO: Consider replacing all uses of this with `CubeTransaction::replacing()`. pub fn set_cube(cube: impl Into, old: Option, new: Option) -> Self { CubeTransaction::replacing(old, new).at(cube.into()) } - /// Expand this transaction to include modifying the given cube, or return an error if - /// that would conflict (by the same definition as transaction merging). - /// - /// If `old` is not [`None`], requires that the existing block is that block or the - /// transaction will fail. - /// If `new` is not [`None`], replaces the existing block with `new`. - pub fn set( - &mut self, - cube: impl Into, - old: Option, - new: Option, - ) -> Result<(), SpaceTransactionConflict> { - let cube: Cube = cube.into(); - self.at(cube) - .merge_from(CubeTransaction::replacing(old, new)) - .map_err(|conflict| SpaceTransactionConflict::Cube { cube, conflict }) - } - /// Provides an [`DrawTarget`](embedded_graphics::prelude::DrawTarget) /// adapter for 2.5D drawing. /// @@ -653,40 +635,6 @@ mod tests { .unwrap_err(); } - #[test] - fn set_cube_mutate_equivalent_to_merge() { - let [b1, b2, b3] = make_some_blocks(); - - // A basic single-cube transaction is the same either way. - let mut t = SpaceTransaction::default(); - t.set([0, 0, 0], Some(b1.clone()), Some(b2.clone())) - .unwrap(); - assert_eq!( - t, - SpaceTransaction::set_cube([0, 0, 0], Some(b1.clone()), Some(b2.clone())), - ); - - // Two-cube transaction. - let prev = t.clone(); - t.set([1, 0, 0], Some(b2.clone()), Some(b3.clone())) - .unwrap(); - assert_eq!( - t, - prev.merge(SpaceTransaction::set_cube( - [1, 0, 0], - Some(b2.clone()), - Some(b3.clone()) - )) - .unwrap(), - ); - - // Conflict - let prev = t.clone(); - t.set([0, 0, 0], Some(b1.clone()), Some(b3.clone())) - .expect_err("should have merge failure"); - assert_eq!(t, prev,); - } - #[test] fn merge_allows_independent() { let [b1, b2, b3] = make_some_blocks();