DN2F55HBRBTHQAJDU4GOOGAEAXH5MIFPQSPEK2NNAPDJPZOOFJFQC
AZMUPEVSHVB3TWP57JUNP7MHBDTI6YNRJPQYEROP6PFMTQ3EABDAC
5SNPPY36EWEDXN6F57PXNPXJNOM5OZESSFHZ2NLPEU74UDWKHPEAC
Y7COVTVYO2MFY7KGICPBFEENWSCRFYJLGVG53LKDWNFUOGXFEZLAC
DOPKLXQZP3TDISHODQNI6GZ57EYE42NG225WHSZMQ3L355YVYPNAC
WRLD7PACYNQI2F3MAYAM5OK4RHO7CZ4OMYWAZ37UQY2IJ4AYS7LAC
C3BUGSBWBKOXFFB6TIHDLQVFV65OKKW6KEUVMP4O2XP3RYMPJ5QAC
SNYOEZI7JMTLJNLM2YTAHBPJEKK2BJZJDOHRIX5676JCF2VNET3QC
R6GLORFO6COA5R7GFFHEZW7FXFJIJB6PTCSF3GBUZSETCE6IW23QC
modifyCopies newCopies =
return $ \oldCard ->
let newQuantity = newCopies . quantity $ oldCard
in Just $ oldCard {quantity = newQuantity}
modifyCategory categoryF =
return $ \oldCard ->
let newCategory = categoryF . Deck.category $ oldCard
in Just $ oldCard {Deck.category = newCategory}
add cardname initialCategory copies decklist =
R $
let newCard = mkCard cardname initialCategory copies
in Map.alter
( \case
Nothing -> Just newCard
Just x -> Just $ over categories (Map.insert (toText initialCategory) copies) x
)
(toText cardname)
$ unR decklist
deltaCopies delta = return $ \oldCard ->
let oldCopies = fromIntegral . unrefine . runNumber . quantity $ oldCard
refinedCopies =
fmap PositiveNumber . eitherToMaybe . refine . fromIntegral $ oldCopies + delta
in fmap (\x -> oldCard {quantity = x}) refinedCopies
remove cardName categoryName decklist =
R $
Map.update
( \card ->
let newCard = over categories (Map.delete (toText categoryName)) card
in if Map.null $ newCard ^. categories
then Nothing
else Just newCard
)
(toText cardName)
decklist
evalManyOn :: (Traversable t) => t (RDefault ()) -> CardMap -> CardMap
evalManyOn x initDeck = flip execState initDeck $ mapM unR x
evalManyOn ::
(Traversable t) => t (R (DeckRep R) -> R (DeckRep R)) -> DeckRep R -> DeckRep R
evalManyOn instr initDeck = unR $ foldl' (\acc f -> f acc) (deck initDeck) instr
let (mb, sb) = T.breakOn "\n\n" content
mb' = mapM (readCard mainboard) (T.lines mb)
sb' = mapM (readCard sideboard) (T.lines . T.stripStart $ sb)
return $ fmap add <$> liftA2 (++) mb' sb'
let (mb, sb) =
bimap
(mapM (parseRecord mainboard) . T.lines)
(mapM (parseRecord sideboard) . T.lines . T.stripStart)
$ T.breakOn "\n\n" content
return $ liftA2 (++) mb sb
parseRecord cat = readRecord >=> \(c, q) -> return $ add c cat q