Beispiel #1
0
        public GeneratedAchievementViewModel(GameViewModel owner, Achievement generatedAchievement)
        {
            _owner = owner;

            Generated = new AchievementViewModel(owner, "Generated");
            if (generatedAchievement != null)
            {
                Generated.LoadAchievement(generatedAchievement);
                Id = Generated.Id;
            }

            Local      = new AchievementViewModel(owner, "Local");
            Unofficial = new AchievementViewModel(owner, "Unofficial");
            Core       = new AchievementViewModel(owner, "Core");

            if (String.IsNullOrEmpty(owner.RACacheDirectory))
            {
                UpdateLocalCommand = DisabledCommand.Instance;
                DeleteLocalCommand = DisabledCommand.Instance;
            }
            else
            {
                UpdateLocalCommand = new DelegateCommand(() => UpdateLocal(owner));
                DeleteLocalCommand = new DelegateCommand(() => DeleteLocal(owner));
            }
        }
Beispiel #2
0
        internal void PopulateEditorList(AchievementScriptInterpreter interpreter)
        {
            var editors = new List <ViewerViewModelBase>();

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

            var selectedEditor = (SelectedEditor != null) ? SelectedEditor.Title : null;

            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 AchievementViewModel(this);
                    achievementViewModel.Generated.Asset = achievement;
                    editors.Add(achievementViewModel);
                }

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

            if (_publishedAchievements.Count > 0 || _publishedLeaderboards.Count > 0)
            {
                MergePublished(editors);
            }

            if (_localAssets != null)
            {
                MergeLocal(editors);
            }

            UpdateTemporaryIds(editors);

            SelectedEditor = editors.FirstOrDefault(e => e.Title == selectedEditor);
            Editors        = editors;
        }
Beispiel #3
0
        private void DeleteLocal(GameViewModel owner)
        {
            owner.UpdateLocal(null, Local.Achievement);

            Local = new AchievementViewModel(owner, "Local");
            OnPropertyChanged(() => Local);
            UpdateModified();
        }
Beispiel #4
0
        private void UpdateLocal(GameViewModel owner)
        {
            var achievement = Generated.Achievement;

            if (achievement.Id == 0 && Local.Id > 0)
            {
                achievement.Id = Local.Id;
            }
            if (!String.IsNullOrEmpty(Local.BadgeName))
            {
                achievement.BadgeName = Local.BadgeName;
            }

            owner.UpdateLocal(achievement, Local.Achievement);

            Local = new AchievementViewModel(owner, "Local");
            Local.LoadAchievement(achievement);

            OnPropertyChanged(() => Local);
            UpdateModified();
        }
Beispiel #5
0
        private bool IsAchievementModified(AchievementViewModel achievement)
        {
            if (achievement.Achievement == null)
            {
                return(false);
            }

            bool isModified = false;

            if (achievement.Title.Text != Generated.Title.Text)
            {
                IsTitleModified = isModified = true;
            }
            if (achievement.Description.Text != Generated.Description.Text)
            {
                IsDescriptionModified = isModified = true;
            }
            if (achievement.Points.Value != Generated.Points.Value)
            {
                IsPointsModified = isModified = true;
            }

            var groups = new List <RequirementGroupViewModel>();

            if (GetRequirementGroups(groups, Generated.Achievement, achievement.Achievement))
            {
                RequirementGroups = groups;
                return(true);
            }

            if (isModified)
            {
                RequirementGroups = Generated.RequirementGroups;
                return(true);
            }

            return(false);
        }
