public static Tile[] LoadTilePackFromResources(string packName)
    {
        string manifestPath = $"packs/{packName}/manifest";
        string manifestText = Resources.Load <TextAsset>(manifestPath).text;

        DataObjectArray[] TileInfo = ScriptingEngine.ParseArray(manifestText).ToArray <DataObjectArray>();

        Tile[] tiles = new Tile[TileInfo.Length];
        for (int i = 0; i < TileInfo.Length; i++)
        {
            Tile tile = new Tile
            {
                TileTexture = Resources.Load <Texture>($"packs/{packName}/{TileInfo[i][0]}") as Texture2D,
                TileType    = int.Parse(TileInfo[i][1].ToString())
            };
            if (tile.TileTexture == null)
            {
                tile.TileTexture = GetMissingTexture();
            }
            Debug.Log($"packs/{packName}/{TileInfo[i][0]}");
            Debug.Log($"Tile: {TileInfo[i][0].ToString()}, Texture: {tile.TileTexture}, Type: {tile.TileType}");
            tiles[i] = tile;
        }

        return(tiles);
    }
Example #2
0
        public void SetUp()
        {
            GlobalConstants.ActionLog = new ActionLog();
            this.ScriptingEngine      = new ScriptingEngine();

            IGameManager gameManager = Mock.Of <IGameManager>(
                manager => manager.RelationshipHandler == Mock.Of <IEntityRelationshipHandler>() &&
                manager.ObjectIconHandler == Mock.Of <IObjectIconHandler>(
                    handler => handler.GetManagedSprites(
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <string>())
                    == new[]
            {
                new SpriteData
                {
                    Name  = "DEFAULT",
                    Parts = new List <SpritePart>
                    {
                        new SpritePart
                        {
                            m_Frames = 1
                        }
                    },
                    State = "DEFAULT"
                }
            }));

            GlobalConstants.GameManager = gameManager;

            this.target = new NeedHandler();
        }
        public void GlobalSetup()
        {
            // для инициализации долбаного глобального TypeManager
            var e = new ScriptingEngine();

            e.AttachAssembly(typeof(FileContext).Assembly);
        }
        public FakeScriptsProvider()
        {
            _sources = new Dictionary <string, ICodeSource>();
            var e = new ScriptingEngine();

            _loader = e.Loader;
        }
Example #5
0
        public ScriptTaskWrapper(ContainerWrapper containerWrapper, string scriptProjectName, bool hasReference, ScriptTaskScope scope) : base(containerWrapper, "STOCK:ScriptTask")
        {
            ScriptTask = Convert.ChangeType(TaskHost.InnerObject, scriptTaskType);
            ScriptTask.ScriptLanguage = cSharpDisplayName;

            if (hasReference)
            {
                ScriptingEngine.VstaHelper.LoadProjectFromStorage(scriptStorages[scriptProjectName]);
            }
            else
            {
                try
                {
                    ScriptingEngine.VstaHelper.LoadNewProject(ScriptTask.ProjectTemplatePath, null, scriptProjectName);
                }
                catch (System.IO.FileNotFoundException ex)
                {
                    throw new InvalidOperationException($"Failed to load dependency {ex.FileName}. Ensure that you have installed the required SSIS components for your version of SQL Server.", ex);
                }

                // Add the ScriptStorage to the global list so it can be accessed later by a ScriptTaskReference.
                if (scope == ScriptTaskScope.Project)
                {
                    scriptStorages[scriptProjectName] = ScriptStorage;
                }
            }

            ScriptingEngine.SaveProjectToStorage();
        }
Example #6
0
        /*
         * public Entity CreateChild(Entity parentRef)
         * {
         *  Dictionary<StatisticIndex, float> childStatistics = s_Cultures[creatureType]
         *  Entity child = new Entity()
         * }
         */

        public void Tick()
        {
            if (m_FulfilmentCounter > 0)
            {
                m_FulfilmentCounter -= 1;
            }

            RegenTicker += 1;
            if (RegenTicker == REGEN_TICK_TIME)
            {
                m_HitPointsRemaining     = Math.Min(m_HitPoints, m_HitPointsRemaining + 1);
                m_ConcentrationRemaining = Math.Min(m_Concentration, m_ConcentrationRemaining + 1);
                m_ComposureRemaining     = Math.Min(m_Composure, m_ComposureRemaining + 1);
                m_ManaRemaining          = Math.Min(m_Mana, m_ManaRemaining + 1);
                RegenTicker = 0;

                foreach (EntityNeed need in m_Needs.Values)
                {
                    need.Tick();
                    Debug.Log("Running LUA script: Tick (" + need.name + ") requested by: " + this.JoyName);
                    ScriptingEngine.RunScript(need.InteractionFileContents, need.name, "Tick", new object[] { new MoonEntity(this) });
                }
            }

            UpdateMe();
        }
