示例#1
0
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            this.commandValidator = new CommandValidator(helper.ConsoleCommands);
            this.consoleNotifier  = new NotifyingTextWriter(Console.Out, this.OnLineWritten);

            this.inputState = helper.Reflection.GetField <InputState>(typeof(Game1), "input").GetValue();

            Console.SetOut(this.consoleNotifier);
            helper.Events.GameLoop.SaveLoaded      += this.OnSaveLoaded;
            helper.Events.GameLoop.UpdateTicked    += this.OnUpdateTicked;
            helper.Events.GameLoop.ReturnedToTitle += this.OnReturnedToTitle;

            this.modConfig = helper.ReadConfig <ChatCommandsConfig>();
            if (this.modConfig.ColorOverrides == null)
            {
                this.modConfig.ColorOverrides = new Dictionary <string, string>();
            }

            Utils.Validate(this.modConfig.ColorOverrides, this.Monitor);

            IEnumerable <ICommand> commands = new ICommand[]
            {
                new ListenCommand(this.Monitor, this.modConfig, this.consoleNotifier),
                new WhisperCommand(this.Monitor),
                new ReplyCommand(this.Monitor)
            };

            foreach (ICommand command in commands)
            {
                command.Register(helper.ConsoleCommands);
            }
        }
示例#2
0
        public override void Entry(IModHelper helper)
        {
            this.commandValidator = new CommandValidator(helper.ConsoleCommands);
            this.consoleNotifier  = new NotifyingTextWriter(Console.Out, this.OnLineWritten);

            this.inputState = helper.Reflection.GetField <InputState>(typeof(Game1), "input").GetValue();

            Console.SetOut(this.consoleNotifier);
            SaveEvents.AfterLoad          += this.SaveEvents_AfterLoad;
            GameEvents.SecondUpdateTick   += this.GameEvents_HalfSecondTick;
            GameEvents.UpdateTick         += this.GameEvents_UpdateTick;
            SaveEvents.AfterReturnToTitle += this.SaveEvents_AfterReturnToTitle;

            this.modConfig = helper.ReadConfig <ChatCommandsConfig>();

            IEnumerable <ICommand> commands = new ICommand[]
            {
                new ListenCommand(this.Monitor, this.modConfig, this.consoleNotifier),
                new WhisperCommand(this.Monitor),
                new ReplyCommand(this.Monitor)
            };

            foreach (ICommand command in commands)
            {
                command.Register(helper.ConsoleCommands);
            }
        }
        public ListenCommand(IMonitor monitor, ChatCommandsConfig config, NotifyingTextWriter writer)
        {
            this.writer  = writer;
            this.monitor = monitor;

            if (config.ListenToConsoleOnStartup)
            {
                this.Handle(null, null);
            }
        }