示例#1
0
        public void TestReplaceOverloadedFunctions()
        {
            Expression testExpression = new Expression("TypeOf(value)", gameLoader.Object);
            Assert.AreEqual("overloadedFunctions.TypeOf(value)", testExpression.Save());

            Expression testExpression2 = new Expression("(TypeOf(element[attribute]) = \"script\")", gameLoader.Object);
            Assert.AreEqual("(overloadedFunctions.TypeOf(element[attribute]) == \"script\")", testExpression2.Save());
        }
示例#2
0
 public EditableScriptData(Element editor, WorldModel worldModel)
 {
     DisplayString = editor.Fields.GetString("display");
     Category = editor.Fields.GetString("category");
     CreateString = editor.Fields.GetString("create");
     AdderDisplayString = editor.Fields.GetString("add");
     IsVisibleInSimpleMode = !editor.Fields.GetAsType<bool>("advanced");
     IsDesktopOnly = editor.Fields.GetAsType<bool>("desktop");
     CommonButton = editor.Fields.GetString("common");
     var expression = editor.Fields.GetString("onlydisplayif");
     if (expression != null)
     {
         m_visibilityExpression = new Expression<bool>(Utility.ConvertVariablesToFleeFormat(expression), new ScriptContext(worldModel, true));
     }
 }
示例#3
0
        public EditorVisibilityHelper(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_parent = parent;
            m_worldModel = worldModel;
            m_relatedAttribute = source.Fields.GetString("relatedattribute");
            if (m_relatedAttribute != null) m_alwaysVisible = false;
            m_visibleIfRelatedAttributeIsType = source.Fields.GetString("relatedattributedisplaytype");
            m_visibleIfElementInheritsType = source.Fields.GetAsType<QuestList<string>>("mustinherit");
            m_notVisibleIfElementInheritsType = source.Fields.GetAsType<QuestList<string>>("mustnotinherit");
            if (m_visibleIfElementInheritsType != null || m_notVisibleIfElementInheritsType != null) m_alwaysVisible = false;
            m_filterGroup = source.Fields.GetString("filtergroup");
            m_filter = source.Fields.GetString("filter");
            if (m_filter != null) m_alwaysVisible = false;

            string expression = source.Fields.GetString("onlydisplayif");
            if (expression != null)
            {
                m_visibilityExpression = new Expression<bool>(Utility.ConvertVariablesToFleeFormat(expression), new TextAdventures.Quest.Scripts.ScriptContext(worldModel, true));
                m_alwaysVisible = false;
            }
        }
示例#4
0
        protected override object ConvertField(Element e, string fieldName, object value)
        {
            if (fieldName == "steps")
            {
                QuestList<string> steps = (QuestList<string>)value;
                QuestList<string> result = new QuestList<string>();

                foreach (string step in steps)
                {
                    if (step.StartsWith("assert:"))
                    {
                        string expr = step.Substring(7);
                        Expression expression = new Expression(expr, e.Loader);
                        result.Add("assert:" + expression.Save());
                    }
                    else
                    {
                        result.Add(step);
                    }
                }
                return result;
            }
            return value;
        }
示例#5
0
 public bool Assert(string expr)
 {
     Expression<bool> expression = new Expression<bool>(expr, new ScriptContext(this));
     Context c = new Context();
     return expression.Execute(c);
 }
示例#6
0
 public void TestSpaceReplacement()
 {
     Expression testExpression = new Expression("object.my attribute", gameLoader.Object);
     Assert.AreEqual(string.Format("object.my{0}attribute", Utility.SpaceReplacementString), testExpression.Save());
 }
示例#7
0
 public void TestSave()
 {
     Expression testExpression = new Expression("myexpression", gameLoader.Object);
     Assert.AreEqual("myexpression", testExpression.Save());
 }
示例#8
0
 public void TestReplaceReservedKeywords()
 {
     Expression testExpression = new Expression("one + var", gameLoader.Object);
     Assert.AreEqual("one + variable_var", testExpression.Save());
 }
示例#9
0
 public void TestNotEquals()
 {
     Expression testExpression = new Expression("one <> two", gameLoader.Object);
     Assert.AreEqual("one != two", testExpression.Save());
 }
示例#10
0
 public void TestGreaterEquals()
 {
     Expression testExpression = new Expression("one >= two", gameLoader.Object);
     Assert.AreEqual("one >= two", testExpression.Save());
 }