implement "relativeto" command
This commit is contained in:
parent
5894a2443c
commit
de2886f7e9
|
@ -6,6 +6,7 @@ use bevy::math::DVec3;
|
||||||
use crate::{actor, nature, world};
|
use crate::{actor, nature, world};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct CommandsPlugin;
|
pub struct CommandsPlugin;
|
||||||
impl Plugin for CommandsPlugin {
|
impl Plugin for CommandsPlugin {
|
||||||
|
@ -163,6 +164,7 @@ pub fn load_defs(
|
||||||
let mut state = ParserState::default();
|
let mut state = ParserState::default();
|
||||||
let mut command;
|
let mut command;
|
||||||
let mut parameters;
|
let mut parameters;
|
||||||
|
let mut id2pos: HashMap<String, DVec3> = HashMap::new();
|
||||||
|
|
||||||
let mut line_nr = -1;
|
let mut line_nr = -1;
|
||||||
while let Some(line) = lines.next() {
|
while let Some(line) = lines.next() {
|
||||||
|
@ -214,11 +216,23 @@ pub fn load_defs(
|
||||||
continue;
|
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"] => {
|
["sphere", "yes"] => {
|
||||||
state.is_sphere = true;
|
state.is_sphere = true;
|
||||||
}
|
}
|
||||||
["id", id] => {
|
["id", id] => {
|
||||||
state.id = id.to_string();
|
state.id = id.to_string();
|
||||||
|
id2pos.insert(state.id.clone(), state.pos.clone());
|
||||||
}
|
}
|
||||||
["alive", "yes"] => {
|
["alive", "yes"] => {
|
||||||
state.is_alive = true;
|
state.is_alive = true;
|
||||||
|
|
Loading…
Reference in a new issue