Beispiel #1
0
        public IScript Create(string script, ScriptContext scriptContext)
        {
            List<string> parameters = null;
            string param = Utility.GetParameter(script);

            int numParams;
            if (param == null)
            {
                numParams = 0;
            }
            else
            {
                parameters = Utility.SplitParameter(param);
                numParams = parameters.Count;
            }

            if (ExpectedParameters.Count() > 0)
            {
                if (!ExpectedParameters.Contains(numParams))
                {
                    throw new Exception(string.Format("Expected {0} parameter(s) in script '{1}'", FormatExpectedParameters(), script));
                }
            }

            return CreateInt(parameters, scriptContext);
        }
Beispiel #2
0
 public GetInputScript(ScriptContext scriptContext, IScriptFactory scriptFactory, IScript callbackScript)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_scriptFactory = scriptFactory;
     m_callbackScript = callbackScript;
 }
Beispiel #3
0
 public ForEachScript(ScriptContext scriptContext, string variable, IFunctionGeneric list, IScript loopScript)
 {
     m_scriptContext = scriptContext;
     m_variable = variable;
     m_list = list;
     m_loopScript = loopScript;
 }
Beispiel #4
0
 public LazyLoadScript(ScriptFactory scriptFactory, string scriptString, ScriptContext scriptContext)
 {
     m_scriptFactory = scriptFactory;
     m_scriptString = scriptString;
     m_scriptContext = scriptContext;
     m_worldModel = scriptFactory.WorldModel;
 }
Beispiel #5
0
        protected override IScript CreateInt(List<string> parameters, ScriptContext scriptContext)
        {
            if (parameters.Count < 2)
            {
                throw new Exception("Expected at least 2 parameters in rundelegate call");
            }

            List<IFunction<object>> paramExpressions = new List<IFunction<object>>();
            IFunction<Element> obj = null;
            int cnt = 0;
            IFunction<string> delegateName = null;

            foreach (string param in parameters)
            {
                cnt++;
                switch (cnt)
                {
                    case 1:
                        obj = new Expression<Element>(param, scriptContext);
                        break;
                    case 2:
                        delegateName = new Expression<string>(param, scriptContext);
                        break;
                    default:
                        paramExpressions.Add(new Expression<object>(param, scriptContext));
                        break;
                }
            }

            return new RunDelegateScript(scriptContext, obj, delegateName, paramExpressions);
        }
Beispiel #6
0
 public RequestScript(ScriptContext scriptContext, string request, IFunction<string> data)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_data = data;
     m_request = (Request)(Enum.Parse(typeof(Request), request));
 }
Beispiel #7
0
 internal IFunction<Element> GetAppliesTo(ScriptContext scriptContext, string value, out string variable)
 {
     string var = Utility.ConvertVariablesToFleeFormat(value).Trim();
     string obj;
     Utility.ResolveObjectDotAttribute(var, out obj, out variable);
     return (obj == null) ? null : new Expression<Element>(obj, scriptContext);
 }
Beispiel #8
0
 public ListAddScript(ScriptContext scriptContext, IFunctionGeneric list, IFunction<object> value)
 {
     m_scriptContext = scriptContext;
     m_list = list;
     m_value = value;
     m_worldModel = scriptContext.WorldModel;
 }
Beispiel #9
0
 protected override IScript CreateInt(List<string> parameters, ScriptContext scriptContext)
 {
     return new PlaySoundScript(scriptContext,
         new Expression<string>(parameters[0], scriptContext),
         new Expression<bool>(parameters[1], scriptContext),
         new Expression<bool>(parameters[2], scriptContext));
 }
Beispiel #10
0
 public DoActionScript(ScriptContext scriptContext, IFunction<Element> obj, IFunction<string> action)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_obj = obj;
     m_action = action;
 }
Beispiel #11
0
 protected override IScript CreateInt(List<string> parameters, ScriptContext scriptContext)
 {
     return new DictionaryAddScript(scriptContext,
         new ExpressionGeneric(parameters[0], scriptContext),
         new Expression<string>(parameters[1], scriptContext),
         new Expression<object>(parameters[2], scriptContext));
 }
Beispiel #12
0
 public DictionaryAddScript(ScriptContext scriptContext, IFunctionGeneric dictionary, IFunction<string> key, IFunction<object> value)
 {
     m_scriptContext = scriptContext;
     m_dictionary = dictionary;
     m_key = key;
     m_value = value;
     m_worldModel = scriptContext.WorldModel;
 }
Beispiel #13
0
 public AskScript(ScriptContext scriptContext, IScriptFactory scriptFactory, IFunction<string> caption, IScript callbackScript)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_scriptFactory = scriptFactory;
     m_caption = caption;
     m_callbackScript = callbackScript;
 }
