Пример #1
0
        public void ComputeRandomCardsGrades()
        {
            const int CardCount = 20;

            CardGenerator cardGenerator = new CardGenerator(new TimeGenerator(), Config, CardCount);

            Dictionary <short, int> gradesCount = new Dictionary <short, int>
            {
                [PracticeState.Due]      = 4,
                [PracticeState.Learning] = 3,
                [PracticeState.New]      = 3
            };

            for (int i = 0; i < CardCount; i++)
            {
                Card card = cardGenerator.Generate();

                ReviewAnswerInfo[] reviewAnswerInfos = card.ComputeGrades();

                reviewAnswerInfos.Should().NotBeNull().And.HaveCount(gradesCount[card.PracticeState]);
            }
        }
Пример #2
0
        public void LearningCard()
        {
            const int CardCount = 20;

            CardGenerator cardGenerator = new CardGenerator(
                new TimeGenerator(), Config, CardCount, 0, 1, 0, 30);

            Card card = new Card(Config);

            Config.LearningSteps.Length.Should().BeGreaterThan(1);

            for (int i = 0; i < CardCount; i++)
            {
                cardGenerator.Generate(card);

                int toGraduation = card.GetLearningStepsLeft();

                card.CurrentReviewTime = DateTime.Now.ToUnixTimestamp();

                card.GetCurrentLearningIndex().Should().Be(0);
                card.GetLearningStepsLeft().Should().Be(card.LearningOrLapsingSteps.Length);

                // Loop until graduation step
                for (int step = 1; step < toGraduation; step++)
                {
                    card.UpdateLearningStep();

                    card.GetCurrentLearningIndex().Should().Be(step);
                    card.GetLearningStepsLeft().Should().Be(toGraduation - step);
                    card.Due.Should().Be(card.CurrentReviewTime + card.LearningOrLapsingSteps[step]);
                }

                card.UpdateLearningStep();
                card.IsDue().Should().Be(true);
            }
        }
