示例#1
0
        public Manus Copy()
        {
            var clone = new Manus();

            clone.allSteps = new List <Step.IStep>(this.allSteps);
            return(clone);
        }
示例#2
0
        public void SetIsManusPlaying(bool state)
        {
            if (state == isPlaying)
            {
                return;
            }

            isPlaying = state;
            UISingleton.instance.uiCanvasGroup.blocksRaycasts = !state;
            skipManusBubble.gameObject.SetActive(state);
            PMWrapper.speedMultiplier = 0.5f;

            if (state)
            {
                UISingleton.instance.textField.deActivateField();
                IDELineMarker.instance.SetState(IDELineMarker.State.Hidden);
                currentManus = Loader.allManuses[PMWrapper.currentLevel].Copy();
                currentManus.NextStep();
            }
            else
            {
                if (currentManus != null)
                {
                    currentManus.FastForwardAllSteps();
                    currentManus = null;
                }

                UISingleton.instance.textField.reActivateField();
                UISingleton.instance.manusBubble.HideMessage();

                PMWrapper.SetLevelCompleted();
                IDELineMarker.SetIDEPosition(PMWrapper.preCode == string.Empty ? 1 : (PMWrapper.preCode.Split('\n').Length + 1));
            }
        }
示例#3
0
        private void FixedUpdate()
        {
            if (currentManus != null)
            {
                currentManus.UpdateSteps();

                if (currentManus.allStepsDone)
                {
                    currentManus = null;

                    // Enable UI
                    SetIsManusPlaying(false);
                }
            }
        }
示例#4
0
        private static Manus BuildFromString(string filename, string manusString)
        {
            List <string> splitManus = new List <string>(manusString.Split(linebreaks, StringSplitOptions.None));
            Manus         manus      = new Manus();

            Step.IStep step          = null;
            string     contentHeader = null;
            string     contentBody   = null;
            string     row;
            int        rowNumber = 0;

            while ((row = DequeueRow(splitManus)) != null)
            {
                rowNumber++;
                row = row.Trim();

                if (step != null)
                {
                    // Try continue content reading
                    if (row.Length > 0 && row[0] == '>')
                    {
                        if (step is Step.IStepNoBody)
                        {
                            throw new ManusBuildingException(step.GetType().Name + " doesn't support body parameters!", rowNumber, filename);
                        }

                        if (contentBody == null)
                        {
                            contentBody = row.Substring(1);
                        }
                        else
                        {
                            contentBody += "\n" + row.Substring(1);
                        }
                    }
                    else
                    {
                        // Reading complete
                        if (contentBody == null && !(step is Step.IStepNoBody))
                        {
                            throw new ManusBuildingException(step.GetType().Name + " requires a body parameter!", rowNumber, filename);
                        }

                        try {
                            step.ParseContent(manus, contentHeader, contentBody);
                        } catch (ManusBuildingException inner) {
                            throw new ManusBuildingException(rowNumber, filename, inner);
                        }
                        manus.allSteps.Add(step);
                        step = null;
                    }
                }

                // Comments
                if (row.StartsWith("//") || row.StartsWith("#"))
                {
                    continue;
                }

                // Empty rows
                if (row.Length == 0)
                {
                    continue;
                }

                if (step == null)
                {
                    if (row[0] == '>')
                    {
                        throw new ManusBuildingException("Unexpected body parameter.", rowNumber, filename);
                    }

                    // Listen for step start
                    Match match = Regex.Match(row, @"^([_\-\wåäöÅÄÖ.,]+):(?:\s*(.+)\s*)?$");

                    if (!match.Success)
                    {
                        match = Regex.Match(row, @"^([_\-\wåäöÅÄÖ.,]+)\s*$");
                        if (!match.Success)
                        {
                            throw new ManusBuildingException("Expected step, got \"" + row + "\"", rowNumber, filename);
                        }
                    }

                    string g1 = match.Groups[1].Value;
                    string g2 = (match.Groups.Count > 2 && match.Groups[2].Success) ? match.Groups[2].Value : null;

                    try {
                        step = GetAppropietStep(g1);
                    } catch (ManusBuildingException inner) {
                        throw new ManusBuildingException(rowNumber, filename, inner);
                    }

                    if (g2 != null && step is Step.IStepNoHeader)
                    {
                        throw new ManusBuildingException(step.GetType().Name + " doesn't support header parameters!", rowNumber, filename);
                    }
                    if (g2 == null && !(step is Step.IStepNoHeader))
                    {
                        throw new ManusBuildingException(step.GetType().Name + " requires a header parameter!", rowNumber, filename);
                    }
                    if (match.Groups.Count != 3 && !(step is Step.IStepNoParameters))
                    {
                        throw new ManusBuildingException(step.GetType().Name + " requires a body parameter!", rowNumber, filename);
                    }

                    contentHeader = g2;
                    contentBody   = null;

                    if (step is Step.IStepNoBody)
                    {
                        // Reading complete
                        try {
                            step.ParseContent(manus, contentHeader, contentBody);
                        } catch (ManusBuildingException inner) {
                            throw new ManusBuildingException(rowNumber, filename, inner);
                        }
                        manus.allSteps.Add(step);
                        step = null;
                    }
                }
            }

            if (step != null)
            {
                // Reading complete
                if (contentBody == null && !(step is Step.IStepNoBody))
                {
                    throw new ManusBuildingException(step.GetType().Name + " requires a body parameter!", rowNumber, filename);
                }

                try {
                    step.ParseContent(manus, contentHeader, contentBody);
                } catch (ManusBuildingException inner) {
                    throw new ManusBuildingException(rowNumber, filename, inner);
                }
                manus.allSteps.Add(step);
                step = null;
            }

            return(manus);
        }