mirror of
https://github.com/stan-smith/FossFLOW.git
synced 2025-12-26 16:09:10 -05:00
feat: executes entry / exit logic for interactions
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import { InteractionReducer } from 'src/types';
|
||||
import { produce } from 'immer';
|
||||
import { generateId, hasMovedTile } from 'src/utils';
|
||||
import { generateId, hasMovedTile, setWindowCursor } from 'src/utils';
|
||||
import { DEFAULT_COLOR } from 'src/config';
|
||||
|
||||
export const AreaTool: InteractionReducer = {
|
||||
type: 'AREA_TOOL',
|
||||
entry: () => {
|
||||
setWindowCursor('crosshair');
|
||||
},
|
||||
exit: () => {
|
||||
setWindowCursor('default');
|
||||
},
|
||||
mousemove: ({ uiState }) => {
|
||||
if (
|
||||
uiState.mode.type !== 'AREA_TOOL' ||
|
||||
|
||||
@@ -5,12 +5,19 @@ import {
|
||||
connectorInputToConnector,
|
||||
connectorToConnectorInput,
|
||||
getConnectorPath,
|
||||
hasMovedTile
|
||||
hasMovedTile,
|
||||
setWindowCursor
|
||||
} from 'src/utils';
|
||||
import { InteractionReducer } from 'src/types';
|
||||
|
||||
export const Connector: InteractionReducer = {
|
||||
type: 'CONNECTOR',
|
||||
entry: () => {
|
||||
setWindowCursor('crosshair');
|
||||
},
|
||||
exit: () => {
|
||||
setWindowCursor('default');
|
||||
},
|
||||
mousemove: ({ uiState, scene }) => {
|
||||
if (
|
||||
uiState.mode.type !== 'CONNECTOR' ||
|
||||
@@ -110,10 +117,10 @@ export const Connector: InteractionReducer = {
|
||||
);
|
||||
}
|
||||
|
||||
const newMode = produce(uiState.mode, (draftState) => {
|
||||
draftState.connector = null;
|
||||
uiState.actions.setMode({
|
||||
type: 'CURSOR',
|
||||
showCursor: true,
|
||||
mousedown: null
|
||||
});
|
||||
|
||||
uiState.actions.setMode(newMode);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ const reducers: { [k in string]: InteractionReducer } = {
|
||||
|
||||
export const useInteractionManager = () => {
|
||||
const rendererRef = useRef<HTMLElement>();
|
||||
const reducerTypeRef = useRef<string>();
|
||||
const uiState = useUiStateStore((state) => {
|
||||
return state;
|
||||
});
|
||||
@@ -66,38 +67,22 @@ export const useInteractionManager = () => {
|
||||
isRendererInteraction: rendererRef.current === e.target
|
||||
};
|
||||
|
||||
// const getTransitionaryState = () => {
|
||||
// if (reducerTypeRef.current === reducer.type) return null;
|
||||
if (reducerTypeRef.current !== reducer.type) {
|
||||
const prevReducer = reducerTypeRef.current
|
||||
? reducers[reducerTypeRef.current]
|
||||
: null;
|
||||
|
||||
// const prevReducerExitFn = reducerTypeRef.current
|
||||
// ? reducers[reducerTypeRef.current].exit
|
||||
// : null;
|
||||
// const nextReducerEntryFn = reducer.entry;
|
||||
if (prevReducer && prevReducer.exit) {
|
||||
prevReducer.exit(baseState);
|
||||
}
|
||||
|
||||
// reducerTypeRef.current = reducer.type;
|
||||
|
||||
// const transitionaryState: State = baseState;
|
||||
|
||||
// const setTransitionaryState = (state: State, transitionaryFn: any) => {
|
||||
// return produce(state, (draft) => {
|
||||
// return transitionaryFn(draft);
|
||||
// });
|
||||
// };
|
||||
|
||||
// if (prevReducerExitFn) {
|
||||
// setTransitionaryState(transitionaryState, prevReducerExitFn);
|
||||
// }
|
||||
|
||||
// if (nextReducerEntryFn) {
|
||||
// setTransitionaryState(transitionaryState, nextReducerEntryFn);
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// };
|
||||
|
||||
// const transitionaryState = getTransitionaryState();
|
||||
if (reducer.entry) {
|
||||
reducer.entry(baseState);
|
||||
}
|
||||
}
|
||||
|
||||
reducerAction(baseState);
|
||||
reducerTypeRef.current = reducer.type;
|
||||
},
|
||||
[scene, uiState]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user