2018-12-30 18:00:05 +08:00
|
|
|
using System.Collections.Generic;
|
2017-07-30 06:02:49 +08:00
|
|
|
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
|
|
|
|
2017-07-31 11:07:07 +08:00
|
|
|
namespace Omegasis.HappyBirthday.Framework
|
2016-10-20 15:15:14 +08:00
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
/// <summary>Provides utility methods for managing in-game objects.</summary>
|
|
|
|
internal class ObjectUtility
|
2016-10-20 15:15:14 +08:00
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
/*********
|
2019-01-06 15:23:07 +08:00
|
|
|
** Fields
|
2017-07-30 06:02:49 +08:00
|
|
|
*********/
|
|
|
|
/// <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
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
if (category > 0)
|
|
|
|
yield break;
|
2016-10-20 15:15:14 +08:00
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
foreach (Object obj in ObjectUtility.ObjectList)
|
2016-10-20 15:15:14 +08:00
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
if (obj.Category == category)
|
2017-07-30 06:02:49 +08:00
|
|
|
yield return obj;
|
2016-10-20 15:15:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-30 06:02:49 +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
|
|
|
}
|
|
|
|
}
|