defs.txt: implement "angularmomentum", "rotationy" commands

This commit is contained in:
yuni 2024-03-20 20:50:57 +01:00
parent 34f63d08a5
commit 8736397cbf

View file

@ -335,6 +335,8 @@ struct ParserState {
pos: Vec3,
model: String,
model_scale: f32,
rotation: Quat,
angular_momentum: Quat,
pronoun: String,
is_lifeform: bool,
is_alive: bool,
@ -353,12 +355,14 @@ impl Default for ParserState {
fn default() -> Self {
Self {
class: DefClass::None,
name: "".to_string(),
name: "NONAME".to_string(),
chat: "".to_string(),
pos: Vec3::new(0.0, 0.0, 0.0),
model: "".to_string(),
model_scale: 1.0,
rotation: Quat::IDENTITY,
angular_momentum: Quat::IDENTITY,
pronoun: "they/them".to_string(),
is_lifeform: false,
is_alive: false,
@ -413,7 +417,10 @@ impl ParserState {
self.reset_message();
}
fn spawn_actor(&mut self, commands: &mut Commands, asset_server: &Res<AssetServer>) {
let component_actor = actor::Actor::default();
let component_actor = actor::Actor {
angular_momentum: self.angular_momentum,
..default()
};
let component_lifeform = actor::LifeForm::default();
let component_talker = actor::Talker {
conv_id: self.chat.clone(),
@ -424,7 +431,7 @@ impl ParserState {
transform: Transform {
translation: self.pos,
scale: Vec3::splat(self.model_scale),
rotation: Quat::from_rotation_y(-PI / 3.),
rotation: self.rotation,
},
scene: asset_server.load(asset_name_to_path(self.model.as_str())),
..default()
@ -494,7 +501,7 @@ pub fn load_defs(
let caps = re1.captures(line);
if caps.is_none() {
if line.trim() != "" {
warn!("Syntax Error in definitions line {}: `{}`", line_nr, line);
error!("Syntax Error in definitions line {}: `{}`", line_nr, line);
}
continue;
}
@ -546,6 +553,25 @@ pub fn load_defs(
continue;
}
}
["rotationy", rotation_y] => {
if let Ok(rotation_y_float) = rotation_y.parse::<f32>() {
state.rotation = Quat::from_rotation_y(PI * rotation_y_float);
}
else {
error!("Can't parse float: {line}");
continue;
}
}
["angularmomentum", x, y, z] => {
if let (Ok(x_float), Ok(y_float), Ok(z_float)) =
(x.parse::<f32>(), y.parse::<f32>(), z.parse::<f32>()) {
state.angular_momentum = Quat::from_euler(EulerRot::XYZ, x_float, y_float, z_float);
}
else {
error!("Can't parse float: {line}");
continue;
}
}
// Parsing chats
["chat", chat_name] => {