예제 #1
0
        private async void UpdateViewModel()
        {
            var profile = AppState.Data.Profile;

            if (!AppState.Data.DefinitionsLoaded || profile == null)
            {
                return;
            }

            viewIsUpdating = true;
            triumphs.Clear();

            PresentationNodeDef = await Definitions.GetPresentationNode(presentationNodeHash);

            if (PresentationNodeDef == null)
            {
                return;
            }

            foreach (var childRecord in PresentationNodeDef.Children.Records)
            {
                var recordDefinition = await Definitions.GetRecord(childRecord.RecordHash);

                var triumph = new Triumph
                {
                    Definition = recordDefinition,
                    Hash       = childRecord.RecordHash,
                    Objectives = new List <Objective>(),
                    Record     = Triumph.FindRecordInProfileOrDefault(childRecord.RecordHash.ToString(), profile)
                };

                if (triumph.Record == null)
                {
                    Log.Info($"Triumph {childRecord.RecordHash} is missing its record from profile data");
                }


                foreach (var objectiveProgress in triumph.ObjectiveProgresses)
                {
                    if (objectiveProgress == null)
                    {
                        continue;
                    }

                    var obj = new Objective {
                        Progress = objectiveProgress
                    };
                    await obj.PopulateDefinition();

                    triumph.Objectives.Add(obj);
                }

                triumphs.Add(triumph);
            }

            viewIsUpdating = false;

            UpdateSelection();
        }
        private async void UpdateViewModel()
        {
            var profile = AppState.Data.Profile;

            if (!AppState.Data.DefinitionsLoaded || profile == null)
            {
                return;
            }

            viewIsUpdating = true;
            triumphs.Clear();

            PresentationNodeDef = await Definitions.GetPresentationNode(presentationNodeHash);

            if (PresentationNodeDef == null)
            {
                return;
            }

            foreach (var childRecord in PresentationNodeDef.Children.Records)
            {
                var recordDefinition = await Definitions.GetRecord(childRecord.RecordHash);

                var triumph = new Triumph
                {
                    Definition = recordDefinition,
                    Hash       = childRecord.RecordHash,
                    Objectives = new List <Objective>(),
                    Record     = Triumph.FindRecordInProfileOrDefault(childRecord.RecordHash.ToString(), profile)
                };

                if (triumph.Record == null)
                {
                    Log.Info($"Triumph {childRecord.RecordHash} is missing its record from profile data");
                }

                var objectives = triumph.Record?.Objectives ?? new List <DestinyObjectiveProgress>();

                var hasIntervalObjectives = (triumph.Record?.IntervalObjectives?.Count ?? 0) > 0;
                var intervalObjectives    = hasIntervalObjectives
                    ? triumph.Record.IntervalObjectives
                    : new List <DestinyObjectiveProgress>();
                var allIntervalsComplete = intervalObjectives.All(v => v.Complete);

                var remainingIntervalObjectives = intervalObjectives.Where(v => !v.Complete);

                objectives.AddRange(remainingIntervalObjectives);
                if (hasIntervalObjectives && allIntervalsComplete)
                {
                    objectives.Add(intervalObjectives.LastOrDefault());
                }

                foreach (var objectiveProgress in objectives)
                {
                    if (objectiveProgress == null)
                    {
                        continue;
                    }

                    var obj = new Objective {
                        Progress = objectiveProgress
                    };
                    await obj.PopulateDefinition();

                    triumph.Objectives.Add(obj);
                }

                triumphs.Add(triumph);
            }

            viewIsUpdating = false;

            UpdateSelection();
        }