All files / src/components/sprites renderSpriteFrameContextMenu.tsx

0% Statements 0/14
0% Branches 0/16
0% Functions 0/5
0% Lines 0/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 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                                                                                                                                                                                                                         
import React, { Dispatch } from "react";
import { UnknownAction } from "redux";
import l10n from "shared/lib/lang/l10n";
import clipboardActions from "store/features/clipboard/clipboardActions";
import {
  ClipboardType,
  ClipboardTypeMetasprites,
} from "store/features/clipboard/clipboardTypes";
import entitiesActions from "store/features/entities/entitiesActions";
import { MenuDivider, MenuItem } from "ui/menu/Menu";
 
interface SpriteFrameContextMenuProps {
  dispatch: Dispatch<UnknownAction>;
  clipboard?: ClipboardType;
  spriteSheetId: string;
  metaspriteId: string;
  selectedMetaspriteIds: string[];
  spriteAnimationId: string;
}
 
const renderSpriteFrameContextMenu = ({
  clipboard,
  spriteSheetId,
  metaspriteId,
  selectedMetaspriteIds,
  spriteAnimationId,
  dispatch,
}: SpriteFrameContextMenuProps) => {
  const selectionIds =
    selectedMetaspriteIds.length === 0 ? [metaspriteId] : selectedMetaspriteIds;
  return [
    <MenuItem
      key="clone"
      onClick={() =>
        dispatch(
          entitiesActions.cloneMetasprites({
            spriteSheetId,
            spriteAnimationId,
            metaspriteIds: selectionIds,
          })
        )
      }
    >
      {l10n(
        selectionIds.length > 1 ? "FIELD_CLONE_FRAMES" : "FIELD_CLONE_FRAME"
      )}
    </MenuItem>,
    <MenuItem
      key="copy"
      onClick={() =>
        dispatch(
          clipboardActions.copyMetasprites({
            metaspriteIds: selectionIds,
            spriteAnimationId,
          })
        )
      }
    >
      {l10n(
        selectionIds.length > 1 ? "MENU_SPRITE_FRAMES_COPY" : "MENU_SPRITE_COPY"
      )}
    </MenuItem>,
    ...(clipboard?.format === ClipboardTypeMetasprites
      ? [
          <MenuItem
            key="paste"
            onClick={() =>
              dispatch(
                clipboardActions.pasteSprite({
                  spriteSheetId,
                  metaspriteId,
                  spriteAnimationId,
                  spriteStateId: "",
                })
              )
            }
          >
            {l10n(
              clipboard.data.metasprites.length > 1
                ? "MENU_SPRITE_FRAMES_PASTE"
                : "MENU_SPRITE_PASTE"
            )}
          </MenuItem>,
        ]
      : []),
    <MenuDivider key="div-delete" />,
    <MenuItem
      key="delete"
      onClick={() =>
        dispatch(
          entitiesActions.removeMetasprites({
            spriteSheetId,
            spriteAnimationId,
            metaspriteIds: selectionIds,
          })
        )
      }
    >
      {l10n(
        selectionIds.length > 1
          ? "MENU_SPRITE_FRAMES_DELETE"
          : "MENU_SPRITE_DELETE"
      )}
    </MenuItem>,
  ];
};
 
export default renderSpriteFrameContextMenu;