-
Notifications
You must be signed in to change notification settings - Fork 7
/
ISprinklerProvider.cs
51 lines (46 loc) · 1.39 KB
/
ISprinklerProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Shockah.FlexibleSprinklers
{
internal interface ISprinklerProvider
{
IReadOnlySet<SprinklerInfo> GetSprinklers(GameLocation location);
}
internal sealed class ObjectSprinklerProvider : ISprinklerProvider
{
public IReadOnlySet<SprinklerInfo> GetSprinklers(GameLocation location)
{
HashSet<SprinklerInfo> results = [];
results.UnionWith(
location.Objects.Values
.Where(o => o.IsSprinkler())
.Select(ModEntry.Instance.GetSprinklerInfo)
);
results.UnionWith(
location.furniture
.Where(o => o.IsSprinkler())
.Select(ModEntry.Instance.GetSprinklerInfo)
);
return results;
}
}
internal sealed class InterceptingSprinklerProvider : ISprinklerProvider
{
private ISprinklerProvider Wrapped { get; init; }
private IEnumerable<Action<GameLocation, ISet<SprinklerInfo>>> Interceptors { get; init; }
public InterceptingSprinklerProvider(ISprinklerProvider wrapped, IEnumerable<Action<GameLocation, ISet<SprinklerInfo>>> interceptors)
{
this.Wrapped = wrapped;
this.Interceptors = interceptors;
}
public IReadOnlySet<SprinklerInfo> GetSprinklers(GameLocation location)
{
var sprinklers = Wrapped.GetSprinklers(location).ToHashSet();
foreach (var interceptor in Interceptors)
interceptor(location, sprinklers);
return sprinklers;
}
}
}