Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Jan 8, 2024
1 parent 0605df9 commit 5c62f7c
Show file tree
Hide file tree
Showing 15 changed files with 453 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CropStacking/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void Entry(IModHelper helper)
SHelper = helper;

helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched;
helper.Events.Input.ButtonPressed += Input_ButtonPressed;
//helper.Events.Input.ButtonPressed += Input_ButtonPressed;

var harmony = new Harmony(ModManifest.UniqueID);
harmony.PatchAll();
Expand Down
2 changes: 1 addition & 1 deletion CropsSurviveSeasonChange/CropsSurviveSeasonChange.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion CropsSurviveSeasonChange/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class ModEntry
{
private static bool CheckKill(bool outdoors, Crop crop, GameLocation environment)
{
if (!Config.ModEnabled || crop.forageCrop.Value || crop.dead.Value || (!Config.IncludeRegrowables && crop.regrowAfterHarvest.Value != -1) || (environment.GetSeasonForLocation() == "winter" && !Config.IncludeWinter))
if (!Config.ModEnabled || crop.forageCrop.Value || crop.dead.Value || (!Config.IncludeRegrowables && crop.GetData().RegrowDays != -1) || (environment.GetSeason() == Season.Winter && !Config.IncludeWinter))
{
return outdoors;
}
Expand Down
4 changes: 2 additions & 2 deletions CropsSurviveSeasonChange/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"Name": "Crops Survive Season Change",
"Author": "aedenthorn",
"Version": "0.1.2",
"Version": "0.2.0",
"Description": "Crops Survive Season Change.",
"UniqueID": "aedenthorn.CropsSurviveSeasonChange",
"EntryDll": "CropsSurviveSeasonChange.dll",
"MinimumApiVersion": "3.15.0",
"MinimumApiVersion": "3.16.0",
"ModUpdater": {
"Repository": "StardewValleyMods",
"User": "aedenthorn",
Expand Down
51 changes: 51 additions & 0 deletions GenieLamp/CodePatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using StardewValley;
using StardewValley.Extensions;
using StardewValley.GameData;
using StardewValley.ItemTypeDefinitions;
using StardewValley.Menus;
using StardewValley.Objects;
using System;
using System.Collections.Generic;
using System.Text;
using Object = StardewValley.Object;
using Rectangle = Microsoft.Xna.Framework.Rectangle;

namespace GenieLamp
{
public partial class ModEntry
{

[HarmonyPatch(typeof(Object), nameof(Object.performUseAction))]
public class Object_performUseAction_Patch
{
public static bool Prefix(Object __instance)
{
if (!Config.ModEnabled || (!__instance.Name.Equals(Config.LampItem) && !__instance.QualifiedItemId.Equals(Config.LampItem)))
return true;
int wishes = __instance.modData.TryGetValue(modKey, out var w) ? int.Parse(w) : 0;
if (wishes >= Config.WishesPerItem)
{
Game1.playSound("cancel", null);
Game1.showRedMessage(SHelper.Translation.Get("NoMoreWishes"));
return true;
}
try
{
Game1.playSound(Config.MenuSound, null);
}
catch { }
AccessTools.Method(typeof(ItemRegistry), "RebuildCache").Invoke(null, new object[0]);

Game1.activeClickableMenu = new ObjectPickMenu( new NamingMenu.doneNamingBehavior(delegate (string target)
{
SpawnItem(target);
}), string.Format(SHelper.Translation.Get("WishMenuTitle"), Config.WishesPerItem - wishes));
return false;
}
}
}
}
27 changes: 27 additions & 0 deletions GenieLamp/GenieLamp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework>net6.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<None Remove="i18n\default.json" />
</ItemGroup>
<ItemGroup>
<Content Include="i18n\default.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
</ItemGroup>

<ItemGroup>
<None Update="manifest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
82 changes: 82 additions & 0 deletions GenieLamp/IGenericModConfigMenuApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Utilities;
using StardewValley;

namespace GenieLamp
{
/// <summary>The API which lets other mods add a config UI through Generic Mod Config Menu.</summary>
public interface IGenericModConfigMenuApi
{
/*********
** Methods
*********/
/****
** Must be called first
****/
/// <summary>Register a mod whose config can be edited through the UI.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="reset">Reset the mod's config to its default values.</param>
/// <param name="save">Save the mod's current config to the <c>config.json</c> file.</param>
/// <param name="titleScreenOnly">Whether the options can only be edited from the title screen.</param>
/// <remarks>Each mod can only be registered once, unless it's deleted via <see cref="Unregister"/> before calling this again.</remarks>
void Register(IManifest mod, Action reset, Action save, bool titleScreenOnly = false);

/// <summary>Add a key binding at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddKeybind(IManifest mod, Func<SButton> getValue, Action<SButton> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);

/// <summary>Add a boolean option at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>

/// <summary>Add a key binding list at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddKeybindList(IManifest mod, Func<KeybindList> getValue, Action<KeybindList> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);

void AddBoolOption(IManifest mod, Func<bool> getValue, Action<bool> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);

/// <summary>Add an integer option at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="min">The minimum allowed value, or <c>null</c> to allow any.</param>
/// <param name="max">The maximum allowed value, or <c>null</c> to allow any.</param>
/// <param name="interval">The interval of values that can be selected.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddNumberOption(IManifest mod, Func<int> getValue, Action<int> setValue, Func<string> name, Func<string> tooltip = null, int? min = null, int? max = null, int? interval = null, string fieldId = null);

/// <summary>Add a string option at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="allowedValues">The values that can be selected, or <c>null</c> to allow any.</param>
/// <param name="formatAllowedValue">Get the display text to show for a value from <paramref name="allowedValues"/>, or <c>null</c> to show the values as-is.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddTextOption(IManifest mod, Func<string> getValue, Action<string> setValue, Func<string> name, Func<string> tooltip = null, string[] allowedValues = null, Func<string, string> formatAllowedValue = null, string fieldId = null);

/// <summary>Remove a mod from the config UI and delete all its options and pages.</summary>
/// <param name="mod">The mod's manifest.</param>
void Unregister(IManifest mod);
}
}
55 changes: 55 additions & 0 deletions GenieLamp/Methods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using HarmonyLib;
using StardewValley;
using StardewValley.ItemTypeDefinitions;
using System.Collections.Generic;

namespace GenieLamp
{
public partial class ModEntry
{

private static void SpawnItem(string target)
{
if (!string.IsNullOrEmpty(target))
{
string itemId = GetItemId(target);
if (!string.IsNullOrEmpty(itemId))
{
var item = ItemRegistry.Create(itemId, 1, 0, true);
if (item is not null)
{
int wishes = Game1.player.ActiveObject.modData.TryGetValue(modKey, out var w) ? int.Parse(w) : 0;
wishes++;
Game1.createItemDebris(item, Game1.player.Position, Game1.player.FacingDirection);
Game1.playSound(Config.WishSound, null);
if(wishes >= Config.WishesPerItem)
{
Game1.player.reduceActiveItemByOne();
if(Game1.player.ActiveObject != null)
{
Game1.player.ActiveObject.modData[modKey] = "0";
}
}
else
{
Game1.player.ActiveObject.modData[modKey] = wishes + "";
}
}
}
}
Game1.activeClickableMenu.exitThisMenu();
}

private static string GetItemId(string target)
{
var dict = AccessTools.StaticFieldRefAccess<Dictionary<string, ItemMetadata>>(typeof(ItemRegistry), "CachedItems");
foreach (var kvp in dict)
{
var data = kvp.Value.GetParsedData();
if (data.DisplayName.Equals(target))
return kvp.Key;
}
return null;
}
}
}
14 changes: 14 additions & 0 deletions GenieLamp/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using StardewModdingAPI;
using StardewModdingAPI.Utilities;

namespace GenieLamp
{
public class ModConfig
{
public bool ModEnabled { get; set; } = true;
public string LampItem { get; set; } = "Golden Mask";
public string MenuSound { get; set; } = "cowboy_explosion";
public string WishSound { get; set; } = "yoba";
public int WishesPerItem { get; set; } = 3;
}
}
100 changes: 100 additions & 0 deletions GenieLamp/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
using StardewValley.ItemTypeDefinitions;
using StardewValley.Objects;
using Object = StardewValley.Object;

namespace GenieLamp
{
/// <summary>The mod entry point.</summary>
public partial class ModEntry : Mod
{

public static IMonitor SMonitor;
public static IModHelper SHelper;
public static ModConfig Config;

public static ModEntry context;

public static string modKey = "aedenthorn.GenieLamp";


/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper)
{
Config = Helper.ReadConfig<ModConfig>();

context = this;

SMonitor = Monitor;
SHelper = helper;

helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched;
helper.Events.GameLoop.DayStarted += GameLoop_DayStarted;

var harmony = new Harmony(ModManifest.UniqueID);
harmony.PatchAll();

}

private void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStartedEventArgs e)
{
Game1.player.addItemToInventory(new Object("124", 1));
}

private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e)
{

// get Generic Mod Config Menu's API (if it's installed)
var configMenu = Helper.ModRegistry.GetApi<IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu");
if (configMenu is not null)
{

// register mod
configMenu.Register(
mod: ModManifest,
reset: () => Config = new ModConfig(),
save: () => Helper.WriteConfig(Config)
);

configMenu.AddBoolOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_ModEnabled_Name"),
getValue: () => Config.ModEnabled,
setValue: value => Config.ModEnabled = value
);

configMenu.AddTextOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_LampItem_Name"),
getValue: () => Config.LampItem,
setValue: value => Config.LampItem = value
);

configMenu.AddNumberOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_WishesPerItem_Name"),
getValue: () => Config.WishesPerItem,
setValue: value => Config.WishesPerItem = value
);

configMenu.AddTextOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_MenuSound_Name"),
getValue: () => Config.MenuSound,
setValue: value => Config.MenuSound = value
);
configMenu.AddTextOption(
mod: ModManifest,
name: () => Helper.Translation.Get("GMCM_Option_WishSound_Name"),
getValue: () => Config.WishSound,
setValue: value => Config.WishSound = value
);

}
}
}
}
Loading

0 comments on commit 5c62f7c

Please sign in to comment.