Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Dispatch, Middleware } from "@reduxjs/toolkit";
import { RootState } from "store/configureStore";
import soundfxActions from "store/features/soundfx/soundfxActions";
import navigationActions from "store/features/navigation/navigationActions";
import actions from "./musicActions";
import { musicSelectors } from "store/features/entities/entitiesState";
import { assetPath } from "shared/lib/helpers/assets";
import API from "renderer/lib/api";
const musicMiddleware: Middleware<Dispatch, RootState> =
(store) => (next) => (action) => {
Iif (actions.playMusic.match(action)) {
const state = store.getState();
const track = musicSelectors.selectById(state, action.payload.musicId);
Iif (track) {
const filename = assetPath("music", track);
if (track.type === "uge") {
API.music.playUGE(filename);
} else {
API.music.playMOD(filename, !track.settings.disableSpeedConversion);
}
}
} else Iif (actions.pauseMusic.match(action)) {
API.music.closeMusic();
} else if (
soundfxActions.playSoundFxBeep.match(action) ||
soundfxActions.playSoundFxTone.match(action) ||
soundfxActions.playSoundFxCrash.match(action) ||
navigationActions.setSection.match(action) ||
navigationActions.setNavigationId.match(action)
) {
store.dispatch(actions.pauseMusic());
}
return next(action);
};
export default musicMiddleware;
|