public void Import(string libPath) { #if DEBUG ColorConsoleMethods.WriteLineColor($"Importing: \"{libPath}\"", ConsoleColor.Magenta); #endif InterpreterState state = this; SysLibrary[] libs = SysLibrary.GetAllLibraries(); if (libs.Any(l => l.GetName() == libPath)) { libs.First(l => l.GetName() == libPath).Import(ref state); return; } if (!libPath.EndsWith(".7slib")) { libPath += ".7slib"; } if (!File.Exists(libPath)) { throw new InterpreterException($"Could not find library \"{libPath}\""); } _7sLibrary lib = _7sLibManager.Load(libPath); UserFunction[] funcs = new Interpreter().GetFuncsFromCode(lib.Content, ref state); foreach (UserFunction f in funcs) { UserFuncs.Add(f); } }
internal static void PrintError(Exception e) { bool hasInnerException = e.InnerException != null; if (e is InterpreterException || (hasInnerException && e.InnerException is InterpreterException)) { ColorConsoleMethods.WriteLineColor($"{(hasInnerException ? e.InnerException.Message : e.Message)}", ConsoleColor.Red); return; } ColorConsoleMethods.WriteLineColor($"{e.GetType()}: {e.Message}\n{e.StackTrace}", ConsoleColor.Red); }
public void ExecuteTurn(Game game) { Utils.PrintPlayerNameInText("%PLAYER%, your turn!\n", this); Location l = game.Map.GetPlayerLocation(game.CurrentPlayer); if (l != null) { l.ExecuteTurn(game); } else { ColorConsoleMethods.WriteLineColor("Player is at a null location! Sending to base!", ConsoleColor.Red); game.Map.SendPlayerToSpawn(game.CurrentPlayer); } }
internal void Load(ref Shell.Shell s) { InvalidReason = string.Empty; valid = true; _ = GetCommands(); if (!valid) { throw new InvalidProgramException("Plugin is not valid!"); } foreach (ShellCommand sc in GetCommands()) { var kv = sc.GetCommandKV(); if (s.commands.ToList().FindIndex(x => x.Key.Name.Equals(kv.Key.Name)) > -1) { ColorConsoleMethods.WriteLineColor($"Command {kv.Key.Name} already exists!", ConsoleColor.Red); continue; } s.commands.Add(kv.Key, kv.Value); } }
public void DrawMap() { string header = "------- MAP -------"; ColorConsoleMethods.WriteLineColor(header, ConsoleColor.White); for (int y = 0; y < mapData.Length; y++) { for (int x = 0; x < mapData[y].Length; x++) { if (mapData[x][y] == null) { Console.Write(" "); } else { var kv = mapData[x][y].GetMapSymbol(); ColorConsoleMethods.WriteColor(kv.Key.ToString(), kv.Value); Console.Write(" "); } } Console.WriteLine("\n"); } ColorConsoleMethods.WriteLineColor("-".PadLeft(header.Length, '-'), ConsoleColor.White); }
internal static void PrintError(Exception e) { ColorConsoleMethods.WriteLineColor($"{e.GetType()}: {e.Message}\n{e.StackTrace}", ConsoleColor.Red); }
public void DrawInventory() { ColorConsoleMethods.WriteLineColor($"You have: {Inventory}", ConsoleColor.Green); }
public void WriteToConsole() { ColorConsoleMethods.WriteColor($"[{Color.ToString().ToUpper()}] {Name}", Color); }