Beispiel #14
0
 public WhileScript(ScriptContext scriptContext, IScriptFactory scriptFactory, IFunction<bool> expression, IScript loopScript)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_scriptFactory = scriptFactory;
     m_expression = expression;
     m_loopScript = loopScript;
 }
Beispiel #15
0
 public RunDelegateScript(ScriptContext scriptContext, IFunction<Element> obj, IFunction<string> del, IList<IFunction<object>> parameters)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_delegate = del;
     m_parameters = new FunctionCallParameters(m_worldModel, parameters);
     m_appliesTo = obj;
 }
Beispiel #16
0
 public PlaySoundScript(ScriptContext scriptContext, IFunction<string> function, IFunction<bool> synchronous, IFunction<bool> loop)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_filename = function;
     m_synchronous = synchronous;
     m_loop = loop;
 }
Beispiel #17
0
        public IScript Create(string script, ScriptContext scriptContext)
        {
            string callback = Utility.GetScript(script.Substring(Keyword.Length).Trim());

            IScript callbackScript = ScriptFactory.CreateScript(callback);

            return new WaitScript(WorldModel, ScriptFactory, callbackScript);
        }
Beispiel #18
0
 public SetFieldScript(ScriptContext scriptContext, IFunction<Element> obj, IFunction<string> field, IFunction<object> value)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_obj = obj;
     m_field = field;
     m_value = value;
 }
Beispiel #19
0
        public IScript Create(string script, ScriptContext scriptContext)
        {
            string afterExpr;
            string param = Utility.GetParameter(script, out afterExpr);
            IScript defaultScript;
            Dictionary<IFunctionGeneric, IScript> cases = ProcessCases(Utility.GetScript(afterExpr), out defaultScript, scriptContext);

            return new SwitchScript(scriptContext, new ExpressionGeneric(param, scriptContext), cases, defaultScript);
        }
Beispiel #20
0
        public IScript Create(string script, ScriptContext scriptContext)
        {
            // Get script after "firsttime" keyword
            script = script.Substring(9).Trim();
            string firstTime = Utility.GetScript(script);
            IScript firstTimeScript = ScriptFactory.CreateScript(firstTime);

            return new FirstTimeScript(WorldModel, ScriptFactory, firstTimeScript);
        }
Beispiel #21
0
        public IScript Create(string script, ScriptContext scriptContext)
        {
            string afterExpr;
            string param = Utility.GetParameter(script, out afterExpr);
            string loop = Utility.GetScript(afterExpr);
            IScript loopScript = ScriptFactory.CreateScript(loop);

            return new WhileScript(scriptContext, ScriptFactory, new Expression<bool>(param, scriptContext), loopScript);
        }
Beispiel #22
0
 public ShowMenuScript(ScriptContext scriptContext, IScriptFactory scriptFactory, IFunction<string> caption, IFunctionGeneric options, IFunction<bool> allowCancel, IScript callbackScript)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_scriptFactory = scriptFactory;
     m_caption = caption;
     m_options = options;
     m_allowCancel = allowCancel;
     m_callbackScript = callbackScript;
 }
Beispiel #23
0
 public ForScript(ScriptContext scriptContext, IScriptFactory scriptFactory, string variable, IFunction<int> from, IFunction<int> to, IScript loopScript)
 {
     m_scriptContext = scriptContext;
     m_worldModel = scriptContext.WorldModel;
     m_scriptFactory = scriptFactory;
     m_variable = variable;
     m_from = from;
     m_to = to;
     m_loopScript = loopScript;
 }
Beispiel #24
0
        private Dictionary<IFunctionGeneric, IScript> ProcessCases(string cases, out IScript defaultScript, ScriptContext scriptContext)
        {
            bool finished = false;
            string remainingCases;
            string afterExpr;
            Dictionary<IFunctionGeneric, IScript> result = new Dictionary<IFunctionGeneric, IScript>();
            defaultScript = null;

            cases = Utility.RemoveSurroundingBraces(cases);

            while (!finished)
            {
                cases = Utility.GetScript(cases, out remainingCases);
                if (cases != null) cases = cases.Trim();

                if (!string.IsNullOrEmpty(cases))
                {
                    if (cases.StartsWith("case"))
                    {
                        string expr = Utility.GetParameter(cases, out afterExpr);
                        string caseScript = Utility.GetScript(afterExpr);
                        IScript script = ScriptFactory.CreateScript(caseScript, scriptContext);

                        // Case expression can have multiple values separated by commas. In Edit mode,
                        // just load this as one expression for editing.

                        if (!scriptContext.WorldModel.EditMode)
                        {
                            var matchList = Utility.SplitParameter(expr);
                            foreach (var match in matchList)
                            {
                                result.Add(new ExpressionGeneric(match, scriptContext), script);
                            }
                        }
                        else
                        {
                            result.Add(new ExpressionGeneric(expr, scriptContext), script);
                        }
                    }
                    else if (cases.StartsWith("default"))
                    {
                        defaultScript = ScriptFactory.CreateScript(cases.Substring(8).Trim());
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid inside switch block: '{0}'", cases));
                    }
                }

                cases = remainingCases;
                if (string.IsNullOrEmpty(cases)) finished = true;
            }

            return result;
        }
        public void Setup()
        {
            m_worldModel = new WorldModel();
            m_scriptFactory = new ScriptFactory(m_worldModel);

            m_constructor = new SwitchScriptConstructor();
            m_constructor.WorldModel = m_worldModel;            
            m_constructor.ScriptFactory = m_scriptFactory;

            scriptContext = new ScriptContext(m_worldModel);
        }
