示例#1
0
    public void RequestHighlightAdd(int start, int end)
    {
        // Add the highlight to the list and sort it
        TextHighlight requestedHighlight = new TextHighlight(start, end);

        highlights.Add(requestedHighlight);
        highlights.Sort();

        // Clean the highlights
        int i = 0;

        // Loop until we check up to (but not including) the last highlight
        while (i < highlights.Count - 1)
        {
            // If this highlight overlaps the next one, we combine them and remove the next one
            if (highlights[i].Overlap(highlights[i + 1]))
            {
                highlights[i] = highlights[i].Union(highlights[i + 1]);
                highlights.RemoveAt(i + 1);

                // We continue without incrementing because we need to check this same highlight again
                // just in case it contained multiple highlights
                continue;
            }
            else
            {
                i++;
            }
        }
    }
        public void TextHighlightInitsWithNoArgs()
        {
            var textHighlights = new TextHighlight();

            Assert.NotNull(textHighlights);
            Assert.IsType <TextHighlight>(textHighlights);
        }
示例#3
0
        /// <summary>
        /// Build the document header (opening) based on input filename extension and existing text highlight configurations
        /// </summary>
        /// <param name="path">full source name</param>
        /// <returns></returns>
        private String GetDocumentHeader(String path)
        {
            //get text higlight for given path
            TextHighlight th = DocumentService.TextHighlightConfiguration.GetTextHighlightForTextFile(path);
            //the base string
            String result = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><script type=\"text/javascript\" src=\"../../syntaxhighlighter_3.0.83/scripts/shCore.js\"></script>";

            //this will be changed depending on extension
            result += "<script type=\"text/javascript\" src=\"../../syntaxhighlighter_3.0.83/scripts/";

            //language
            result += th.JsName;

            result += "\"></script>";

            //this is about theme
            result += "<link type=\"text/css\" rel=\"stylesheet\" href=\"../../syntaxhighlighter_3.0.83/styles/";

            result += th.Theme;

            result += "\"/><script type=\"text/javascript\">SyntaxHighlighter.all();</script></head><body style=\"background: white; font-family: Helvetica;  margin: 0px\"><script type=\"syntaxhighlighter\"  class=\"brush: ";

            //brush
            result += th.BrushAlias;

            //and the last one
            result += "\"><![CDATA[";

            return(result);
        }
        public void TextHighlightInits()
        {
            var text       = "some highlighted text";
            var occurrence = 1;

            var textHighlights = new TextHighlight(text, occurrence);

            Assert.NotNull(textHighlights);
            Assert.IsType <TextHighlight>(textHighlights);
            Assert.Equal(text, textHighlights.Text);
            Assert.Equal(occurrence, textHighlights.Occurrence);
        }
示例#5
0
 private void Start()
 {
     writeText     = variableHolder.GetComponent <WriteText>();
     textHighlight = variableHolder.GetComponent <TextHighlight>();
     goText.color  = new Color(0, 255, 0, 1);
     wpm           = writeText.wpm;
     constWPM      = writeText.constWPM;
     gamePaused    = false;
     stopwatch     = writeText.stopwatch;
     numOfChars    = writeText.numOfChars;
     pauseUI.SetActive(false);
 }
        /// <summary>
        /// Get a highlighter for a file based on extension
        /// </summary>
        /// <param name="path">source file full path</param>
        /// <returns></returns>
        public TextHighlight GetTextHighlightForTextFile(String path)
        {
            String        extension = path.Substring(path.LastIndexOf("."));
            TextHighlight th        = null;

            foreach (TextHighlight t in textHighlights)
            {
                if (t.FilenameExtension.Equals(extension))
                {
                    th = t;
                    break;
                }
            }
            return(th);
        }
示例#7
0
    // Use this for initialization
    void Start()
    {
        Title.transform.position = new Vector3(0.2f, 6f, 0);
        GameStartFlag            = false;
        House      = gameObject.transform.Find("HouseImage");
        HouseImage = House.GetComponent <Image>();
        mc         = Player.GetComponent <MoveCharacter>();
        mc.enabled = false;
        tmPro      = Text.GetComponent <TextMeshProUGUI>();
        material   = tmPro.fontMaterial;
        th         = Text.GetComponent <TextHighlight>();
        TextRect   = Text.GetComponent <RectTransform>();
        sources    = gameObject.GetComponents <AudioSource>();

        //Debug.Log("STart");
    }
示例#8
0
    public void RequestHighlightRemove(int start, int end)
    {
        TextHighlight negator = new TextHighlight(start, end);

        int i = 0;

        while (i < highlights.Count)
        {
            // Negate the current highlight
            List <TextHighlight> negation = highlights[i].Negate(negator);

            // Remove the highlight and replace it with the results of the negation
            highlights.RemoveAt(i);
            highlights.InsertRange(i, negation);

            // Advance past the negation results just added
            i += negation.Count;
        }
    }
