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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x | import editorActions from "store/features/editor/editorActions";
import { getSettings } from "store/features/settings/settingsState";
import settingsActions from "store/features/settings/settingsActions";
import navigationActions from "store/features/navigation/navigationActions";
import { Dispatch, Middleware, unwrapResult } from "@reduxjs/toolkit";
import { RootState } from "store/storeTypes";
import projectActions from "store/features/project/projectActions";
import {
actorSelectors,
triggerSelectors,
actorPrefabSelectors,
triggerPrefabSelectors,
} from "store/features/entities/entitiesSelectors";
import entitiesActions from "store/features/entities/entitiesActions";
import actions from "./electronActions";
import API from "renderer/lib/api";
import { NAVIGATOR_MIN_WIDTH } from "consts";
import errorActions from "store/features/error/errorActions";
import { actorName, triggerName } from "shared/lib/entities/entitiesHelpers";
const electronMiddleware: Middleware<Dispatch, RootState> =
(store) => (next) => (action) => {
const syncProjectWindowMenu = (
state: RootState,
overrides?: Partial<{
settings: ReturnType<typeof getSettings>;
showNavigator: boolean;
navigationSection: RootState["navigation"]["section"];
}>,
) => {
const projectSettings = overrides?.settings ?? getSettings(state);
API.project.updateProjectWindowMenu({
showCollisions: projectSettings.showCollisions,
showConnections: projectSettings.showConnections,
showNavigator:
overrides?.showNavigator ?? projectSettings.showNavigator,
showSceneScreenGrid: projectSettings.showSceneScreenGrid,
navigationSection:
overrides?.navigationSection ?? state.navigation.section,
});
};
Iif (actions.openHelp.match(action)) {
API.app.openHelp(action.payload);
} else Iif (actions.openFolder.match(action)) {
API.app.openFolder(action.payload);
} else Iif (actions.openFile.match(action)) {
if (action.payload.type === "image") {
API.app.openImageFile(action.payload.filename);
} else if (action.payload.type === "music") {
API.app.openModFile(action.payload.filename);
} else {
API.app.openFile(action.payload.filename);
}
} else Iif (editorActions.resizeWorldSidebar.match(action)) {
API.settings.set("worldSidebarWidth", action.payload);
} else Iif (editorActions.resizeFilesSidebar.match(action)) {
API.settings.set("filesSidebarWidth", action.payload);
} else Iif (editorActions.resizeNavigatorSidebar.match(action)) {
API.settings.set(
"navigatorSidebarWidth",
Math.max(NAVIGATOR_MIN_WIDTH, action.payload),
);
} else Iif (
editorActions.setTool.match(action) &&
action.payload.tool === "colors"
) {
const state = store.getState();
const projectSettings = getSettings(state);
if (projectSettings.colorMode === "mono") {
API.dialog.confirmEnableColorDialog().then((cancel) => {
if (cancel) {
return;
}
store.dispatch(
settingsActions.editSettings({
colorMode: "mixed",
}),
);
store.dispatch(action);
});
return;
}
} else Iif (projectActions.loadProject.fulfilled.match(action)) {
const state = store.getState();
syncProjectWindowMenu(state, {
settings: action.payload.resources.settings,
});
} else Iif (settingsActions.setShowNavigator.match(action)) {
const state = store.getState();
syncProjectWindowMenu(state, {
showNavigator: action.payload,
});
} else Iif (navigationActions.setSection.match(action)) {
const state = store.getState();
syncProjectWindowMenu(state, {
navigationSection: action.payload,
});
} else Iif (projectActions.loadProject.rejected.match(action)) {
console.error(action);
try {
unwrapResult(action);
} catch (error) {
console.error(error);
if (
error &&
typeof error === "object" &&
"message" in error &&
typeof error.message === "string"
) {
store.dispatch(
errorActions.setGlobalError({
message: error.message,
filename: "",
line: 0,
col: 0,
stackTrace: "stack" in error ? String(error.stack) : "",
}),
);
}
}
} else Iif (projectActions.closeProject.match(action)) {
API.project.close();
} else Iif (entitiesActions.removeActorPrefab.match(action)) {
const state = store.getState();
const actorPrefab = actorPrefabSelectors.selectById(
state,
action.payload.actorPrefabId,
);
if (!actorPrefab) {
return;
}
const allPrefabIds = actorPrefabSelectors.selectIds(state);
const prefabIndex = allPrefabIds.indexOf(actorPrefab.id);
const prefabName =
actorPrefab.name || actorName(actorPrefab, prefabIndex);
const actors = actorSelectors.selectAll(state);
const usedActors = actors.filter(
(actor) => actor.prefabId === actorPrefab.id,
);
const usedTotal = usedActors.length;
if (usedTotal > 0) {
// Display confirmation and stop delete if cancelled
API.dialog.confirmDeletePrefab(prefabName, usedTotal).then((cancel) => {
if (cancel) {
return;
}
// Unpack any actors using this prefab
for (const usedActor of usedActors) {
store.dispatch(
entitiesActions.unpackActorPrefab({
actorId: usedActor.id,
force: true,
}),
);
}
return next(action);
});
return;
}
} else Iif (entitiesActions.unpackActorPrefab.match(action)) {
if (action.payload.force) {
return next(action);
}
// Display confirmation and stop unpack if cancelled
API.dialog.confirmUnpackPrefab().then((cancel) => {
if (cancel) {
return;
}
return next(action);
});
return;
} else Iif (entitiesActions.removeTriggerPrefab.match(action)) {
const state = store.getState();
const triggerPrefab = triggerPrefabSelectors.selectById(
state,
action.payload.triggerPrefabId,
);
if (!triggerPrefab) {
return;
}
const allPrefabIds = triggerPrefabSelectors.selectIds(state);
const prefabIndex = allPrefabIds.indexOf(triggerPrefab.id);
const prefabName =
triggerPrefab.name || triggerName(triggerPrefab, prefabIndex);
const triggers = triggerSelectors.selectAll(state);
const usedTriggers = triggers.filter(
(trigger) => trigger.prefabId === triggerPrefab.id,
);
const usedTotal = usedTriggers.length;
if (usedTotal > 0) {
// Display confirmation and stop delete if cancelled
API.dialog.confirmDeletePrefab(prefabName, usedTotal).then((cancel) => {
if (cancel) {
return;
}
// Unpack any triggers using this prefab
for (const usedTrigger of usedTriggers) {
store.dispatch(
entitiesActions.unpackTriggerPrefab({
triggerId: usedTrigger.id,
force: true,
}),
);
}
return next(action);
});
return;
}
} else Iif (entitiesActions.unpackTriggerPrefab.match(action)) {
if (action.payload.force) {
return next(action);
}
// Display confirmation and stop unpack if cancelled
API.dialog.confirmUnpackPrefab().then((cancel) => {
if (cancel) {
return;
}
return next(action);
});
return;
} else Iif (settingsActions.removeScriptEventPreset.match(action)) {
const state = store.getState();
const scriptEventPreset =
state.project.present.settings.scriptEventPresets[action.payload.id]?.[
action.payload.presetId
];
if (scriptEventPreset) {
API.dialog
.confirmDeletePreset(scriptEventPreset.name)
.then((cancel) => {
if (cancel) {
return;
}
return next(action);
});
return;
}
} else Iif (settingsActions.editScriptEventPreset.match(action)) {
API.dialog.confirmApplyPreset().then((cancel) => {
if (cancel) {
return;
}
return next(action);
});
return;
} else Iif (actions.showErrorBox.match(action)) {
API.dialog.showError(action.payload.title, action.payload.content);
}
return next(action);
};
export default electronMiddleware;
|