-
-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathGroupStats.cs
66 lines (52 loc) · 2.14 KB
/
GroupStats.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Linq;
using Microsoft.Xna.Framework;
using Pathoschild.Stardew.Automate.Framework.Storage;
namespace Pathoschild.Stardew.Automate.Framework.Commands.Summary;
/// <summary>Metadata about a machine group in a location.</summary>
internal class GroupStats
{
/*********
** Accessors
*********/
/// <summary>A human-readable name for the group.</summary>
public string Name { get; }
/// <summary>The machine types in the group.</summary>
public GroupMachineStats[] Machines { get; }
/// <summary>The container types in the group.</summary>
public GroupContainerStats[] Containers { get; }
/// <summary>Whether this group represents all the chests connected to a Junimo chest.</summary>
public bool IsJunimoGroup { get; }
/// <summary>The underlying machine group.</summary>
public IMachineGroup MachineGroup { get; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="machineGroup">The machine group to analyze.</param>
public GroupStats(IMachineGroup machineGroup)
{
this.MachineGroup = machineGroup;
if (machineGroup.IsGlobalGroup)
this.Name = "Distributed group";
else
{
Vector2 tile = machineGroup.GetTiles(machineGroup.LocationKey).FirstOrDefault();
this.Name = $"Group at ({tile.X}, {tile.Y})";
}
this.IsJunimoGroup = machineGroup.IsGlobalGroup;
this.Machines = machineGroup.Machines
.GroupBy(p => p.MachineTypeID)
.Select(p => new GroupMachineStats(p.Key, p))
.ToArray();
this.Containers =
(
from container in machineGroup.Containers
let storage = container.GetStoragePreference()
let takeItems = container.GetTakingItemsPreference()
group container by new { container.Name, storage, takeItems } into containerGroup
let key = containerGroup.Key
select new GroupContainerStats(key.Name, key.storage, key.takeItems, containerGroup.ToArray())
)
.ToArray();
}
}