private static void SetCustomScriptPath(PyScript script, string newPath) { var sp = _internalData[script]; sp.Custom = newPath; _internalData[script] = sp; }
private static string GetDefaultPath(PyScript script, bool allowNull) { var sp = _internalData[script]; if (sp.Default == null && !allowNull) { sp.Default = EmbeddedScriptToDisk(script); } _internalData[script] = sp; return(sp.Default); }
private static string GetPyScriptFileName(PyScript script) { switch (script) { case PyScript.GetProjectInfo: return(PyGetProjInfo); case PyScript.MixdownAudio: return(PyMixdownAudio); default: return(null); } }
public Fighter(int id, Database.Records.MonsterLevelRecord monster, Engines.Map.MonsterGroup group) { this.Drops = new FightDrops(this); this.MonsterGroup = group; this.Monster = monster; this._id = id; this._currentLife = this.Monster.Life; this.IsHuman = false; this.IsReady = true; this.IsDead = false; switch (Monster.GetTemplate.AI) { case 0: this.ArtificialBrain = new AI.StaticAI(this); break; case 1: case 2: this.ArtificialBrain = new AI.BasicAI(this); break; case 3: this.ArtificialBrain = new AI.FearfulAI(this); break; case 4: this.ArtificialBrain = new AI.ScriptedAI(this); if (this.Monster.GetTemplate.HasScriptAI()) { var scriptID = this.Monster.GetTemplate.Script; var script = new PyScript("Scripts/AI/" + scriptID); script.Load(this); (this.ArtificialBrain as AI.ScriptedAI).Script = script; } break; } this.CurrentAP = Stats.GetMaxActionPoints; this.CurrentMP = Stats.GetMaxMovementPoints; }
private void ExecutePythonScript(string script, string args, PyScript pyScript) { string result = string.Empty; ProcessStartInfo psi = new ProcessStartInfo(pyStart); psi.Arguments = script + " " + args; psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.UseShellExecute = false; psi.CreateNoWindow = true; using (Process p = new Process()) { // Run python script p.StartInfo = psi; p.Start(); p.WaitForExit(); // Check status if (p.ExitCode == 0) { result = p.StandardOutput.ReadToEnd(); } else { MessageBox.Show("Pytyhon script " + script + " exited with return code " + p.ExitCode, "Error", MessageBoxButton.OK, MessageBoxImage.Error); // Show failed message and change color textBlockRecoveredMessage.Foreground = new SolidColorBrush(Colors.Red); textBlockRecoveredMessage.Text = "Failed!"; return; } if (pyScript == PyScript.Encode) { Thread.Sleep(1000); // Clear recovered message (of any) textBlockRecoveredMessage.Text = ""; // Open output image outputImageSaveName = inputImageSaveName + "_hidden.png"; outputImagePath = pyScriptsBaseDir + "out/" + outputImageSaveName; imageOutput.Source = CreateBitmapImage(outputImagePath).Clone(); // Open residual image residualImagePath = inputImageSaveName + "_residual.png"; residualImagePath = pyScriptsBaseDir + "out/" + residualImagePath; imageResidual.Source = CreateBitmapImage(residualImagePath).Clone(); } else if (pyScript == PyScript.Decode) { // Check if failed to decode var a = result.ToString().Substring(0, result.Length - 2); if (result.ToString().Substring(0, result.Length - 2).Equals("Failed to decode!")) { // Show failed to decde message and change color textBlockRecoveredMessage.Foreground = new SolidColorBrush(Colors.Red); textBlockRecoveredMessage.Text = "Failed!"; } else { // Show return message textBlockRecoveredMessage.Foreground = new SolidColorBrush(Colors.GreenYellow); textBlockRecoveredMessage.Text = result; } } } }
private static string GetCustomPath(PyScript script) { var custom = _internalData[script].Custom; return(File.Exists(custom) ? custom : null); }
private static string GetScriptPath(PyScript script) { var path = GetCustomPath(script) ?? GetDefaultPath(script, false); return(path); }
public static string EmbeddedScriptToDisk(PyScript script, string dir = null) { var rsName = GetPyScriptFileName(script); return(EmbeddedScriptToDisk(rsName, dir)); }