Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Common/Common.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@
<Compile Include="$(MSBuildThisFileDirectory)Integrations\BushBloomMod\BushBloomModIntegration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\BushBloomMod\IBushBloomModApi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\CustomBush\CustomBushIntegration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)integrations\custombush\CustomBushType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\CustomBush\ICustomBush.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\CustomBush\ICustomBushApi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)integrations\custombush\ICustomBushData.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\CustomBush\ICustomBushDrop.cs" />
<Compile Include="$(MSBuildThisFileDirectory)integrations\custombush\ICustomBushDrops.cs" />
<Compile Include="$(MSBuildThisFileDirectory)integrations\custombush\ICustomBushProgressRule.cs" />
<Compile Include="$(MSBuildThisFileDirectory)integrations\custombush\ICustomBushProgressRules.cs" />
<Compile Include="$(MSBuildThisFileDirectory)integrations\custombush\ICustomBushStage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)integrations\custombush\ICustomBushStages.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\CustomFarmingRedux\CustomFarmingReduxIntegration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\CustomFarmingRedux\ICustomFarmingApi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integrations\ExtraMachineConfig\ExtraMachineConfigIntegration.cs" />
Expand Down
16 changes: 15 additions & 1 deletion Common/Integrations/CustomBush/CustomBushIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI;
using StardewValley.TerrainFeatures;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

Expand All @@ -12,5 +15,16 @@ internal class CustomBushIntegration : BaseIntegration<ICustomBushApi>
/// <param name="modRegistry">An API for fetching metadata about loaded mods.</param>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
public CustomBushIntegration(IModRegistry modRegistry, IMonitor monitor)
: base("CustomBush", "furyx639.CustomBush", "1.2.0", modRegistry, monitor) { }
: base("CustomBush", "furyx639.CustomBush", "2.0.0-beta.1", modRegistry, monitor) { }

/// <summary>Try to get the custom bush model associated with the given bush.</summary>
/// <param name="bush">The bush to check.</param>
/// <param name="customBush">The resulting custom bush, if applicable.</param>
/// <returns>True if the custom bush associated with the given bush is found.</returns>
public bool TryGetBush(Bush bush, [NotNullWhen(true)] out ICustomBush? customBush)
{
customBush = null;

return this.IsLoaded && this.ModApi.TryGetBush(bush, out customBush);
}
}
22 changes: 22 additions & 0 deletions Common/Integrations/CustomBush/CustomBushType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using StardewValley.TerrainFeatures;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <summary>Represents the bush types.</summary>
public enum CustomBushType
{
/// <summary>Small bush</summary>
Small = Bush.smallBush,

/// <summary>Medium bush</summary>
Medium = Bush.mediumBush,

/// <summary>Large bush</summary>
Large = Bush.largeBush,

/// <summary>Tea bush</summary>
Tea = Bush.greenTeaBush,

/// <summary>Walnut bush</summary>
Walnut = Bush.walnutBush
}
56 changes: 35 additions & 21 deletions Common/Integrations/CustomBush/ICustomBush.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics.CodeAnalysis;
using StardewValley;
using StardewValley.GameData;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <summary>Model used for custom bushes.</summary>
/// <summary>Represents a distinct instance of a custom bush.</summary>
public interface ICustomBush
{
/// <summary>Gets the age needed to produce.</summary>
int AgeToProduce { get; }
/// <summary>Gets the condition pertaining to the bush's current season.</summary>
public string? Condition { get; }

/// <summary>Gets the day of month to begin producing.</summary>
int DayToBeginProducing { get; }
/// <summary>Gets the bush data.</summary>
public ICustomBushData Data { get; }

/// <summary>Gets the description of the bush.</summary>
string Description { get; }
/// <summary>Gets the custom bush's id.</summary>
public string Id { get; }

/// <summary>Gets the display name of the bush.</summary>
string DisplayName { get; }
/// <summary>Gets a value indicating whether the bush is in season.</summary>
public bool IsInSeason { get; }

/// <summary>Gets the default texture used when planted indoors.</summary>
string IndoorTexture { get; }
/// <summary>Gets the current shake off item (if any).</summary>
public Item? Item { get; }

/// <summary>Gets the season in which this bush will produce its drops.</summary>
List<Season> Seasons { get; }
/// <summary>Gets an offset to the bush sprite.</summary>
public int SpriteOffset { get; }

/// <summary>Gets the rules which override the locations that custom bushes can be planted in.</summary>
List<PlantableRule> PlantableLocationRules { get; }
/// <summary>Gets the current bush stage.</summary>
public ICustomBushStage Stage { get; }

/// <summary>Gets the texture of the tea bush.</summary>
string Texture { get; }
/// <summary>Gets the number of counted days in the stage.</summary>
public int StageCounter { get; }

/// <summary>Gets the row index for the custom bush's sprites.</summary>
int TextureSpriteRow { get; }
/// <summary>Gets the bush's stage id.</summary>
public string StageId { get; }

/// <summary>Gets the bush's texture.</summary>
public Texture2D Texture { get; }

/// <summary>Tests a Game State Query condition, passing the relevant parameters.</summary>
/// <param name="condition">The condition to test.</param>
/// <returns>True if the condition is null or empty, or if the condition passes.</returns>
bool TestCondition(string? condition);

/// <summary>Try to produce an item drop.</summary>
/// <param name="drop">The drop to produce.</param>
/// <param name="item">The item produced from the drop.</param>
/// <returns>True if the drop could be produced.</returns>
bool TryProduceDrop(ICustomBushDrop drop, [NotNullWhen(true)] out Item? item);
}
31 changes: 14 additions & 17 deletions Common/Integrations/CustomBush/ICustomBushApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using StardewValley.TerrainFeatures;

