Skip to content

Commit

Permalink
When toggling collision layer visibility reset opacity if set below d…
Browse files Browse the repository at this point in the history
…efault. Reduces confusion if opacity was set very low
  • Loading branch information
chrismaltby committed Oct 24, 2024
1 parent 1d6af1f commit 9560f4c
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/store/features/settings/settingsMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
import { Dispatch, Middleware } from "@reduxjs/toolkit";
import { RootState } from "store/configureStore";
import settingsActions from "./settingsActions";
import { getSettings } from "store/features/settings/settingsState";
import { defaultProjectSettings } from "consts";

const settingsMiddleware: Middleware<Dispatch, RootState> =
(store) => (next) => (action) => {
next(action);

// When color mode changes reset previewAsMono to false
if (
settingsActions.editSettings.match(action) &&
action.payload.colorMode
) {
store.dispatch(
settingsActions.editSettings({
previewAsMono: false,
})
);
if (settingsActions.editSettings.match(action)) {
// When color mode changes reset previewAsMono to false
if (action.payload.colorMode) {
store.dispatch(
settingsActions.editSettings({
previewAsMono: false,
})
);
}
// When collisions enabled set opacity to a min of 50%
if (action.payload.showCollisions) {
const state = store.getState();
const settings = getSettings(state);
const defaultOpacity = defaultProjectSettings.collisionLayerOpacity;
if (settings.collisionLayerOpacity < defaultOpacity) {
store.dispatch(
settingsActions.editSettings({
collisionLayerOpacity: defaultOpacity,
})
);
}
}
}
};

Expand Down

0 comments on commit 9560f4c

Please sign in to comment.