Пример #1
0
        public bool IsTriggered(World world)
        {
            try
            {
                if (!_bindings.ContainsKey(world))
                {
                    BindTo(world);
                }
            }
            catch (Roslyn.Compilers.CompilationErrorException)
            {
                // suppress compilation errors and return false.
                _bindings[world] = new WorldBinding { CompilationFailed = true };

                return false;
            }

            if (!_bindings[world].CompilationFailed)
            {
                return _bindings[world].Trigger.Execute();
            }
            else
            {
                return false;
            }
        }
Пример #2
0
        public void BindTo(World world)
        {
            WorldBinding b = new WorldBinding();

            b.Session = Session.Create(world.GlobalObjectRoot);
            _engine.Execute("using System; using Demotic.Core; using Demotic.Core.ObjectSystem; using W3b.Sine;", b.Session);

            b.Trigger = _engine.CompileSubmission<bool>(_triggerSource, b.Session, isInteractive: true);
            b.Effect = _engine.CompileSubmission<bool>(_effectSource, b.Session, isInteractive: false);

            _bindings[world] = b;
        }