コード例 #1
0
ファイル: DeckListModel.cs プロジェクト: rajeshwarn/Mtgdb
        public DeckListModel(
            CardRepository repo,
            CollectedCardsDeckTransformation transformation,
            CollectionEditorModel collection)
        {
            _repo             = repo;
            _transformation   = transformation;
            _collectionEditor = collection;

            _collectionEditor.CollectionChanged += collectionChanged;
            _state.Collection           = _collectionEditor.Snapshot();
            _repo.PriceLoadingComplete += priceLoadingComplete;
        }
コード例 #2
0
        public DeckListModel(
            CardRepository repo,
            CollectedCardsDeckTransformation transformation,
            CollectionEditorModel collection)
        {
            _repo             = repo;
            _transformation   = transformation;
            _collectionEditor = collection;

            _collectionEditor.CollectionChanged += collectionChanged;
            _state.Collection           = _collectionEditor.Snapshot();
            _repo.PriceLoadingComplete += priceLoadingComplete;

            Serializer = new JsonSerializer();

            Serializer.Converters.Add(
                new UnformattedJsonConverter(type =>
                                             typeof(IEnumerable <int>).IsAssignableFrom(type)));
        }
コード例 #3
0
ファイル: DeckModel.cs プロジェクト: rajeshwarn/Mtgdb
        public DeckModel(Deck originalDeck, CardRepository repo, CollectionSnapshot collection, CollectedCardsDeckTransformation transformation)
        {
            int countInMain(Card c) => Deck.MainDeck.Count.TryGet(c.Id);
            int countTotal(Card c, int countInDeck) => countInDeck;
            int countCollected(Card c, int countInDeck) => Math.Min(countInDeck, Collection.GetCount(c));
            int countCollectedSide(Card c, int countInDeck) => (Collection.GetCount(c) - countInMain(c)).WithinRange(0, countInDeck);

            float priceTotal(Card c, int countInDeck) => countInDeck * (c.PriceMid ?? 0f);
            float priceCollected(Card c, int countInDeck) => countCollected(c, countInDeck) * (c.PriceMid ?? 0f);
            float priceCollectedSide(Card c, int countInDeck) => countCollectedSide(c, countInDeck) * (c.PriceMid ?? 0f);

            IList <string> generatedMana(Card c, int countInDeck) => c.GeneratedManaArr;

            float f0() => 0f;
            int i0() => 0;
            float fSum(float a, float b) => a + b;
            int iSum(int a, int b) => a + b;
            float fE(float a) => a;
            int iE(int a) => a;
            Deck deck() => Deck;

            _priceTotalCache =
                new DeckAggregateCache <float, float, float>(repo, deck, f0, fSum, priceTotal, fE);

            _countTotalCache =
                new DeckAggregateCache <int, int, int>(repo, deck, i0, iSum, countTotal, iE);

            _priceCollectedCache =
                new DeckAggregateCache <float, float, float>(repo, deck, f0, fSum, priceCollected, fE);

            _countCollectedCache =
                new DeckAggregateCache <int, int, int>(repo, deck, i0, iSum, countCollected, iE);

            _priceCollectedSideCache =
                new DeckAggregateCache <float, float, float>(repo, deck, f0, fSum, priceCollectedSide, fE);

            _countCollectedSideCache =
                new DeckAggregateCache <int, int, int>(repo, deck, i0, iSum, countCollectedSide, iE);

            _generatedManaCache = new DeckAggregateCache <IList <string>, Dictionary <string, int>, string>(
                repo,
                () => OriginalDeck,
                () => new Dictionary <string, int>(Str.Comparer),
                (a, b) =>
            {
                foreach (string s in b)
                {
                    a.TryGetValue(s, out int count);
                    count++;
                    a[s] = count;
                }

                return(a);
            },
                generatedMana,
                a => string.Concat(a.Keys.OrderBy(s => KeywordDefinitions.GeneratedMana.IndexOf(s, Str.Comparer))));

            _filterNone           = c => true;
            _filterPriceIsUnknown = c => !c.PriceMid.HasValue;

            _filterIsCreature   = c => c.TypesArr.IndexOf("creature", Str.Comparer) >= 0;
            _filterIsLand       = c => c.TypesArr.IndexOf("land", Str.Comparer) >= 0;
            _filterIsOtherSpell = c => !_filterIsCreature(c) && !_filterIsLand(c);

            _filterIsLandAndPriceIsUnknown       = c => _filterIsLand(c) && _filterPriceIsUnknown(c);
            _filterIsCreatureAndPriceIsUnknown   = c => _filterIsCreature(c) && _filterPriceIsUnknown(c);
            _filterIsOtherSpellAndPriceIsUnknown = c => _filterIsOtherSpell(c) && _filterPriceIsUnknown(c);

            Collection      = collection;
            _repo           = repo;
            _transformation = transformation;
            OriginalDeck    = originalDeck;
        }