implemented birth (child)
This commit is contained in:
parent
6f01b486ae
commit
722e58d7ad
2 changed files with 68 additions and 18 deletions
|
|
@ -76,7 +76,7 @@ pub async fn mine_chunk_and_sweep(turtle: TurtleCommander, pos: Vec3, chunk: Vec
|
|||
async fn devore(turtle: &TurtleCommander) {
|
||||
let turtles: Vec<u32> = turtle.inventory().await.into_iter().enumerate()
|
||||
.filter(|(_,b)| b.as_ref().is_some_and(|b| b.name.contains("turtle")))
|
||||
.map(|(i,_)| i as u32).collect();
|
||||
.map(|(i,_)| (i + 1) as u32).collect();
|
||||
|
||||
if turtles.is_empty() {
|
||||
return;
|
||||
|
|
@ -90,7 +90,8 @@ async fn devore(turtle: &TurtleCommander) {
|
|||
let staging = position.pos - position.dir.unit();
|
||||
|
||||
turtle.goto(Position::new(staging, position.dir)).await;
|
||||
turtle.execute(Select(i as u32)).await;
|
||||
warn!("devoring {i}");
|
||||
turtle.execute(Select(i)).await;
|
||||
turtle.execute(Place).await;
|
||||
turtle.execute(CycleFront).await;
|
||||
loop {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use tracing::error;
|
||||
use tracing::trace;
|
||||
use tokio;
|
||||
use blocks::Vec3;
|
||||
|
|
@ -40,6 +41,7 @@ pub fn turtle_api() -> Router<SharedControl> {
|
|||
Router::new()
|
||||
.route("/new", post(create_turtle))
|
||||
.route("/:id/update", post(command))
|
||||
.route("/:id/setPosition", post(update_position))
|
||||
.route("/client.lua", get(client))
|
||||
.route("/:id/setGoal", post(set_goal))
|
||||
.route("/:id/cancelTask", post(cancel))
|
||||
|
|
@ -55,6 +57,22 @@ pub fn turtle_api() -> Router<SharedControl> {
|
|||
.route("/updateAll", get(update_turtles))
|
||||
}
|
||||
|
||||
pub(crate) async fn update_position(
|
||||
Path(id): Path<u32>,
|
||||
State(state): State<SharedControl>,
|
||||
Json(req): Json<Position>,
|
||||
) -> &'static str {
|
||||
let state = &mut state.read().await;
|
||||
let turtle = state.turtles.get(id as usize);
|
||||
if let Some(turtle) = turtle {
|
||||
turtle.write().await.position = req;
|
||||
info!("updated position");
|
||||
} else {
|
||||
error!("position update failed");
|
||||
}
|
||||
|
||||
"ACK"
|
||||
}
|
||||
pub(crate) async fn register_turtle(
|
||||
Path(id): Path<u32>,
|
||||
State(state): State<SharedControl>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue