Example #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();
        }
Example #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);
            }
        }
Example #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));
            }
        }
Example #4
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);
                }
            }
        }
Example #5
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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #11
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));
        }
Example #12
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();
        }
Example #13
0
        /// <summary>
        /// Build the console variables for interfacing the engine and the console.
        /// </summary>
        /// <param name="console">The console.</param>
        public static void Build(ConsoleManager console)
        {
            console.RegisterVariable(
                "e_running",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            return GameEngine.Instance.IsRunning.ToString();
                        }
                });

            console.RegisterVariable(
                "e_time_delta",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            return GameEngine.Instance.Delta.ToString();
                        }
                });

            console.RegisterVariable(
                "e_timer",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            return GameEngine.Instance.Timer.Elapsed.TotalSeconds.ToString();
                        }
                });

            console.RegisterVariable(
                "e_state",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            if (GameEngine.Instance.StateManager.CurrentState == null)
                            {
                                return "null";
                            }

                            return GameEngine.Instance.StateManager.CurrentState.GetType().ToString();
                        }
                });

            console.RegisterVariable(
                "e_fps",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            return GameEngine.Instance.FPS.ToString();
                        }
                });

            console.RegisterVariable(
                "e_frameskip",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            return GameEngine.Instance.FrameSkip.ToString();
                        }
                });

            console.RegisterVariable(
                "e_clearcolor",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            return GameEngine.Instance.ClearColor.R.ToString() + ", " + GameEngine.Instance.ClearColor.G.ToString() + ", " + GameEngine.Instance.ClearColor.B.ToString();
                        }
                });

            console.RegisterVariable(
                "e_clearcolor_r",
                new DelegateConVar()
                {
                    GetFunc = () =>
                        {
                            return GameEngine.Instance.ClearColor.R.ToString();
                        },

                    SetFunc = (value) =>
                        {
                            GameEngine.Instance.ClearColor = new SFML.Graphics.Color(byte.Parse(value), GameEngine.Instance.ClearColor.G, GameEngine.Instance.ClearColor.B, GameEngine.Instance.ClearColor.A);
                        }
                });

            console.RegisterVariable(
                "e_clearcolor_g",
                new DelegateConVar()
                {
                    GetFunc = () =>
                    {
                        return GameEngine.Instance.ClearColor.G.ToString();
                    },

                    SetFunc = (value) =>
                    {
                        GameEngine.Instance.ClearColor = new SFML.Graphics.Color(GameEngine.Instance.ClearColor.R, byte.Parse(value), GameEngine.Instance.ClearColor.B, GameEngine.Instance.ClearColor.A);
                    }
                });

            console.RegisterVariable(
                "e_clearcolor_b",
                new DelegateConVar()
                {
                    GetFunc = () =>
                    {
                        return GameEngine.Instance.ClearColor.B.ToString();
                    },

                    SetFunc = (value) =>
                    {
                        GameEngine.Instance.ClearColor = new SFML.Graphics.Color(GameEngine.Instance.ClearColor.R, GameEngine.Instance.ClearColor.G, byte.Parse(value), GameEngine.Instance.ClearColor.A);
                    }
                });

            console.RegisterVariable(
                "e_task_count",
                new DelegateConVar()
                {
                    GetFunc = () =>
                    {
                        return GameEngine.Instance.Scheduler.Tasks.Count.ToString();
                    }
                });
        }
Example #14
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);
        }
Example #15
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]));
            }
        }
Example #16
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);
 }
Example #17
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);
            }
        }
Example #18
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;
        }
Example #19
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;
                    }
            }
        }
Example #20
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;
        }
Example #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);
            }
        }
Example #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);
        }
Example #23
0
 public static void NullCommand(ConsoleManager console, ExecutableCommand cmd)
 {
 }
Example #24
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);
        }
Example #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));
        }
Example #26
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);
            }
        }
Example #27
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());
            }
        }
Example #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);
            }
        }
Example #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);
        }
Example #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());
            }
        }