示例#9
0
    private void FreezeUntilHighlightAbsent(ItemID item, int articleIndex, TextHighlight targetHighlight)
    {
        NotebookUI notebook = GameManager.Instance.NotebookUI;
        ResearchEncyclopediaArticleInputField inputField = notebook.GetComponentInChildren <ResearchEncyclopediaArticleInputField>(true);

        // Get the list of all highlights in this encyclopedia article
        List <TextHighlight> highlights = notebook
                                          .Data.Research.GetEntry(item)
                                          .GetArticleData(articleIndex).Highlights;

        FreezingScheduler.FreezeUntilConditionIsMet(() =>
        {
            // Get an index of any highlight that overlaps the target highlight
            int indexOfMatch = highlights.FindIndex(current => targetHighlight.Overlap(current));
            // Freeze until no overlapping highlights found and notebook is open to research tab
            return(indexOfMatch < 0 && notebook.IsOpen && notebook.TabPicker.CurrentTab == NotebookTab.Research);
        });
        HighlightingScheduler.SetHighlights(HighlightNotebookButton(),
                                            HighlightNotebookTabButton(NotebookTab.Research),
                                            HighlightEraseButton());
    }
示例#10
0
    private void FreezeUntilHighlightPresent(ItemID item, int articleIndex, TextHighlight targetHighlight)
    {
        // Cache some useful values
        NotebookUI notebook = GameManager.Instance.NotebookUI;

        // Get the list of all highlights in this encyclopedia article
        List <TextHighlight> highlights = notebook
                                          .Data.Research.GetEntry(item)
                                          .GetArticleData(articleIndex).Highlights;

        FreezingScheduler.FreezeUntilConditionIsMet(() =>
        {
            // Get index of a highlight that this highlight contains
            int indexOfMatch = highlights.FindIndex(current => current.Contains(targetHighlight));
            // Freeze until highlight is found and notebook is open to research tab
            return(indexOfMatch >= 0 && notebook.IsOpen && notebook.TabPicker.CurrentTab == NotebookTab.Research);
        });
        HighlightingScheduler.SetHighlights(HighlightNotebookButton(),
                                            HighlightNotebookTabButton(NotebookTab.Research),
                                            HighlightHighlightButton());
    }
        /// <summary>
        /// Construct a configuration from a configuration xml file
        /// </summary>
        /// <param name="configurationXmlFile">configuration xml file</param>
        public TextHighlightConfiguration(String configurationXmlFile)
        {
            if (textHighlights == null)
            {
                XmlTextReader textReader = new XmlTextReader(configurationXmlFile);
                textHighlights = new List <TextHighlight>();
                while (textReader.Read())
                {
                    if (textReader.NodeType == XmlNodeType.Element && textReader.Name.Equals("sourceCodeFormatterConf"))
                    {
                        while (!(textReader.NodeType == XmlNodeType.EndElement && textReader.Name.Equals("sourceCodeFormatterConf")))
                        {
                            if (textReader.Read())
                            {
                                if (textReader.NodeType == XmlNodeType.Element && textReader.Name.Equals("conf"))
                                {
                                    TextHighlight th = new TextHighlight();

                                    while (!(textReader.NodeType == XmlNodeType.EndElement && textReader.Name.Equals("conf")))
                                    {
                                        if (textReader.Read())
                                        {
                                            if (textReader.NodeType == XmlNodeType.Element && textReader.Name.Equals("brushAlias"))
                                            {
                                                String text = null;
                                                while (!(textReader.NodeType == XmlNodeType.EndElement && textReader.Name.Equals("brushAlias")))
                                                {
                                                    if (textReader.Read())
                                                    {
                                                        if (textReader.NodeType == XmlNodeType.Text)
                                                        {
                                                            text = textReader.Value.ToString();
                                                        }
                                                    }
                                                }
                                                th.BrushAlias = text;
                                            }
                                            else if (textReader.NodeType == XmlNodeType.Element && textReader.Name.Equals("jsName"))
                                            {
                                                String text = null;
                                                while (!(textReader.NodeType == XmlNodeType.EndElement && textReader.Name.Equals("jsName")))
                                                {
                                                    if (textReader.Read())
                                                    {
                                                        if (textReader.NodeType == XmlNodeType.Text)
                                                        {
                                                            text = textReader.Value.ToString();
                                                        }
                                                    }
                                                }
                                                th.JsName = text;
                                            }
                                            else if (textReader.NodeType == XmlNodeType.Element && textReader.Name.Equals("filenameExtension"))
                                            {
                                                String text = null;
                                                while (!(textReader.NodeType == XmlNodeType.EndElement && textReader.Name.Equals("filenameExtension")))
                                                {
                                                    if (textReader.Read())
                                                    {
                                                        if (textReader.NodeType == XmlNodeType.Text)
                                                        {
                                                            text = textReader.Value.ToString();
                                                        }
                                                    }
                                                }
                                                th.FilenameExtension = text;
                                            }
                                            else if (textReader.NodeType == XmlNodeType.Element && textReader.Name.Equals("theme"))
                                            {
                                                String text = null;
                                                while (!(textReader.NodeType == XmlNodeType.EndElement && textReader.Name.Equals("theme")))
                                                {
                                                    if (textReader.Read())
                                                    {
                                                        if (textReader.NodeType == XmlNodeType.Text)
                                                        {
                                                            text = textReader.Value.ToString();
                                                        }
                                                    }
                                                }
                                                th.Theme = text;
                                            }
                                        }
                                    }
                                    if (th.IsAccepted)
                                    {
                                        textHighlights.Add(th);
                                        System.Console.WriteLine("New Conf:" + th.ToString());
                                    }
                                    else
                                    {
                                        System.Console.WriteLine("Skipped:" + th.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
                textReader.Close();
            }
        }