Esempio n. 1
0
        public static void Clear(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for clear (expected 0, got {0})", cmd.Arguments.Count));
            }

            GameEngine.Instance.ConsoleViewer.Clear();
        }
Esempio n. 2
0
        public static void ConVars(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for convars (expected 0, got {0})", cmd.Arguments.Count));
            }

            foreach (string name in console.Variables.Keys.OrderBy(i => i))
            {
                ConsoleManager.ConsoleLog.Info(name);
            }
        }
Esempio n. 3
0
        public static void Capture(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 1)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for capture (expected 1, got {0})", cmd.Arguments.Count));
            }

            SFML.Graphics.Image image = GameEngine.Instance.Window.Capture();
            if (!image.SaveToFile(cmd.Arguments[0].Value))
            {
                ConsoleManager.ConsoleLog.Warn(string.Format("Unable to save screen capture to {0}", cmd.Arguments[0].Value));
            }
        }
Esempio n. 4
0
        public static void Create(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count > 1)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_create (expected 0 or 1, got {0})", cmd.Arguments.Count));
            }

            string name = null;
            if (cmd.Arguments.Count == 1)
            {
                name = cmd.Arguments[0].Value;
            }

            Entity entity = GameEngine.Instance.EntityManager.CreateEntity(name);
            ConsoleManager.ConsoleLog.Info("Created entity " + entity.Id);
        }
Esempio n. 5
0
        public static void List(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for asset_list (expected 0, got {0})", cmd.Arguments.Count));
            }

            foreach (KeyValuePair<Type, Dictionary<string, WeakReference>> pair in GameEngine.Instance.AssetManager.Assets)
            {
                ConsoleManager.ConsoleLog.Info(pair.Key.FullName);
                foreach (KeyValuePair<string, WeakReference> asset in pair.Value)
                {
                    ConsoleManager.ConsoleLog.Info((asset.Value.IsAlive ? "+" : "-") + asset.Key);
                }
            }
        }
Esempio n. 6
0
        public static void AttachComponent(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_attach (expected 2, got {0})", cmd.Arguments.Count));
            }

            long id = long.Parse(cmd.Arguments[0].Value);

            Entity entity = GameEngine.Instance.EntityManager.GetEntityById(id);
            if (entity == null)
            {
                throw new NullReferenceException(string.Format("Unknown entity id \"{0}\"", id));
            }

            IComponent component = GameEngine.Instance.EntityManager.CreateComponent(cmd.Arguments[1].Value);
            entity.AddComponent(component.GetType(), component);
        }
Esempio n. 7
0
        public static void Alias(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for alias (expected 2, got {0})", cmd.Arguments.Count));
            }

            string name = cmd.Arguments[0].Value;

            console.RegisterCommand(
                new CommandInfo()
                {
                    Command = AliasExecution,
                    Name = name,
                    Usage = name + " (ALIAS)",
                    Help = cmd.Arguments[1].Value
                },
                true);
        }
Esempio n. 8
0
        public static void Load(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for asset_load (expected 2, got {0})", cmd.Arguments.Count));
            }

            string typeName = cmd.Arguments[0].Value;
            string key = cmd.Arguments[1].Value;

            Type type = TypeUtilities.GetGlobalType(typeName);

            if (type == null)
            {
                throw new ArgumentException(string.Format("Unknown type \"{0}\"", typeName));
            }

            GameEngine.Instance.AssetManager.Load(type, key);
        }
Esempio n. 9
0
        public static void CreateTemplate(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 1 && cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_create_template (expected 1 or 2, got {0})", cmd.Arguments.Count));
            }

            Entity entity = null;
            if (cmd.Arguments.Count == 1)
            {
                entity = GameEngine.Instance.EntityManager.CreateEntityFromTemplate(cmd.Arguments[0].Value);
            }
            else
            {
                entity = GameEngine.Instance.EntityManager.CreateEntityFromTemplateWithName(cmd.Arguments[0].Value, cmd.Arguments[1].Value);
            }

            ConsoleManager.ConsoleLog.Info("Created entity " + entity.Id);
        }
Esempio n. 10
0
        public static void ChangeState(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 1)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for changestate (expected 1, got {0})", cmd.Arguments.Count));
            }

            string typeName = cmd.Arguments[0].Value;
            Type type = TypeUtilities.GetGlobalType(typeName);
            if (type == null)
            {
                throw new ArgumentException(string.Format("Unknown type \"{0}\"", typeName));
            }

            if (!typeof(IGameState).IsAssignableFrom(type))
            {
                throw new ArgumentException(string.Format("Type \"{0}\" is not assignable to IGameState", typeName));
            }

            GameEngine.Instance.StateManager.ChangeState(type);
        }
Esempio n. 11
0
        public static void PropertyBuild(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 1)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_prop_build (expected 1, got {0})", cmd.Arguments.Count));
            }

            long id = long.Parse(cmd.Arguments[0].Value);

            Entity entity = GameEngine.Instance.EntityManager.GetEntityById(id);
            if (entity == null)
            {
                throw new NullReferenceException(string.Format("Unknown entity id \"{0}\"", id));
            }

            entity.BuildProperties(properties);
        }