Expand All @@ -8,22 +7,20 @@ namespace Pathoschild.Stardew.Common.Integrations.CustomBush;
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "The naming convention is defined by the Custom Bush mod.")]
public interface ICustomBushApi
{
/// <summary>Try to get the custom bush model associated with the given bush.</summary>
/// <param name="bush">The bush.</param>
/// <param name="customBush">When this method returns, contains the custom bush associated with the given bush, if found; otherwise, it contains null.</param>
/// <returns>True if the custom bush associated with the given bush is found; otherwise, false.</returns>
bool TryGetCustomBush(Bush bush, out ICustomBush? customBush);
/// <summary>Determine if the bush is a custom bush.</summary>
/// <param name="bush">The bush to check.</param>
/// <returns>True if the bush is a custom bush.</returns>
public bool IsCustomBush(Bush bush);

/// <summary>Try to get the custom bush model and id associated with the given bush.</summary>
/// <param name="bush">The bush.</param>
/// <param name="customBush">When this method returns, contains the custom bush associated with the given bush, if found; otherwise, it contains null.</param>
/// <param name="id">The internal bush ID.</param>
/// <returns>True if the custom bush associated with the given bush is found; otherwise, false.</returns>
bool TryGetCustomBush(Bush bush, out ICustomBush? customBush, [NotNullWhen(true)] out string? id);
/// <summary>Try to get the custom bush instance associated with the given bush.</summary>
/// <param name="bush">The bush to check.</param>
/// <param name="customBush">The resulting custom bush, if applicable.</param>
/// <returns>True if a custom bush was found.</returns>
public bool TryGetBush(Bush bush, [NotNullWhen(true)] out ICustomBush? customBush);

/// <summary>Try to get the custom bush drop associated with the given bush id.</summary>
/// <param name="id">The id of the bush.</param>
/// <param name="drops">When this method returns, contains the items produced by the custom bush.</param>
/// <returns>True if the drops associated with the given id is found; otherwise, false.</returns>
bool TryGetDrops(string id, [NotNullWhen(true)] out IList<ICustomBushDrop>? drops);
/// <summary>Try to get the custom bush model associated with the given bush.</summary>
/// <param name="bush">The bush to check.</param>
/// <param name="customBushData">The resulting custom bush, if applicable.</param>
/// <returns>True if a custom bush was found.</returns>
public bool TryGetData(Bush bush, [NotNullWhen(true)] out ICustomBushData? customBushData);
}
38 changes: 38 additions & 0 deletions Common/Integrations/CustomBush/ICustomBushData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using StardewValley;
using StardewValley.GameData;
using System.Collections.Generic;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <summary>Model used for custom bush data.</summary>
public interface ICustomBushData
{
/// <summary>Gets a list of conditions where any have to match for the bush to produce items.</summary>
public List<string> ConditionsToProduce { get; }

/// <summary>Gets the description of the bush.</summary>
public string Description { get; }

/// <summary>Gets the display name of the bush.</summary>
public string DisplayName { get; }

/// <summary>Gets a unique identifier for the custom bush.</summary>
public string Id { get; }

/// <summary>Gets the initial bush stage.</summary>
public string InitialStage { get; }

/// <summary>Gets the rules which override the locations that custom bushes can be planted in.</summary>
public List<PlantableRule> PlantableLocationRules { get; }

/// <summary>Gets all the growth stages.</summary>
public ICustomBushStages Stages { get; }

/// <summary>Try to get the age to mature.</summary>
/// <returns>The age in which <see cref="ConditionsToProduce"/> will return true; otherwise, 0.</returns>
public int GetAgeToMature();

/// <summary>Try to get the seasons.</summary>
/// <returns>The seasons in which <see cref="ConditionsToProduce" /> will return true.</returns>
public List<Season> GetSeasons();
}
25 changes: 16 additions & 9 deletions Common/Integrations/CustomBush/ICustomBushDrop.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
using StardewValley;
using StardewValley.GameData;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <summary>An item produced by a Custom Bush bush.</summary>
public interface ICustomBushDrop : ISpawnItemData
{
/// <summary>Gets the specific season when the item can be produced.</summary>
Season? Season { get; }
/// <summary>A game state query which indicates whether the item should be added. Defaults to always added.</summary>
public string? Condition { get; }

/// <summary>Gets the probability that the item will be produced.</summary>
float Chance { get; }
/// <summary>Gets a unique ID for this entry within the current list.</summary>
public string? Id { get; }

/// <summary>A game state query which indicates whether the item should be added. Defaults to always added.</summary>
string? Condition { get; }
/// <summary>Gets a value indicating whether the drop can replace an existing item.</summary>
public bool ReplaceItem { get; }

/// <summary>Gets an offset to the bush sprite when this item is produced.</summary>
public int SpriteOffset { get; }

/// <summary>Try to get the chance for the drop based on its condition.</summary>
/// <returns>Returns the chance of the drop being produced.</returns>
public float GetChance();

/// <summary>An ID for this entry within the current list (not the item itself, which is <see cref="P:StardewValley.GameData.GenericSpawnItemData.ItemId" />). This only needs to be unique within the current list. For a custom entry, you should use a globally unique ID which includes your mod ID like <c>ExampleMod.Id_ItemName</c>.</summary>
string? Id { get; }
/// <summary>Try to get the earliest day for the drop based on its condition.</summary>
/// <returns>Returns the first day of the drop being produced.</returns>
public int GetDay();
}
8 changes: 8 additions & 0 deletions Common/Integrations/CustomBush/ICustomBushDrops.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <summary>Model used for the collection of custom bush drops.</summary>
public interface ICustomBushDrops : IList<ICustomBushDrop>
{
}
21 changes: 21 additions & 0 deletions Common/Integrations/CustomBush/ICustomBushProgressRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <summary>Represents rules for a custom bush to progress into a different stage.</summary>
public interface ICustomBushProgressRule
{
/// <summary>A game state query which determines whether the bush should grow to the indicated stage.</summary>
public string? Condition { get; }

/// <summary>Gets a unique ID for this entry within the current list.</summary>
public string? Id { get; }

/// <summary>Gets the items dropped when the conditions for this rule are met.</summary>
public ICustomBushDrops ItemsDropped { get; }

/// <summary>Gets the stage that the bush should grow to.</summary>
public string StageId { get; }

/// <summary>Get the stage counter condition for this rule.</summary>
/// <returns>Returns the stage counter.</returns>
public int GetStageCounter();
}
12 changes: 12 additions & 0 deletions Common/Integrations/CustomBush/ICustomBushProgressRules.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <inheritdoc />
public interface ICustomBushProgressRules : IList<ICustomBushProgressRule>
{
/// <summary>Try to get the minimum stage counter for any condition with the given stage id.</summary>
/// <param name="id">The stage id, or any.</param>
/// <returns>Returns the stage counter or -1 if the stage id cannot be reached.</returns>
public int GetCounterTo(string? id);
}
28 changes: 28 additions & 0 deletions Common/Integrations/CustomBush/ICustomBushStage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.Xna.Framework;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <summary>Represents a stage that a custom bush can change into.</summary>
public interface ICustomBushStage
{
/// <summary>Gets the bush type for the growth stage.</summary>
public CustomBushType BushType { get; }

/// <summary>A game state query which indicates whether the bush should increment the days in its current stage.</summary>
public string? ConditionToProgress { get; }

/// <summary>Gets the default texture used when planted indoors.</summary>
public string IndoorTexture { get; }

/// <summary>Gets or sets the items produced by this custom bush.</summary>
public ICustomBushDrops ItemsProduced { get; }

/// <summary>Gets the rules for progressing.</summary>
public ICustomBushProgressRules ProgressRules { get; }

/// <summary>Gets the coordinates for the sprite at this stage.</summary>
public Point SpritePosition { get; }

/// <summary>Gets the texture of the tea bush.</summary>
public string Texture { get; }
}
11 changes: 11 additions & 0 deletions Common/Integrations/CustomBush/ICustomBushStages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace Pathoschild.Stardew.Common.Integrations.CustomBush;

/// <inheritdoc />
public interface ICustomBushStages : IDictionary<string, ICustomBushStage>
{
/// <summary>Try to get sequential stages starting from an initial stage.</summary>
/// <returns>Stages that go from initial to last without any repeated elements.</returns>
public IEnumerable<(ICustomBushStage Stage, string Id, int Counter)> GetSequentialStages();
}
Loading