示例#1
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // load config
            this.Config = this.Helper.ReadConfig <ModConfig>();
            this.Keys   = this.Config.Controls.ParseControls(helper.Input, this.Monitor);

            // load translations
            L10n.Init(helper.Translation);

            // load & validate database
            this.LoadMetadata();
            this.IsDataValid = this.Metadata.LooksValid();
            if (!this.IsDataValid)
            {
                this.Monitor.Log("The data.json file seems to be missing or corrupt. Lookups will be disabled.", LogLevel.Error);
                this.IsDataValid = false;
            }

            // validate translations
            if (!helper.Translation.GetTranslations().Any())
            {
                this.Monitor.Log("The translation files in this mod's i18n folder seem to be missing. The mod will still work, but you'll see 'missing translation' messages. Try reinstalling the mod to fix this.", LogLevel.Warn);
            }

            // hook up events
            helper.Events.GameLoop.GameLaunched += this.OnGameLaunched;
            helper.Events.GameLoop.DayStarted   += this.OnDayStarted;
            helper.Events.Display.RenderedHud   += this.OnRenderedHud;
            helper.Events.Display.MenuChanged   += this.OnMenuChanged;
            helper.Events.Input.ButtonPressed   += this.OnButtonPressed;
            if (this.Config.HideOnKeyUp)
            {
                helper.Events.Input.ButtonReleased += this.OnButtonReleased;
            }
        }