Set up the game review page along with #229

Merged
savanni merged 24 commits from otg/game-review into main 2024-03-31 23:37:51 +00:00
2 changed files with 19 additions and 3 deletions
Showing only changes of commit b70d927eac - Show all commits

View File

@ -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),
}
})
})
}
}

View File

@ -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(&gtk::Label::new(Some("white player")), 0, 2, 1, 1);