Render the board with the completed game state.

This commit is contained in:
Savanni D'Gerinel 2024-03-24 16:16:50 -04:00
parent 3a7f204883
commit b70d927eac
2 changed files with 19 additions and 3 deletions

View File

@ -44,7 +44,7 @@ use gtk::{
subclass::prelude::*, subclass::prelude::*,
}; };
use image::io::Reader as ImageReader; use image::io::Reader as ImageReader;
use otg_core::Color; use otg_core::{Color, Coordinate};
use std::{cell::RefCell, io::Cursor, rc::Rc}; use std::{cell::RefCell, io::Cursor, rc::Rc};
const WIDTH: i32 = 800; const WIDTH: i32 = 800;
@ -178,11 +178,24 @@ impl Goban {
); );
let _ = ctx.stroke(); 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(|col| {
vec![3, 9, 15].into_iter().for_each(|row| { vec![3, 9, 15].into_iter().for_each(|row| {
pen.star_point(ctx, col, 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),
}
})
})
} }
} }

View File

@ -54,9 +54,12 @@ impl GameReview {
pub fn new(api: CoreApi, record: GameRecord) -> Self { pub fn new(api: CoreApi, record: GameRecord) -> Self {
let s: Self = Object::builder().build(); 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(&board, 0, 0, 2, 2);
s.attach(&gtk::Label::new(Some("white player")), 0, 2, 1, 1); s.attach(&gtk::Label::new(Some("white player")), 0, 2, 1, 1);