Esempio n. 12
0
 /// <summary>
 /// Used internally by the alias command to execute aliases.
 /// </summary>
 /// <param name="console">The console.</param>
 /// <param name="cmd">The command.</param>
 private static void AliasExecution(ConsoleManager console, ExecutableCommand cmd)
 {
     CommandList commands = ScriptUtilities.ParseString(console.GetCommand(cmd.Name).Help);
     console.Execute(commands);
 }
Esempio n. 13
0
        public static void Repeat(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for repeat (expected 2, got {0})", cmd.Arguments.Count));
            }

            int n = int.Parse(cmd.Arguments[0].Value);
            string cmds = cmd.Arguments[1].Value;

            CommandList commands = ScriptUtilities.ParseString(cmds);
            for (int i = 0; i < n; i++)
            {
                console.Execute(commands);
            }
        }
Esempio n. 14
0
        public static void Help(ConsoleManager console, ExecutableCommand cmd)
        {
            switch (cmd.Arguments.Count)
            {
                default:
                    throw new ArgumentException(string.Format("Wrong number of arguments for help (expected 0 or 1, got {0})", cmd.Arguments.Count));

                case 0:
                    {
                        foreach (CommandInfo command in console.Commands.Values.OrderBy(i => i.Name))
                        {
                            ConsoleManager.ConsoleLog.Info(string.Format("{0} - {1}", command.Usage, command.Help));
                        }

                        break;
                    }

                case 1:
                    {
                        string name = cmd.Arguments[0].Value;
                        CommandInfo command = null;
                        try
                        {
                            command = console.GetCommand(name);
                        }
                        catch (Exception)
                        {
                            ConsoleManager.ConsoleLog.Warn(string.Format("Unknown command \"{0}\"", name));
                            return;
                        }

                        ConsoleManager.ConsoleLog.Info(string.Format("{0} - {1}", command.Usage, command.Help));

                        break;
                    }
            }
        }
Esempio n. 15
0
        public static void SetName(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_set_name (expected 2, got {0})", cmd.Arguments.Count));
            }

            long id = long.Parse(cmd.Arguments[0].Value);
            string name = cmd.Arguments[1].Value;

            Entity entity = GameEngine.Instance.EntityManager.GetEntityById(id);
            if (entity == null)
            {
                throw new NullReferenceException(string.Format("Unknown entity id \"{0}\"", id));
            }

            entity.Name = name;
        }
Esempio n. 16
0
        public static void PropertySet(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_prop_add (expected 2, got {0})", cmd.Arguments.Count));
            }

            properties[cmd.Arguments[0].Value] = cmd.Arguments[1].Value;
        }
Esempio n. 17
0
        public static void PropertyList(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_prop_list (expected 0, got {0})", cmd.Arguments.Count));
            }

            foreach (string key in properties.Keys)
            {
                ConsoleManager.ConsoleLog.Info(string.Format("{0} = {1}", key, properties[key]));
            }
        }
Esempio n. 18
0
        public static void PropertyInit(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_prop_init (expected 0, got {0})", cmd.Arguments.Count));
            }

            properties.Clear();
        }
Esempio n. 19
0
        public static void GetVariable(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 1)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for get (expected 1, got {0})", cmd.Arguments.Count));
            }

            string varName = cmd.Arguments[0].Value;

            IConVar var = console.GetVariable(varName);
            ConsoleManager.ConsoleLog.Info(string.Format("{0} = {1}", varName, var.Value));
        }
Esempio n. 20
0
        /// <summary>
        /// Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <exception cref="System.ArgumentException">
        /// Unknown command or variable
        /// or
        /// Wrong number of arguments.
        /// </exception>
        public void Execute(ExecutableCommand command)
        {
            CommandInfo info = null;

            try
            {
                info = this.GetCommand(command.Name);
            }
            catch (KeyNotFoundException)
            {
                IConVar var = null;
                try
                {
                    var = this.GetVariable(command.Name);
                }
                catch (KeyNotFoundException)
                {
                    throw new ArgumentException(string.Format("Unknown command or variable \"{0}\"", command.Name));
                }

                switch (command.Arguments.Count)
                {
                    default:
                        throw new ArgumentException(string.Format("Wrong number of arguments for <internal-get-set> (expected 0 or 1, got {0})", command.Arguments.Count));

                    case 0:
                        command.Arguments.Insert(0, new BasicCommandArgument() { RawValue = command.Name });
                        command.Name = "get";
                        break;

                    case 1:
                        command.Arguments.Insert(0, new BasicCommandArgument() { RawValue = command.Name });
                        command.Name = "set";
                        break;
                }

                this.Execute(command);

                return;
            }

            info.Command.Invoke(this, command);
        }
