예제 #1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="UpdateAchievementViewModel"/> class.
            /// </summary>
            public UpdateAchievementViewModel(GeneratedAchievementViewModel achievement)
            {
                Achievement = achievement;

                if (!achievement.IsGenerated || achievement.CompareState == GeneratedCompareState.Same)
                {
                    IsUpdated = false;
                }
            }
예제 #2
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));
        }
예제 #3
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));
        }
예제 #4
0
        private void MergePublished(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;
                }
            }

            using (var stream = File.OpenRead(fileName))
            {
                var publishedData = new JsonObject(stream);
                Title = publishedData.GetField("Title").StringValue;

                var publishedAchievements = publishedData.GetField("Achievements");
                var coreCount             = 0;
                var corePoints            = 0;
                var unofficialCount       = 0;
                var unofficialPoints      = 0;
                foreach (var publishedAchievement in publishedAchievements.ObjectArrayValue)
                {
                    var points = publishedAchievement.GetField("Points").IntegerValue.GetValueOrDefault();
                    var title  = publishedAchievement.GetField("Title").StringValue;

                    var id          = publishedAchievement.GetField("ID").IntegerValue.GetValueOrDefault();
                    var achievement = achievements.OfType <GeneratedAchievementViewModel>().FirstOrDefault(a => a.Generated.Id == id);
                    if (achievement == null)
                    {
                        achievement = achievements.OfType <GeneratedAchievementViewModel>().FirstOrDefault(a => String.Compare(a.Generated.Title.Text, title, StringComparison.CurrentCultureIgnoreCase) == 0);
                        if (achievement == null)
                        {
                            achievement = new GeneratedAchievementViewModel(this, null);
                            achievements.Add(achievement);
                        }
                    }

                    var builder = new AchievementBuilder();
                    builder.Id          = id;
                    builder.Title       = title;
                    builder.Description = publishedAchievement.GetField("Description").StringValue;
                    builder.Points      = publishedAchievement.GetField("Points").IntegerValue.GetValueOrDefault();
                    builder.BadgeName   = publishedAchievement.GetField("BadgeName").StringValue;
                    builder.ParseRequirements(Tokenizer.CreateTokenizer(publishedAchievement.GetField("MemAddr").StringValue));

                    var builtAchievement = builder.ToAchievement();
                    builtAchievement.Published    = UnixEpoch.AddSeconds(publishedAchievement.GetField("Created").IntegerValue.GetValueOrDefault());
                    builtAchievement.LastModified = UnixEpoch.AddSeconds(publishedAchievement.GetField("Modified").IntegerValue.GetValueOrDefault());

                    if (publishedAchievement.GetField("Flags").IntegerValue == 5)
                    {
                        achievement.Unofficial.LoadAchievement(builtAchievement);
                        unofficialCount++;
                        unofficialPoints += points;
                    }
                    else
                    {
                        achievement.Core.LoadAchievement(builtAchievement);
                        coreCount++;
                        corePoints += points;
                    }
                }

                CoreAchievementCount        = coreCount;
                CoreAchievementPoints       = corePoints;
                UnofficialAchievementCount  = unofficialCount;
                UnofficialAchievementPoints = unofficialPoints;

                _logger.WriteVerbose(String.Format("Merged {0} core achievements ({1} points)", coreCount, corePoints));
                _logger.WriteVerbose(String.Format("Merged {0} unofficial achievements ({1} points)", unofficialCount, unofficialPoints));
            }
        }
예제 #5
0
        internal void PopulateEditorList(AchievementScriptInterpreter interpreter)
        {
            var editors = new List <GeneratedItemViewModelBase>();

            if (Script != null)
            {
                editors.Add(Script);
            }

            if (interpreter != null)
            {
                GeneratedAchievementCount = interpreter.Achievements.Count();
                editors.Capacity         += GeneratedAchievementCount;

                if (!String.IsNullOrEmpty(interpreter.RichPresence))
                {
                    var richPresenceViewModel = new RichPresenceViewModel(this, interpreter.RichPresence);
                    if (richPresenceViewModel.Lines.Any())
                    {
                        richPresenceViewModel.SourceLine = interpreter.RichPresenceLine;
                        editors.Add(richPresenceViewModel);
                    }
                }

                foreach (var achievement in interpreter.Achievements)
                {
                    var achievementViewModel = new GeneratedAchievementViewModel(this, achievement);
                    editors.Add(achievementViewModel);
                }

                foreach (var leaderboard in interpreter.Leaderboards)
                {
                    editors.Add(new LeaderboardViewModel(this, leaderboard));
                }
            }
            else
            {
                GeneratedAchievementCount = 0;
            }

            if (!String.IsNullOrEmpty(RACacheDirectory))
            {
                if (_isN64)
                {
                    MergePublishedN64(GameId, editors);
                }
                else
                {
                    MergePublished(GameId, editors);
                }

                MergeLocal(GameId, editors);
            }

            int nextLocalId = 111000001;

            foreach (var achievement in editors.OfType <GeneratedAchievementViewModel>())
            {
                if (achievement.Local != null && achievement.Local.Id >= nextLocalId)
                {
                    nextLocalId = achievement.Local.Id + 1;
                }
            }

            foreach (var achievement in editors.OfType <GeneratedAchievementViewModel>())
            {
                if (achievement.Local != null && achievement.Local.Id == 0)
                {
                    achievement.Local.Id = nextLocalId++;
                }

                achievement.UpdateCommonProperties(this);
            }

            Editors = editors;
        }