Example #1
0
 public UndoMultiScriptAddRemove(MultiScript appliesTo, IScript script, bool isAdd, int?index)
 {
     m_appliesTo = appliesTo;
     m_script    = script;
     m_isAdd     = isAdd;
     m_index     = index;
 }
Example #2
0
 protected override ScriptBase CloneScript()
 {
     MultiScript clone = new MultiScript(m_worldModel);
     clone.m_scripts = new List<IScript>();
     foreach (IScript script in m_scripts)
     {
         IScript clonedScript = (IScript)script.Clone();
         clonedScript.Parent = clone;
         clone.m_scripts.Add(clonedScript);
     }
     return clone;
 }
Example #3
0
        protected override ScriptBase CloneScript()
        {
            MultiScript clone = new MultiScript(m_worldModel);

            clone.m_scripts = new List <IScript>();
            foreach (IScript script in m_scripts)
            {
                IScript clonedScript = (IScript)script.Clone();
                clonedScript.Parent = clone;
                clone.m_scripts.Add(clonedScript);
            }
            return(clone);
        }
Example #4
0
        private MultiScript CreateMultiScript(params string[] lines)
        {
            // Creates a new MultiScript with mock IScripts, with .Line returning each
            // line passed in as a parameter.

            List<IScript> source = new List<IScript>();
            foreach (string line in lines)
            {
                var script = new Mock<IScript>();
                script.Setup(s => s.Line).Returns(line);
                source.Add(script.Object);
            }

            MultiScript result = new MultiScript(m_worldModel, source.ToArray());
            result.UndoLog = m_worldModel.UndoLogger;

            return result;
        }
Example #5
0
 public UndoMultiScriptLoadCode(MultiScript appliesTo, List <IScript> oldScripts, List <IScript> newScripts)
 {
     m_appliesTo  = appliesTo;
     m_oldScripts = oldScripts;
     m_newScripts = newScripts;
 }
Example #6
0
 public void AddElseIf()
 {
     IScript newScript = new MultiScript(Controller.WorldModel);
     IElseIfScript newElseIf = m_ifScript.AddElseIf(string.Empty, newScript);
 }
Example #7
0
 public void AddElse()
 {
     IScript newScript = new MultiScript(Controller.WorldModel);
     m_ifScript.SetElse(newScript);
 }
Example #8
0
        public IScript CreateScript(string line, ScriptContext scriptContext, bool lazy, bool addExceptionsToLog = true)
        {
            MultiScript result = new MultiScript(m_worldModel);
            bool finished = false;
            IScript lastIf = null;
            IScript lastComment = null;
            IScript lastFirstTime = null;
            IfScriptConstructor ifConstructor = null;
            
            if (lazy)
            {
                return new LazyLoadScript(this, line, scriptContext);
            }

            line = Utility.RemoveSurroundingBraces(line);
            line = Utility.RemoveComments(line, m_worldModel.EditMode);

            while (!finished)
            {
                string remainingScript;
                try
                {
                    line = Utility.GetScript(line, out remainingScript);
                }
                catch (Exception ex)
                {
                    if (addExceptionsToLog)
                    {
                        AddError(string.Format("Error adding script '{0}': {1}", line, ex.Message));
                        break;
                    }
                    throw;
                }

                if (line != null)
                {
                    line = line.Trim();
                }

                if (!string.IsNullOrEmpty(line))
                {
                    IScript newScript = null;
                    bool dontAdd = false;
                    bool addedError = false;

                    if (line.StartsWith("else"))
                    {
                        if (lastIf == null)
                        {
                            AddError("Unexpected 'else' (error with parent 'if'?):" + line);
                        }
                        else
                        {
                            if (line.StartsWith("else if"))
                            {
                                ifConstructor.AddElseIf(lastIf, line, scriptContext);
                            }
                            else
                            {
                                ifConstructor.AddElse(lastIf, line, scriptContext);
                            }
                        }
                        dontAdd = true;
                    }
                    else if (line.StartsWith("otherwise"))
                    {
                        if (lastFirstTime == null)
                        {
                            AddError("Unexpected 'otherwise' (error with parent 'firsttime'?):" + line);
                        }
                        else
                        {
                            FirstTimeScriptConstructor.AddOtherwiseScript(lastFirstTime, line, this);
                        }
                        dontAdd = true;
                    }
                    else
                    {
                        IScriptConstructor constructor = GetScriptConstructor(line);

                        if (constructor is CommentScriptConstructor)
                        {
                            if (lastComment != null)
                            {
                                ((CommentScript)lastComment).AddLine(line);
                                dontAdd = true;
                            }
                            else
                            {
                                newScript = constructor.Create(line, scriptContext);
                                lastComment = newScript;
                            }
                        }
                        else
                        {
                            lastIf = null;
                            lastComment = null;
                            lastFirstTime = null;

                            if (constructor != null)
                            {
                                try
                                {
                                    if (m_lazyLoadingEnabled)
                                    {
                                        newScript = new LazyLoadScript(this, constructor, line, scriptContext);
                                    }
                                    else
                                    {
                                        newScript = constructor.Create(line, scriptContext);
                                    }

                                    if (constructor.Keyword == "if")
                                    {
                                        ifConstructor = (IfScriptConstructor)constructor;
                                        lastIf = newScript;
                                    }
                                    if (constructor.Keyword == "firsttime")
                                    {
                                        lastFirstTime = newScript;
                                    }
                                }
                                catch (Ciloci.Flee.ExpressionCompileException ex)
                                {
                                    AddError(string.Format("Error compiling expression in '{0}': {1}", line, ex.Message));
                                    addedError = true;
                                }
                                catch (Exception ex)
                                {
                                    AddError(string.Format("Error adding script '{0}': {1}", line, ex.Message));
                                    addedError = true;
                                }
                            }

                            if (!addedError)
                            {
                                if (newScript == null)
                                {
                                    // See if the script is like "myvar = 2". newScript will be null otherwise.
                                    newScript = m_setConstructor.Create(line, scriptContext);
                                }

                                if (newScript == null)
                                {
                                    // See if the script calls a procedure defined by the game
                                    newScript = m_procConstructor.Create(line, scriptContext);
                                }
                            }
                        }
                    }

                    if (!dontAdd && !addedError)
                    {
                        if (newScript == null)
                        {
                            AddError(string.Format("Unrecognised script command '{0}'", line));
                        }
                        else
                        {
                            if (!m_lazyLoadingEnabled)
                            {
                                newScript.Line = line;
                            }
                            result.Add(newScript);
                        }
                    }
                }

                line = remainingScript;
                if (string.IsNullOrEmpty(line)) finished = true;
            }

            return result;
        }
