aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx/UI/Models/CheatNode.cs
blob: 8e9aee254d7083be39c044cab1a52aea48b04098 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Ryujinx.Ava.UI.ViewModels;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;

namespace Ryujinx.Ava.UI.Models
{
    public class CheatNode : BaseModel
    {
        private bool _isEnabled = false;
        public ObservableCollection<CheatNode> SubNodes { get; } = new();
        public string CleanName => Name[1..^7];
        public string BuildIdKey => $"{BuildId}-{Name}";
        public bool IsRootNode { get; }
        public string Name { get; }
        public string BuildId { get; }
        public string Path { get; }
        public bool IsEnabled
        {
            get
            {
                if (SubNodes.Count > 0)
                {
                    return SubNodes.ToList().TrueForAll(x => x.IsEnabled);
                }

                return _isEnabled;
            }
            set
            {
                foreach (var cheat in SubNodes)
                {
                    cheat.IsEnabled = value;
                    cheat.OnPropertyChanged();
                }

                _isEnabled = value;
            }
        }

        public CheatNode(string name, string buildId, string path, bool isRootNode, bool isEnabled = false)
        {
            Name = name;
            BuildId = buildId;
            Path = path;
            IsEnabled = isEnabled;
            IsRootNode = isRootNode;

            SubNodes.CollectionChanged += CheatsList_CollectionChanged;
        }

        private void CheatsList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            OnPropertyChanged(nameof(IsEnabled));
        }
    }
}