removed boardstate
This commit is contained in:
+7
-19
@@ -393,22 +393,10 @@ impl Board {
|
||||
}
|
||||
}
|
||||
|
||||
/// The scriptable world: the current [`Board`] plus (in the future) runtime-only
|
||||
/// state such as a shared variable blackboard.
|
||||
///
|
||||
/// `BoardState` is a sibling of the [`ScriptHost`] inside [`GameState`] and is
|
||||
/// held behind an `Rc<RefCell<…>>`. Keeping it separate from the script engine is
|
||||
/// what lets host functions hold a shared handle to the world without aliasing the
|
||||
/// borrow that is currently running the engine.
|
||||
pub struct BoardState {
|
||||
/// The active game board.
|
||||
pub board: Board,
|
||||
}
|
||||
|
||||
/// Holds the active game world and provides game-logic operations.
|
||||
///
|
||||
/// `GameState` is the boundary between the engine (rendering, input) and the
|
||||
/// game data. It owns the world ([`BoardState`], behind a shared `Rc<RefCell>`),
|
||||
/// game data. It owns the board (behind a shared `Rc<RefCell<Board>>`),
|
||||
/// the message log, and the [`ScriptHost`] driving object scripts. Front-ends and
|
||||
/// internal logic reach the board through [`board`](GameState::board) /
|
||||
/// [`board_mut`](GameState::board_mut). Scripts read the board directly and
|
||||
@@ -416,7 +404,7 @@ pub struct BoardState {
|
||||
/// after each script batch.
|
||||
pub struct GameState {
|
||||
/// The scriptable world, shared with the script host's read getters.
|
||||
board_state: Rc<RefCell<BoardState>>,
|
||||
board: Rc<RefCell<Board>>,
|
||||
/// The in-game message log, oldest first (newest pushed at the end).
|
||||
pub log: Vec<LogLine>,
|
||||
/// The Rhai scripting runtime driving this board's scripted objects.
|
||||
@@ -430,10 +418,10 @@ impl GameState {
|
||||
/// call [`GameState::run_init`] once the game is ready to start. Any script
|
||||
/// compile errors are surfaced into the log here.
|
||||
pub fn new(board: Board) -> Self {
|
||||
let board_state = Rc::new(RefCell::new(BoardState { board }));
|
||||
let scripts = ScriptHost::new(&board_state);
|
||||
let board = Rc::new(RefCell::new(board));
|
||||
let scripts = ScriptHost::new(&board);
|
||||
let mut state = Self {
|
||||
board_state,
|
||||
board,
|
||||
log: Vec::new(),
|
||||
scripts,
|
||||
};
|
||||
@@ -444,12 +432,12 @@ impl GameState {
|
||||
|
||||
/// Borrows the active board for reading (e.g. by a front-end renderer).
|
||||
pub fn board(&self) -> Ref<'_, Board> {
|
||||
Ref::map(self.board_state.borrow(), |bs| &bs.board)
|
||||
self.board.borrow()
|
||||
}
|
||||
|
||||
/// Borrows the active board for mutation.
|
||||
pub fn board_mut(&self) -> RefMut<'_, Board> {
|
||||
RefMut::map(self.board_state.borrow_mut(), |bs| &mut bs.board)
|
||||
self.board.borrow_mut()
|
||||
}
|
||||
|
||||
/// Appends a styled message to the log.
|
||||
|
||||
Reference in New Issue
Block a user