forked from Pathoschild/StardewMods
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModEntry.cs
More file actions
124 lines (110 loc) · 5.08 KB
/
ModEntry.cs
File metadata and controls
124 lines (110 loc) · 5.08 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
using System.Collections.Generic;
using System.Linq;
using Pathoschild.Stardew.FastAnimations.Framework;
using Pathoschild.Stardew.FastAnimations.Handlers;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
namespace Pathoschild.Stardew.FastAnimations
{
/// <summary>The mod entry point.</summary>
internal class ModEntry : Mod
{
/*********
** Fields
*********/
/// <summary>The mod configuration.</summary>
private ModConfig Config;
/// <summary>The animation handlers which skip or accelerate specific animations.</summary>
private IAnimationHandler[] Handlers;
/*********
** Public methods
*********/
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
public override void Entry(IModHelper helper)
{
this.Config = helper.ReadConfig<ModConfig>();
this.Handlers = this.GetHandlers(this.Config).ToArray();
helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded;
helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
helper.Events.Player.Warped += this.OnWarped;
}
/*********
** Private methods
*********/
/****
** Events
****/
/// <summary>The method invoked after the player loads a saved game.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
{
// initialize handlers
foreach (IAnimationHandler handler in this.Handlers)
handler.OnNewLocation(Game1.currentLocation);
}
/// <summary>The method invoked after the player warps to a new location.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnWarped(object sender, WarpedEventArgs e)
{
if (!Context.IsWorldReady || Game1.eventUp || !this.Handlers.Any() || !e.IsLocalPlayer)
return;
foreach (IAnimationHandler handler in this.Handlers)
handler.OnNewLocation(e.NewLocation);
}
/// <summary>The method invoked when the player presses a keyboard button.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event data.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (Game1.eventUp || !this.Handlers.Any())
return;
int playerAnimationID = this.Helper.Reflection.GetField<int>(Game1.player.FarmerSprite, "currentSingleAnimation").GetValue();
foreach (IAnimationHandler handler in this.Handlers)
{
if (handler.IsEnabled(playerAnimationID))
{
handler.Update(playerAnimationID);
break;
}
}
}
/****
** Methods
****/
/// <summary>Get the enabled animation handlers.</summary>
private IEnumerable<IAnimationHandler> GetHandlers(ModConfig config)
{
// player animations
if (config.EatAndDrinkSpeed > 1 || config.DisableEatAndDrinkConfirmation)
yield return new EatingHandler(this.Helper.Reflection, config.EatAndDrinkSpeed, config.DisableEatAndDrinkConfirmation);
if (config.FishingSpeed > 1)
yield return new FishingHandler(config.FishingSpeed);
if (config.MilkSpeed > 1)
yield return new MilkingHandler(config.MilkSpeed);
if (config.ShearSpeed > 1)
yield return new ShearingHandler(config.ShearSpeed);
if (config.ToolSwingSpeed > 1)
yield return new ToolSwingHandler(config.ToolSwingSpeed);
if (config.WeaponSwingSpeed > 1)
yield return new WeaponSwingHandler(config.WeaponSwingSpeed);
// world animations
if (config.BreakGeodeSpeed > 1)
yield return new BreakingGeodeHandler(config.BreakGeodeSpeed);
if (config.CasinoSlotsSpeed > 1)
yield return new CasinoSlotsHandler(config.CasinoSlotsSpeed, this.Helper.Reflection);
if (config.PamBusSpeed > 1)
yield return new PamBusHandler(config.PamBusSpeed);
if (config.TreeFallSpeed > 1)
yield return new TreeFallingHandler(config.TreeFallSpeed, this.Helper.Reflection);
// UI animations
if (config.TitleMenuTransitionSpeed > 1)
yield return new TitleMenuHandler(config.TitleMenuTransitionSpeed, this.Helper.Reflection);
if (config.LoadGameBlinkSpeed > 1)
yield return new LoadGameMenuHandler(config.LoadGameBlinkSpeed, this.Helper.Reflection);
}
}
}