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
110 lines (98 loc) · 4.39 KB
/
Copy pathModEntry.cs
File metadata and controls
110 lines (98 loc) · 4.39 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
using System;
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
{
/*********
** Properties
*********/
/// <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();
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
LocationEvents.CurrentLocationChanged += this.LocationEvents_CurrentLocationChanged;
}
/*********
** 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 SaveEvents_AfterLoad(object sender, EventArgs e)
{
// initialise 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 LocationEvents_CurrentLocationChanged(object sender, EventArgsCurrentLocationChanged e)
{
if (!Context.IsWorldReady || Game1.eventUp || !this.Handlers.Any())
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 GameEvents_UpdateTick(object sender, EventArgs e)
{
if (!Context.IsWorldReady || 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)
{
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.EatAndDrinkSpeed > 1)
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.TreeFallSpeed > 1)
yield return new TreeFallingHandler(config.TreeFallSpeed, this.Helper.Reflection);
}
}
}