Esempio n. 21
0
        public static void IfLess(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 3 && cmd.Arguments.Count != 4)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for if_less (expected 3 or 4, got {0})", cmd.Arguments.Count));
            }

            double a = double.Parse(cmd.Arguments[0].Value);
            double b = double.Parse(cmd.Arguments[1].Value);
            string ifTrue = cmd.Arguments[2].Value;
            string ifFalse = cmd.Arguments.Count == 4 ? cmd.Arguments[3].Value : null;

            if (ifTrue != null && !string.Empty.Equals(ifTrue) && a < b)
            {
                CommandList commands = ScriptUtilities.ParseString(ifTrue);
                console.Execute(commands);
            }
            else if (ifFalse != null && !string.Empty.Equals(ifFalse))
            {
                CommandList commands = ScriptUtilities.ParseString(ifFalse);
                console.Execute(commands);
            }
        }
Esempio n. 22
0
        public static void Include(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 1)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for include (expected 1, got {0})", cmd.Arguments.Count));
            }

            string filename = cmd.Arguments[0].Value;

            CommandList commands = GameEngine.Instance.AssetManager.Load<CommandList>(filename);
            console.Execute(commands);
        }
Esempio n. 23
0
 public static void NullCommand(ConsoleManager console, ExecutableCommand cmd)
 {
 }
Esempio n. 24
0
        public static void ListComponents(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_component_list (expected 0, got {0})", cmd.Arguments.Count));
            }

            foreach (string component in GameEngine.Instance.EntityManager.ComponentRegistry.Keys.OrderBy(i => i))
            {
                ConsoleManager.ConsoleLog.Info(component);
            }
        }
Esempio n. 25
0
        public static void SetVariable(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for set (expected 2, got {0})", cmd.Arguments.Count));
            }

            string varName = cmd.Arguments[0].Value;
            string value = cmd.Arguments[1].Value;
            IConVar var = null;

            if (!console.ContainsVariable(varName))
            {
                var = new BasicConVar();
                console.RegisterVariable(varName, var);
            }
            else
            {
                var = console.GetVariable(varName);
            }

            var.Value = value;

            ConsoleManager.ConsoleLog.Info(string.Format("set {0} = \"{1}\"", varName, value));
        }
Esempio n. 26
0
        public static void List(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_list (expected 0, got {0})", cmd.Arguments.Count));
            }

            foreach (Entity entity in GameEngine.Instance.EntityManager.Entities.Values)
            {
                ConsoleManager.ConsoleLog.Info(entity.ToString());
            }
        }
Esempio n. 27
0
        public static void Timer(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 2)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for timer (expected 2, got {0})", cmd.Arguments.Count));
            }

            string secondsString = cmd.Arguments[0].Value;
            float seconds = 0;
            if (!float.TryParse(secondsString, out seconds))
            {
                throw new ArgumentException(string.Format("Unable to parse \"{0}\" to a float", secondsString));
            }

            string command = cmd.Arguments[1].Value;

            TaskInfo task = new TaskInfo()
            {
                ExecuteAfter = seconds,
                Task = () =>
                    {
                        try
                        {
                            console.Execute(ScriptUtilities.ParseString(command));
                        }
                        catch (Exception e)
                        {
                            ConsoleManager.ConsoleLog.Warn("Unable to execute delayed commands", e);
                        }
                    }
            };

            GameEngine.Instance.Scheduler.ScheduleTask(task);
        }
Esempio n. 28
0
        public static void ListTemplates(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 0)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_template_list (expected 0, got {0})", cmd.Arguments.Count));
            }

            foreach (string template in GameEngine.Instance.EntityManager.TemplateRegistry.Keys)
            {
                ConsoleManager.ConsoleLog.Info(template);
            }
        }
Esempio n. 29
0
        public static void Echo(ConsoleManager console, ExecutableCommand cmd)
        {
            string str = string.Empty;
            foreach (ICommandArgument arg in cmd.Arguments)
            {
                str += arg.Value + " ";
            }

            if (str.Length > 0)
            {
                str = str.Substring(0, str.Length - 1);
            }

            ConsoleManager.ConsoleLog.Info(str);
        }
Esempio n. 30
0
        public static void Info(ConsoleManager console, ExecutableCommand cmd)
        {
            if (cmd.Arguments.Count != 1)
            {
                throw new ArgumentException(string.Format("Wrong number of arguments for entity_info (expected 1, got {0})", cmd.Arguments.Count));
            }

            long id = long.Parse(cmd.Arguments[0].Value);

            Entity entity = GameEngine.Instance.EntityManager.GetEntityById(id);
            if (entity == null)
            {
                throw new NullReferenceException(string.Format("Unknown entity id \"{0}\"", id));
            }

            ConsoleManager.ConsoleLog.Info(entity.ToString());
            ConsoleManager.ConsoleLog.Info("Components:");
            foreach (IComponent component in entity.Components.Values)
            {
                ConsoleManager.ConsoleLog.Info("\t" + component.ToString());
            }
        }