void Awake() { player = GameObject.FindGameObjectWithTag("Player"); director = GameObject.FindGameObjectWithTag("Director"); if (!player.GetComponent<EngineScript>()) player.AddComponent<EngineScript>(); engine = player.GetComponent<EngineScript>(); waypointPrefab = director.GetComponent<PointsScript>().waypoint; lookpointPrefab = director.GetComponent<PointsScript>().lookPoint; curvepointPrefab = director.GetComponent<PointsScript>().curvePoint; if (!GameObject.Find("Waypoint Container")) { waypointContainer = new GameObject(); waypointContainer.name = "Waypoint Container"; waypointContainer.transform.position = player.transform.position; //waypointContainer.transform.parent = player.transform; } else waypointContainer = GameObject.Find("Waypoint Container"); if (!GameObject.FindGameObjectWithTag("Waypoint")) CreateInitialWaypointList(5); }
public void StartService(EngineScript instance) { doubleElectricity = UnityEngine.Object.Instantiate(Resources.Load("Prefabs\\DoubleElectricity") as GameObject); electricitySphere = UnityEngine.Object.Instantiate(Resources.Load("Prefabs\\ElectricitySphere") as GameObject); guysBehaviorService = instance.GetService <GuysBehaviorService>(); }
public void StartService(EngineScript instance) { interactionService = instance.GetService <InteractionService>(); lightningService = instance.GetService <LightningService>(); var uiService = instance.GetService <UIService>(); #if DEBUG interactionService.KeyDownD += () => { uiService.ActivatePauseMenu(); Time.timeScale = 0f; }; interactionService.KeyDownF += () => { uiService.DeactivatePauseMenu(); Time.timeScale = 1f; }; #endif interactionService.OneTouchBegin += (pos) => lightningService.ShowSphereLihgtning(pos); interactionService.OneTouchMove += (pos) => lightningService.ShowSphereLihgtning(pos); interactionService.OneTouchEnd += () => lightningService.HideSphereLihgtning(); interactionService.DoubleTouchBegin += (pos1, pos2) => lightningService.ShowDoubleLihgtning(pos1, pos2); interactionService.DoubleTouchMoved += (pos1, pos2) => lightningService.ShowDoubleLihgtning(pos1, pos2); interactionService.DoubleTouchEnd += () => lightningService.HideDoubleLihgtning(); }
// Use this for initialization void Start() { // first search for some required world objects listOfWeapons = GameObject.Find("ListOfWeapons"); foreach (Transform childTrans in this.transform) { if (childTrans.CompareTag("WeaponPickupIndicator")) { pickUpIndicator = childTrans.gameObject; Transform indicatorCanvasTrans = pickUpIndicator.transform.FindChild("Canvas"); } if (childTrans.CompareTag("Engine")) { currentEngineScript = childTrans.gameObject.GetComponent <EngineScript>(); } } if (listOfWeapons && pickUpIndicator) { usable = true; } closestWeaponDist = weaponGrabDist; playerRB = this.GetComponent <Rigidbody2D>(); prevRotation = playerRB.rotation; prevPrevRotation = playerRB.rotation; if (!usable) { Debug.Log("WeaponControl.cs not initialized due to missing elements"); // missing certain elements so terminate script Destroy(this); } }
//c indicates where the child's parent is in relation to it private void createChild(ShipChromosomeNode n, ChildNode c, ShipController s) { GameObject g = (GameObject)GameObject.Instantiate( Resources.Load(n.isEngine ? Config.ENGINE_PREFAB_LOCATION : Config.HEAVY_BLOCK_PREFAB_LOCATION), Vector3.zero, Quaternion.identity); if (n.isEngine) { EngineScript engine = g.GetComponent <EngineScript>(); engine.initialize(s, n.startEngageAngle, n.rangeEngageAngle); } g.transform.parent = transform; g.transform.localPosition = Vector3.zero; g.transform.localRotation = Quaternion.Euler(0, 0, n.relativeRotation); Vector3 colliderSize = g.GetComponent <MeshCollider>().bounds.size; switch (c) { case ChildNode.TOP: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(0, -colliderSize.y, 0)); break; case ChildNode.BOTTOM: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(0, colliderSize.y, 0)); break; case ChildNode.LEFT: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(colliderSize.x, 0, 0)); break; case ChildNode.RIGHT: g.transform.localPosition = g.transform.localPosition + rotateByThisRotation(new Vector3(-colliderSize.x, 0, 0)); break; } if (Physics.OverlapSphere(g.transform.position, (colliderSize.y < colliderSize.x ? colliderSize.y : colliderSize.x) / 2.1f).Length > 1) { GameObject.Destroy(g); return; } //FixedJoint fixedJoint = g.AddComponent<FixedJoint>(); //fixedJoint.enableCollision = false; //fixedJoint.connectedBody = rigidbody; BlockScript b = g.GetComponent <BlockScript>(); b.initialize(n, s); }
public Engine(EngineScript engineScript, string snapshotsFolder) { if (snapshotsFolder != null) { SnapshotsFolder = snapshotsFolder; if (!Directory.Exists(SnapshotsFolder)) { Directory.CreateDirectory(SnapshotsFolder); } Logger.Information("snapshotsFolder: ", SnapshotsFolder); } ScreenshotHelper = new ScreenshotHelper(this); Name = engineScript.Name; Title = engineScript.Title; Description = engineScript.Description; // Default, mandatory columns SnapshotColumnsDefinition.Add(new EngineSnapshotColumnDefinition { Key = "SavedAt", HeaderText = "Saved At", Order = 0, // first column }); SnapshotColumnsDefinition.Add(new EngineSnapshotColumnDefinition { Key = "Notes", HeaderText = "Notes", Order = 999, // last column }); }
public void StartService(EngineScript instance) { timer = GameObject.Find("Timer").GetComponent <TextMeshProUGUI>(); score = GameObject.Find("Score").GetComponent <TextMeshProUGUI>(); ui = GameObject.Find("UI"); pauseMenuPanel = GameObject.Find("PauseMenu"); pauseMenuPanel.SetActive(false); }
public void StartService(EngineScript instance) { uiService = instance.GetService <UIService>(); xMin = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0)).x; xMax = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, 0)).x; yMin = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0)).y; yMax = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, 0)).y; }
private void comboBoxEngineOther_SelectionChangeCommitted(object sender, EventArgs e) { if (comboBoxEngineOther.SelectedItem is EngineScript backupEngine) { _selectedEngineScript = backupEngine; labelEngineDescription.Text = backupEngine.Description; labelWarning.Text = "WARNING: Third party engine script might be unsafe, use at your own risk!"; wizardPageEngine.AllowNext = true; } }
public async Task InitializeEngineInstanceTest(string scriptFilePath) { //different fix for type deserialization. Makes opening files slow but can be used if the other fix fails string scriptFileText = File.ReadAllText(scriptFilePath); dynamic scriptFileObj = JsonConvert.DeserializeObject(scriptFileText); ImportedNamespaces = JsonConvert.DeserializeObject <Dictionary <string, List <AssemblyReference> > >(JsonConvert.SerializeObject(scriptFileObj["ImportedNamespaces"])); AssembliesList = NamespaceMethods.GetAssemblies(ImportedNamespaces); NamespacesList = NamespaceMethods.GetNamespacesList(ImportedNamespaces); EngineScript = CSharpScript.Create("", ScriptOptions.Default.WithReferences(AssembliesList).WithImports(NamespacesList)); EngineScriptState = await EngineScript.RunAsync(); EngineScriptState = await EngineScriptState.ContinueWithAsync($"string {GenerateGuidPlaceHolder()} = \"\";"); }
void Start() { currRotation = new Vector3(0, 0, 0); initialDeltaTime = Time.fixedDeltaTime; SR = GetComponent <SpriteRenderer>(); origColor = SR.color; currColor = origColor; foreach (Transform child in this.transform.parent) { if (child.CompareTag("Engine")) { currentEngineScript = child.gameObject.GetComponent <EngineScript>(); } } }
private void radioButtonEngineOther_CheckedChanged(object sender, EventArgs e) { if (radioButtonEngineOther.Checked) { comboBoxEngineOfficial.SelectedItem = null; comboBoxEngineOther.SelectedItem = null; comboBoxEngineOfficial.Enabled = false; comboBoxEngineOther.Enabled = true; labelEngineDescription.Text = ""; _selectedEngineScript = null; } wizardPageEngine.AllowNext = false; }
private void comboBoxEngineOfficial_SelectionChangeCommitted(object sender, EventArgs e) { if (comboBoxEngineOfficial.SelectedItem is EngineScript backupEngine) { _selectedEngineScript = backupEngine; labelEngineDescription.Text = backupEngine.Description; if (backupEngine.IsAltered(true)) { labelWarning.Text = "WARNING: The files of this engine have been altered! Use at your own risk!"; } else { labelWarning.Text = ""; } wizardPageEngine.AllowNext = true; } }
public bool LoadEngineAndProfile(EngineScript engineScript, ProfileFile profileFile) { // init Engine instance if (profileFile == null) { ActiveEngine = new Engine(engineScript, null); } else { string name = Path.GetFileNameWithoutExtension(profileFile.FilePath); ActiveEngine = new Engine(engineScript, Path.Combine(profileFile.RootFolder, name)); } // Set engine variables (name, namespace) _lua["_engine_"] = ActiveEngine; _lua.NewTable("_engine_namespace_"); foreach (EngineScriptFile backupEngineFile in engineScript.Files) { if (backupEngineFile.IsToc) { continue; } if (!LoadFile(backupEngineFile)) { ActiveEngine = null; return(false); } } if (profileFile != null) { LoadSettings(profileFile.Settings); LoadSnapshots(profileFile.Snapshots); } return(true); }
private void Setup() { sysScr = GetComponent <SystemScript>(); gridPos = sysScr.GridPos; playerID = gridPos.Z; ship = LevelManager.Instance.Ships [playerID].GetComponent <ShipScript> (); pwrMngr = ship.GetComponent <ShipPowerMngr> (); hScr = sysScr.GetOriginObj().GetComponent <HealthScript> (); //ship.IncreaseEvasionChance (componentCapacity); pwrMngr.PowerSetup(systemType, powerReq); originEngScr = GetOriginEngine(); if (this == originEngScr) { isOrigin = true; } originEngScr.fullPwrReq += powerReq; if (isOrigin) { pwrMngr.AddToSysScrList(systemType, sysScr); } /* 220418 * if (NetManager.Instance != null) { * if (playerID == NetManager.Instance.localPlayerID) { * PowerManager.Instance.GetEngine (this); * PowerManager.Instance.UpdateSystemCapacity (systemType, powerReq); * isLocal = true; * } * } */ }
public void StartService(EngineScript instance) { }
static void Main(string[] args) { chdir("../../../"); Window window = new Window(); window.Create("application-03", (int)DisplayWidth, (int)DisplayHeight); GraphicsDevice.Instance.Create(window, FullScreen); SoundDevice.Instance.Create(window.Handle); #if DEBUG var runner = CommandRunner.Execute(); var monitor = GameSystemMonitor.Execute(); #endif foreach (var file in Directory.GetFiles("res/mission/", "*.cs")) { var assembly = ScriptCompiler.CompileAssemblyFromFile(new ScriptCompilerParameters() { BaseClassName = "GameScript", BatchScriptStyle = false, ClassName = "Mission", GenerateExecutable = false, GenerateInMemory = true, PythonScopeStyle = false, }, file); Missions.MissionAssemblies.Add(Path.GetFileNameWithoutExtension(file), assembly); } SceneManager.SetNextScene(new TitleScene()); window.Updated += () => { EngineScript.update(); GameScript.update(); GraphicsDeviceContext.Instance.Clear(ColorCode.Black); if (SceneManager.Running) { DrawLoadingStatus(SceneManager.Scene); } else { if (SceneManager.Scene != null) { if (!SceneManager.Running) { SceneManager.NextScene(); } } else { Entity.BroadcastMessage(UpdateMessage); Entity.BroadcastMessage(RenderMessage); Entity.BroadcastMessage(TranslucentRenderMessage); Entity.BroadcastMessage(DrawMessage); } } GraphicsDeviceContext.Instance.Present(); if (pressed(KeyCode.Escape)) { window.Close(); } Entity.Update(); }; try { EngineScript.initialize(); GameScript.initialize(); window.Start(); } finally { #if DEBUG GameSystemMonitor.Shutdown(monitor); CommandRunner.Shutdown(runner); #endif Entity.Clear(); ResourceManager.CleanUp(); EngineScript.finalize(); GameScript.finalize(); GraphicsDeviceContext.Instance.Dispose(); GraphicsDevice.Instance.Dispose(); SoundDevice.Instance.Dispose(); } }
private EngineScript GetOriginEngine() { EngineScript _engScr = sysScr.GetOriginObj().GetComponent <EngineScript> (); return(_engScr); }
public void setEngineScript(EngineScript ES) { engScript = ES; }
public bool LoadEngine(EngineScript engineScript) { return(LoadEngineAndProfile(engineScript, null)); }
protected void CreateProfile(DataSet dataSet) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSet.Name); DirectoryInfo directoryInfo = new DirectoryInfo(path); Assert.IsNotNull(directoryInfo, "Scripts directory is null"); Assert.IsTrue(directoryInfo.Exists, "Scripts directory does not exist"); EngineScript engineScript = EngineScriptManager.LoadEngineScript(directoryInfo); Assert.IsNotNull(engineScript, "EngineScript not loaded properly"); Assert.AreEqual(dataSet.Name, engineScript.Name); Assert.AreEqual(dataSet.Title, engineScript.Title); Assert.AreEqual(dataSet.Author, engineScript.Author); Assert.AreEqual(dataSet.FileCount, engineScript.Files.Count); Assert.IsTrue(engineScript.IsValid()); Assert.IsFalse(engineScript.IsAltered(true)); Assert.IsTrue(engineScript.Official); LuaManager luaManager = new LuaManager(); bool loadEngine = luaManager.LoadEngine(engineScript); Assert.IsTrue(loadEngine); if (!Directory.Exists(dataSet.SourceFolder)) { Directory.CreateDirectory(dataSet.SourceFolder); } foreach (var setting in luaManager.ActiveEngine.Settings.Where(s => s.Kind == EngineSettingKind.Setup).OrderBy(s => - s.Index)) { Assert.IsTrue(dataSet.Settings.ContainsKey(setting.Name)); if (setting is EngineSettingCombobox settingCombobox) { settingCombobox.Value = (int)dataSet.Settings[setting.Name]; } if (setting is EngineSettingFolderBrowser settingFolder) { Assert.IsTrue(settingFolder.CanAutoDetect == dataSet.CanAutoDetect); if (dataSet.CanAutoDetect) { Assert.IsNotNull(settingFolder.OnAutoDetect); Assert.DoesNotThrow(() => { string s = settingFolder.OnAutoDetect?.Call().FirstOrDefault() as string; Assert.IsNotNull(s); }); } settingFolder.Value = (string)dataSet.Settings[setting.Name]; } } Assert.IsNotNull(luaManager.ActiveEngine.OnSetupValidate); Assert.DoesNotThrow(() => { bool?b = luaManager.ActiveEngine.OnSetupValidate.Call().First() as bool?; Assert.IsNotNull(b); Assert.IsTrue(b.Value); }); if (luaManager.ActiveEngine.OnSetupSuggestProfileName != null) { Assert.DoesNotThrow(() => { string s = luaManager.ActiveEngine.OnSetupSuggestProfileName.Call().First() as string; Assert.IsFalse(string.IsNullOrEmpty(s)); Assert.IsTrue(HgUtility.IsValidFileName(s)); Assert.AreEqual(dataSet.SuggestProfileName, s); }); } if (luaManager.ActiveEngine.ReadMe != null) { Assert.DoesNotThrow(() => { string s = luaManager.ActiveEngine.ReadMe.Call().First() as string; Assert.IsFalse(string.IsNullOrEmpty(s)); }); } var profileFile = new ProfileFile { EngineScriptName = engineScript.Name, Name = dataSet.ProfileName }; luaManager.SaveSnapshots(profileFile); luaManager.SaveSettings(profileFile); string filePath = Path.Combine(dataSet.SourceFolder, dataSet.ProfileName + "_Create.shp"); profileFile.FilePath = filePath; ProfileFile.Save(profileFile); Assert.DoesNotThrow(() => { profileFile.Release(); }); string expected = File.ReadAllText(Path.Combine(dataSet.DataRoot, "Original", dataSet.ProfileName + "_Create.shp")); expected = expected.Replace(@"%SOURCEFOLDER%", dataSet.SourceFolder.Replace(@"\", @"\\")); string produced = File.ReadAllText(filePath); Assert.AreEqual(expected, produced); luaManager.Release(); Directory.Delete(dataSet.SourceFolder, true); }
private void Awake() { engineScript = this; }
public void CheckBackupRestore(DataSetSatisfactory dataSetSatisfactory) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSetSatisfactory.Name); DirectoryInfo directoryInfo = new DirectoryInfo(path); Assert.IsNotNull(directoryInfo, "Scripts directory is null"); Assert.IsTrue(directoryInfo.Exists, "Scripts directory does not exist"); EngineScript engineScript = EngineScriptManager.LoadEngineScript(directoryInfo); Assert.IsNotNull(engineScript, "EngineScript not loaded properly"); if (!Directory.Exists(dataSetSatisfactory.SourceFolder)) { Directory.CreateDirectory(dataSetSatisfactory.SourceFolder); } string profilePathOrigin = Path.Combine(dataSetSatisfactory.DataRoot, @"Original", dataSetSatisfactory.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSetSatisfactory.SourceFolder, dataSetSatisfactory.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSetSatisfactory.SourceFolder.Replace(@"\", @"\\")); File.WriteAllText(profilePathSimulation, content); ProfileFile profileFile = ProfileFile.Load(profilePathSimulation); Assert.IsNotNull(profileFile); LuaManager luaManager = new LuaManager(); Assert.IsNotNull(luaManager); bool loadEngine = luaManager.LoadEngineAndProfile(engineScript, profileFile); Assert.IsTrue(loadEngine); if (luaManager.ActiveEngine.OnOpened != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnOpened.Call(); }); } if (luaManager.ActiveEngine.OnInitialized != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnInitialized.Call(); }); } var setting = luaManager.ActiveEngine.SettingByName("IncludeAutosave"); if (setting is EngineSettingCheckbox s) { s.Value = true; } // End of open Directory.CreateDirectory(dataSetSatisfactory.SourceFolder); Thread.Sleep(100); string fileSource = Path.Combine(dataSetSatisfactory.DataRoot, @"Original"); string fileDest = dataSetSatisfactory.SourceFolder; foreach (var files in dataSetSatisfactory.Watchers.OrderBy(x => x.Key)) { foreach (var file in files.Value.Files) { File.Copy( Path.Combine(fileSource, file), Path.Combine(fileDest, file)); } Thread.Sleep(100); Assert.DoesNotThrow(() => { luaManager.ActiveEngine.ActionSnapshotBackup(ActionSource.HotKey, files.Value.SnapshotAutosave != ""); }); Assert.AreEqual(1, luaManager.ActiveEngine.Snapshots.Count); EngineSnapshot snapshot = luaManager.ActiveEngine.Snapshots.First(); Assert.AreSame(snapshot, luaManager.ActiveEngine.LastSnapshot); Assert.AreEqual(files.Value.SnapshotSaveAt, RoundSavedAt(snapshot.SavedAt)); Assert.AreEqual(files.Value.SnapshotBuildVersion, snapshot.CustomValueByKey("BuildVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSaveVersion, snapshot.CustomValueByKey("SaveVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSessionName, snapshot.CustomValueByKey("SessionName").ToString()); Assert.AreEqual(files.Value.SnapshotPlayedTime, snapshot.CustomValueByKey("PlayedTime").ToString()); Assert.AreEqual(files.Value.SnapshotAutosave, snapshot.CustomValueByKey("Autosave").ToString()); Assert.DoesNotThrow(() => { luaManager.ActiveEngine.ActionSnapshotRestore(ActionSource.HotKey, luaManager.ActiveEngine.LastSnapshot); }); luaManager.ActiveEngine.Snapshots.Clear(); foreach (var file in files.Value.Files) { File.Delete(Path.Combine(fileDest, file)); } Thread.Sleep(100); } luaManager.Release(); Directory.Delete(dataSetSatisfactory.SourceFolder, true); }
protected void OpenProfile(DataSet dataSet) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSet.Name); DirectoryInfo directoryInfo = new DirectoryInfo(path); Assert.IsNotNull(directoryInfo, "Scripts directory is null"); Assert.IsTrue(directoryInfo.Exists, "Scripts directory does not exist"); EngineScript engineScript = EngineScriptManager.LoadEngineScript(directoryInfo); Assert.IsNotNull(engineScript, "EngineScript not loaded properly"); Assert.AreEqual(dataSet.Name, engineScript.Name); Assert.AreEqual(dataSet.Title, engineScript.Title); Assert.AreEqual(dataSet.Author, engineScript.Author); Assert.AreEqual(dataSet.FileCount, engineScript.Files.Count); Assert.IsTrue(engineScript.IsValid()); Assert.IsFalse(engineScript.IsAltered(true)); Assert.IsTrue(engineScript.Official); if (!Directory.Exists(dataSet.SourceFolder)) { Directory.CreateDirectory(dataSet.SourceFolder); } string profilePathOrigin = Path.Combine(dataSet.DataRoot, @"Original", dataSet.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSet.SourceFolder, dataSet.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSet.SourceFolder.Replace(@"\", @"\\")); File.WriteAllText(profilePathSimulation, content); ProfileFile profileFile = ProfileFile.Load(profilePathSimulation); Assert.IsNotNull(profileFile); LuaManager luaManager = new LuaManager(); Assert.IsNotNull(luaManager); bool loadEngine = luaManager.LoadEngineAndProfile(engineScript, profileFile); Assert.IsTrue(loadEngine); if (luaManager.ActiveEngine.OnOpened != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnOpened.Call(); }); } int catCount = 0; luaManager.ActiveEngine.OnCategoriesChanges += () => { catCount++; }; int snapCount = 0; luaManager.ActiveEngine.OnSnapshotsChanges += () => { snapCount++; }; if (luaManager.ActiveEngine.OnInitialized != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnInitialized.Call(); }); } if (luaManager.ActiveEngine.OnLoaded != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnLoaded.Call(); }); } Assert.AreEqual(1, catCount); Assert.AreEqual(1, snapCount); // End of open luaManager.SaveSettings(profileFile); luaManager.SaveSnapshots(profileFile); ProfileFile.Save(profileFile); Assert.DoesNotThrow(() => { profileFile.Release(); }); string expected = File.ReadAllText(profilePathOrigin); expected = expected.Replace(@"%SOURCEFOLDER%", dataSet.SourceFolder.Replace(@"\", @"\\")); string produced = File.ReadAllText(profilePathSimulation); Assert.AreEqual(expected, produced); luaManager.Release(); Directory.Delete(dataSet.SourceFolder, true); }
public void CheckWatcher(DataSetSatisfactory dataSetSatisfactory) { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Scripts", dataSetSatisfactory.Name); DirectoryInfo directoryInfo = new DirectoryInfo(path); Assert.IsNotNull(directoryInfo, "Scripts directory is null"); Assert.IsTrue(directoryInfo.Exists, "Scripts directory does not exist"); EngineScript engineScript = EngineScriptManager.LoadEngineScript(directoryInfo); Assert.IsNotNull(engineScript, "EngineScript not loaded properly"); if (!Directory.Exists(dataSetSatisfactory.SourceFolder)) { Directory.CreateDirectory(dataSetSatisfactory.SourceFolder); } string profilePathOrigin = Path.Combine(dataSetSatisfactory.DataRoot, @"Original", dataSetSatisfactory.ProfileName + "_Open.shp"); string profilePathSimulation = Path.Combine(dataSetSatisfactory.SourceFolder, dataSetSatisfactory.ProfileName + "_Open.shp"); File.Copy(profilePathOrigin, profilePathSimulation); string content = File.ReadAllText(profilePathSimulation); content = content.Replace(@"%SOURCEFOLDER%", dataSetSatisfactory.SourceFolder.Replace(@"\", @"\\")); File.WriteAllText(profilePathSimulation, content); ProfileFile profileFile = ProfileFile.Load(profilePathSimulation); Assert.IsNotNull(profileFile); LuaManager luaManager = new LuaManager(); Assert.IsNotNull(luaManager); bool loadEngine = luaManager.LoadEngineAndProfile(engineScript, profileFile); Assert.IsTrue(loadEngine); if (luaManager.ActiveEngine.OnOpened != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnOpened.Call(); }); } int catCount = 0; luaManager.ActiveEngine.OnCategoriesChanges += () => { catCount++; }; int snapCount = 0; luaManager.ActiveEngine.OnSnapshotsChanges += () => { snapCount++; }; int backupCount = 0; luaManager.ActiveEngine.OnAutoBackupOccurred += success => { if (success) { backupCount++; } }; if (luaManager.ActiveEngine.OnInitialized != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnInitialized.Call(); }); } Assert.IsNotNull(luaManager.ActiveEngine.Watcher); var setting = luaManager.ActiveEngine.SettingByName("IncludeAutosave"); if (setting is EngineSettingCheckbox s) { s.Value = true; } WatcherManager watcherManager = new WatcherManager(luaManager.ActiveEngine.Watcher) { IsProcessRunning = () => true }; // int backupStatus = 0; watcherManager.AutoBackupStatusChanged += () => { // backupStatus++; }; if (luaManager.ActiveEngine.OnLoaded != null) { Assert.DoesNotThrow(() => { luaManager.ActiveEngine.OnLoaded.Call(); }); } Assert.AreEqual(1, catCount); Assert.AreEqual(1, snapCount); // End of open Assert.AreEqual(AutoBackupStatus.Disabled, watcherManager.AutoBackupStatus); Thread.Sleep(100); watcherManager.SetAutoBackup(true); Assert.AreEqual(AutoBackupStatus.Enabled, watcherManager.AutoBackupStatus); string fileSource = Path.Combine(dataSetSatisfactory.DataRoot, @"Original"); string fileDest = dataSetSatisfactory.SourceFolder; foreach (var files in dataSetSatisfactory.Watchers.OrderBy(x => x.Key)) { backupCount = 0; foreach (var file in files.Value.Files) { // this engine requires file changes //using (var fileStream = File.Create(Path.Combine(fileDest, file))) //{ } //Thread.Sleep(100); using (var fileStream = File.OpenWrite(Path.Combine(fileDest, file))) { var bytes = File.ReadAllBytes(Path.Combine(fileSource, file)); fileStream.Write(bytes, 0, bytes.Length); } Thread.Sleep(100); } Thread.Sleep(500); Assert.GreaterOrEqual(backupCount, 1); Assert.AreEqual(1, luaManager.ActiveEngine.Snapshots.Count); EngineSnapshot snapshot = luaManager.ActiveEngine.Snapshots.First(); Assert.AreSame(snapshot, luaManager.ActiveEngine.LastSnapshot); Assert.AreEqual(files.Value.SnapshotSaveAt, RoundSavedAt(snapshot.SavedAt)); Assert.AreEqual(files.Value.SnapshotBuildVersion, snapshot.CustomValueByKey("BuildVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSaveVersion, snapshot.CustomValueByKey("SaveVersion").ToString()); Assert.AreEqual(files.Value.SnapshotSessionName, snapshot.CustomValueByKey("SessionName").ToString()); Assert.AreEqual(files.Value.SnapshotPlayedTime, snapshot.CustomValueByKey("PlayedTime").ToString()); Assert.AreEqual(files.Value.SnapshotAutosave, snapshot.CustomValueByKey("Autosave").ToString()); luaManager.ActiveEngine.Snapshots.Clear(); foreach (var file in files.Value.Files) { File.Delete(Path.Combine(fileDest, file)); } Thread.Sleep(100); } watcherManager.Release(); luaManager.Release(); Directory.Delete(dataSetSatisfactory.SourceFolder, true); }
public static EngineScript LoadEngineScript(DirectoryInfo dirInfo) { EngineScript engineScript = null; foreach (FileInfo fileInfo in dirInfo.GetFiles("*.toc", SearchOption.TopDirectoryOnly)) { string filename = Path.GetFileNameWithoutExtension(fileInfo.Name); if (filename == dirInfo.Name) { string fileRelativePath = Path.Combine(dirInfo.Name, fileInfo.Name); engineScript = new EngineScript { Name = filename }; var engineScriptFile = new EngineScriptFile { FileName = fileRelativePath, FileFullName = fileInfo.FullName, IsToc = true }; engineScript.Files.Add(engineScriptFile); List <string> tocContent = File.ReadAllLines(fileInfo.FullName).ToList(); foreach (string line in tocContent) { string trimmedLine = line.Trim(); if (trimmedLine.StartsWith("##")) { if (TocReadValue(trimmedLine, "## Title:", out var value)) { engineScript.Title = value; continue; } if (TocReadValue(trimmedLine, "## Author:", out value)) { engineScript.Author = value; continue; } if (TocReadValue(trimmedLine, "## Description:", out value)) { if (!string.IsNullOrEmpty(engineScript.Description)) { engineScript.Description += Environment.NewLine; } engineScript.Description += value; continue; } } if (!string.IsNullOrEmpty(trimmedLine) && !trimmedLine.StartsWith("##") && trimmedLine.EndsWith(".lua")) { fileRelativePath = Path.Combine(dirInfo.Name, trimmedLine); string fileFullPath = Path.Combine(dirInfo.FullName, trimmedLine); engineScriptFile = new EngineScriptFile { FileName = fileRelativePath, FileFullName = fileFullPath, IsToc = false }; engineScript.Files.Add(engineScriptFile); } } break; // only one toc file per profile engine } } return(engineScript); }
public void StartService(EngineScript instance) { guysBehaviorService = instance.GetService <GuysBehaviorService>(); }
public void StartService(EngineScript instance) { uiService = instance.GetService <UIService>(); }
void OnFocus() { player = GameObject.FindGameObjectWithTag("Player"); engine = player.GetComponent<EngineScript>(); if (!GameObject.FindGameObjectWithTag("Waypoint")) engine.waypoints.Clear(); }