Example #9
0
        public IScript CreateScript(string line, Element proc)
        {
            string remainingScript;
            IScript newScript;
            MultiScript result = new MultiScript();
            bool finished = false;
            IScript lastIf = null;
            IScript lastFirstTime = null;
            bool dontAdd;
            bool addedError;
            IfScriptConstructor ifConstructor = null;

            line = Utility.RemoveSurroundingBraces(line);

            while (!finished)
            {
                line = Utility.GetScript(line, out remainingScript);
                if (line != null)
                {
                    line = line.Trim();
                    line = Utility.RemoveComments(line);
                }

                if (!string.IsNullOrEmpty(line))
                {
                    newScript = null;
                    dontAdd = false;
                    addedError = false;

                    if (line.StartsWith("else"))
                    {
                        if (lastIf == null)
                        {
                            AddError("Unexpected 'else' (error with parent 'if'?):" + line);
                        }
                        else
                        {
                            if (line.StartsWith("else if"))
                            {
                                ifConstructor.AddElseIf(lastIf, line, proc);
                            }
                            else
                            {
                                ifConstructor.AddElse(lastIf, line, proc);
                            }
                        }
                        dontAdd = true;
                    }
                    else if (line.StartsWith("otherwise"))
                    {
                        if (lastFirstTime == null)
                        {
                            AddError("Unexpected 'otherwise' (error with parent 'firsttime'?):" + line);
                        }
                        else
                        {
                            FirstTimeScriptConstructor.AddOtherwiseScript(lastFirstTime, line, this);
                        }
                        dontAdd = true;
                    }
                    else
                    {
                        lastIf = null;
                        IScriptConstructor constructor = GetScriptConstructor(line);

                        if (constructor != null)
                        {
                            try
                            {
                                newScript = constructor.Create(line, proc);
                                if (constructor.Keyword == "if")
                                {
                                    ifConstructor = (IfScriptConstructor)constructor;
                                    lastIf = newScript;
                                }
                                if (constructor.Keyword == "firsttime")
                                {
                                    lastFirstTime = newScript;
                                }
                            }
                            catch (Exception ex)
                            {
                                AddError(string.Format("Error adding script '{0}': {1}", line, ex.Message));
                                addedError = true;
                            }
                        }

                        if (newScript == null)
                        {
                            // See if the script is like "myvar = 2". newScript will be null otherwise.
                            newScript = m_setConstructor.Create(line, proc);
                        }

                        if (newScript == null)
                        {
                            // See if the script calls a procedure defined by the game
                            newScript = m_procConstructor.Create(line, proc);
                        }
                    }

                    if (!dontAdd)
                    {
                        if (newScript == null)
                        {
                            if (!addedError) AddError(string.Format("Unrecognised script command '{0}'", line));
                        }
                        else
                        {
                            newScript.Line = line;
                            result.Add(newScript);
                        }
                    }
                }

                line = remainingScript;
                if (string.IsNullOrEmpty(line)) finished = true;
            }

            return result;
        }
Example #10
0
 private string GetLinesString(MultiScript multiScript)
 {
     return string.Join(";", multiScript.Scripts.Select(s => s.Line));
 }
Example #11
0
 public UndoMultiScriptAddRemove(MultiScript appliesTo, IScript script, bool isAdd, int? index)
 {
     m_appliesTo = appliesTo;
     m_script = script;
     m_isAdd = isAdd;
     m_index = index;
 }
Example #12
0
 public UndoMultiScriptLoadCode(MultiScript appliesTo, List<IScript> oldScripts, List<IScript> newScripts)
 {
     m_appliesTo = appliesTo;
     m_oldScripts = oldScripts;
     m_newScripts = newScripts;
 }