Example #7
0
 private void btnLoadTrack_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var dlg = new OpenFileDialog();
         dlg.Filter           = "AX-Script files (*.axs)|*.axs";
         dlg.InitialDirectory = Environment.CurrentDirectory;
         dlg.RestoreDirectory = true;
         if (dlg.ShowDialog(this) == true)
         {
             if (Engine == null)
             {
                 Engine = new ScriptingEngine(map);
             }
             Engine.LoadScript(dlg.FileName);
         }
         else
         {
             Close();
         }
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show(this, ex.Message);
         Close();
     }
 }
Example #8
0
 private LibraryLoader(RuntimeEnvironment _env, ScriptingEngine _engine)
     : base(new LoadedModuleHandle(), true)
 {
     this._env = _env;
     this._engine = _engine;
     this._customized = false;
 }
Example #9
0
        public void Test2()
        {
            var s = ScriptingEngine.Eval("return \"hello\";");

            Console.WriteLine("Running ScriptingTests.Test2 :: " + s);
            Assert.Equal("hello", s);
        }
Example #10
0
        public int Start()
        {
            int exitCode = 0;

            try
            {
                MachineInstance.Current.EventProcessor = new DefaultEventProcessor();
                _engine.UpdateContexts();
                _engine.NewObject(_module);
                exitCode = 0;
            }
            catch (ScriptInterruptionException e)
            {
                exitCode = e.ExitCode;
            }
            catch (Exception e)
            {
                _host.ShowExceptionInfo(e);
                exitCode = 1;
            }
            finally
            {
                _engine.DebugController?.NotifyProcessExit(exitCode);
                _engine.Dispose();
                _engine = null;
            }

            return(exitCode);
        }
Example #11
0
 private LibraryLoader(RuntimeEnvironment _env, ScriptingEngine _engine)
     : base(new LoadedModuleHandle(), true)
 {
     this._env        = _env;
     this._engine     = _engine;
     this._customized = false;
 }
Example #12
0
        public void Test1()
        {
            var s = ScriptingEngine.Eval("2+2");

            //Console.WriteLine("Running ScriptingTests.Test1 :: "+s);
            Assert.Equal("4", s);
        }
Example #13
0
        public void SetUp()
        {
            ActionLog actionLog = new ActionLog();

            GlobalConstants.ActionLog = actionLog;
            this.scriptingEngine      = new ScriptingEngine();

            this.RelationshipHandler = new EntityRelationshipHandler();

            ICultureHandler cultureHandler = Mock.Of <ICultureHandler>(
                handler => handler.Cultures == new ICulture[]
            {
                Mock.Of <ICulture>(culture => culture.RomanceTypes ==
                                   new string[]
                {
                    "heteroromantic",
                    "homoromantic",
                    "panromantic",
                    "aromantic"
                })
            });

            GlobalConstants.GameManager = Mock.Of <IGameManager>(
                manager => manager.RelationshipHandler == this.RelationshipHandler &&
                manager.CultureHandler == cultureHandler);

            this.target = new EntityRomanceHandler();

            this.heteroromantic = this.target.Get("heteroromantic");
            this.homoromantic   = this.target.Get("homoromantic");
            this.biromantic     = this.target.Get("panromantic");
            this.aromantic      = this.target.Get("aromantic");
        }
Example #14
0
 public void Configure(IServiceProvider services)
 {
     // в режиме тестирования app-instance может быть null
     Application     = services.GetService <ApplicationInstance>();
     ScriptsProvider = services.GetRequiredService <IFileProvider>();
     Engine          = services.GetRequiredService <IApplicationRuntime>().Engine;
 }
Example #15
0
 public ConsoleScreen(DemoGame game) : base(game)
 {
     BlockDrawing  = false;
     BlockUpdating = false;
     console       = game.Services.GetService <ConsoleComponent>();
     console.ToggleOpenClose();
     scriptManager = game.Services.GetService <ScriptingEngine>();
 }
Example #16
0
        public LibraryResolver(ScriptingEngine engine, RuntimeEnvironment env)
        {
            _env    = env;
            _engine = engine;
            _libs   = new List <Library>();

            this.SearchDirectories = new List <string>();
        }
Example #17
0
        private LibraryLoader(LoadedModuleHandle moduleHandle, RuntimeEnvironment _env, ScriptingEngine _engine) : base(moduleHandle)
        {
            this._env        = _env;
            this._engine     = _engine;
            this._customized = true;

            _engine.InitializeSDO(this);
        }
Example #18
0
        public LibraryResolver(ScriptingEngine engine, RuntimeEnvironment env)
        {
            _env = env;
            _engine = engine;
            _libs = new List<Library>();

            this.SearchDirectories = new List<string>();
        }