Пример #3
0
        private void genCard_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(chainId.Text))
            {
                MessageBox.Show(Resources.CHAIN_ID_EMPTY, Resources.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (_c == null || !_c.IsComplete())
            {
                MessageBox.Show(Resources.CANNOT_SAVE_IF_NOT_GENERATED_OR_INCOMPLETE,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cidSaveDialog.FileName = _c.Dcs + "-" + _c.Dad + "-" + _c.Dac + ".pdf";
            cidSaveDialog.Filter   = Resources.PDF_FILTER;

            if (cidSaveDialog.ShowDialog() == DialogResult.OK)
            {
                var cg = new CardGenerator(_c, "cryptid-id-template.pdf");
                cg.Generate(cidSaveDialog.FileName, Convert.FromBase64String(chainId.Text));
            }
        }
Пример #4
0
 public void StartGame(Button startBatton)
 {
     startBatton.gameObject.SetActive(false);
     _informationPanel = new InformationPanel(_gameStartData.GameLevel, _gameStartData.GameTry, _gameStartData.GamePoints, _informationPanelDrawer);
     _cardGenerator.Generate(_gameStartData.CardAmount + Difficulty());
 }
Пример #5
0
        public async Task <IActionResult> Patch(Guid id, [FromBody] Card card, bool?forceGeneration)
        {
            using (var repository = new Repository(HttpContext.GetUserGuid()))
            {
                if (!AuthorizeService.HashRight(repository.ServiceUser?.Role, Rights.EditCard))
                {
                    return(Forbid());
                }

                var cardModel = await repository.Context.Cards.FindByGuidAsync(id);

                await repository.Context.Entry(cardModel).Reference(x => x.Status).LoadAsync();

                var isFinal = cardModel.Status.Guid == PredefinedGuids.Final;
                if (isFinal && !AuthorizeService.HashRight(repository.ServiceUser?.Role, Rights.AllowCardStatusChange))
                {
                    return(Forbid("Card is marked as final"));
                }

                await repository.Context.Entry(cardModel).Reference(x => x.Creator).LoadAsync();

                var isMyCard = repository.ServiceUser?.Guid == cardModel.Creator.Guid;
                if (!isMyCard && !AuthorizeService.HashRight(repository.ServiceUser?.Role, Rights.AllowOthersCardEdit))
                {
                    return(Forbid("This is not your card"));
                }

                await repository.Context.Entry(cardModel).Reference(x => x.Faction).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.Serie).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.Type).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.Status).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.ArtworkLicense).LoadAsync();

                var serieModel = await repository.Context.Series.FindByGuidAsync(card.Serie.Guid);

                var factionModel = await repository.Context.Factions.FindByGuidAsync(card.Faction.Guid);

                var cardTypeModel = await repository.Context.CardTypes.FindByGuidAsync(card.Type.Guid);

                var statusModel = await repository.Context.Statuses.FindByGuidAsync(card.Status.Guid);

                var ruleSetModel = await repository.Context.RuleSets.FindByGuidAsync(card.RuleSet.Guid);

                var artworkLicenseModel = await repository.Context.Licenses.FindByGuidAsync(card.ArtworkLicense?.Guid);

                bool hasLayoutChanges = forceGeneration.HasValue && forceGeneration.Value;

                if (card.Name != cardModel.Name)
                {
                    hasLayoutChanges = true;
                }
                if (card.Faction.Guid != cardModel.Faction.Guid)
                {
                    hasLayoutChanges = true;
                }
                if (card.Type.Guid != cardModel.Type.Guid)
                {
                    hasLayoutChanges = true;
                }

                if (card.FirstName != cardModel.FirstName)
                {
                    hasLayoutChanges = true;
                }
                if (card.LastName != cardModel.LastName)
                {
                    hasLayoutChanges = true;
                }
                if (card.Artist != cardModel.Artist)
                {
                    hasLayoutChanges = true;
                }
                if (card.SubType != cardModel.SubType)
                {
                    hasLayoutChanges = true;
                }
                if (card.Cost != cardModel.Cost)
                {
                    hasLayoutChanges = true;
                }
                if (card.Loyalty != cardModel.Loyalty)
                {
                    hasLayoutChanges = true;
                }
                if (card.Attack != cardModel.Attack)
                {
                    hasLayoutChanges = true;
                }
                if (card.Defense != cardModel.Defense)
                {
                    hasLayoutChanges = true;
                }
                if (card.Info != cardModel.Info)
                {
                    hasLayoutChanges = true;
                }

                if (card.MarkdownText != cardModel.MarkdownText)
                {
                    hasLayoutChanges = true;
                }



                cardModel.Patch(card, serieModel, factionModel, cardTypeModel, statusModel, ruleSetModel, artworkLicenseModel, repository.ServiceUser);
                await repository.Context.SaveChangesAsync();

                await repository.Context.Entry(cardTypeModel).Reference(x => x.TemplateInfo).LoadAsync();

                card      = cardModel.FromDal();
                card.Type = cardModel.Type.FromDal(true);
                await repository.Context.SaveChangesAsync();

                if (hasLayoutChanges)
                {
                    var jobId = cardModel.PngCreationJobId;
                    if (!string.IsNullOrEmpty(jobId))
                    {
                        BackgroundJob.Delete(jobId);
                    }

                    var cardGenerator = new CardGenerator(card);
                    await cardGenerator.Generate();

                    await cardGenerator.Generate(false);

                    cardModel.PngCreationJobId = BackgroundJob.Schedule(() => CardGenerator.CreatePngJob(card.Guid, card.Faction.Name, card.Type.Name), TimeSpan.FromMinutes(1));
                }
                await repository.Context.SaveChangesAsync();

                return(Ok(cardModel.FromDal()));
            }
        }
Пример #6
0
 public void Generate()
 {
     CardGenerator.Generate(id_t, id);
 }
Пример #7
0
 void Start()
 {
     unitFreeList.Clear();
     cardGen.Generate();
 }
