implement "relativeto" command

This commit is contained in:
yuni 2024-04-01 17:45:28 +02:00
parent 5894a2443c
commit de2886f7e9

View file

@ -6,6 +6,7 @@ use bevy::math::DVec3;
use crate::{actor, nature, world};
use regex::Regex;
use std::f32::consts::PI;
use std::collections::HashMap;
pub struct CommandsPlugin;
impl Plugin for CommandsPlugin {
@ -163,6 +164,7 @@ pub fn load_defs(
let mut state = ParserState::default();
let mut command;
let mut parameters;
let mut id2pos: HashMap<String, DVec3> = HashMap::new();
let mut line_nr = -1;
while let Some(line) = lines.next() {
@ -214,11 +216,23 @@ pub fn load_defs(
continue;
}
}
["relativeto", id] => {
match id2pos.get(&id.to_string()) {
Some(pos) => {
state.pos += *pos;
}
None => {
error!("Specified `relativeto` command but could not find id `{id}`");
continue;
}
}
}
["sphere", "yes"] => {
state.is_sphere = true;
}
["id", id] => {
state.id = id.to_string();
id2pos.insert(state.id.clone(), state.pos.clone());
}
["alive", "yes"] => {
state.is_alive = true;