Beispiel #1
0
        private void LoadFromFolder(object sender, EventArgs e)
        {
            this.Monitor.Log("Loading delegates", LogLevel.Info);
            this.modContent = this.modContent ?? new ContentManager(Game1.content.ServiceProvider, this.contentPath);

            // Get all xnbs that need delegates
            foreach (string mod in Directory.GetDirectories(Path.Combine(Helper.DirectoryPath, "Content")))
            {
                ContentInjector injector = ContentAPI.GetInjector(this, Path.GetFileName(mod));
                injector.RegisterDirectoryAssets(mod);
            }
        }
Beispiel #2
0
        public override void Entry(IModHelper helper)
        {
            config = helper.ReadConfig <ModConfig>();
            if (!config.ModEnabled)
            {
                return;
            }

            this.contentPath = Path.Combine(this.Helper.DirectoryPath, "Content");
            if (!Directory.Exists(this.contentPath))
            {
                try {
                    this.Monitor.Log($"Creating directory {this.contentPath}");
                    Directory.CreateDirectory(this.contentPath);
                } catch (Exception ex) {
                    this.Monitor.Log($"Could not create directory {this.contentPath}! Please create it yourself.", LogLevel.Error);
                    this.Monitor.Log(ex.Message, LogLevel.Error);
                    return;
                }
            }

            this.itemLoader = new ItemLoader();
            this.merger     = new ContentMerger();

            GameEvents.UpdateTick += UpdateTick;
            LocationEvents.CurrentLocationChanged += CurrentLocationChanged;
            GraphicsEvents.OnPreRenderEvent       += OnPreRenderEvent;
            GameEvents.LoadContent += LoadFromFolder;

            ItemCustom custom = new ItemCustom("SCCL.custom");

            ControlEvents.KeyPressed += (sender, e) => {
                switch (e.KeyPressed)
                {
                case Microsoft.Xna.Framework.Input.Keys.R:
                    Game1.player.addItemToInventory(new ModObject(custom));
                    break;

                case Microsoft.Xna.Framework.Input.Keys.T:
                    itemLoader.Save();
                    break;

                case Microsoft.Xna.Framework.Input.Keys.Y:
                    itemLoader.Load();
                    break;
                }
            };

            #region Console Commands
            Helper.ConsoleCommands.Add("SCCLEnable", "Enables a content injector | SCCLEnable <injector>", (cmd, args) => {
                if (args.Length >= 1)
                {
                    string name = args[0];
                    if (ContentAPI.InjectorExists(name))
                    {
                        ContentAPI.GetInjector(this, name).Enabled = true;
                        Monitor.Log(name + " is enabled", LogLevel.Info);
                    }
                    else
                    {
                        Monitor.Log("No injector with name '" + name + "' exists!", LogLevel.Warn);
                    }
                }
                else
                {
                    Monitor.Log("Injector name was not specified", LogLevel.Warn);
                }
            });
            Helper.ConsoleCommands.Add("SCCLDisable", "Disables a content injector | SCCLEnable <injector>", (cmd, args) => {
                if (args.Length >= 1)
                {
                    string name = args[0];
                    if (ContentAPI.InjectorExists(name))
                    {
                        ContentAPI.GetInjector(this, name).Enabled = false;
                        Monitor.Log(name + " is disabled", LogLevel.Info);
                    }
                    else
                    {
                        Monitor.Log("No injector with name '" + name + "' exists!", LogLevel.Warn);
                    }
                }
                else
                {
                    Monitor.Log("Injector name was not specified", LogLevel.Warn);
                }
            });
            Helper.ConsoleCommands.Add("SCCLList", "Lists all content injectors | SCCLList", (cmd, args) => {
                this.Monitor.Log("Registered injectors: " + string.Join(", ", ContentAPI.GetAllInjectors()), LogLevel.Info);
            });
            Helper.ConsoleCommands.Add("SCCLReload", "Reloads the config (ModEnabled is ignored) | SCCLReload", (cmd, args) => {
                this.config = this.Helper.ReadConfig <ModConfig>();
                // TODO: remove all previously loaded assets
                this.LoadFromFolder(this, new EventArgs());
            });
            #endregion
        }