All files / src/store/features/editor editorActions.ts

100% Statements 14/14
100% Branches 6/6
100% Functions 2/2
100% Lines 14/14

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 3923x   23x 23x                           23x 11x 11x 11x 2x           11x 9x   11x 7x       23x   23x  
import { actions } from "./editorState";
import { AppThunk } from "store/storeTypes";
import settingsActions from "store/features/settings/settingsActions";
import { TOOL_TILES } from "consts";
 
type SelectSceneTileForPaintingPayload = {
  tilesetId: string;
  tileIndex: number;
  width?: number;
  height?: number;
  tilesetWidth?: number;
  autotile?: boolean;
  persistTileset?: boolean;
  activateTool?: boolean;
};
 
const selectSceneTileForPainting =
  (payload: SelectSceneTileForPaintingPayload): AppThunk =>
  (dispatch) => {
    dispatch(actions.setSelectedSceneTile(payload));
    if (payload.persistTileset) {
      dispatch(
        settingsActions.editSettings({
          selectedSceneTilesetId: payload.tilesetId,
        }),
      );
    }
    if (payload.autotile !== undefined) {
      dispatch(actions.setSelectedSceneTileAutotile(payload.autotile));
    }
    if (payload.activateTool !== false) {
      dispatch(actions.setTool({ tool: TOOL_TILES }));
    }
  };
 
const allActions = { ...actions, selectSceneTileForPainting };
 
export default allActions;