Skip to content

Commit

Permalink
fix: bug with dragging offscreen, locked stations and partial recalc …
Browse files Browse the repository at this point in the history
…and weird angles in/out of stations
  • Loading branch information
CalliEve committed Dec 18, 2024
1 parent 42c543d commit 9dac7fa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/algorithm/cost_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ fn calc_station_exit_cost(
node,
false,
)
.map(|c| c / 2.0);
.map(|c| c / 5.0);
}
}

Expand All @@ -374,7 +374,8 @@ fn calc_station_exit_cost(
station.get_pos(),
node,
true,
);
)
.map(|c| c / 5.0);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/canvas/mouse_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ use crate::MapState;
pub fn on_mouse_out(map_state: &mut MapState) {
map_state.clear_selected_line();
map_state.clear_box_select();
map_state.clear_drag_offset();
}
2 changes: 1 addition & 1 deletion src/components/canvas/mouse_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn on_mouse_up(map_state: &mut MapState, ev: &UiEvent, shift_key: bool) {
.get_drag_offset()
.is_some()
{
map_state.set_drag_offset(None);
map_state.clear_drag_offset();
}

// Handle a click while having an operation selected
Expand Down
19 changes: 15 additions & 4 deletions src/components/organisms/canvas_controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::{
MapState,
},
models::Map,
unwrap_or_return,
utils::{
IDData,
IDManager,
Expand Down Expand Up @@ -128,22 +129,32 @@ pub fn CanvasControls() -> impl IntoView {
});

// Handle the response from the algorithm.
let handle_algorithm_response = move |resp: AlgorithmResponse| {
let handle_algorithm_response = move |resp: AlgorithmResponse, partial: bool| {
if resp.success
|| map_state
.get_untracked()
.get_algorithm_settings()
.output_on_fail
{
map_state.update(|state| {
state.set_map(resp.map);
if partial {
unwrap_or_return!(state
.get_mut_map()
.update_from_partial(&resp.map));
} else {
state.set_map(resp.map);
}
});
IDManager::from_data(resp.id_manager_data);
}
};

// Dispatch the algorithm request.
let algorithm_req = create_action(move |req: &AlgorithmRequest| {
map_state.update_untracked(|state| {
state.clear_all_selections();
});

let req = req.clone();
async move {
let (abort_handle, resp_stream) = executor
Expand All @@ -162,7 +173,7 @@ pub fn CanvasControls() -> impl IntoView {
let last = resp_stream
.inspect(|resp| {
if req.midway_updates {
handle_algorithm_response(resp.clone());
handle_algorithm_response(resp.clone(), req.partial);
}
})
.fold(
Expand All @@ -175,7 +186,7 @@ pub fn CanvasControls() -> impl IntoView {
// now.
if !req.midway_updates {
if let Some(resp) = last {
handle_algorithm_response(resp);
handle_algorithm_response(resp, req.partial);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/state/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl MapState {
self.clear_box_select();
self.clear_clicked_on_station();
self.clear_clicked_on_edge();
self.clear_drag_offset();
}

/// A getter method for the [`Map`].
Expand Down Expand Up @@ -310,6 +311,11 @@ impl MapState {
self.drag_offset = offset;
}

/// Clear the drag offset.
pub fn clear_drag_offset(&mut self) {
self.drag_offset = None;
}

/// A getter method for the last loaded map.
pub fn get_last_loaded(&self) -> Option<&Map> {
self.last_loaded
Expand Down

0 comments on commit 9dac7fa

Please sign in to comment.