Beispiel #26
0
        public IScript Create(string script, ScriptContext scriptContext)
        {
            List<IFunction<object>> paramExpressions = null;
            string procName, afterParameter;

            string param = Utility.GetParameter(script, out afterParameter);
            IScript paramScript = null;

            // Handle functions of the form
            //    SomeFunction (parameter) { script }
            if (afterParameter != null)
            {
                afterParameter = afterParameter.Trim();
                if (afterParameter.Length > 0)
                {
                    string paramScriptString = Utility.GetScript(afterParameter);
                    paramScript = ScriptFactory.CreateScript(paramScriptString);
                }
            }

            if (param == null && paramScript == null)
            {
                procName = script;
            }
            else
            {
                if (param != null)
                {
                    List<string> parameters = Utility.SplitParameter(param);
                    procName = script.Substring(0, script.IndexOf('(')).Trim();
                    paramExpressions = new List<IFunction<object>>();
                    if (param.Trim().Length > 0)
                    {
                        foreach (string s in parameters)
                        {
                            paramExpressions.Add(new Expression<object>(s, scriptContext));
                        }
                    }
                }
                else
                {
                    procName = script.Substring(0, script.IndexOfAny(new char[] { '{', ' ' }));
                }
            }

            if (!WorldModel.EditMode && WorldModel.Procedure(procName) == null)
            {
                throw new Exception(string.Format("Function not found: '{0}'", procName));
            }
            else
            {
                return new FunctionCallScript(WorldModel, procName, paramExpressions, paramScript);
            }
        }
Beispiel #27
0
 protected override IScript CreateInt(List<string> parameters, ScriptContext scriptContext)
 {
     switch (parameters.Count)
     {
         case 1:
             return new CreateScript(scriptContext, new Expression<string>(parameters[0], scriptContext));
         case 2:
             return new CreateScript(scriptContext, new Expression<string>(parameters[0], scriptContext), new Expression<string>(parameters[1], scriptContext));
     }
     return null;
 }
Beispiel #28
0
 protected override IScript CreateInt(List<string> parameters, ScriptContext scriptContext)
 {
     switch (parameters.Count)
     {
         case 2:
             return new DoActionScript(scriptContext, new Expression<Element>(parameters[0], scriptContext), new Expression<string>(parameters[1], scriptContext));
         case 3:
             return new DoActionScript(scriptContext, new Expression<Element>(parameters[0], scriptContext), new Expression<string>(parameters[1], scriptContext), new Expression<IDictionary>(parameters[2], scriptContext));
     }
     return null;
 }
Beispiel #29
0
        public void AddElseIf(IScript script, string elseIfScript, ScriptContext scriptContext)
        {
            IScript add = GetElse(elseIfScript, scriptContext);
            if (add.Line == "") return;

            // GetElse uses the ScriptFactory to parse the "else if" block, so it will return
            // a MultiScript containing an IfScript with one expression and one "then" script block.

            IIfScript elseIf = (IIfScript)((IMultiScript)add).Scripts.First();

            ((IIfScript)script).AddElseIf(elseIf.Expression, elseIf.ThenScript);
        }
Beispiel #30
0
        public IScript Create(string script, ScriptContext scriptContext)
        {
            string afterExpr;
            string param = Utility.GetParameter(script, out afterExpr);
            string callback = Utility.GetScript(afterExpr);

            string[] parameters = Utility.SplitParameter(param).ToArray();
            if (parameters.Count() != 1)
            {
                throw new Exception(string.Format("'ask' script should have 1 parameter: 'ask ({0})'", param));
            }
            IScript callbackScript = ScriptFactory.CreateScript(callback);

            return new AskScript(scriptContext, ScriptFactory, new Expression<string>(parameters[0], scriptContext), callbackScript);
        }
Beispiel #31
0
 protected override IScript CreateInt(List <string> parameters, ScriptContext scriptContext)
 {
     return(new SetFieldScript(scriptContext, new Expression <Element>(parameters[0], scriptContext), new Expression <string>(parameters[1], scriptContext), new Expression <object>(parameters[2], scriptContext)));
 }