32 lines
689 B
Rust
32 lines
689 B
Rust
use crate::SIMS;
|
|
use cultivar_common::prelude::*;
|
|
|
|
use sp_runtime_interface::runtime_interface;
|
|
|
|
#[allow(dead_code)]
|
|
#[runtime_interface]
|
|
pub trait Api {
|
|
fn say(msg: &str) {
|
|
println!("{msg}");
|
|
}
|
|
|
|
fn walk(
|
|
sim_id: SimId,
|
|
entity_id: EntityId,
|
|
direction: Direction,
|
|
) -> Result<Result<Position, (Position, WalkError)>, SimError> {
|
|
if let Some(mut sim) = SIMS.write().sims.get_mut(&sim_id) {
|
|
let sim = sim.value_mut();
|
|
if let Some(entity) = sim.entities.get_mut(&entity_id) {
|
|
match entity {
|
|
Entity::Ferris(entity) => Ok(entity.walk(&sim.board, direction)),
|
|
}
|
|
} else {
|
|
Err(SimError::EntityNotFound)
|
|
}
|
|
} else {
|
|
Err(SimError::SimNotFound)
|
|
}
|
|
}
|
|
}
|