module Mischief.Assets.Image where import Codec.Picture qualified as P import Data.Text qualified as T import Mischief.Assets.Internal.Asset import Mischief.ECS import Mischief.ECS.Utils newtype Image = Image P.DynamicImage deriving anyclass (Typeable Image [HookRel Image] [Hook Image] Set DefaultComponentType IsExclusive (IsExclusiveRel Image) (Typeable Image, IsExclusive (IsExclusiveRel Image)) => Set DefaultComponentType -> [Hook Image] -> [Hook Image] -> [Hook Image] -> [HookRel Image] -> [HookRel Image] -> [HookRel Image] -> Component Image forall c. (Typeable c, IsExclusive (IsExclusiveRel c)) => Set DefaultComponentType -> [Hook c] -> [Hook c] -> [Hook c] -> [HookRel c] -> [HookRel c] -> [HookRel c] -> Component c $crequired :: Set DefaultComponentType required :: Set DefaultComponentType $conAdd :: [Hook Image] onAdd :: [Hook Image] $conSet :: [Hook Image] onSet :: [Hook Image] $conRemove :: [Hook Image] onRemove :: [Hook Image] $conAddRel :: [HookRel Image] onAddRel :: [HookRel Image] $conSetRel :: [HookRel Image] onSetRel :: [HookRel Image] $conRemoveRel :: [HookRel Image] onRemoveRel :: [HookRel Image] Component) instance Asset Image where type Saveable Image = False loadAsset :: FilePath -> Text -> IO (Either Text Image) loadAsset !FilePath path Text _ = do (DynamicImage -> Image) -> Either Text DynamicImage -> Either Text Image forall a b. (a -> b) -> Either Text a -> Either Text b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap DynamicImage -> Image Image (Either Text DynamicImage -> Either Text Image) -> (Either FilePath DynamicImage -> Either Text DynamicImage) -> Either FilePath DynamicImage -> Either Text Image forall b c a. (b -> c) -> (a -> b) -> a -> c . (FilePath -> Text) -> Either FilePath DynamicImage -> Either Text DynamicImage forall a c b. (a -> c) -> Either a b -> Either c b mapLeft FilePath -> Text T.pack (Either FilePath DynamicImage -> Either Text Image) -> IO (Either FilePath DynamicImage) -> IO (Either Text Image) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> FilePath -> IO (Either FilePath DynamicImage) P.readImage FilePath path