Example #19
0
        public void Test4()
        {
            var se = new ScriptingEngine();
            var s  = se.Exec("var x = 1;");

            Console.WriteLine("Running ScriptingTests.Test4 :: '" + s + "'");
            s = se.Exec("return x == 1 ? 2 : 0;");
            Assert.Equal("2", s);
        }
Example #20
0
        private LibraryLoader(LoadedModuleHandle moduleHandle, RuntimeEnvironment _env, ScriptingEngine _engine): base(moduleHandle)
        {
            this._env = _env;
            this._engine = _engine;
            this._customized = true;

            _engine.InitializeSDO(this);

        }
Example #21
0
        public void DynamicTableInScript()
        {
            var db     = new DbManagement().GetDb("f*x");
            var result =
                new ScriptingEngine(db,
                                    @"db.GetTable<float>(""Aussen.Wetterstation.(?<k>[TF]).*?$"", ""time > now() - 1M"")
.Transform(i => i.GroupByHours(1, o => o.Mean()))
.ZipAndAdd(""Sum"", t => t.T + t.F)").Execute();
        }
Example #22
0
        public void Initialise()
        {
            ActionLog actionLog = new ActionLog();

            GlobalConstants.ActionLog = actionLog;
            this.ScriptingEngine      = new ScriptingEngine();

            this.target = new EntitySkillHandler();
        }
Example #23
0
        public void SetUp()
        {
            ActionLog actionLog = new ActionLog();

            GlobalConstants.ActionLog = actionLog;
            this.scriptingEngine      = new ScriptingEngine();

            this.target = new EntitySexualityHandler();
            this.RelationshipHandler = new EntityRelationshipHandler();
        }
        private LoadedModuleHandle CreateModule(string source)
        {
            var engine = new ScriptingEngine();

            engine.Environment = new RuntimeEnvironment();
            var compiler = engine.GetCompilerService();
            var byteCode = compiler.CreateModule(engine.Loader.FromString(source));

            return(engine.LoadModuleImage(byteCode));
        }
        public WebApplicationEngine()
        {
            Engine             = new ScriptingEngine();
            Environment        = new RuntimeEnvironment();
            Engine.Environment = Environment;

            Engine.AttachAssembly(Assembly.GetExecutingAssembly(), Environment);
            Engine.AttachAssembly(typeof(SystemGlobalContext).Assembly, Environment);
            Engine.Initialize();
        }
Example #26
0
        public MinimalTypeSystemHack()
        {
            var Engine      = new ScriptingEngine();
            var Environment = new RuntimeEnvironment();

            Engine.Environment = Environment;

            Engine.AttachAssembly(typeof(WebApplicationEngine).Assembly, Environment);
            Engine.AttachAssembly(typeof(SystemGlobalContext).Assembly, Environment);
        }
Example #27
0
        private static async void RunMain()
        {
            var engine = new ScriptingEngine();

            Console.Write("Basic Arithmetic...");
            var addResult = await engine.EvaluateAsync <int>("1 + 2");

            TestUtil.WriteResult(TestUtil.Match(3, addResult));

            Console.Write("Testing variables...");
            engine.Globals["X"] = 1;
            engine.Globals["Y"] = 2;
            var variableAddResult = await engine.EvaluateAsync <int>("Globals[\"X\"] + Globals[\"Y\"]");

            TestUtil.WriteResult(TestUtil.Match(engine.Globals["X"] + engine.Globals["Y"], variableAddResult));

            Console.Write("Testing precompiled script basic arithmetic...");
            var precompiledAddScript = engine.CompileScript("1 + 2");
            var precompiledAddResult = await precompiledAddScript.RunAsync <int>();

            TestUtil.WriteResult(TestUtil.Match(3, precompiledAddResult));

            Console.WriteLine("Testing passing objects to script...");
            engine.Globals["Creature"] = new Dog();
            await engine.RunAsync("Globals[\"Creature\"].Bark()");

            Console.WriteLine("Completed Scripting Engine tests");

            Console.Write("Testing Sandboxing...");

            var securityParams = new SandboxSecurityParameters();

            //securityParams.UseZoneSecurity = true; //This is very weak

            securityParams.AllowScripting();

            var scriptSandbox = new ScriptSandbox(securityParams, Guid.NewGuid().ToString("N"));

            Console.WriteLine("Sandbox Created.");

            Console.Write("Basic arithmetic precompiled script in sandbox...");
            var sandboxedPrecompileAddScript       = scriptSandbox.SandboxedEngine.CompileScript("1 + 2");
            var sandboxedPrecompileAddScriptResult = sandboxedPrecompileAddScript.RunSync <int>();

            TestUtil.WriteResult(TestUtil.Match(3, sandboxedPrecompileAddScriptResult));

            /*
             * Console.Write("Basic arithmetic in sandbox...");
             * var sandboxedAddResult = scriptSandbox.SandboxedEngine.EvaluateSync<int>("1 + 2");
             * TestUtil.WriteResult(TestUtil.Match(3, sandboxedAddResult));
             */

            Console.WriteLine("All tests completed");
            Console.ReadLine();
        }
Example #28
0
        public HostedScriptEngine()
        {
            _engine = new ScriptingEngine();
            _env    = new RuntimeEnvironment();
            _engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly(), _env);

            _globalCtx = new SystemGlobalContext();
            _globalCtx.EngineInstance = _engine;

            _env.InjectObject(_globalCtx, false);
        }
