Skip to content

Commit 571bad3

Browse files
gajopclaude
andcommitted
Refactor sbc into feature-first layout + domain-agnostic command system
Move command_system out of commands/ to sbc/command_system/, with its built-in commands under command_system/commands/. Split heightmap into heightmap/{commands,model,tests}. Make command_system domain-agnostic: Context no longer holds per-domain manager fields. Domain models self-register via an inventory ModelFactory and are reached type-erased through ctx.model::<T>(); SBC builds the registry once and fans history events over the models generically. commands_api no longer re-exports any domain type. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6d916fb commit 571bad3

40 files changed

Lines changed: 277 additions & 224 deletions
File renamed without changes.
File renamed without changes.

native/src/sbc/commands/command_system/clear_undo_redo_command.rs renamed to native/src/sbc/command_system/commands/clear_undo_redo_command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use serde::Deserialize;
22

3-
use super::command::Command;
4-
use super::context::{CommandManagerIntent, Context};
5-
use super::registry::register_command;
3+
use super::super::command::Command;
4+
use super::super::context::{CommandManagerIntent, Context};
5+
use super::super::registry::register_command;
66

77
#[derive(Deserialize)]
88
pub struct ClearUndoRedoCommand;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mod clear_undo_redo_command;
2+
mod redo_command;
3+
mod set_multiple_command_mode_command;
4+
mod undo_command;

native/src/sbc/commands/command_system/redo_command.rs renamed to native/src/sbc/command_system/commands/redo_command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use serde::Deserialize;
22

3-
use crate::sbc::commands::command_system::registry::register_command;
3+
use crate::sbc::command_system::registry::register_command;
44

5-
use super::command::Command;
6-
use super::context::{CommandManagerIntent, Context};
5+
use super::super::command::Command;
6+
use super::super::context::{CommandManagerIntent, Context};
77

88
#[derive(Deserialize)]
99
pub struct RedoCommand;

native/src/sbc/commands/command_system/set_multiple_command_mode_command.rs renamed to native/src/sbc/command_system/commands/set_multiple_command_mode_command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use serde::Deserialize;
22

3-
use super::command::Command;
4-
use super::context::{CommandManagerIntent, Context};
5-
use super::registry::register_command;
3+
use super::super::command::Command;
4+
use super::super::context::{CommandManagerIntent, Context};
5+
use super::super::registry::register_command;
66

77
#[derive(Deserialize)]
88
pub struct SetMultipleCommandModeCommand {

native/src/sbc/commands/command_system/undo_command.rs renamed to native/src/sbc/command_system/commands/undo_command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use serde::Deserialize;
22

3-
use super::command::Command;
4-
use super::context::{CommandManagerIntent, Context};
5-
use super::registry::register_command;
3+
use super::super::command::Command;
4+
use super::super::context::{CommandManagerIntent, Context};
5+
use super::super::registry::register_command;
66

77
#[derive(Deserialize)]
88
pub struct UndoCommand;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use spring_native::prelude::NativeInterfaceRef;
2+
3+
use crate::sbc::command_system::command::CommandId;
4+
use crate::sbc::command_system::model::{Model, Models};
5+
6+
/// A command's request back to the command manager, applied after `execute`
7+
/// returns so it doesn't re-enter the manager mid-call.
8+
pub enum CommandManagerIntent {
9+
Undo,
10+
Redo,
11+
Clear,
12+
SetMultipleCommandMode(bool),
13+
}
14+
15+
pub struct Context<'a> {
16+
pub interface: &'a NativeInterfaceRef,
17+
pub current_command_id: CommandId,
18+
pub command_manager_intents: Vec<CommandManagerIntent>,
19+
models: &'a mut Models,
20+
}
21+
22+
impl<'a> Context<'a> {
23+
pub fn new(
24+
interface: &'a NativeInterfaceRef,
25+
command_id: CommandId,
26+
models: &'a mut Models,
27+
) -> Self {
28+
Context {
29+
interface,
30+
current_command_id: command_id,
31+
command_manager_intents: Vec::new(),
32+
models,
33+
}
34+
}
35+
36+
/// The domain model of type `T` (panics if no feature registered one).
37+
pub fn model<T: Model>(&mut self) -> &mut T {
38+
self.models.get::<T>()
39+
}
40+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)