nightshade_api/
environment.rs1use crate::runner::{SUN_NAME, lookup_named};
4use nightshade::prelude::*;
5
6pub enum Background {
8 Sky,
10 Color([f32; 4]),
12 Hdr(Vec<u8>),
14}
15
16pub fn set_background(world: &mut World, background: Background) {
19 match background {
20 Background::Sky => {
21 world.resources.render_settings.atmosphere = Atmosphere::Sky;
22 }
23 Background::Color(color) => {
24 world.resources.render_settings.atmosphere = Atmosphere::None;
25 world.resources.render_settings.clear_color = color;
26 }
27 Background::Hdr(bytes) => {
28 load_hdr_skybox(world, bytes);
29 }
30 }
31}
32
33#[inline]
35pub fn show_grid(world: &mut World, enabled: bool) {
36 world.resources.debug_draw.show_grid = enabled;
37}
38
39#[inline]
41pub fn set_ambient(world: &mut World, color: [f32; 4]) {
42 world.resources.render_settings.ambient_light = color;
43}
44
45#[inline]
48pub fn set_fog(world: &mut World, fog: Option<Fog>) {
49 world.resources.render_settings.fog = fog;
50}
51
52#[inline]
54pub fn set_bloom(world: &mut World, enabled: bool) {
55 world.resources.render_settings.bloom_enabled = enabled;
56}
57
58pub fn set_time_of_day(world: &mut World, hour: f32) {
63 if world
64 .resources
65 .renderer_state
66 .day_night
67 .sun_entity
68 .is_none()
69 {
70 world.resources.renderer_state.day_night.sun_entity = lookup_named(world, SUN_NAME);
71 }
72 world.resources.render_settings.atmosphere = Atmosphere::DayNight;
73 world.resources.renderer_state.day_night.auto_cycle = true;
74 world.resources.renderer_state.day_night.speed = 0.0;
75 world.resources.renderer_state.day_night.hour = hour;
76}
77
78#[inline]
80pub fn set_title(world: &mut World, title: &str) {
81 world.resources.window.title = title.to_string();
82}
83
84pub fn screenshot(world: &mut World, path: std::path::PathBuf) {
86 queue_render_command(
87 world,
88 RenderCommand::CaptureScreenshot {
89 path: Some(path),
90 max_dimension: None,
91 },
92 );
93}