Example #1
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param>
 public DataParser(GameHelper gameHelper)
 {
     this.GameHelper = gameHelper;
 }
Example #2
0
        /// <summary>Get the viewport coordinates represented by a tile position.</summary>
        /// <param name="tile">The tile position.</param>
        public static Rectangle GetScreenCoordinatesFromTile(Vector2 tile)
        {
            Vector2 position = GameHelper.GetScreenCoordinatesFromAbsolute(tile * new Vector2(Game1.tileSize));

            return(new Rectangle((int)position.X, (int)position.Y, Game1.tileSize, Game1.tileSize));
        }
Example #3
0
        /// <summary>Get the recipe ingredients.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        /// <param name="reflectionHelper">Simplifies access to private game code.</param>
        public static RecipeModel[] GetRecipes(Metadata metadata, IReflectionHelper reflectionHelper)
        {
            List <RecipeModel> recipes = new List <RecipeModel>();

            // cooking recipes
            recipes.AddRange(
                from entry in CraftingRecipe.cookingRecipes
                let recipe = new CraftingRecipe(entry.Key, isCookingRecipe: true)
                             select new RecipeModel(recipe, reflectionHelper)
                );

            // crafting recipes
            recipes.AddRange(
                from entry in CraftingRecipe.craftingRecipes
                let recipe = new CraftingRecipe(entry.Key, isCookingRecipe: false)
                             select new RecipeModel(recipe, reflectionHelper)
                );

            // recipes not available from game data
            recipes.AddRange(
                from entry in metadata.Recipes
                select new RecipeModel(entry.Name, entry.Type, entry.Ingredients, () => GameHelper.GetObjectBySpriteIndex(entry.Output), false, entry.ExceptIngredients)
                );

            return(recipes.OrderBy(p => p.Name).ToArray());
        }
 /*********
 ** Private methods
 *********/
 /****
 ** Event handlers
 ****/
 /// <summary>The method invoked when a new day starts.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event data.</param>
 private void TimeEvents_AfterDayStarted(object sender, EventArgs e)
 {
     // reset low-level cache once per game day (used for expensive queries that don't change within a day)
     GameHelper.ResetCache(this.Metadata, this.Helper.Reflection, this.Helper.Translation, this.Monitor);
 }
Example #5
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 <RawModConfig>().GetParsed(this.Monitor);

            // load database
            this.LoadMetadata();
#if TEST_BUILD
            this.OverrideFileWatcher = new FileSystemWatcher(this.PathOnDisk, this.DatabaseFileName)
            {
                EnableRaisingEvents = true
            };
            this.OverrideFileWatcher.Changed += (sender, e) =>
            {
                this.LoadMetadata();
                this.TargetFactory  = new TargetFactory(this.Metadata);
                this.DebugInterface = new DebugInterface(this.TargetFactory, this.Config)
                {
                    Enabled = this.DebugInterface.Enabled
                };
            };
#endif

            // initialise functionality
            this.CurrentVersion = new SemanticVersion(this.ModManifest.Version.ToString());
            this.TargetFactory  = new TargetFactory(this.Metadata, this.Helper.Reflection);
            this.DebugInterface = new DebugInterface(this.TargetFactory, this.Config, this.Monitor);

            // hook up events
            {
                // reset low-level cache once per game day (used for expensive queries that don't change within a day)
                SaveEvents.AfterLoad += (sender, e) => GameHelper.ResetCache(this.Metadata, this.Helper.Reflection);
                SaveEvents.AfterSave += (sender, e) => GameHelper.ResetCache(this.Metadata, this.Helper.Reflection);

                // hook up game events
                GameEvents.GameLoaded += (sender, e) => this.ReceiveGameLoaded();
                GraphicsEvents.OnPostRenderHudEvent += (sender, e) => this.ReceiveInterfaceRendering(Game1.spriteBatch);
                MenuEvents.MenuClosed += (sender, e) => this.ReceiveMenuClosed(e.PriorMenu);

                // hook up keyboard
                if (this.Config.Keyboard.HasAny())
                {
                    ControlEvents.KeyPressed += (sender, e) => this.ReceiveKeyPress(e.KeyPressed, this.Config.Keyboard);
                    if (this.Config.HideOnKeyUp)
                    {
                        ControlEvents.KeyReleased += (sender, e) => this.ReceiveKeyRelease(e.KeyPressed, this.Config.Keyboard);
                    }
                }

                // hook up controller
                if (this.Config.Controller.HasAny())
                {
                    ControlEvents.ControllerButtonPressed  += (sender, e) => this.ReceiveKeyPress(e.ButtonPressed, this.Config.Controller);
                    ControlEvents.ControllerTriggerPressed += (sender, e) => this.ReceiveKeyPress(e.ButtonPressed, this.Config.Controller);
                    if (this.Config.HideOnKeyUp)
                    {
                        ControlEvents.ControllerButtonReleased  += (sender, e) => this.ReceiveKeyRelease(e.ButtonReleased, this.Config.Controller);
                        ControlEvents.ControllerTriggerReleased += (sender, e) => this.ReceiveKeyRelease(e.ButtonReleased, this.Config.Controller);
                    }
                }
            }

            // validate metadata
            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;
            }
        }