From cc198f5465e0282d1a126d66e2203c9259656096 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 31 Mar 2024 04:10:54 +0200 Subject: [PATCH] add "light" command, add cozy illumination to pizza place --- src/defs.txt | 13 ++++++++++--- src/world.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/defs.txt b/src/defs.txt index 7e21cf8..73bbca8 100644 --- a/src/defs.txt +++ b/src/defs.txt @@ -78,18 +78,25 @@ actor -8000 -1000 -100 monolith actor -3300 10 0 pizzeria scale 40 mass 1000000 - rotationy -0.25 + rotationy 0.30 angularmomentum 0 0 0 actor -3400 73 -13 pizzasign scale 20 mass 200 rotationy 0.45 - angularmomentum 0.00001 0 0.0003 - actor -3295 3 -32 suit + angularmomentum 0.1 0 0.2 + actor -3316 0 0 lightorb + scale 0.5 + light FF8F4A 1000000 + actor -3314 7 -2 lightorb + scale 0.5 + light FF8F4A 1000000 + actor -3330 10 0 suit name "Space Pizza™" chatid pizzeria mass 200.0 alive yes + angularmomentum 0.02 0.03 0.01 pronoun it chat pizzeria name "Space Pizza™" diff --git a/src/world.rs b/src/world.rs index a105cc6..faae258 100644 --- a/src/world.rs +++ b/src/world.rs @@ -26,6 +26,7 @@ fn asset_name_to_path(name: &str) -> &'static str { "asteroid2" => ASSET_ASTEROID2, "moonlet" => "models/moonlet.glb#Scene0", "monolith" => "models/monolith_neon.glb#Scene0", + "lightorb" => "models/lightorb.glb#Scene0", "MeteorAceGT" => "models/MeteorAceGT.glb#Scene0", "pizzeria" => "models/pizzeria2.glb#Scene0", "pizzasign" => "models/pizzasign.glb#Scene0", @@ -228,6 +229,8 @@ struct ParserState { collider: Collider, camdistance: f32, suit_integrity: f32, + light_brightness: f32, + light_color: Option, // Chat fields delay: f64, @@ -276,6 +279,8 @@ impl Default for ParserState { collider: Collider::sphere(1.0), camdistance: default_actor.camdistance, suit_integrity: 1.0, + light_brightness: 0.0, + light_color: None, delay: 0.0, text: "".to_string(), @@ -529,6 +534,22 @@ pub fn load_defs( continue; } } + ["light", color_hex, brightness] => { + if let Ok(brightness_float) = brightness.parse::() { + if let Ok(color) = Color::hex(color_hex) { + state.light_color = Some(color); + state.light_brightness = brightness_float; + } + else { + error!("Can't parse hexadecimal color code: {line}"); + continue; + } + } + else { + error!("Can't parse float: {line}"); + continue; + } + } // Parsing chats ["chat", chat_name] => { @@ -719,6 +740,23 @@ fn spawn_entities( ..default() }); } + if let Some(color) = state.light_color { + actor.insert(PointLightBundle { + point_light: PointLight { + intensity: state.light_brightness, + color: color, + range: 100.0, + radius: 100.0, + ..default() + }, + transform: Transform { + translation: state.pos, + scale: Vec3::splat(state.model_scale), + rotation: state.rotation, + }, + ..default() + }); + } if !state.chat.is_empty() { actor.insert(actor::Talker { conv_id: state.chat.clone(),