Beispiel #1
0
        private void MergePublishedN64(int gameId, List <GeneratedItemViewModelBase> achievements)
        {
            var fileName = Path.Combine(RACacheDirectory, gameId + ".json");

            if (!File.Exists(fileName))
            {
                fileName = Path.Combine(RACacheDirectory, gameId + ".txt");
                if (!File.Exists(fileName))
                {
                    return;
                }
            }

            var count  = 0;
            var points = 0;

            var officialAchievements = new LocalAchievements(fileName);

            foreach (var publishedAchievement in officialAchievements.Achievements)
            {
                var achievement = achievements.OfType <GeneratedAchievementViewModel>().FirstOrDefault(a => String.Compare(a.Generated.Title.Text, publishedAchievement.Title, StringComparison.CurrentCultureIgnoreCase) == 0);
                if (achievement == null)
                {
                    achievement = new GeneratedAchievementViewModel(this, null);
                    achievements.Add(achievement);
                }

                achievement.Core.LoadAchievement(publishedAchievement);
                count++;
                points += publishedAchievement.Points;
            }

            fileName = Path.Combine(RACacheDirectory, gameId + "-Unofficial.txt");
            if (File.Exists(fileName))
            {
                var unofficialAchievements = new LocalAchievements(fileName);
                foreach (var publishedAchievement in unofficialAchievements.Achievements)
                {
                    var achievement = achievements.OfType <GeneratedAchievementViewModel>().FirstOrDefault(a => String.Compare(a.Generated.Title.Text, publishedAchievement.Title, StringComparison.CurrentCultureIgnoreCase) == 0);
                    if (achievement == null)
                    {
                        achievement = new GeneratedAchievementViewModel(this, null);
                        achievements.Add(achievement);
                    }

                    achievement.Unofficial.LoadAchievement(publishedAchievement);
                    count++;
                    points += publishedAchievement.Points;
                }
            }

            CoreAchievementCount  = count;
            CoreAchievementPoints = points;

            _logger.WriteVerbose(String.Format("Merged {0} published achievements ({1} points)", count, points));
        }
Beispiel #2
0
        private void MergeLocal(int gameId, List <GeneratedItemViewModelBase> achievements)
        {
            var fileName = Path.Combine(RACacheDirectory, gameId + "-User.txt");

            _localAchievements = new LocalAchievements(fileName);

            if (String.IsNullOrEmpty(_localAchievements.Title))
            {
                _localAchievements.Title = Title;
            }

            var localAchievements = new List <Achievement>(_localAchievements.Achievements);

            foreach (var achievement in achievements.OfType <GeneratedAchievementViewModel>())
            {
                Achievement localAchievement = null;
                if (achievement.Id > 0)
                {
                    localAchievement = localAchievements.FirstOrDefault(a => a.Id == achievement.Id);
                }

                if (localAchievement == null)
                {
                    localAchievement = localAchievements.FirstOrDefault(a => String.Compare(a.Title, achievement.Generated.Title.Text, StringComparison.CurrentCultureIgnoreCase) == 0);
                    if (localAchievement == null)
                    {
                        localAchievement = localAchievements.FirstOrDefault(a => a.Description == achievement.Generated.Description.Text);
                        if (localAchievement == null)
                        {
                            // TODO: attempt to match achievements by requirements
                            continue;
                        }
                    }
                }

                localAchievements.Remove(localAchievement);

                achievement.Local.LoadAchievement(localAchievement);
            }

            foreach (var localAchievement in localAchievements)
            {
                var vm = new GeneratedAchievementViewModel(this, null);
                vm.Local.LoadAchievement(localAchievement);
                achievements.Add(vm);
            }

            LocalAchievementCount  = _localAchievements.Achievements.Count();
            LocalAchievementPoints = _localAchievements.Achievements.Sum(a => a.Points);

            _logger.WriteVerbose(String.Format("Merged {0} local achievements ({1} points)", LocalAchievementCount, LocalAchievementPoints));
        }
Beispiel #3
0
        public void RegressionTest(string scriptFileName)
        {
            if (scriptFileName == "No scripts found.")
            {
                return;
            }

            var outputFileName   = scriptFileName.Substring(0, scriptFileName.Length - 9) + ".updated.txt";
            var expectedFileName = scriptFileName.Substring(0, scriptFileName.Length - 9) + ".txt";

            var interpreter = new AchievementScriptInterpreter();

            interpreter.Run(Tokenizer.CreateTokenizer(File.Open(scriptFileName, FileMode.Open)));

            Assert.IsNull(interpreter.ErrorMessage);

            var mockFileSystemService = new Mock <IFileSystemService>();

            mockFileSystemService.Setup(s => s.CreateFile(It.IsAny <string>())).Returns((string path) => File.Create(path));

            var localAchievements = new LocalAchievements(outputFileName, mockFileSystemService.Object);

            localAchievements.Title = Path.GetFileNameWithoutExtension(scriptFileName);
            foreach (var achievement in interpreter.Achievements)
            {
                localAchievements.Replace(null, achievement);
            }
            localAchievements.Commit("Author");

            if (interpreter.Leaderboards.Any())
            {
                using (var file = File.Open(outputFileName, FileMode.Append))
                {
                    using (var fileWriter = new StreamWriter(file))
                    {
                        fileWriter.WriteLine("=== Leaderboards ===");
                        foreach (var leaderboard in interpreter.Leaderboards)
                        {
                            fileWriter.Write("0:");
                            fileWriter.Write("\"STA:");
                            fileWriter.Write(leaderboard.Start);
                            fileWriter.Write("::CAN:");
                            fileWriter.Write(leaderboard.Cancel);
                            fileWriter.Write("::SUB:");
                            fileWriter.Write(leaderboard.Submit);
                            fileWriter.Write("::VAL:");
                            fileWriter.Write(leaderboard.Value);
                            fileWriter.Write("\":");
                            fileWriter.Write(leaderboard.Format);
                            fileWriter.Write(":\"");
                            fileWriter.Write(leaderboard.Title);
                            fileWriter.Write("\":\"");
                            fileWriter.Write(leaderboard.Description);
                            fileWriter.WriteLine("\"");
                        }
                    }
                }
            }

            if (!String.IsNullOrEmpty(interpreter.RichPresence))
            {
                using (var file = File.Open(outputFileName, FileMode.Append))
                {
                    using (var fileWriter = new StreamWriter(file))
                    {
                        fileWriter.WriteLine("=== Rich Presence ===");
                        fileWriter.WriteLine(interpreter.RichPresence);
                    }
                }
            }

            Assert.IsTrue(File.Exists(expectedFileName), expectedFileName + " not found");

            FileAssert.AreEqual(expectedFileName, outputFileName);

            File.Delete(outputFileName);
        }