use rhai::Engine; use crate::api::board::BoardRef; use crate::player::PlayerRef; use crate::script::Registerable; use crate::utils::ErrorSink; /// GameState stores player state but Board stores its position, and we want one /// object to register with Rhai #[derive(Clone)] pub struct PlayerWithPos(pub PlayerRef, pub BoardRef); impl Registerable for PlayerWithPos { fn register(engine: &mut Engine, _error_sink: ErrorSink) { engine.register_type_with_name::("Player") .register_get("gems", |player: &mut PlayerWithPos| player.0.borrow().gems) .register_get("health", |player: &mut PlayerWithPos| player.0.borrow().health) .register_get("max_health", |player: &mut PlayerWithPos| player.0.borrow().max_health) .register_get("keys", |player: &mut PlayerWithPos| player.0.borrow().keys) .register_get("x", |player: &mut PlayerWithPos| player.1.borrow().player.x) .register_get("y", |player: &mut PlayerWithPos| player.1.borrow().player.y); } }