Added in file loading for birthday gifts.
This commit is contained in:
parent
222c1e49e5
commit
75a70a9f78
|
@ -1,5 +1,4 @@
|
|||
|
||||
using StardewValley;
|
||||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
|
@ -89,20 +89,48 @@ namespace Omegasis.HappyBirthday
|
|||
public GiftManager()
|
||||
{
|
||||
this.BirthdayGifts = new List<Item>();
|
||||
this.loadVillagerBirthdayGifts();
|
||||
}
|
||||
|
||||
public void loadVillagerBirthdayGifts()
|
||||
/// <summary>
|
||||
/// Load birthday gift information from disk. Preferably from BirthdayGift.json in the mod's directory.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string,string> loadVillagerBirthdayGifts()
|
||||
{
|
||||
if (File.Exists("BirthdayGifts.json"))
|
||||
if (HappyBirthday.Config.useLegacyBirthdayFiles == false)
|
||||
{
|
||||
|
||||
if (File.Exists("BirthdayGifts.json"))
|
||||
{
|
||||
HappyBirthday.ModMonitor.Log("Load from BirthdayGifts.json");
|
||||
this.defaultBirthdayGifts = HappyBirthday.ModHelper.Data.ReadJsonFile<Dictionary<string, string>>(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "BirthdayGifts.json"));
|
||||
return this.defaultBirthdayGifts;
|
||||
}
|
||||
else
|
||||
{
|
||||
HappyBirthday.ModMonitor.Log("BirthdayGifts.json created from default birthday gift information and can be overridden.");
|
||||
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "BirthdayGifts.json"), this.defaultBirthdayGifts);
|
||||
return defaultBirthdayGifts;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(HappyBirthday.ModHelper.DirectoryPath, this.defaultBirthdayGifts);
|
||||
|
||||
if (File.Exists(Path.Combine(Game1.content.RootDirectory, "Data", "PossibleBirthdayGifts.xnb"))){
|
||||
HappyBirthday.ModMonitor.Log("Legacy loading detected. Attempting to load from StardewValley/Content/Data/PossibleBirthdayGifts.xnb");
|
||||
this.defaultBirthdayGifts = Game1.content.Load<Dictionary<string, string>>(Path.Combine("Data", "PossibleBirthdayGifts"));
|
||||
return this.defaultBirthdayGifts;
|
||||
}
|
||||
else
|
||||
{
|
||||
HappyBirthday.ModMonitor.Log("No birthday gift information found. Loading from internal birthday list");
|
||||
return this.defaultBirthdayGifts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>Get the default gift items.</summary>
|
||||
|
@ -113,7 +141,7 @@ namespace Omegasis.HappyBirthday
|
|||
try
|
||||
{
|
||||
// read from birthday gifts file
|
||||
IDictionary<string, string> data = Game1.content.Load<Dictionary<string, string>>("Data\\BirthdayGifts");
|
||||
IDictionary<string, string> data = loadVillagerBirthdayGifts();
|
||||
data.TryGetValue(name, out string text);
|
||||
if (text != null)
|
||||
{
|
||||
|
|
|
@ -64,8 +64,16 @@ namespace Omegasis.HappyBirthday
|
|||
|
||||
public static IModHelper ModHelper;
|
||||
|
||||
public static IMonitor ModMonitor;
|
||||
|
||||
/// <summary>
|
||||
/// Class to handle all birthday messages for this mod.
|
||||
/// </summary>
|
||||
public BirthdayMessages messages;
|
||||
|
||||
/// <summary>
|
||||
/// Class to handle all birthday gifts for this mod.
|
||||
/// </summary>
|
||||
public GiftManager giftManager;
|
||||
|
||||
/*********
|
||||
|
@ -89,6 +97,7 @@ namespace Omegasis.HappyBirthday
|
|||
StardewModdingAPI.Events.GraphicsEvents.OnPostRenderHudEvent += GraphicsEvents_OnPostRenderHudEvent; ;
|
||||
//MultiplayerSupport.initializeMultiplayerSupport();
|
||||
ModHelper = Helper;
|
||||
ModMonitor = Monitor;
|
||||
|
||||
messages = new BirthdayMessages();
|
||||
giftManager = new GiftManager();
|
||||
|
@ -137,6 +146,10 @@ namespace Omegasis.HappyBirthday
|
|||
private void GraphicsEvents_OnPostRenderGuiEvent(object sender, EventArgs e)
|
||||
{
|
||||
if (Game1.activeClickableMenu == null) return;
|
||||
//Don't do anything if birthday has not been chosen yet.
|
||||
if (PlayerData == null) return;
|
||||
if (PlayerData.BirthdaySeason == null || PlayerData.BirthdayDay==0) return;
|
||||
|
||||
if (PlayerData.BirthdaySeason.ToLower() != Game1.currentSeason.ToLower()) return;
|
||||
if (Game1.activeClickableMenu is Billboard)
|
||||
{
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
<Compile Include="HappyBirthday.cs" />
|
||||
<Compile Include="Framework\Messages.cs" />
|
||||
<Compile Include="Framework\ObjectUtility.cs" />
|
||||
<Compile Include="PossibleGifts.cs" />
|
||||
<Compile Include="GiftManager.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue