All files / src/shared/lib/helpers sprites.ts

100% Statements 16/16
100% Branches 7/7
100% Functions 2/2
100% Lines 15/15

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 271x         16x 16x 8x 4x   4x 2x   2x   8x 4x   4x 2x   2x   16x 16x    
export const maxSpriteTilesForBackgroundTilesLength = (
  backgroundTilesLength: number,
  isCGBOnly: boolean,
  spriteMode: "8x8" | "8x16",
) => {
  const max8x16SpriteTiles = (): number => {
    if (isCGBOnly) {
      if (backgroundTilesLength <= 256) {
        return 192;
      }
      if (backgroundTilesLength * 0.5 < 192) {
        return 192 - Math.ceil((backgroundTilesLength / 2 - 128) / 2) * 2;
      }
      return 128;
    }
    if (backgroundTilesLength <= 128) {
      return 96;
    }
    if (backgroundTilesLength < 192) {
      return 96 - Math.ceil((backgroundTilesLength - 128) / 2);
    }
    return 64;
  };
  const baseTileCount = max8x16SpriteTiles();
  return spriteMode === "8x16" ? baseTileCount : baseTileCount * 2;
};