Exemplo n.º 1
0
        public void Load()
        {
            engine = new SharpScript();
            engine.CompileCode(Template.Code, new InterfaceInteraction(this, spriteBatch, this.PlayerEntity));

            engine.Invoke("Initialize");
        }
Exemplo n.º 2
0
        public void SharpScript_works_with_code()
        {
            SharpScript            script  = new SharpScript("test", _codeAll);
            IEnumerable <IElement> result  = script.OnElement(_maction.Object, _melement.Object);
            IEnumerable <IElement> result2 = script.OnCompleted(_maction.Object);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result2);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(1, result2.Count());
        }
Exemplo n.º 3
0
        public void SharpScript_works_with_only_OnCompleted()
        {
            SharpScript            script  = new SharpScript("test", _codeOnCompleted);
            IEnumerable <IElement> result  = script.OnElement(_maction.Object, _melement.Object);
            IEnumerable <IElement> result2 = script.OnCompleted(_maction.Object);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result2);
            Assert.AreEqual(0, result.Count());
            Assert.AreEqual(1, result2.Count());
            var elem = result2.First();

            Assert.AreEqual("testaction", elem.Name);
            Assert.AreEqual("0", elem.Id);
        }
Exemplo n.º 4
0
 public void Load(string loc)
 {
     script = new SharpScript();
     try {
         string location = Environment.CurrentDirectory + "\\Scripts\\Logic\\" + loc + (loc.EndsWith(".cs") ? "" : ".cs");
         name = loc.Split('0')[0];
         string code = File.ReadAllText(location);
         script.CompileCode(code);
         script.Invoke("Load", this);
         Console.WriteLine("s_0: " + s_0);
     } catch (Exception e) {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("-- Error (" + e.GetType() + "): " + e.Message);
         Console.ResetColor();
     }
 }
Exemplo n.º 5
0
        public void SharpScript_works_with_functions()
        {
            bool        onelement   = false;
            bool        oncompleted = false;
            bool        onerror     = false;
            bool        onfinally   = false;
            SharpScript script      = new SharpScript("test", (a, e) => { onelement = true; return(null); }, a => { oncompleted = true; return(null); },
                                                      (a, ex) => { onerror = true; return(null); }, a => { onfinally = true; });
            IEnumerable <IElement> result  = script.OnElement(_maction.Object, _melement.Object);
            IEnumerable <IElement> result2 = script.OnCompleted(_maction.Object);
            IEnumerable <IElement> result3 = script.OnError(_maction.Object, new Exception());

            script.OnFinally(_maction.Object);
            Assert.IsTrue(onelement);
            Assert.IsTrue(oncompleted);
            Assert.IsTrue(onerror);
            Assert.IsTrue(onfinally);
            Assert.IsNotNull(result);
            Assert.IsNotNull(result2);
            Assert.IsNotNull(result3);
            Assert.AreEqual(0, result.Count());
            Assert.AreEqual(0, result2.Count());
            Assert.AreEqual(0, result3.Count());
        }