Add day_started signal and related functionality to event bus and systems

This commit is contained in:
2026-01-24 19:06:17 +01:00
parent 266fa4ac1d
commit 93200fc1aa
13 changed files with 61 additions and 46 deletions

View File

@@ -10,5 +10,6 @@ pub const LIFT_VISUAL_HEIGHT: &str = "lift_visual_height";
pub const CAMERA_TRAUMA: &str = "camera_trauma";
pub const HAZARD_SPAWNED: &str = "hazard_spawned";
pub const HAZARD_RESOLVED: &str = "hazard_resolved";
pub const DAY_STARTED: &str = "day_started";
pub const VIGNETTE_INTENSITY_PARAM: &str = "vignette_intensity";

View File

@@ -43,6 +43,9 @@ impl EventBus {
#[signal]
fn hazard_resolved(type_: HazardType);
#[signal]
fn day_started(day_index: i32);
#[func]
pub fn publish_lift_effort(&mut self, strength: f32) {
self.base_mut()
@@ -95,4 +98,10 @@ impl EventBus {
self.base_mut()
.emit_signal("hazard_resolved", &[type_.to_variant()]);
}
#[func]
pub fn publish_day_started(&mut self, day_index: i32) {
self.base_mut()
.emit_signal("day_started", &[day_index.to_variant()]);
}
}

View File

@@ -93,12 +93,13 @@ impl BenchPressSystem {
self.current_progress += self.power_per_click * delta;
if self.current_progress >= self.target_value {
bus.clone().bind_mut().publish_lift_completed(true);
self.is_lift_complete = true;
bus.call_deferred("publish_lift_completed", &[true.to_variant()]);
}
}
#[func]
fn on_lift_completed(&mut self) {
fn on_lift_completed(&mut self, _success: bool) {
self.is_lift_complete = true;
}

View File

@@ -52,6 +52,7 @@ impl INode for CameraShakeSystem {
&self.base().callable("on_focus_changed"),
);
bus.connect(consts::CAMERA_TRAUMA, &self.base().callable("add_trauma"));
bus.connect(consts::DAY_STARTED, &self.base().callable("on_day_started"));
self.event_bus = Some(bus);
}
@@ -103,4 +104,15 @@ impl CameraShakeSystem {
self.trauma += amount;
self.trauma = self.trauma.clamp(0.0, 1.0);
}
#[func]
fn on_day_started(&mut self, _day_index: i32) {
self.trauma = 0.0;
self.current_focus = 0.0;
if let Some(camera) = &mut self.camera {
camera.set_offset(Vector2::ZERO);
camera.set_rotation(0.0);
}
}
}

View File

@@ -116,7 +116,9 @@ impl INode for DeadliftSystem {
if self.hold_timer >= self.target_value {
bus.clone().bind_mut().publish_camera_trauma(1.0);
bus.clone().bind_mut().publish_lift_completed(true);
bus.call_deferred("publish_lift_completed", &[true.to_variant()]);
self.is_lift_complete = true;
}
}
}
@@ -134,7 +136,7 @@ impl DeadliftSystem {
}
#[func]
fn on_lift_completed(&mut self) {
fn on_lift_completed(&mut self, _success: bool) {
self.is_lift_complete = true;
}

View File

@@ -120,6 +120,10 @@ impl GameManager {
.set_available_hazards(config_bind.available_hazards.clone());
}
if let Some(bus) = &mut self.event_bus {
bus.clone().bind_mut().publish_day_started(index);
}
if let Some(l) = &mut self.day_label {
l.set_text(&config_bind.day_title);
}
@@ -136,9 +140,6 @@ impl GameManager {
game.queue_free();
self.current_mini_game = None;
}
if let Some(hs) = &mut self.hazard_system {
hs.bind_mut().clear_hazards();
}
}
fn handle_win(&mut self) {

View File

@@ -56,6 +56,8 @@ impl INode for HazardSystem {
&self.base().callable("on_hazard_resolved"),
);
bus.connect(consts::DAY_STARTED, &self.base().callable("on_day_started"));
self.event_bus = Some(bus);
}
@@ -170,4 +172,11 @@ impl HazardSystem {
}
}
}
#[func]
fn on_day_started(&mut self, _day_index: i32) {
self.clear_hazards();
self.timer = 0.0;
self.current_focus = 0.0;
}
}

View File

@@ -43,6 +43,7 @@ impl INode for TunnelSystem {
consts::FOCUS_RELEASED,
&self.base().callable("on_focus_release"),
);
bus.connect(consts::DAY_STARTED, &self.base().callable("on_day_started"));
self.event_bus = Some(bus);
}
@@ -114,4 +115,22 @@ impl TunnelSystem {
fn on_focus_release(&mut self) {
self.is_efforting = false;
}
#[func]
fn on_day_started(&mut self, _day_index: i32) {
self.current_focus = 0.0;
self.is_efforting = false;
if let Some(overlay) = &mut self.vignette_overlay {
if let Some(material) = overlay.get_material() {
if let Ok(mut mat) = material.try_cast::<ShaderMaterial>() {
mat.set_shader_parameter(consts::VIGNETTE_INTENSITY_PARAM, &0.0.to_variant());
}
}
}
if let Some(bus) = &mut self.event_bus {
bus.bind_mut().publish_focus_changed(0.0);
}
}
}