Example #29
0
        private void StartEngine()
        {
            var Environment = new RuntimeEnvironment();

            engine             = new ScriptingEngine();
            engine.Environment = Environment;
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(XmlReaderImpl)), Environment);
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(XdtoObjectType)), Environment);
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(Definitions)), Environment);
            engine.Initialize();
        }
Example #30
0
        /// <summary>
        /// Creates a new instance of the game
        /// </summary>
        public League()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Maps are stored as MPQ files - this allows us to read the data
            MpqContent = new ZipContentManager(Services, "maps/" + Settings.Default.map + ".zip");
            Script     = new ScriptingEngine(this);

            Engine = this;
        }
Example #31
0
        private static IApplicationRuntime CreateWebEngineMock()
        {
            var webAppMoq = new Mock <IApplicationRuntime>();
            var engine    = new ScriptingEngine()
            {
                Environment = new RuntimeEnvironment()
            };

            webAppMoq.SetupGet(x => x.Engine).Returns(engine);
            webAppMoq.SetupGet(x => x.Environment).Returns(engine.Environment);
            return(webAppMoq.Object);
        }
        private void InitializeDirectiveResolver(ScriptingEngine engine, RuntimeEnvironment env, string libRoot, string[] additionals)
        {
            var libResolver = new LibraryResolver(engine, env);

            libResolver.LibraryRoot = libRoot;
            if (additionals != null)
            {
                libResolver.SearchDirectories.AddRange(additionals);
            }

            engine.DirectiveResolvers.Add(libResolver);
        }
Example #33
0
        public ScriptSandbox(SandboxSecurityParameters securityParameters, string sandboxName)
        {
            SandboxDomain = CreateSandboxedAppDomain(securityParameters, sandboxName);
            foreach (Assembly availableAssembly in securityParameters.AvailableAssemblies)
            {
                SandboxDomain.Load(availableAssembly.FullName);
            }

            var isolated = new SandboxedCommand <ScriptingEngine>(SandboxDomain);

            SandboxedEngine = isolated.Value;
        }
Example #34
0
        public HostedScriptEngine()
        {
            _engine = new ScriptingEngine();
            _env = new RuntimeEnvironment();
            _engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly(), _env);

            _globalCtx = new SystemGlobalContext();
            _globalCtx.EngineInstance = _engine;

            _env.InjectObject(_globalCtx, false);
            _engine.Environment = _env;
            
            InitLibrariesByDefault();

        }
Example #35
0
        public static LibraryLoader Create(ScriptingEngine engine, RuntimeEnvironment env, string processingScript)
        {
            var code = engine.Loader.FromFile(processingScript);
            var compiler = engine.GetCompilerService();
            compiler.DefineVariable("ЭтотОбъект", SymbolType.ContextProperty);

            for (int i = 0; i < _methods.Count; i++)
            {
                var mi = _methods.GetMethodInfo(i);
                compiler.DefineMethod(mi);
            }

            var module = compiler.CreateModule(code);
            var loadedModule = engine.LoadModuleImage(module);

            return new LibraryLoader(loadedModule, env, engine);
        }
Example #36
0
 public int Start()
 {
     try
     {
         _engine.NewObject(_module);
         return 0;
     }
     catch (ScriptInterruptionException e)
     {
         return e.ExitCode;
     }
     catch (Exception e)
     {
         _host.ShowExceptionInfo(e);
         return 1;
     }
     finally
     {
         _engine.Dispose();
         _engine = null;
     }
 }
Example #37
0
 public static LibraryLoader Create(ScriptingEngine engine, RuntimeEnvironment env)
 {
     return new LibraryLoader(env, engine);
 }
 internal AttachedScriptsFactory(ScriptingEngine engine)
 {
     _loadedModules = new Dictionary<string, LoadedModule>(StringComparer.InvariantCultureIgnoreCase);
     _fileHashes = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
     _engine = engine;
 }
Example #39
0
 internal Process(IHostApplication host, LoadedModuleHandle src, ScriptingEngine runtime)
 {
     _host = host;
     _engine = runtime;
     _module = src;
 }