/// <summary>
        /// Parse XML comment and returns structurized info
        /// </summary>
        /// <param name="originalComment"></param>
        /// <returns></returns>
        public static CommentStructure ParseCommentStructure(String originalComment)
        {
            if(String.IsNullOrEmpty(originalComment))
            {
                return null;
            }

            // Remove // and /**/ from comments to improve their readability
            var lines = originalComment
                .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => s.Trim(new[] { '*', '/', '|', ' ' }))
                .Where(s => !String.IsNullOrEmpty(s))
                .ToArray();

            String resultStr = string.Join(Environment.NewLine, lines);

            CommentStructure result = new CommentStructure();

            //Try to load comments as XML
            if (resultStr.Contains("</"))
            {
                try
                {
                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml("<root>" + resultStr + "</root>");
                    var summaryNode = xmlDoc.SelectSingleNode("//summary");
                    if (summaryNode != null)
                    {
                        result.Summary = summaryNode.InnerText.Trim();
                        summaryNode.InnerXml = string.Empty;
                    }

                    var returnsNode = xmlDoc.SelectSingleNode("//returns");
                    if (returnsNode != null)
                    {
                        result.Returns = returnsNode.InnerText.Trim();
                        returnsNode.InnerXml = string.Empty;
                    }

                    var paramNodes = xmlDoc.SelectNodes("//param");
                    if (paramNodes != null)
                    {
                        foreach (XmlElement paramElt in paramNodes)
                        {
                            result.Parameters.Add(new KeyValuePair<string, string>(paramElt.GetAttribute("name").Trim(), paramElt.InnerText.Trim()));
                            paramElt.InnerXml = string.Empty;
                        }
                    }

                    result.OtherText = xmlDoc.InnerText.Trim();
                    return result;
                }
                catch {
                    //no luck
                }
            }

            result.OtherText = resultStr;
            return result;
        }
Exemple #2
0
        /// <summary>
        /// Parse XML comment and returns structurized info
        /// </summary>
        /// <param name="originalComment"></param>
        /// <returns></returns>
        public static CommentStructure ParseCommentStructure(String originalComment)
        {
            if (String.IsNullOrEmpty(originalComment))
            {
                return(null);
            }

            // Remove // and /**/ from comments to improve their readability
            var lines = originalComment
                        .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s.Trim(new[] { '*', '/', '|', ' ' }))
                        .Where(s => !String.IsNullOrEmpty(s))
                        .ToArray();

            String resultStr = string.Join(Environment.NewLine, lines);

            CommentStructure result = new CommentStructure();

            //Try to load comments as XML
            if (resultStr.Contains("</"))
            {
                try
                {
                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml("<root>" + resultStr + "</root>");
                    var summaryNode = xmlDoc.SelectSingleNode("//summary");
                    if (summaryNode != null)
                    {
                        result.Summary       = summaryNode.InnerText.Trim();
                        summaryNode.InnerXml = string.Empty;
                    }

                    var returnsNode = xmlDoc.SelectSingleNode("//returns");
                    if (returnsNode != null)
                    {
                        result.Returns       = returnsNode.InnerText.Trim();
                        returnsNode.InnerXml = string.Empty;
                    }

                    var paramNodes = xmlDoc.SelectNodes("//param");
                    if (paramNodes != null)
                    {
                        foreach (XmlElement paramElt in paramNodes)
                        {
                            result.Parameters.Add(new KeyValuePair <string, string>(paramElt.GetAttribute("name").Trim(), paramElt.InnerText.Trim()));
                            paramElt.InnerXml = string.Empty;
                        }
                    }

                    result.OtherText = xmlDoc.InnerText.Trim();
                    return(result);
                }
                catch {
                    //no luck
                }
            }

            result.OtherText = resultStr;
            return(result);
        }
Exemple #3
0
    public void CreateComment(bool abort = false)
    {
        ShowCommentMenu();

        if (abort)
        {
            commentField.text = "";
            return;
        }

        CommentStructure cs = Instantiate(commentPrefab, commentsContent).GetComponent <CommentStructure>();

        cs.SetCommentInfo(currentUsername, commentField.text);

        lastLevelShown.comments.Add(new KeyValuePair <string, string>(currentUsername, commentField.text));

        scrollbar.enabled = lastLevelShown.comments.Count > 2;
        commentsContent.GetComponent <VerticalLayoutGroup>().padding.right = lastLevelShown.comments.Count > 2 ? 50 : 20;

        Invoke(nameof(SetCommentsSize), 0.1f);

        commentField.text = "";
    }
Exemple #4
0
    public void ApplyLevelInfo(LevelInfo level, LevelSummary ls, bool setActiveFalse = false)
    {
        if ((lastLevelShown != null && level == null) || setActiveFalse)
        {
            lastLevelShown = null;

            puzzleInfo.SetActive(false);
            return;
        }
        else if (lastLevelShown == null && level != null)
        {
            puzzleInfo.SetActive(true);
        }

        levelname.text   = level.levelname;
        size.text        = "Size: " + level.size + "x" + level.size;
        username.text    = "MADE BY " + level.username;
        description.text = level.description;

        likeGO.SetActive(level.type == LevelInfo.LevelType.Online);
        commentsGO.SetActive(level.type == LevelInfo.LevelType.Online);
        commentGOButton.SetActive(level.type == LevelInfo.LevelType.Online);

        if (level.type == LevelInfo.LevelType.Online)
        {
            string likesS = level.likesNumber < 10 ? "0" + level.likesNumber.ToString() : level.likesNumber.ToString();
            likes.text = likesS;
            ls.ApplyInfo(level);

            string user       = "";
            string usersLiked = level.usersLiked;
            heartLike.color = Color.white;

            for (int i = 0; i < usersLiked.Length; ++i)
            {
                if (usersLiked[i] == ',')
                {
                    if (user == currentUsername)
                    {
                        heartLike.color = Color.green;
                    }

                    user = "";
                    continue;
                }

                user += usersLiked[i];
            }

            for (int i = 0; i < commentsContent.childCount; ++i)
            {
                Destroy(commentsContent.GetChild(i).gameObject);
            }

            for (int i = 0; i < level.comments.Count; ++i)
            {
                CommentStructure cs = Instantiate(commentPrefab, commentsContent).GetComponent <CommentStructure>();
                cs.SetCommentInfo(level.comments[i].Key, level.comments[i].Value);
            }

            scrollbar.enabled = level.comments.Count > 2;
            commentsContent.GetComponent <VerticalLayoutGroup>().padding.right = level.comments.Count > 2 ? 50 : 20;

            Invoke(nameof(SetCommentsSize), 0.1f);
        }

        editButton.SetActive(level.type == LevelInfo.LevelType.Local);
        deleteButton.SetActive(level.username == currentUsername || level.type == LevelInfo.LevelType.Local);
        lastLevelShown = level;
    }