/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="reflection">Simplifies access to private game code.</param> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="config">The mod configuration.</param> /// <param name="codex">Provides subject entries.</param> /// <param name="jsonAssets">The Json Assets API.</param> public ItemLookupProvider(IReflectionHelper reflection, GameHelper gameHelper, ModConfig config, ISubjectRegistry codex, JsonAssetsIntegration jsonAssets) : base(reflection, gameHelper) { this.Config = config; this.Codex = codex; this.JsonAssets = jsonAssets; }
/********* ** Public methods *********/ /**** ** Constructors ****/ /// <summary>Construct an instance.</summary> /// <param name="metadata">Provides metadata that's not available from the game data directly.</param> /// <param name="translations">Provides translations stored in the mod folder.</param> /// <param name="reflection">Simplifies access to private game code.</param> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="jsonAssets">The Json Assets API.</param> public TargetFactory(Metadata metadata, ITranslationHelper translations, IReflectionHelper reflection, GameHelper gameHelper, JsonAssetsIntegration jsonAssets) { this.Metadata = metadata; this.Translations = translations; this.Reflection = reflection; this.GameHelper = gameHelper; this.JsonAssets = jsonAssets; }
/********* ** Public methods *********/ /**** ** Constructors ****/ /// <summary>Construct an instance.</summary> /// <param name="reflection">Simplifies access to private game code.</param> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="codex">Constructs subjects for target values.</param> public TargetFactory(IReflectionHelper reflection, GameHelper gameHelper, JsonAssetsIntegration jsonAssets, SubjectFactory codex) { this.Reflection = reflection; this.GameHelper = gameHelper; this.JsonAssets = jsonAssets; this.GameHelper = gameHelper; this.Codex = codex; }
/********* ** Private methods *********/ /// <summary>Get the in-world sprite sheet for a target.</summary> /// <param name="target">The target whose texture to get.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="texture">The custom sprite texture.</param> /// <param name="sourceRect">The custom area within the texture. </param> /// <returns>Returns true if the entity has a custom sprite, else false.</returns> private void GetSpriteSheet(Crop target, JsonAssetsIntegration jsonAssets, out Texture2D texture, out Rectangle sourceRect) { // get from Json Assets if (jsonAssets.IsLoaded && jsonAssets.TryGetCustomSpriteSheet(target, out texture, out sourceRect, currentSpriteOnly: true)) { return; } // use vanilla logic texture = Game1.cropSpriteSheet; sourceRect = this.Reflection.GetMethod(target, "getSourceRect").Invoke <Rectangle>(target.rowInSpriteSheet.Value); }
/********* ** Private methods *********/ /// <summary>Get the in-world sprite sheet for a target.</summary> /// <param name="target">The target whose texture to get.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="texture">The custom sprite texture.</param> /// <param name="sourceRect">The custom area within the texture. </param> /// <returns>Returns true if the entity has a custom sprite, else false.</returns> public void GetSpriteSheet(FruitTree target, JsonAssetsIntegration jsonAssets, out Texture2D texture, out Rectangle sourceRect) { // get from Json Assets if (jsonAssets.IsLoaded && jsonAssets.TryGetCustomSpriteSheet(target, out texture, out sourceRect)) { return; } // use vanilla logic texture = FruitTree.texture; sourceRect = new Rectangle(x: 0, y: target.treeType.Value * 5 * 16, width: 432, height: 80); }
/********* ** Private methods *********/ /// <summary>Get the in-world sprite sheet for a target.</summary> /// <param name="target">The target whose texture to get.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="texture">The custom sprite texture.</param> /// <param name="sourceRect">The custom area within the texture. </param> /// <returns>Returns true if the entity has a custom sprite, else false.</returns> public void GetSpriteSheet(Crop target, JsonAssetsIntegration jsonAssets, out Texture2D texture, out Rectangle sourceRect) { // get from Json Assets if (jsonAssets.IsLoaded && jsonAssets.TryGetCustomSpriteSheet(target, out texture, out sourceRect)) { return; } // use vanilla logic texture = Game1.cropSpriteSheet; sourceRect = new Rectangle(x: target.rowInSpriteSheet.Value % 2 * 128, y: target.rowInSpriteSheet.Value / 2 * 16 * 2, width: 128, height: 32); }
/********* ** Private methods *********/ /// <summary>Get the in-world sprite sheet for a target.</summary> /// <param name="target">The target whose texture to get.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="texture">The custom sprite texture.</param> /// <param name="sourceRect">The custom area within the texture. </param> /// <returns>Returns true if the entity has a custom sprite, else false.</returns> /// <remarks>Derived from <see cref="Crop.draw"/>.</remarks> private void GetSpriteSheet(Crop target, JsonAssetsIntegration jsonAssets, out Texture2D texture, out Rectangle sourceRect) { // get from Json Assets if (jsonAssets.IsLoaded && jsonAssets.TryGetCustomSpriteSheet(target, out texture, out sourceRect, currentSpriteOnly: true)) { return; } // use vanilla logic texture = Game1.cropSpriteSheet; sourceRect = this.Reflection.GetField <Rectangle>(target, "sourceRect").GetValue(); if (target.forageCrop.Value) { texture = Game1.mouseCursors; } }
/********* ** Private methods *********/ /**** ** Event handlers ****/ /// <summary>The method invoked on the first update tick, once all mods are initialized.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void OnGameLaunched(object sender, GameLaunchedEventArgs e) { if (!this.IsDataValid) { return; } // get mod APIs JsonAssetsIntegration jsonAssets = new JsonAssetsIntegration(this.Helper.ModRegistry, this.Monitor); // initialize functionality var customFarming = new CustomFarmingReduxIntegration(this.Helper.ModRegistry, this.Monitor); this.GameHelper = new GameHelper(customFarming, this.Metadata); this.TargetFactory = new TargetFactory(this.Helper.Reflection, this.GameHelper, jsonAssets, new SubjectFactory(this.Metadata, this.Helper.Translation, this.Helper.Reflection, this.GameHelper, this.Config)); this.DebugInterface = new DebugInterface(this.GameHelper, this.TargetFactory, this.Config, this.Monitor); }
/********* ** Private methods *********/ /**** ** Event handlers ****/ /// <summary>The method invoked on the first update tick, once all mods are initialized.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void OnGameLaunched(object sender, GameLaunchedEventArgs e) { if (!this.IsDataValid) { return; } // get mod APIs JsonAssetsIntegration jsonAssets = new JsonAssetsIntegration(this.Helper.ModRegistry, this.Monitor); // initialize functionality var customFarming = new CustomFarmingReduxIntegration(this.Helper.ModRegistry, this.Monitor); var producerFramework = new ProducerFrameworkModIntegration(this.Helper.ModRegistry, this.Monitor); this.GameHelper = new GameHelper(customFarming, producerFramework, this.Metadata, this.Helper.Reflection); this.TargetFactory = new TargetFactory(this.Helper.Reflection, this.GameHelper, this.Config, jsonAssets, () => this.Config.EnableTileLookups); this.DebugInterface = new DebugInterface(this.GameHelper, this.TargetFactory, this.Config, this.Monitor); }
/********* ** Private methods *********/ /// <summary>Get the in-world sprite sheet for a target.</summary> /// <param name="target">The target whose texture to get.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="texture">The custom sprite texture.</param> /// <param name="sourceRect">The custom area within the texture. </param> /// <returns>Returns true if the entity has a custom sprite, else false.</returns> /// <remarks>Derived from <see cref="Crop.draw"/>.</remarks> private void GetSpriteSheet(Crop target, JsonAssetsIntegration jsonAssets, out Texture2D texture, out Rectangle sourceRect) { // get from Json Assets if (jsonAssets.IsLoaded && jsonAssets.TryGetCustomSpriteSheet(target, out texture, out sourceRect, currentSpriteOnly: true)) { return; } // use vanilla logic texture = Game1.cropSpriteSheet; sourceRect = this.Reflection.GetField <Rectangle>(target, "sourceRect").GetValue(); if (target.forageCrop.Value) { texture = Game1.mouseCursors; if (target.whichForageCrop.Value == Crop.forageCrop_ginger) { sourceRect = new Rectangle(128 + (int)((Game1.currentGameTime.TotalGameTime.TotalMilliseconds + (this.Tile.X * 111f + this.Tile.Y * 77f)) % 800.0 / 200.0) * 16, 128, 16, 16); } } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="value">The underlying in-game entity.</param> /// <param name="tilePosition">The object's tile position in the current location (if applicable).</param> /// <param name="reflectionHelper">Simplifies access to private game code.</param> /// <param name="jsonAssets">The Json Assets API.</param> public CropTarget(GameHelper gameHelper, HoeDirt value, Vector2?tilePosition, IReflectionHelper reflectionHelper, JsonAssetsIntegration jsonAssets) : base(gameHelper, SubjectType.Crop, value, tilePosition) { this.Reflection = reflectionHelper; this.GetSpriteSheet(value.crop, jsonAssets, out this.Texture, out this.SourceRect); }
/********* ** Public methods *********/ /**** ** Constructors ****/ /// <summary>Construct an instance.</summary> /// <param name="reflection">Simplifies access to private game code.</param> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="config">The mod configuration.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="showRawTileInfo">Whether to show raw tile info like tilesheets and tile indexes.</param> public TargetFactory(IReflectionHelper reflection, GameHelper gameHelper, Func <ModConfig> config, JsonAssetsIntegration jsonAssets, Func <bool> showRawTileInfo) { this.GameHelper = gameHelper; ISubjectRegistry codex = this; this.LookupProviders = new ILookupProvider[] { new BuildingLookupProvider(reflection, gameHelper, codex), new CharacterLookupProvider(reflection, gameHelper, config, codex), new ItemLookupProvider(reflection, gameHelper, config, codex, jsonAssets), new TerrainFeatureLookupProvider(reflection, gameHelper, codex, jsonAssets), new TileLookupProvider(reflection, gameHelper, config, showRawTileInfo) }; }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="value">The underlying in-game entity.</param> /// <param name="jsonAssets">The Json Assets API.</param> /// <param name="tilePosition">The object's tile position in the current location (if applicable).</param> public FruitTreeTarget(GameHelper gameHelper, FruitTree value, JsonAssetsIntegration jsonAssets, Vector2?tilePosition = null) : base(gameHelper, SubjectType.FruitTree, value, tilePosition) { this.GetSpriteSheet(value, jsonAssets, out this.Texture, out this.SourceRect); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="reflection">Simplifies access to private game code.</param> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="jsonAssets">The Json Assets API.</param> public TerrainFeatureLookupProvider(IReflectionHelper reflection, GameHelper gameHelper, JsonAssetsIntegration jsonAssets) : base(reflection, gameHelper) { this.JsonAssets = jsonAssets; }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="reflection">Simplifies access to private game code.</param> /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param> /// <param name="codex">Provides subject entries.</param> /// <param name="jsonAssets">The Json Assets API.</param> public TerrainFeatureLookupProvider(IReflectionHelper reflection, GameHelper gameHelper, ISubjectRegistry codex, JsonAssetsIntegration jsonAssets) : base(reflection, gameHelper) { this.Codex = codex; this.JsonAssets = jsonAssets; }