forked from aedenthorn/StardewValleyMods
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29f64fc
commit 7b9cb36
Showing
27 changed files
with
1,012 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using StardewValley; | ||
using StardewValley.Buildings; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace CustomFarmBuildings | ||
{ | ||
/// <summary>The mod entry point.</summary> | ||
public partial class ModEntry | ||
{ | ||
private static void Building_prefix(Building __instance, BluePrint blueprint, Vector2 tileLocation) | ||
{ | ||
if (!Config.EnableMod || !buildingDict.TryGetValue(blueprint.name, out CustomBuildingData data)) | ||
return; | ||
|
||
__instance.tilesWide.Value = data.width; | ||
__instance.tilesHigh.Value = data.height; | ||
__instance.humanDoor.Value = ; | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.Xna.Framework; | ||
using System.Collections.Generic; | ||
|
||
namespace CustomFarmBuildings | ||
{ | ||
public class CustomBuildingData | ||
{ | ||
public string name; | ||
public string description; | ||
public string mapPath; | ||
public string texturePath; | ||
public int width; | ||
public int height; | ||
public Point humanDoor; | ||
public Point animalDoor; | ||
public int maxOccupants; | ||
public int daysToConstruct; | ||
public bool magical; | ||
public bool decoratable; | ||
public int cost; | ||
public List<MaterialData> materials = new List<MaterialData>(); | ||
} | ||
|
||
public class MaterialData | ||
{ | ||
public string id; | ||
public int amount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Version>1.0.0</Version> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<EnableHarmony>true</EnableHarmony> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="assets\backs.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="assets\cards.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="assets\numbers.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="manifest.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using StardewModdingAPI; | ||
using System; | ||
|
||
namespace CustomFarmBuildings | ||
{ | ||
/// <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 section title at the current position in the form.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="text">The title text shown in the form.</param> | ||
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the title, or <c>null</c> to disable the tooltip.</param> | ||
void AddSectionTitle(IManifest mod, Func<string> text, Func<string> tooltip = null); | ||
|
||
/// <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> | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
| ||
using StardewModdingAPI; | ||
using StardewModdingAPI.Utilities; | ||
|
||
namespace CustomFarmBuildings | ||
{ | ||
public class ModConfig | ||
{ | ||
public bool EnableMod { get; set; } = true; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using HarmonyLib; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using StardewModdingAPI; | ||
using StardewValley; | ||
using StardewValley.Buildings; | ||
using System.Collections.Generic; | ||
|
||
namespace CustomFarmBuildings | ||
{ | ||
/// <summary>The mod entry point.</summary> | ||
public partial class ModEntry : Mod, IAssetLoader | ||
{ | ||
|
||
public static IMonitor SMonitor; | ||
public static IModHelper SHelper; | ||
public static ModConfig Config; | ||
|
||
public static ModEntry context; | ||
public static readonly string dictPath = "Mods/aedenthorn.CustomFarmBuildings/dict"; | ||
public static Dictionary<string, CustomBuildingData> buildingDict = new Dictionary<string, CustomBuildingData>(); | ||
|
||
/// <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.SaveLoaded += GameLoop_SaveLoaded; | ||
|
||
|
||
var harmony = new Harmony(ModManifest.UniqueID); | ||
|
||
harmony.Patch( | ||
original: AccessTools.Constructor(typeof(Building), new System.Type[] { typeof(BluePrint), typeof(Vector2) }), | ||
prefix: new HarmonyMethod(typeof(ModEntry), nameof(ModEntry.Building_prefix)) | ||
); | ||
} | ||
|
||
private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e) | ||
{ | ||
buildingDict = Helper.Content.Load<Dictionary<string, CustomBuildingData>>(dictPath, ContentSource.GameContent); | ||
|
||
Monitor.Log($"Loaded {buildingDict.Count} building templates"); | ||
} | ||
|
||
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: () => "Mod Enabled", | ||
getValue: () => Config.EnableMod, | ||
setValue: value => Config.EnableMod = value | ||
); | ||
} | ||
|
||
} | ||
|
||
/// <summary>Get whether this instance can load the initial version of the given asset.</summary> | ||
/// <param name="asset">Basic metadata about the asset being loaded.</param> | ||
public bool CanLoad<T>(IAssetInfo asset) | ||
{ | ||
if (!Config.EnableMod) | ||
return false; | ||
|
||
return asset.AssetNameEquals(dictPath); | ||
} | ||
|
||
/// <summary>Load a matched asset.</summary> | ||
/// <param name="asset">Basic metadata about the asset being loaded.</param> | ||
public T Load<T>(IAssetInfo asset) | ||
{ | ||
Monitor.Log("Loading dictionary"); | ||
|
||
return (T)(object)new Dictionary<string, CustomBuildingData>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"Name": "Custom Farm Buildings", | ||
"Author": "aedenthorn", | ||
"Version": "0.1.0", | ||
"Description": "Custom Farm Buildings.", | ||
"UniqueID": "aedenthorn.CustomFarmBuildings", | ||
"EntryDll": "CustomFarmBuildings.dll", | ||
"MinimumApiVersion": "3.13.0", | ||
"ModUpdater": { | ||
"Repository": "StardewValleyMods", | ||
"User": "aedenthorn", | ||
"Directory": "_releases", | ||
"ModFolder": "CustomFarmBuildings" | ||
}, | ||
"UpdateKeys": [ "Nexus:" ], | ||
"Dependencies": [ | ||
{ | ||
"UniqueID": "Platonymous.ModUpdater", | ||
"IsRequired": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.