Beispiel #6
0
        private void LoadGame(int gameId, string raCacheDirectory)
        {
            _game = new GameViewModel(GameId.Value.GetValueOrDefault(), "", raCacheDirectory);
            _game.PopulateEditorList(null);
            DialogTitle = "New Script - " + _game.Title;

            _achievements.Clear();
            _ticketNotes.Clear();
            _memoryItems.Clear();
            MemoryAddresses.Rows.Clear();

            var unofficialAchievements = new List <DumpAchievementItem>();

            foreach (var achievement in _game.Editors.OfType <GeneratedAchievementViewModel>())
            {
                AchievementViewModel source = achievement.Core;
                if (source.Achievement == null)
                {
                    source = achievement.Unofficial;
                    if (source.Achievement == null)
                    {
                        continue;
                    }
                }

                var dumpAchievement = new DumpAchievementItem(achievement.Id, source.Title.Text);
                if (achievement.Core.Achievement == null)
                {
                    dumpAchievement.IsUnofficial = true;
                    unofficialAchievements.Add(dumpAchievement);
                }
                else
                {
                    _achievements.Add(dumpAchievement);
                }

                foreach (var group in source.RequirementGroups)
                {
                    foreach (var requirement in group.Requirements)
                    {
                        if (requirement.Requirement == null)
                        {
                            continue;
                        }

                        if (requirement.Requirement.Left != null && requirement.Requirement.Left.IsMemoryReference)
                        {
                            var memoryItem = AddMemoryAddress(requirement.Requirement.Left);
                            if (memoryItem != null && !dumpAchievement.MemoryAddresses.Contains(memoryItem))
                            {
                                dumpAchievement.MemoryAddresses.Add(memoryItem);
                            }
                        }

                        if (requirement.Requirement.Right != null && requirement.Requirement.Right.IsMemoryReference)
                        {
                            var memoryItem = AddMemoryAddress(requirement.Requirement.Right);
                            if (memoryItem != null && !dumpAchievement.MemoryAddresses.Contains(memoryItem))
                            {
                                dumpAchievement.MemoryAddresses.Add(memoryItem);
                            }
                        }
                    }
                }

                dumpAchievement.IsSelected       = true;
                dumpAchievement.PropertyChanged += DumpAchievement_PropertyChanged;
            }

            foreach (var unofficialAchievement in unofficialAchievements)
            {
                _achievements.Add(unofficialAchievement);
            }

            foreach (var kvp in _game.Notes)
            {
                FieldSize size  = FieldSize.Byte;
                Token     token = new Token(kvp.Value, 0, kvp.Value.Length);
                if (token.Contains("16-bit", StringComparison.OrdinalIgnoreCase) ||
                    token.Contains("16 bit", StringComparison.OrdinalIgnoreCase))
                {
                    size = FieldSize.Word;
                }
                else if (token.Contains("32-bit", StringComparison.OrdinalIgnoreCase) ||
                         token.Contains("32 bit", StringComparison.OrdinalIgnoreCase))
                {
                    size = FieldSize.DWord;
                }

                AddMemoryAddress(new Field {
                    Size = size, Type = FieldType.MemoryAddress, Value = (uint)kvp.Key
                });
            }

            if (_achievements.Count == 0)
            {
                SelectedCodeNotesFilter = CodeNoteFilter.All;
            }

            UpdateMemoryGrid();

            IsGameLoaded     = true;
            GameId.IsEnabled = false;

            if (_achievements.Count > 0)
            {
                ServiceRepository.Instance.FindService <IBackgroundWorkerService>().RunAsync(MergeOpenTickets);
            }
        }
