mischief-assets-0.1.0.0: src/Mischief/Assets/Internal/Kdl/Collection.hs
module Mischief.Assets.Internal.Kdl.Collection where
import Data.Data
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Maybe
import Data.Text (Text)
import KDL qualified
import Mischief.ECS.Utils
newtype KdlCollection a = KdlCollection (Map Text [a]) deriving (Show)
colGetU :: Text -> KdlCollection a -> a
colGetU = (unwrap .) . colGet
colGet :: Text -> KdlCollection a -> Maybe a
colGet a b = case colGetMany a b of
(x : _) -> Just x
_ -> Nothing
colGetMany :: Text -> KdlCollection a -> [a]
colGetMany t (KdlCollection m) = fromMaybe [] (Map.lookup t m)
colDecodeWith :: (Typeable a) => KDL.NodeDecoder a -> KDL.NodeListDecoder (KdlCollection a)
colDecodeWith = (KdlCollection <$>) . KDL.remainingNodesWith