Repository navigation
Expand file tree
/
Copy pathGroupSizeController.cs
More file actions
125 lines (110 loc) · 4.09 KB
/
Copy pathGroupSizeController.cs
File metadata and controls
125 lines (110 loc) · 4.09 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using Kitchen;
using KitchenData;
using Unity.Entities;
namespace KitchenCustomDifficulty
{
[UpdateAfter(typeof(StartNewDay))]
[UpdateInGroup(typeof(TimeManagementGroup))]
internal class GroupSizeController : NightSystem
{
private struct SCacheGroupSize : IComponentData
{
public int Min;
public int Max;
}
private static bool usingCustom = false;
private static GroupSizeController instance;
protected override void Initialise()
{
base.Initialise();
instance = this;
}
protected override void OnUpdate()
{
}
private void _SetCustomGroupSizes()
{
if (Require(out SKitchenParameters sKitchenParameters))
{
int minGroupSize = sKitchenParameters.Parameters.MinimumGroupSize;
int maxGroupSize = sKitchenParameters.Parameters.MaximumGroupSize;
int minGroupSizePref = Main.PrefSysManager.Get<int>(Main.CUSTOMERS_MIN_GROUP_SIZE_ID);
int maxGroupSizePref = Main.PrefSysManager.Get<int>(Main.CUSTOMERS_MAX_GROUP_SIZE_ID);
switch (minGroupSizePref)
{
case -2:
break;
case -1:
minGroupSize = Main.DefaultValuesDict[Main.CUSTOMERS_MIN_GROUP_SIZE_ID];
break;
default:
minGroupSize = minGroupSizePref;
break;
}
switch (maxGroupSizePref)
{
case -2:
break;
case -1:
maxGroupSize = Main.DefaultValuesDict[Main.CUSTOMERS_MAX_GROUP_SIZE_ID];
break;
default:
maxGroupSize = maxGroupSizePref;
break;
}
if (maxGroupSize < minGroupSize)
maxGroupSize = minGroupSize;
sKitchenParameters.Parameters.MinimumGroupSize = minGroupSize;
sKitchenParameters.Parameters.MaximumGroupSize = maxGroupSize;
Set(sKitchenParameters);
}
}
private void _ResetKitchenParameters()
{
if (Has<SKitchenParameters>())
{
SKitchenParameters sKitchenParameters = GetOrDefault<SKitchenParameters>();
if (TryGetSingleton(out SCacheGroupSize cache))
{
sKitchenParameters.Parameters.MinimumGroupSize = cache.Min;
sKitchenParameters.Parameters.MaximumGroupSize = cache.Max;
Set(sKitchenParameters);
}
}
}
private void _CacheKitchenParameters()
{
if (!usingCustom)
{
SKitchenParameters sKitchenParameters = GetOrDefault<SKitchenParameters>();
Set(new SCacheGroupSize
{
Min = sKitchenParameters.Parameters.MinimumGroupSize,
Max = sKitchenParameters.Parameters.MaximumGroupSize
});
}
}
private void _UpdateCacheOnParameterChange(ParameterEffect parameterEffect)
{
SCacheGroupSize cache = GetOrDefault<SCacheGroupSize>();
cache.Min += parameterEffect.Parameters.MinimumGroupSize;
cache.Max += parameterEffect.Parameters.MaximumGroupSize;
Set(cache);
}
public static void UseCustomKitchenParameters()
{
instance._CacheKitchenParameters();
usingCustom = true;
instance._SetCustomGroupSizes();
}
public static void ResetKitchenParameters()
{
instance._ResetKitchenParameters();
usingCustom = false;
}
public static void HandleVanillaParameterChange(ParameterEffect parameterEffect)
{
instance._UpdateCacheOnParameterChange(parameterEffect);
}
}
}