singleCubemapMipFiles :: MonadIO m => CubeMapSelection -> m (MipmapChain (Cubemap FilePath))
singleCubemapMipFiles CubeMapSelection{..} = do
  selectedFiles <- io $ filter selectionFiles . map fromString <$> getDirectoryContents (fpToString selectionDirectory)

  let mipmaps   = groupWith (fst.selectionLevelAndSide) selectedFiles
      cubes     = map (cubeFromList.sortWith (snd.selectionLevelAndSide)) $ mipmaps
      mMipCubes :: Maybe (MipmapChain (Cubemap FilePath))
      mMipCubes = mipMapChain $ map (fmap (mappend selectionDirectory)) cubes

  case mMipCubes of
    Nothing -> io $ throwIO $ LoadCubeMapException $ "at least one complete cube map with base texture for MipMapChain required!"
    Just mipCubes  -> return $ mipCubes
  where
  cubeFromList [right,left,top,bottom,front,back] = Cubemap right left top bottom front back
  cubeFromList _ = error "singleCubemapMipFiles: invalid pattern"
singleCubemapMipFiles :: MonadIO m => CubeMapSelection -> m (MipmapChain (Cubemap FilePath))
singleCubemapMipFiles CubeMapSelection{..} = do
  selectedFiles <- io $ filter selectionFiles . map fromString <$> getDirectoryContents (fpToString selectionDirectory)

  let mipmaps   = groupWith (fst.selectionLevelAndSide) selectedFiles
      cubes     = map (cubeFromList.sortWith (snd.selectionLevelAndSide)) $ mipmaps
      mMipCubes :: Maybe (MipmapChain (Cubemap FilePath))
      mMipCubes = mipMapChain $ map (fmap (mappend selectionDirectory)) cubes

  case mMipCubes of
    Nothing -> io $ throwIO $ LoadCubeMapException $ "at least one complete cube map with base texture for MipMapChain required!"
    Just mipCubes  -> return $ mipCubes
  where
  cubeFromList [right,left,top,bottom,front,back] = Cubemap right left top bottom front back
  cubeFromList _ = error "singleCubemapMipFiles: invalid pattern"
singleCubemapMipFiles CubeMapSelection{..} = do
  selectedFiles <- io $ filter selectionFiles . map fromString <$> getDirectoryContents (fpToString selectionDirectory)

  let mipmaps   = groupWith (fst.selectionLevelAndSide) selectedFiles
      cubes     = map (cubeFromList.sortWith (snd.selectionLevelAndSide)) $ mipmaps
      mMipCubes :: Maybe (MipmapChain (Cubemap FilePath))
      mMipCubes = mipMapChain $ map (fmap (mappend selectionDirectory)) cubes

  case mMipCubes of
    Nothing -> io $ throwIO $ LoadCubeMapException $ "at least one complete cube map with base texture for MipMapChain required!"
    Just mipCubes  -> return $ mipCubes
  where
  cubeFromList [right,left,top,bottom,front,back] = Cubemap right left top bottom front back
  cubeFromList _ = error "singleCubemapMipFiles: invalid pattern"