少年修仙传客户端基础资源
dabaoji
2023-11-13 0a23e1b83f8fda8ab9f9e32fe71c26c431faf63a
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System;
using System.IO;
using System.Linq;
 
namespace Movinarc
{
    public class TreeNode
    {
        public TreeNode()
        {
            children = new List<TreeNode>();
            lastCheckedState = isChecked;
        }
        //dynamic
        public TreeNode root;
 
        public bool isTreeEmpty
        {
            get
            {
                return root.children == null || root.children.Count <= 0;
            }
        }
 
        public bool isExpanded = false;
        public bool isRoot = false;
 
        public TreeNode parent;
        public string name;
        public bool isChecked;
        public bool lastCheckedState;
        //Primary Key - dynamic
        public string path;
 
        //dynamic
        public bool isDirectory;
 
        public List<TreeNode> children;
 
        public List<string> pathList()
        {
            return new List<string>(path.Split(new []{ '/' }, System.StringSplitOptions.RemoveEmptyEntries));
        }
 
        public List<string> pathList(string path)
        {
            return new List<string>(path.Split(new []{ '/' }, System.StringSplitOptions.RemoveEmptyEntries));
        }
 
        public List<TreeNode> parents
        {
            get
            {
                return new List<TreeNode>(getParents(this));
            }
        }
 
        private IEnumerable<TreeNode> getParents(TreeNode node)
        {
            if (parent != null)
            {
                yield return parent;
                getParents(parent);
            }
        }
 
        public TreeNode AddNode(TreeNode node)
        {
            children.Add(node);
            return node;
        }
 
        public TreeNode AddNode(string name, bool isChecked)
        {
            TreeNode node = new TreeNode();
            node.parent = this;
            node.name = name;
            node.isChecked = isChecked;
            node.lastCheckedState = isChecked;
            children.Add(node);
            return node;
        }
 
        bool Exists()
        {
            return false;
        }
 
        public bool PathExists(string path)
        {
            return checkPathExists(pathList(path), root);
        }
 
        private bool checkPathExists(List<string> pathList, TreeNode fromNode)
        {
            if (pathList != null)
            {
                if (pathList.Count > 0)
                {
                    if (isTreeEmpty)
                        return false;
                    foreach (var ch in fromNode.children)
                    {
                        string n0 = pathList[0];
                        if (ch.name.Equals(n0, StringComparison.OrdinalIgnoreCase))
                        {
                            pathList.RemoveAt(0);
                            return checkPathExists(pathList, ch);
                      
                        }
                    }
                }
 
            }
            if (pathList.Count == 0)
                return true;
            else
                return false;
        }
 
        public TreeNode GetNodeInPath(string path, TreeNode root)
        {
            return checkGetNodeInPath(pathList(path), root);
        }
 
        private TreeNode checkGetNodeInPath(List<string> pathList, TreeNode fromNode)
        {
 
            if (pathList != null)
            {
                if (pathList.Count > 0)
                {
                    string n0 = pathList[0];
 
                    foreach (var child in fromNode.children)
                    {
                        if (child.name.Equals(n0, StringComparison.OrdinalIgnoreCase))
                        {
                            pathList.RemoveAt(0);
                            return checkGetNodeInPath(pathList, child);
                        }
                    }
                }
 
            }
            if (pathList.Count == 0)
                return fromNode;
            else
                return null;
        }
 
        public TreeNode GetParentNodeInPath(string path, TreeNode root)
        {
            return checkGetParentNodeInPath(pathList(path), root);
        }
 
        private TreeNode checkGetParentNodeInPath(List<string> pathList, TreeNode fromNode)
        {
 
            if (pathList != null)
            {
                if (pathList.Count > 0)
                {
                    pathList.RemoveAt(pathList.Count - 1);
                    return GetNodeInPath(listToPath(pathList), fromNode);
                }
            }
            return root;
        }
 
        public static string listToPath(List<string> list)
        {
            string joint = String.Join("/", list.ToArray());
            joint = iHateSlashes(joint);
            return joint;
        }
 
        public static string iHateSlashes(string which)
        {
            if (which.Length > 0)
            {
                if (which[which.Length - 1] == '/')
                    which = which.Remove(which.Length - 1);
                if (which[0] == '/')
                    which = which.Remove(0);
            }
            return which;
        }
 
        public bool ExistsInChildren(string name, bool recursive)
        {
            return false;
        }
 
        public List<TreeNode> FindByName(string name)
        {
            return null;
        }
    }
 
 }