Beispiel #7
0
        private void MergeAchievements(List <ViewerViewModelBase> editors, IEnumerable <AssetBase> assets,
                                       Action <AssetViewModelBase, AssetBase> assign)
        {
            var mergeAssets = new List <AssetBase>(assets);

            if (mergeAssets.Count == 0)
            {
                return;
            }

            var assetEditors = new List <AssetViewModelBase>();

            if (assets.First() is Achievement)
            {
                assetEditors.AddRange(editors.OfType <AchievementViewModel>());
            }
            else
            {
                assetEditors.AddRange(editors.OfType <LeaderboardViewModel>());
            }

            // first pass - look for ID matches
            for (int i = assetEditors.Count - 1; i >= 0; i--)
            {
                AssetBase mergeAsset  = null;
                var       assetEditor = assetEditors[i];

                if (assetEditor.Generated.Id > 0)
                {
                    mergeAsset = mergeAssets.FirstOrDefault(a => a.Id == assetEditor.Generated.Id);
                }
                if (mergeAsset == null && assetEditor.Published.Id > 0)
                {
                    mergeAsset = mergeAssets.FirstOrDefault(a => a.Id == assetEditor.Published.Id);
                }

                if (mergeAsset != null)
                {
                    assign(assetEditor, mergeAsset);

                    mergeAssets.Remove(mergeAsset);
                    assetEditors.RemoveAt(i);
                }
            }

            // second pass - look for title matches
            for (int i = mergeAssets.Count - 1; i >= 0; i--)
            {
                var mergeAsset  = mergeAssets[i];
                var assetEditor = assetEditors.FirstOrDefault(a =>
                                                              (String.Compare(a.Generated.Title.Text, mergeAsset.Title, StringComparison.InvariantCultureIgnoreCase) == 0 ||
                                                               String.Compare(a.Published.Title.Text, mergeAsset.Title, StringComparison.InvariantCultureIgnoreCase) == 0)
                                                              );

                if (assetEditor != null)
                {
                    assign(assetEditor, mergeAsset);

                    mergeAssets.RemoveAt(i);
                    assetEditors.Remove(assetEditor);
                }
            }

            // third pass - look for description matches
            for (int i = mergeAssets.Count - 1; i >= 0; i--)
            {
                var mergeAsset  = mergeAssets[i];
                var assetEditor = assetEditors.FirstOrDefault(a =>
                                                              String.Compare(a.Generated.Description.Text, mergeAsset.Description, StringComparison.InvariantCultureIgnoreCase) == 0);

                if (assetEditor != null)
                {
                    assign(assetEditor, mergeAsset);

                    mergeAssets.RemoveAt(i);
                    assetEditors.Remove(assetEditor);
                }
            }

            // TODO: attempt to match requirements

            // create new entries for each remaining unmerged achievement
            foreach (var mergeAsset in mergeAssets)
            {
                AssetViewModelBase assetEditor;

                if (mergeAsset is Achievement)
                {
                    assetEditor = new AchievementViewModel(this);
                }
                else
                {
                    assetEditor = new LeaderboardViewModel(this);
                }

                assign(assetEditor, mergeAsset);
                editors.Add(assetEditor);
            }
        }
Beispiel #8
0
        internal void UpdateCommonProperties(GameViewModel owner)
        {
            if (Local.Modified == ModifiedState.Unmodified)
            {
                var localAchievement = Local.Achievement;
                Local = new AchievementViewModel(owner, "Local");
                Local.LoadAchievement(localAchievement);
            }

            if (Unofficial.Modified == ModifiedState.Unmodified)
            {
                var unofficialAchievement = Unofficial.Achievement;
                Unofficial = new AchievementViewModel(owner, "Unofficial");
                Unofficial.LoadAchievement(unofficialAchievement);
            }

            if (Core.Modified == ModifiedState.Unmodified)
            {
                var coreAchievement = Core.Achievement;
                Core = new AchievementViewModel(owner, "Core");
                Core.LoadAchievement(coreAchievement);
            }

            if (Generated.Achievement != null)
            {
                Id = Generated.Id;
                SetBinding(TitleProperty, new ModelBinding(Generated.Title, TextFieldViewModel.TextProperty, ModelBindingMode.OneWay));
                SetBinding(DescriptionProperty, new ModelBinding(Generated.Description, TextFieldViewModel.TextProperty, ModelBindingMode.OneWay));
                SetBinding(PointsProperty, new ModelBinding(Generated.Points, IntegerFieldViewModel.ValueProperty, ModelBindingMode.OneWay));
            }
            else if (Core.Achievement != null)
            {
                Title       = Core.Title.Text;
                Description = Core.Description.Text;
                Points      = Core.Points.Value.GetValueOrDefault();
            }
            else if (Unofficial.Achievement != null)
            {
                Title       = Unofficial.Title.Text;
                Description = Unofficial.Description.Text;
                Points      = Unofficial.Points.Value.GetValueOrDefault();
            }
            else if (Local.Achievement != null)
            {
                Title       = Local.Title.Text;
                Description = Local.Description.Text;
                Points      = Local.Points.Value.GetValueOrDefault();
            }

            if (Core.Achievement != null)
            {
                Id = Core.Id;
            }
            else if (Unofficial.Achievement != null)
            {
                Id = Unofficial.Id;
            }
            else if (Local.Achievement != null)
            {
                Id = Local.Id;
            }

            UpdateModified();
        }