From 4b511c12d37d339e1279787019179ccd1a866e0a Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Sun, 15 Dec 2019 15:46:36 +0200 Subject: [PATCH] fsharp(ygosim): feat: added the basic structure and lenses for the CardInstance type and a toCardInstance helper for monsters Signed-off-by: prescientmoon --- fsharp/ygosim/src/Card.fs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/fsharp/ygosim/src/Card.fs b/fsharp/ygosim/src/Card.fs index 909fd68..392d540 100644 --- a/fsharp/ygosim/src/Card.fs +++ b/fsharp/ygosim/src/Card.fs @@ -124,18 +124,34 @@ module Card = | Spell of BaseCard<'s> * SpellCardDetails | Trap of BaseCard<'s> * TrapCardDetails - let monster card: option> = - match card with - | Monster m -> Some m - | _ -> None - module Card = let inline baseCard f card = _1 f card let inline cardDetails f card = _2 f card let inline level f card = (_2 << MonsterCardDetails.level) f card - type CardInstance<'s> = Card<'s> + type CardInstance<'s> = + { template: Card<'s> + id: int } + + + module CardInstance = + let inline template f card = f card.template <&> fun v -> { card with template = v } + let inline _id f card = f card.id <&> fun v -> { card with id = v } + + +module Monster = + open Card + + let monster card: option * int> = + match card.template with + | Monster m -> Some(m, card.id) + | _ -> None + + + let toCardInstance (card: Monster<'a>, _id): CardInstance<'a> = + { template = Monster card + id = _id } module Decklist = type Decklist =