Implement game tree navigation #237

Merged
savanni merged 6 commits from savanni/tree-navigation into main 2024-05-23 13:04:25 +00:00
7 changed files with 12 additions and 20 deletions
Showing only changes of commit 15c4ae9bad - Show all commits

View File

@ -115,8 +115,6 @@ pub struct Core {
impl Core { impl Core {
pub fn new(config: Config) -> Self { pub fn new(config: Config) -> Self {
println!("config: {:?}", config);
let library = match config.get::<LibraryPath>() { let library = match config.get::<LibraryPath>() {
Some(ref path) if path.to_path_buf().exists() => { Some(ref path) if path.to_path_buf().exists() => {
Some(Database::open_path(path.to_path_buf()).unwrap()) Some(Database::open_path(path.to_path_buf()).unwrap())

View File

@ -611,7 +611,6 @@ mod test {
), ),
]; ];
println!("{}", board);
for (board, coordinate, group, liberties) in test_cases { for (board, coordinate, group, liberties) in test_cases {
assert_eq!(board.group(&coordinate), group.as_ref()); assert_eq!(board.group(&coordinate), group.as_ref());
assert_eq!( assert_eq!(

View File

@ -352,7 +352,6 @@ impl DepthTree {
.unwrap() .unwrap()
.traverse_pre_order() .traverse_pre_order()
.fold(0, |max, node| { .fold(0, |max, node| {
println!("node depth: {}", node.data().depth);
if node.data().depth > max { if node.data().depth > max {
node.data().depth node.data().depth
} else { } else {

View File

@ -102,22 +102,11 @@ impl Goban {
} }
pub fn set_board_state(&mut self, board_state: otg_core::Goban) { pub fn set_board_state(&mut self, board_state: otg_core::Goban) {
println!("updating board state");
*self.imp().board_state.borrow_mut() = board_state; *self.imp().board_state.borrow_mut() = board_state;
self.queue_draw(); self.queue_draw();
} }
fn redraw(&self, ctx: &cairo::Context, width: i32, height: i32) { fn redraw(&self, ctx: &cairo::Context, width: i32, height: i32) {
println!("{} x {}", width, height);
/*
let background = load_pixbuf(
"/com/luminescent-dreams/otg-gtk/wood_texture.jpg",
false,
WIDTH + 40,
HEIGHT + 40,
);
*/
let background = self let background = self
.imp() .imp()
.resource_manager .resource_manager

View File

@ -60,9 +60,11 @@ impl ReviewTree {
s s
} }
fn redraw(&self, ctx: &Context, _width: i32, _height: i32) { pub fn queue_draw(&self) {
println!("redraw: {} {}", _width, _height); self.drawing_area.queue_draw();
}
fn redraw(&self, ctx: &Context, _width: i32, _height: i32) {
#[allow(deprecated)] #[allow(deprecated)]
let context = WidgetExt::style_context(&self.widget); let context = WidgetExt::style_context(&self.widget);
#[allow(deprecated)] #[allow(deprecated)]

View File

@ -67,6 +67,7 @@ impl GameReview {
pub struct GameReview { pub struct GameReview {
widget: gtk::Box, widget: gtk::Box,
goban: Rc<RefCell<Option<Goban>>>, goban: Rc<RefCell<Option<Goban>>>,
review_tree: Rc<RefCell<Option<ReviewTree>>>,
resources: ResourceManager, resources: ResourceManager,
view: Rc<RefCell<GameReviewViewModel>>, view: Rc<RefCell<GameReviewViewModel>>,
@ -80,7 +81,8 @@ impl GameReview {
let s = Self { let s = Self {
widget, widget,
goban: Rc::new(RefCell::new(None)), goban: Default::default(),
review_tree: Default::default(),
resources, resources,
view, view,
}; };
@ -89,7 +91,6 @@ impl GameReview {
keypress_controller.connect_key_pressed({ keypress_controller.connect_key_pressed({
let s = s.clone(); let s = s.clone();
move |_, key, _, _| { move |_, key, _, _| {
println!("keystroke: {}", key);
let mut view = s.view.borrow_mut(); let mut view = s.view.borrow_mut();
match key { match key {
Key::Down => view.next_move(), Key::Down => view.next_move(),
@ -105,6 +106,10 @@ impl GameReview {
Some(ref mut goban) => goban.set_board_state(view.game_view()), Some(ref mut goban) => goban.set_board_state(view.game_view()),
None => {} None => {}
}; };
match *s.review_tree.borrow() {
Some(ref tree) => tree.queue_draw(),
None => {}
}
Propagation::Stop Propagation::Stop
} }
}); });
@ -161,6 +166,7 @@ impl GameReview {
self.widget.append(&sidebar); self.widget.append(&sidebar);
*self.goban.borrow_mut() = Some(board); *self.goban.borrow_mut() = Some(board);
*self.review_tree.borrow_mut() = Some(review_tree);
} }
fn redraw(&self) { fn redraw(&self) {

View File

@ -306,7 +306,6 @@ impl Move {
let column = column_char as u8 - b'a'; let column = column_char as u8 - b'a';
let row_char = parts.next().unwrap(); let row_char = parts.next().unwrap();
let row = row_char as u8 - b'a'; let row = row_char as u8 - b'a';
println!("[{}] {} [{}] {}", row_char, row, column_char, column);
Some((row, column)) Some((row, column))
} else { } else {
unimplemented!("moves must contain exactly two characters"); unimplemented!("moves must contain exactly two characters");