diff --git a/otg/gtk/src/components/goban.rs b/otg/gtk/src/components/goban.rs index 3a13c73..3d4fe3a 100644 --- a/otg/gtk/src/components/goban.rs +++ b/otg/gtk/src/components/goban.rs @@ -44,7 +44,7 @@ use gtk::{ subclass::prelude::*, }; use image::io::Reader as ImageReader; -use otg_core::Color; +use otg_core::{Color, Coordinate}; use std::{cell::RefCell, io::Cursor, rc::Rc}; const WIDTH: i32 = 800; @@ -178,11 +178,24 @@ impl Goban { ); let _ = ctx.stroke(); }); + + // This doesn't work except on 19x19 boads. This code needs to be adjusted to at least + // handle 13x13 and 9x9. Non-standard boards are On Their Own (TM). vec![3, 9, 15].into_iter().for_each(|col| { vec![3, 9, 15].into_iter().for_each(|row| { pen.star_point(ctx, col, row); }); }); + + (0..board.size.height).for_each(|row| { + (0..board.size.width).for_each(|column| { + match board.stone(&Coordinate{ row, column }) { + None => {}, + Some(Color::White) => pen.stone(ctx, row, column, Color::White, None), + Some(Color::Black) => pen.stone(ctx, row, column, Color::Black, None), + } + }) + }) } } diff --git a/otg/gtk/src/views/game_review.rs b/otg/gtk/src/views/game_review.rs index 170f8d1..857a0d8 100644 --- a/otg/gtk/src/views/game_review.rs +++ b/otg/gtk/src/views/game_review.rs @@ -54,9 +54,12 @@ impl GameReview { pub fn new(api: CoreApi, record: GameRecord) -> Self { let s: Self = Object::builder().build(); - let board_repr = otg_core::Goban::default(); + // It's actually really bad to be just throwing away errors. Panics make everyone unhappy. + // This is not a fatal error, so I'll replace this `unwrap` call with something that + // renders the board and notifies the user of a problem that cannot be resolved. + let board_repr = otg_core::Goban::default().apply_moves(record.mainline()).unwrap(); + let board = Goban::new(board_repr); - let board = Goban::new(otg_core::Goban::default()); /* s.attach(&board, 0, 0, 2, 2); s.attach(>k::Label::new(Some("white player")), 0, 2, 1, 1);