Пример #8
0
        public async Task <HttpResponseMessage> Patch([FromUri] Guid id, [FromBody] Card card)
        {
            var principal = HttpContext.Current.User as Principal;

            using (var repository = new Repository(principal.UserId))
            {
                if (repository.ServiceUser == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.Forbidden));
                }
                var cardModel = await repository.Context.Cards.FindByGuidAsync(id);

                await repository.Context.Entry(cardModel).Reference(x => x.Status).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.Creator).LoadAsync();

                if (repository.ServiceUser != null)
                {
                    await repository.Context.Entry(repository.ServiceUser).Reference(x => x.Role).LoadAsync();

                    if (cardModel.Status.Guid == PredefinedGuids.Final)
                    {
                        if (repository.ServiceUser.Role.Guid == PredefinedGuids.Developer ||
                            repository.ServiceUser.Role.Guid != PredefinedGuids.Administrator ||
                            repository.ServiceUser.Role.Guid != PredefinedGuids.ServiceUser)
                        {
                            return(Request.CreateResponse(HttpStatusCode.Forbidden, "Card is marked as final"));
                        }
                    }
                }



                await repository.Context.Entry(cardModel).Reference(x => x.Faction).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.Serie).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.Type).LoadAsync();

                await repository.Context.Entry(cardModel).Reference(x => x.Status).LoadAsync();

                var serieModel = await repository.Context.Series.FindByGuidAsync(card.Serie.Guid);

                var factionModel = await repository.Context.Factions.FindByGuidAsync(card.Faction.Guid);

                var cardTypeModel = await repository.Context.CardTypes.FindByGuidAsync(card.Type.Guid);

                var statusModel = await repository.Context.Statuses.FindByGuidAsync(card.Status.Guid);

                var ruleSetModel = await repository.Context.RuleSets.FindByGuidAsync(card.RuleSet.Guid);

                var hasLayoutChanges = false;

                if (card.Name != cardModel.Name)
                {
                    hasLayoutChanges = true;
                }
                if (card.Faction.Guid != cardModel.Faction.Guid)
                {
                    hasLayoutChanges = true;
                }
                if (card.Type.Guid != cardModel.Type.Guid)
                {
                    hasLayoutChanges = true;
                }

                if (card.FirstName != cardModel.FirstName)
                {
                    hasLayoutChanges = true;
                }
                if (card.LastName != cardModel.LastName)
                {
                    hasLayoutChanges = true;
                }
                if (card.Artist != cardModel.Artist)
                {
                    hasLayoutChanges = true;
                }
                if (card.SubType != cardModel.SubType)
                {
                    hasLayoutChanges = true;
                }
                if (card.Cost != cardModel.Cost)
                {
                    hasLayoutChanges = true;
                }
                if (card.Loyalty != cardModel.Loyalty)
                {
                    hasLayoutChanges = true;
                }
                if (card.Attack != cardModel.Attack)
                {
                    hasLayoutChanges = true;
                }
                if (card.Defense != cardModel.Defense)
                {
                    hasLayoutChanges = true;
                }
                if (card.Info != cardModel.Info)
                {
                    hasLayoutChanges = true;
                }
                if (card.LayoutText != cardModel.LayoutText)
                {
                    hasLayoutChanges = true;
                }

                cardModel.Patch(card, serieModel, factionModel, cardTypeModel, statusModel, ruleSetModel, repository.ServiceUser);



                if (hasLayoutChanges)
                {
                    var jobId = cardModel.PngCreationJobId;
                    if (!string.IsNullOrEmpty(jobId))
                    {
                        BackgroundJob.Delete(jobId);
                    }

                    var cardGenerator = new CardGenerator(card);
                    await cardGenerator.Generate();

                    await cardGenerator.Generate(false);

                    cardModel.PngCreationJobId = BackgroundJob.Schedule(() => CardGenerator.CreatePngJob(card.Guid, card.Faction.Name, card.Type.Name), TimeSpan.FromMinutes(1));
                }
                await repository.Context.SaveChangesAsync();

                return(Request.CreateResponse(cardModel.FromDal()));
            }
        }