Stephen Seo
8838dbae69
Remove state::MessageBus in favor of String messages sent to Wrapper from Slot. Update Slot state from inside Wrapper::update such that changes should be immediately visible per Slot (moved code from Wrapper::rendered, fixing updates not being immediately visble).
98 lines
4 KiB
Rust
98 lines
4 KiB
Rust
use std::cell::Cell;
|
|
use std::rc::Rc;
|
|
use yew::prelude::*;
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
pub enum BoardState {
|
|
Empty,
|
|
Cyan,
|
|
Magenta,
|
|
}
|
|
|
|
impl Default for BoardState {
|
|
fn default() -> Self {
|
|
Self::Empty
|
|
}
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
pub enum Turn {
|
|
CyanPlayer,
|
|
MagentaPlayer,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct SharedState {
|
|
pub board: [Rc<Cell<BoardState>>; 56],
|
|
pub turn: Cell<Turn>,
|
|
pub info_text_ref: NodeRef,
|
|
}
|
|
|
|
impl Default for SharedState {
|
|
fn default() -> Self {
|
|
Self {
|
|
// cannot use [<type>; 56] because Rc does not impl Copy
|
|
board: [
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
],
|
|
turn: Cell::new(Turn::CyanPlayer),
|
|
info_text_ref: NodeRef::default(),
|
|
}
|
|
}
|
|
}
|