Exemplo n.º 1
0
        public void TestModify()
        {
            string raw = @"test_demon =
            {
                group =
                {
                    base = 50

                    modifier =
                    {
                        value = 50
                        condition =
                        {
                            equal = {sub.a, 1}
                        }
                    }
                } 
            }";

            DataVisit.Visitor.InitVisitMap(typeof(TestData));
            DataVisit.Visitor.SetVisitData(TestData.inst);

            Parser.Semantic.Visitor.GetValueFunc = DataVisit.Visitor.Get;
            Parser.Semantic.Visitor.SetValueFunc = DataVisit.Visitor.Set;

            var       syntaxItem = SyntaxItem.RootParse(raw);
            TestDemon demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            Assert.AreEqual(100, demo.group.CalcValue());

            TestData.inst.sub.a = 2;
            Assert.AreEqual(50, demo.group.CalcValue());
        }
Exemplo n.º 2
0
        public void TestEqual()
        {
            string    raw        = @"test_demon =
            {
                condition =
                {
                    equal = {1, 1}
                }
            }";
            var       syntaxItem = SyntaxItem.RootParse(raw);
            TestDemon demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            Assert.IsTrue(demo.condition.Rslt());

            raw        = @"test_demon =
            {
                condition =
                {
                    equal = {1, 12}
                }
            }";
            syntaxItem = SyntaxItem.RootParse(raw);
            demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            Assert.IsFalse(demo.condition.Rslt());
        }
Exemplo n.º 3
0
        public void TestReduce()
        {
            string raw = @"test_demon =
            {
                selected =
                {
                    reduce = {sub.a, 1}
                }
            }";

            DataVisit.Visitor.InitVisitMap(typeof(TestData));
            DataVisit.Visitor.SetVisitData(TestData.inst);

            Parser.Semantic.Visitor.GetValueFunc = DataVisit.Visitor.Get;
            Parser.Semantic.Visitor.SetValueFunc = DataVisit.Visitor.Set;

            var       syntaxItem = SyntaxItem.RootParse(raw);
            TestDemon demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            TestData.inst.sub.a = 1;

            demo.operation.Do();

            Assert.AreEqual(0, TestData.inst.sub.a);
        }
Exemplo n.º 4
0
        public void TestAnd()
        {
            string raw = @"test_demon =
            {
                condition =
                {
                    and =
                    {
                        less = {1, 12}
                        greater = {1, 0}
                    }
                }
            }";

            var       syntaxItem = SyntaxItem.RootParse(raw);
            TestDemon demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            Assert.IsTrue(demo.condition.Rslt());


            raw = @"test_demon =
            {
                condition =
                {
                    and =
                    {
                        less = {1, 12}
                        greater = {1, 12}
                    }
                }
            }";

            syntaxItem = SyntaxItem.RootParse(raw);
            demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            Assert.IsFalse(demo.condition.Rslt());

            raw = @"test_demon =
            {
                condition =
                {
                    and =
                    {
                        less = {1, 0}
                        greater = {1, 12}
                    }
                }
            }";

            syntaxItem = SyntaxItem.RootParse(raw);
            demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            Assert.IsFalse(demo.condition.Rslt());
        }
Exemplo n.º 5
0
 public static T Load <T>(string fileName, string fileContent)
 {
     try
     {
         var syntaxItem = SyntaxItem.RootParse(fileContent);
         return(SemanticParser.DoParser <T>(syntaxItem));
     }
     catch (Exception e)
     {
         throw new Exception($"Parse error in script:{fileName}", e);
     }
 }
Exemplo n.º 6
0
        public void TestBaseValue()
        {
            string    raw        = @"test_demon =
            {
                group =
                {
                    base = 100
                } 
            }";
            var       syntaxItem = SyntaxItem.RootParse(raw);
            TestDemon demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            Assert.AreEqual(100, demo.group.CalcValue());
        }
Exemplo n.º 7
0
        public void Test1()
        {
            string raw = @"title = EVENT_TEST_TITLE
desc = EVENT_TEST_DESC

option =
{
	desc = EVENT_TEST_OPTION_1_DESC
}";

            var syntaxItem = SyntaxItem.RootParse(raw);

            SemanticParser.DoParser <Modder.GEvent>(syntaxItem);
        }
Exemplo n.º 8
0
        public void TestRiskStart()
        {
            string raw = @"test_demon =
            {
                selected =
                {
                    risk.start = RISK_TEST
                }
            }";

            DataVisit.Visitor.InitVisitMap(typeof(TestData));
            DataVisit.Visitor.SetVisitData(TestData.inst);

            Parser.Semantic.Visitor.GetValueFunc = DataVisit.Visitor.Get;
            Parser.Semantic.Visitor.SetValueFunc = DataVisit.Visitor.Set;

            var       syntaxItem = SyntaxItem.RootParse(raw);
            TestDemon demo       = SemanticParser.DoParser <TestDemon>(syntaxItem.Find("test_demon"));

            demo.operation.Do();

            Assert.AreEqual("RISK_TEST", TestData.inst.risk.start);
        }