Stardew_Valley_Mods/GeneralMods/HappyBirthday/Framework/ObjectUtility.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2017-07-28 08:28:39 +08:00
using System.Collections.Generic;
using System.Linq;
2017-07-28 08:28:39 +08:00
using StardewValley;
using Object = StardewValley.Object;
2016-10-20 15:15:14 +08:00
namespace Omegasis.HappyBirthday.Framework
2016-10-20 15:15:14 +08:00
{
/// <summary>Provides utility methods for managing in-game objects.</summary>
internal class ObjectUtility
2016-10-20 15:15:14 +08:00
{
/*********
** Properties
*********/
/// <summary>The cached object data.</summary>
private static readonly Object[] ObjectList = ObjectUtility.GetAllObjects().ToArray();
/*********
** Public methods
*********/
/// <summary>Get objects with the given category.</summary>
/// <param name="category">The category for which to find objects.</param>
public static IEnumerable<Object> GetObjectsInCategory(int category)
2016-10-20 15:15:14 +08:00
{
if (category > 0)
yield break;
2016-10-20 15:15:14 +08:00
foreach (Object obj in ObjectUtility.ObjectList)
2016-10-20 15:15:14 +08:00
{
if (obj.category == category)
yield return obj;
2016-10-20 15:15:14 +08:00
}
}
/*********
** Private methods
*********/
/// <summary>Get all objects defined by the game.</summary>
private static IEnumerable<Object> GetAllObjects()
{
foreach (int key in Game1.content.Load<Dictionary<int, string>>("Data\\ObjectInformation").Keys)
yield return new Object(key, 1);
}
2016-10-20 15:15:14 +08:00
}
}