-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
613 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod buildings; | ||
mod solar_setup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use godot::builtin::{NodePath, Vector3}; | ||
use godot::engine::{light_3d, DirectionalLight3D, Node3D, Time}; | ||
use godot::obj::Gd; | ||
use godot_rust_script::{godot_script_impl, GodotScript}; | ||
|
||
use crate::util::logger; | ||
|
||
#[derive(GodotScript, Debug)] | ||
#[script(base = Node3D)] | ||
struct SolarSetup { | ||
/// Reference to the sun child node. | ||
#[export(node_path = ["DirectionalLight3D"])] | ||
pub sun: NodePath, | ||
|
||
/// Reference to the moon child node. | ||
#[export(node_path = ["DirectionalLight3D"])] | ||
pub moon: NodePath, | ||
|
||
#[export(range(min = 1.0, max = 120.0, step = 1.0))] | ||
pub day_length: u64, | ||
|
||
base: Gd<Node3D>, | ||
} | ||
|
||
#[godot_script_impl] | ||
impl SolarSetup { | ||
fn sun(&self) -> Option<Gd<DirectionalLight3D>> { | ||
self | ||
.base | ||
.get_window() | ||
.and_then(|root| root.get_node(self.sun.clone())) | ||
.map(|node| node.cast()) | ||
} | ||
|
||
pub fn _physics_process(&mut self, _delta: f64) { | ||
let day_length = self.day_length * 60 * 1000; | ||
let time = Time::singleton().get_ticks_msec() % (day_length * 2); | ||
|
||
let sun_pos = time as f32 * (360.0 / (day_length * 2) as f32); | ||
|
||
let Some(mut sun) = self.sun() else { | ||
logger::error!("no sun is assigned to solar setup!"); | ||
|
||
return; | ||
}; | ||
|
||
self.base | ||
.set_rotation_degrees(Vector3::new(sun_pos, 0.0, 0.0)); | ||
|
||
sun.set_param( | ||
light_3d::Param::ENERGY, | ||
if sun_pos > 190.0 { 0.0 } else { 1.0 }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[gd_resource type="ShaderMaterial" load_steps=6 format=3 uid="uid://c26tq15swq4at"] | ||
|
||
[ext_resource type="Shader" uid="uid://dadtbq4ym2chm" path="res://resources/Shaders/sky.tres" id="1_gixr0"] | ||
|
||
[sub_resource type="Gradient" id="Gradient_klkl5"] | ||
offsets = PackedFloat32Array(0.354386, 0.421053, 0.610526) | ||
colors = PackedColorArray(0, 0, 0, 1, 0.137255, 0.32549, 0.639216, 1, 0.137255, 0.32549, 0.639216, 1) | ||
|
||
[sub_resource type="GradientTexture2D" id="GradientTexture2D_scq8q"] | ||
gradient = SubResource("Gradient_klkl5") | ||
fill_from = Vector2(0, 1) | ||
fill_to = Vector2(0, 0) | ||
|
||
[sub_resource type="Gradient" id="Gradient_0sht1"] | ||
interpolation_color_space = 1 | ||
offsets = PackedFloat32Array(0.0350877, 0.463158) | ||
colors = PackedColorArray(1, 0.466667, 0, 1, 0.375132, 0.588795, 0.748625, 1) | ||
|
||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_lmpjt"] | ||
gradient = SubResource("Gradient_0sht1") | ||
|
||
[resource] | ||
shader = ExtResource("1_gixr0") | ||
shader_parameter/moon_size = 0.06 | ||
shader_parameter/Texture2DParameter = SubResource("GradientTexture2D_scq8q") | ||
shader_parameter/sun_rise_gradient = SubResource("GradientTexture1D_lmpjt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.