-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModConfig.cs
More file actions
153 lines (119 loc) · 5.35 KB
/
ModConfig.cs
File metadata and controls
153 lines (119 loc) · 5.35 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System.Reflection;
using System.Runtime.Serialization;
using ItsStardewTime.Framework;
using ItsStardewTime.Framework.Config;
using ItsStardewTime.Framework.enums;
using ItsStardewTime.Framework.enums.Extensions;
using StardewModdingAPI;
using StardewValley;
namespace ItsStardewTime
{
internal class ModConfig
{
// Speed of Time Options
/// <summary>Whether to change tick length on festival days.</summary>
public bool EnableOnFestivalDays = true;
/// <summary>Whether to show a notification about the time flow changes when you enter a location or pause.</summary>
public bool TimeFlowChangeNotifications = false;
/// <summary>The time speed for in-game locations, measured in seconds per in-game minute.</summary>
public ModSecondsPerMinuteConfig SecondsPerMinute = new();
// Freeze Time Options
/// <summary>Whether objects should pass time when game time is frozen.</summary>
public bool ObjectsPassTimeWhenTimeIsFrozen = false;
/// <summary>The mod configuration for where time should be frozen.</summary>
public ModFreezeTimeConfig FreezeTime = new();
// Clock Display
public bool DisplayEveryMinute = true;
public bool ShowPauseX = true;
public bool Use24HourFormat = false;
// Multiplayer Options
public bool DisplayVotePauseMessages = true;
public bool TimeFlowChangeNotificationsMultiplayer = false;
// Multiplayer Host Options
public PauseMode PauseMode = PauseMode.Fair;
public bool AnyCutscenePauses = true;
public bool LockMonsters = true;
public bool EnableVotePause = true;
public double VoteThresholdPercent
{
get;
set;
} = 1.0;
public TimeSpeedMode TimeSpeedMode = TimeSpeedMode.Average;
public bool RelativeTimeSpeed = true;
// Controls
/// <summary>The keyboard bindings used to control the flow of time. See available keys at <a href="https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.keys.aspx" />.</summary>
public ModControlsConfig Keys = new();
// Internal config
public bool ShouldMergePauseInMultiplayerConfigOnNextRun = true;
public bool ShouldMergeTimeSlowConfigOnNextRun = true;
/*********
** Public methods
*********/
/// <summary>Get whether time should be frozen at a given location.</summary>
/// <param name="location">The game location.</param>
private bool ShouldFreeze(GameLocation location)
{
return FreezeTime.ShouldFreeze(location);
}
/// <summary>Get whether the time should be frozen at a given time of day.</summary>
/// <param name="time">The time of day in 24-hour military format (e.g. 1600 for 8pm).</param>
private bool ShouldFreeze(int time)
{
return time >= FreezeTime.AnywhereAtTime;
}
/// <summary>Get whether the time should be frozen.</summary>
/// <param name="time">The time of day in 24-hour military format (e.g. 1600 for 8pm).</param>
/// <param name="location">The game location.</param>
public AutoFreezeReason ShouldFreeze(int time, GameLocation location)
{
if (ShouldFreeze(time))
return AutoFreezeReason.FrozenAtTime;
if (ShouldFreeze(location))
return AutoFreezeReason.FrozenForLocation;
return AutoFreezeReason.None;
}
/// <summary>Get whether time settings should be applied on a given day.</summary>
/// <param name="season">The season to check.</param>
/// <param name="dayOfMonth">The day of month to check.</param>
public bool ShouldScale(string season, int dayOfMonth)
{
Season season_number = (Season)Utility.getSeasonNumber(season);
return EnableOnFestivalDays || !Utility.isFestivalDay(dayOfMonth, season_number);
}
/// <summary>Get the number of milliseconds per 10 minutes to apply for a location.</summary>
/// <param name="location">The game location.</param>
public int GetMillisecondsPerTenMinuteInterval(GameLocation location)
{
return (int)(SecondsPerMinute.GetSecondsPerMinute(location) * 1000 * 10);
}
public void Update(ModConfig other)
{
foreach (FieldInfo field in typeof(ModConfig).GetFields())
{
field.SetValue(this, field.GetValue(other));
}
}
public double GetVoteThresholdCount(int playerCount) => Math.Ceiling(VoteThresholdPercent * playerCount);
/*********
** Private methods
*********/
/// <summary>The method called after the config file is deserialized.</summary>
/// <param name="context">The deserialization context.</param>
[OnDeserialized]
private void OnDeserializedMethod(StreamingContext context)
{
SecondsPerMinute ??= new();
FreezeTime ??= new();
Keys ??= new();
if (PauseMode.IsDeprecated())
{
PauseMode = PauseMode.Fair;
}
if (TimeSpeedMode.IsDeprecated())
{
TimeSpeedMode = TimeSpeedMode.Average;
}
}
}
}