From de2886f7e964e53b0d1c48c6f56d2e43b078fc79 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 1 Apr 2024 17:45:28 +0200 Subject: [PATCH] implement "relativeto" command --- src/commands.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index d259fff..7c31e2d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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 = 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;