Files
kiln/kiln-core/src/api/player.rs
T

23 lines
1.0 KiB
Rust
Raw Normal View History

2026-06-28 00:12:52 -05:00
use rhai::Engine;
2026-07-07 23:55:27 -05:00
use crate::api::board::BoardRef;
use crate::player::PlayerRef;
2026-06-28 00:12:52 -05:00
use crate::script::Registerable;
2026-07-07 23:55:27 -05:00
use crate::utils::ErrorSink;
2026-06-28 00:12:52 -05:00
/// GameState stores player state but Board stores its position, and we want one
/// object to register with Rhai
2026-07-07 23:55:27 -05:00
#[derive(Clone)]
pub struct PlayerWithPos(pub PlayerRef, pub BoardRef);
2026-06-28 00:12:52 -05:00
impl Registerable for PlayerWithPos {
fn register(engine: &mut Engine, _error_sink: ErrorSink) {
engine.register_type_with_name::<PlayerWithPos>("Player")
2026-07-07 23:55:27 -05:00
.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);
2026-06-28 00:12:52 -05:00
}
}