-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathModEntry.cs
152 lines (115 loc) · 5.86 KB
/
ModEntry.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
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
using StardewModdingAPI;
using StardewModdingAPI.Events;
using AccessibleTiles.Integrations;
using AccessibleTiles.Modules.GridMovement;
using StardewValley;
using System;
using AccessibleTiles.Modules.ObjectTracker;
using Microsoft.Xna.Framework.Input;
namespace AccessibleTiles {
/// <summary>The mod entry point.</summary>
public class ModEntry : Mod {
public ModConfig Config;
public ModIntegrations Integrations;
public GridMovement GridMovement;
private ObjectTracker ObjectTracker;
public Boolean IsUsingPathfinding = false;
public int? LastGridMovementDirection = null;
public InputButton? LastGridMovementButtonPressed = null;
/*********
** Public methods
*********/
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper) {
this.Config = this.Helper.ReadConfig<ModConfig>();
this.GridMovement = new GridMovement(this);
this.ObjectTracker = new ObjectTracker(this, this.Config);
helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched;
helper.Events.Input.ButtonPressed += Input_ButtonPressed;
helper.Events.Input.ButtonsChanged += Input_ButtonsChanged;
helper.Events.Player.Warped += Player_Warped;
helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded;
helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked;
}
public void Output(string text, bool say = false) {
this.Monitor.Log(text + (!say ? " (Not Read)" : ""), say ? LogLevel.Info : LogLevel.Debug);
if(say) {
Integrations.SRSay(text);
}
}
public ModConfig GetModConfig() {
return this.Config;
}
private void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e) {
if(LastGridMovementButtonPressed != null) {
SButton button = LastGridMovementButtonPressed.Value.ToSButton();
if (Game1.activeClickableMenu == null && !GridMovement.is_moving && !this.Config.GridMovementOverrideKey.IsDown() && (this.Helper.Input.IsDown(button) || this.Helper.Input.IsSuppressed(button))) {
GridMovement.HandleGridMovement(LastGridMovementDirection.Value, LastGridMovementButtonPressed.Value);
}
}
}
private void GameLoop_SaveLoaded(object sender, SaveLoadedEventArgs e) {
ObjectTracker.GetLocationObjects();
}
private void Player_Warped(object sender, WarpedEventArgs e) {
GridMovement.PlayerWarped(sender, e);
ObjectTracker.GetLocationObjects(reset_focus: true);
}
private void Input_ButtonsChanged(object sender, ButtonsChangedEventArgs e) {
if (Game1.activeClickableMenu != null) return;
if(this.Config.ToggleGridMovementKey.JustPressed()) {
this.Config.GridMovementActive = !this.Config.GridMovementActive;
string output = "Grid Movement Status: " + (this.Config.GridMovementActive ? "Active" : "Inactive");
Output(output, true);
} else {
ObjectTracker.HandleKeys(sender, e);
}
}
private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e) {
if (Game1.player.controller != null) {
if(this.Config.OTCancelAutoWalking.JustPressed()) {
Game1.player.controller.endBehaviorFunction(Game1.player, Game1.currentLocation);
}
this.Helper.Input.Suppress(e.Button);
return;
}
if (GridMovement.is_warping == true) {
this.Helper.Input.Suppress(e.Button);
}
e.Button.TryGetStardewInput(out InputButton keyboardButton);
e.Button.TryGetController(out Buttons controllerButton);
if (Game1.activeClickableMenu == null && !this.Config.GridMovementOverrideKey.IsDown()) {
if (this.Config.GridMovementActive) {
foreach (InputButton Button in Game1.options.moveUpButton) {
if (keyboardButton.Equals(Button) || controllerButton.Equals(Buttons.DPadUp)) {
GridMovement.HandleGridMovement(0, Button);
this.Helper.Input.Suppress(e.Button);
}
}
foreach (InputButton Button in Game1.options.moveRightButton) {
if (keyboardButton.Equals(Button) || controllerButton.Equals(Buttons.DPadRight)) {
GridMovement.HandleGridMovement(1, Button);
this.Helper.Input.Suppress(e.Button);
}
}
foreach (InputButton Button in Game1.options.moveDownButton) {
if (keyboardButton.Equals(Button) || controllerButton.Equals(Buttons.DPadDown)) {
GridMovement.HandleGridMovement(2, Button);
this.Helper.Input.Suppress(e.Button);
}
}
foreach (InputButton Button in Game1.options.moveLeftButton) {
if (keyboardButton.Equals(Button) || controllerButton.Equals(Buttons.DPadLeft)) {
GridMovement.HandleGridMovement(3, Button);
this.Helper.Input.Suppress(e.Button);
}
}
}
}
}
private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e) {
this.Integrations = new ModIntegrations(this);
}
}
}