/*
         * Return a list of board full paths, in the Arcweave hierarchy context.
         */
        public static void GetBoardsFullPaths(Project project, List <string> IDs, List <string> paths)
        {
            BoardFolder root = project.GetRootBoardFolder();

            if (root == null)
            {
                Debug.LogWarning("[Arcweave] Cannot find root board. Maybe the exported json is corrupted, or the format has changed.");
                return;
            }

            // Do first depth iteration here to skip appending "Root" to all paths
            for (int i = 0; i < root.childIds.Length; i++)
            {
                IBoardEntry child = project.GetBoardEntry(root.childIds[i]);
                BoardHierarchyWalker(project, child, "", IDs, paths);
            }
        }
Beispiel #2
0
        /*
         * Read board folder.
         */
        private static void ReadBoardFolder(BoardFolder bf, Project project, JSONNode node)
        {
            bf.name     = bf.id;
            bf.realName = node["name"];

            JSONArray idxArray = node["children"].AsArray;

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

            bf.childIds = new int[idxArray.Count];

            for (int i = 0; i < idxArray.Count; i++)
            {
                bf.childIds[i] = idxArray[i].AsInt;
            }
        }
Beispiel #3
0
        /*
         * Read boards from JSON entry.
         */
        public static void ReadBoards(Project project, JSONClass boardRoot)
        {
            string boardsPath = "Assets" + ProjectUtils.projectResourceFolder + "Boards/";

            List <Board>       tmp        = new List <Board>();
            List <BoardFolder> tmpFolders = new List <BoardFolder>();

            IEnumerator children = boardRoot.GetEnumerator();

            while (children.MoveNext())
            {
                // Get current
                KeyValuePair <string, JSONNode> current = (children.Current != null) ?
                                                          (KeyValuePair <string, JSONNode>)children.Current : default(KeyValuePair <string, JSONNode>);
                JSONNode child = current.Value;

                // Get its ID
                string id = current.Key;

                bool isFolder = child["children"] != null;

                if (isFolder)
                {
                    BoardFolder folder = ScriptableObject.CreateInstance <BoardFolder>();
                    folder.id = id;
                    ReadBoardFolder(folder, project, child);
                    tmpFolders.Add(folder);
                    AssetDatabase.CreateAsset(folder, boardsPath + folder.name + ".asset");
                }
                else
                {
                    Board board = ScriptableObject.CreateInstance <Board>();
                    board.id = id;
                    ReadBoard(board, project, child);
                    tmp.Add(board);
                    AssetDatabase.CreateAsset(board, boardsPath + board.name + ".asset");
                }
            }

            project.boards       = tmp.ToArray();
            project.boardFolders = tmpFolders.ToArray();
        }
        /*
         * Read board folder.
         */
        private static void ReadBoardFolder(BoardFolder bf, Project project, JSONNode node)
        {
            bf.name     = bf.id;
            bf.realName = node["name"];

            JSONArray hashArray = node["children"].AsArray;

            if (hashArray.Count == 0)
            {
                bf.childIds = new string[0];
                return;
            }

            bf.childIds = new string[hashArray.Count];

            for (int i = 0; i < hashArray.Count; i++)
            {
                bf.childIds[i] = hashArray[i];
            }
        }
        /*
         * Recursive static function to iterate over the Board Folder hierarchy and build two lists.
         * IDs list contains the Hash IDs of the resulting boards, while paths contain the computed Hierachy paths, as they were in Arcweave.
         */
        public static void BoardHierarchyWalker(Project project, IBoardEntry entry, string prefix, List <string> IDs, List <string> paths)
        {
            if (entry is Board)
            {
                Board b = entry as Board;
                IDs.Add(b.id);
                paths.Add(prefix + b.realName);
            }
            else if (entry is BoardFolder)
            {
                BoardFolder bf        = entry as BoardFolder;
                string      newPrefix = prefix + bf.realName + "/";

                for (int i = 0; i < bf.childIds.Length; i++)
                {
                    IBoardEntry child = project.GetBoardEntry(bf.childIds[i]);
                    BoardHierarchyWalker(project, child, newPrefix, IDs, paths);
                }
            }
            else
            {
                Debug.LogWarning("[Arcweave] Unexpected type of board entry: " + entry);
            }
        }