add setting for flashlight strength

This commit is contained in:
yuni 2024-09-22 03:40:12 +02:00
parent 93293092ce
commit c48e5cdb3a
6 changed files with 36 additions and 9 deletions

View file

@ -113,7 +113,7 @@ A variety of relatively simple game systems should interact with each other to c
- Spacesuit energy distribution into: - Spacesuit energy distribution into:
- [X] Residual Light Amplification - [X] Residual Light Amplification
- [X] Augmented Reality - [X] Augmented Reality
- [ ] Flashlight intensity - [X] Flashlight intensity
- [ ] AI assistance systems - [ ] AI assistance systems
- [ ] Thruster boost - [ ] Thruster boost
- [ ] G-force dampeners - [ ] G-force dampeners

View file

@ -21,6 +21,8 @@ use bevy_xpbd_3d::prelude::*;
pub const ENGINE_SPEED_FACTOR: f32 = 30.0; pub const ENGINE_SPEED_FACTOR: f32 = 30.0;
const MAX_TRANSMISSION_DISTANCE: f32 = 100.0; const MAX_TRANSMISSION_DISTANCE: f32 = 100.0;
const MAX_INTERACT_DISTANCE: f32 = 50.0; const MAX_INTERACT_DISTANCE: f32 = 50.0;
const POWER_DRAIN_FLASHLIGHT: [f32; 3] = [200e3, 1500e3, 2500e3];
pub const FLASHLIGHT_INTENSITY: [f32; 3] = [10e6, 400e6, 2e9]; // in lumens
pub struct ActorPlugin; pub struct ActorPlugin;
impl Plugin for ActorPlugin { impl Plugin for ActorPlugin {
@ -272,7 +274,7 @@ pub fn update_power(
let d = time.delta_seconds(); let d = time.delta_seconds();
for mut battery in &mut q_battery { for mut battery in &mut q_battery {
if settings.flashlight_active { if settings.flashlight_active {
battery.power -= 2400e3 * d; // 2.4MW battery.power -= POWER_DRAIN_FLASHLIGHT[prefs.flashlight_power] * d; // 2.4MW
if battery.power <= 0.0 { if battery.power <= 0.0 {
settings.flashlight_active = false; settings.flashlight_active = false;
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));

View file

@ -816,6 +816,7 @@ fn spawn_entities(
mut achievement_tracker: ResMut<var::AchievementTracker>, mut achievement_tracker: ResMut<var::AchievementTracker>,
mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>, mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>,
settings: Res<var::Settings>, settings: Res<var::Settings>,
prefs: Res<var::Preferences>,
) { ) {
for state_wrapper in er_spawn.read() { for state_wrapper in er_spawn.read() {
let state = &state_wrapper.0; let state = &state_wrapper.0;
@ -1073,7 +1074,7 @@ fn spawn_entities(
..default() ..default()
}, },
spot_light: SpotLight { spot_light: SpotLight {
intensity: 400_000_000.0, // lumens intensity: actor::FLASHLIGHT_INTENSITY[prefs.flashlight_power],
color: Color::WHITE, color: Color::WHITE,
shadows_enabled: true, shadows_enabled: true,
inner_angle: PI32 / 8.0 * 0.85, inner_angle: PI32 / 8.0 * 0.85,

View file

@ -88,6 +88,7 @@ pub enum GameEvent {
SetThirdPerson(Turn), SetThirdPerson(Turn),
SetRotationStabilizer(Turn), SetRotationStabilizer(Turn),
SetShadows(Turn), SetShadows(Turn),
UpdateFlashlight,
Achievement(String), Achievement(String),
} }
@ -141,7 +142,7 @@ impl Cycle {
} }
} }
pub fn setup(mut settings: ResMut<Settings>, prefs: Res<var::Preferences>) { pub fn setup(mut settings: ResMut<Settings>, prefs: ResMut<var::Preferences>) {
settings.hud_active = prefs.augmented_reality; settings.hud_active = prefs.augmented_reality;
settings.radio_mode = prefs.radio_station; settings.radio_mode = prefs.radio_station;
settings.set_noise_cancellation_mode(prefs.noise_cancellation_mode); settings.set_noise_cancellation_mode(prefs.noise_cancellation_mode);
@ -159,6 +160,7 @@ pub fn handle_game_event(
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>, mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
mut q_window: Query<&mut Window, With<PrimaryWindow>>, mut q_window: Query<&mut Window, With<PrimaryWindow>>,
mut q_light: Query<&mut DirectionalLight>, mut q_light: Query<&mut DirectionalLight>,
mut q_flashlight: Query<&mut SpotLight, With<actor::PlayersFlashLight>>,
mut mapcam: ResMut<camera::MapCam>, mut mapcam: ResMut<camera::MapCam>,
mut log: ResMut<hud::Log>, mut log: ResMut<hud::Log>,
opt: Res<var::CommandLineOptions>, opt: Res<var::CommandLineOptions>,
@ -255,6 +257,11 @@ pub fn handle_game_event(
hud::LogLevel::Achievement, hud::LogLevel::Achievement,
); );
} }
GameEvent::UpdateFlashlight => {
for mut spotlight in &mut q_flashlight {
spotlight.intensity = actor::FLASHLIGHT_INTENSITY[prefs.flashlight_power];
}
}
} }
} }
} }

View file

@ -67,6 +67,7 @@ pub const MENUDEF: &[(&str, MenuAction)] = &[
("", MenuAction::ToggleAR), ("", MenuAction::ToggleAR),
("", MenuAction::ChangeARAvatar), ("", MenuAction::ChangeARAvatar),
("", MenuAction::ModLightAmp), ("", MenuAction::ModLightAmp),
("", MenuAction::ModFlashlightPower),
("", MenuAction::ToggleSound), ("", MenuAction::ToggleSound),
("", MenuAction::ToggleMusic), ("", MenuAction::ToggleMusic),
("", MenuAction::ToggleCamera), ("", MenuAction::ToggleCamera),
@ -82,6 +83,7 @@ pub enum MenuAction {
ToggleAR, ToggleAR,
ChangeARAvatar, ChangeARAvatar,
ModLightAmp, ModLightAmp,
ModFlashlightPower,
ToggleSound, ToggleSound,
ToggleMusic, ToggleMusic,
ToggleCamera, ToggleCamera,
@ -488,6 +490,10 @@ pub fn update_menu(
let n = prefs.light_amp; let n = prefs.light_amp;
text.sections[i].value = format!("Light Amplification: {n}/3\n"); text.sections[i].value = format!("Light Amplification: {n}/3\n");
} }
MenuAction::ModFlashlightPower => {
let n = prefs.flashlight_power + 1;
text.sections[i].value = format!("Flashlight Power: {n}/3\n");
}
MenuAction::ChangeARAvatar => { MenuAction::ChangeARAvatar => {
if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) { if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) {
let avatar_title = ava.3; let avatar_title = ava.3;
@ -594,6 +600,14 @@ pub fn handle_input(
ew_updateoverlays.send(hud::UpdateOverlayVisibility); ew_updateoverlays.send(hud::UpdateOverlayVisibility);
ew_updatemenu.send(UpdateMenuEvent); ew_updatemenu.send(UpdateMenuEvent);
} }
MenuAction::ModFlashlightPower => {
prefs.flashlight_power += 1;
if prefs.flashlight_power > 2 {
prefs.flashlight_power = 0;
}
ew_game.send(GameEvent::UpdateFlashlight);
ew_updatemenu.send(UpdateMenuEvent);
}
MenuAction::ToggleMusic => { MenuAction::ToggleMusic => {
ew_game.send(GameEvent::SetMusic(Next)); ew_game.send(GameEvent::SetMusic(Next));
ew_updatemenu.send(UpdateMenuEvent); ew_updatemenu.send(UpdateMenuEvent);

View file

@ -453,6 +453,7 @@ pub struct Preferences {
pub shadows_sun: bool, pub shadows_sun: bool,
pub avatar: usize, pub avatar: usize,
pub light_amp: usize, // 0-3 pub light_amp: usize, // 0-3
pub flashlight_power: usize, // 0-2
#[serde(skip)] #[serde(skip)]
pub source_file: Option<String>, pub source_file: Option<String>,
@ -566,23 +567,25 @@ pub fn load_prefs() -> Preferences {
}; };
match toml.parse::<DocumentMut>() { match toml.parse::<DocumentMut>() {
Ok(doc) => match toml_edit::de::from_document::<Preferences>(doc) { Ok(doc) => match toml_edit::de::from_document::<Preferences>(doc) {
Ok(mut pref) => { Ok(mut prefs) => {
if let Some(path) = &path { if let Some(path) = &path {
println!("Loaded preference file from {path}"); println!("Loaded preference file from {path}");
} else { } else {
println!("Loaded preferences from internal defaults"); println!("Loaded preferences from internal defaults");
} }
pref.source_file = path; prefs.source_file = path;
return pref; prefs.flashlight_power = prefs.flashlight_power.clamp(0, 2);
prefs.light_amp = prefs.light_amp.clamp(0, 3);
prefs
} }
Err(error) => { Err(error) => {
eprintln!("Error: Failed to read preference line: {error}"); eprintln!("Error: Failed to read preference line: {error}");
return Preferences::default(); Preferences::default()
} }
}, },
Err(error) => { Err(error) => {
eprintln!("Error: Failed to open preferences: {error}"); eprintln!("Error: Failed to open preferences: {error}");
return Preferences::default(); Preferences::default()
} }
} }
} }