no need for scriptstate any more
This commit is contained in:
+11
-10
@@ -1,21 +1,22 @@
|
||||
use rhai::Engine;
|
||||
use crate::player::Player;
|
||||
use crate::api::board::BoardRef;
|
||||
use crate::player::PlayerRef;
|
||||
use crate::script::Registerable;
|
||||
use crate::utils::{ErrorSink, PlayerPos};
|
||||
use crate::utils::ErrorSink;
|
||||
|
||||
/// GameState stores player state but Board stores its position, and we want one
|
||||
/// object to register with Rhai
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PlayerWithPos(pub Player, pub PlayerPos);
|
||||
#[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::<PlayerWithPos>("Player")
|
||||
.register_get("gems", |player: &mut PlayerWithPos| player.0.gems)
|
||||
.register_get("health", |player: &mut PlayerWithPos| player.0.health)
|
||||
.register_get("max_health", |player: &mut PlayerWithPos| player.0.max_health)
|
||||
.register_get("keys", |player: &mut PlayerWithPos| player.0.keys)
|
||||
.register_get("x", |player: &mut PlayerWithPos| player.1.x)
|
||||
.register_get("y", |player: &mut PlayerWithPos| player.1.y);
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user