示例#1
0
        internal void UpdateLocal(Achievement achievement, Achievement localAchievement)
        {
            if (achievement == null)
            {
                _logger.WriteVerbose(String.Format("Deleting {0} from local achievements", localAchievement.Title));

                var previous = _localAchievements.Replace(localAchievement, null);
                if (previous != null && previous.Points != 0)
                {
                    LocalAchievementPoints -= previous.Points;
                }

                LocalAchievementCount--;
            }
            else
            {
                if (localAchievement != null)
                {
                    _logger.WriteVerbose(String.Format("Updating {0} in local achievements", achievement.Title));
                }
                else
                {
                    _logger.WriteVerbose(String.Format("Committing {0} to local achievements", achievement.Title));
                }

                var previous = _localAchievements.Replace(localAchievement, achievement);
                if (previous != null)
                {
                    var diff = achievement.Points - previous.Points;
                    if (diff != 0)
                    {
                        LocalAchievementPoints += diff;
                    }
                }
                else
                {
                    LocalAchievementCount++;
                    LocalAchievementPoints += achievement.Points;
                }
            }

            _localAchievements.Commit(ServiceRepository.Instance.FindService <ISettings>().UserName);
        }
示例#2
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);
        }