Skip to content

Commit

Permalink
Update TillableGround
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkfalcon committed Aug 26, 2018
1 parent e19056f commit 6aaed56
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
8 changes: 6 additions & 2 deletions TillableGround/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace TillableGround {
using StardewModdingAPI;

namespace TillableGround {
class ModConfig {
public bool TillAnywhere { get; set; } = false;
public bool AllowTillingAnywhere { get; set; } = false;
public SButton AllowTillingKeybind { get; set; } = SButton.H;
public SButton PreventTillingKeybind { get; set; } = SButton.U;
}
}
32 changes: 21 additions & 11 deletions TillableGround/TillableGround.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using StardewValley;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using xTile.Layers;
using xTile.Tiles;

namespace TillableGround {
public class TillableGround : Mod {
Expand All @@ -11,7 +13,7 @@ public class TillableGround : Mod {
public override void Entry(IModHelper helper) {
Config = Helper.ReadConfig<ModConfig>();

if (Config.TillAnywhere) {
if (Config.AllowTillingAnywhere) {
InputEvents.ButtonReleased += InputEvents_ButtonReleased;
}
else {
Expand All @@ -21,14 +23,16 @@ public override void Entry(IModHelper helper) {

void InputEvents_ButtonPressed( object sender, EventArgsInput e ) {
if (!Context.IsWorldReady) { return; }

if (e.Button == SButton.H) {
Vector2 tile = e.Cursor.Tile;
int x = (int)tile.X, y = (int)tile.Y;
if (Utility.tileWithinRadiusOfPlayer(x, y, 1, Game1.player)) {
SetTileTillable(x, y);
FancyTillFeedback(x, y);
}

Vector2 tile = e.Cursor.Tile;
int x = (int)tile.X, y = (int)tile.Y;
if (e.Button == Config.AllowTillingKeybind) {
SetTileTillable(x, y);
FancyTillFeedback(x, y, "Tillable");
}
else if (e.Button == Config.PreventTillingKeybind) {
SetTileUntillable(x, y);
FancyTillFeedback(x, y, "Untillable");
}
}

Expand All @@ -45,6 +49,12 @@ public void SetTileTillable(int x, int y) {
Game1.currentLocation.setTileProperty(x, y, "Back", "Diggable", "T");
}

public void SetTileUntillable(int x, int y) {
Layer layer = Game1.currentLocation.map.GetLayer("Back");
Tile tile = layer.PickTile(new xTile.Dimensions.Location(x, y) * Game1.tileSize, Game1.viewport.Size);
tile.Properties.Remove("Diggable");
}

public List<Vector2> GetHoedTiles() {
Farmer player = Game1.player;
Vector2 vector = player.GetToolLocation(false);
Expand All @@ -54,14 +64,14 @@ public List<Vector2> GetHoedTiles() {
Invoke<List<Vector2>>(offset, player.toolPower, player);
}

public void FancyTillFeedback(int x, int y) {
public void FancyTillFeedback(int x, int y, string message) {
// Add the hoe animation without hoeing
Game1.currentLocation.temporarySprites.Add(
new TemporaryAnimatedSprite(12, new Vector2(x * 64f, y * 64f), Color.White, 8,
Game1.random.NextDouble() < 0.5, 50f, 0, -1, -1f, -1, 0)
);

Game1.addHUDMessage(new HUDMessage("Made tile tillable", 3) {
Game1.addHUDMessage(new HUDMessage("Made tile " + message, 3) {
noIcon = true,
timeLeft = HUDMessage.defaultTime / 4
});
Expand Down
2 changes: 1 addition & 1 deletion TillableGround/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "TillableGround",
"Author": "hawkfalcon",
"Version": "1.1.0",
"Version": "2.0.0",
"Description": "Make any tile tillable (so you can use your hoe on it)",
"UniqueID": "hawkfalcon.TillableGround",
"EntryDll": "TillableGround.dll",
Expand Down

0 comments on commit 6aaed56

Please sign in to comment.