Skip to content

Commit

Permalink
Merge pull request #28 from Denifia/develop
Browse files Browse the repository at this point in the history
fixes and version bump
  • Loading branch information
Denifia authored Apr 29, 2017
2 parents c3c03f6 + 5daca82 commit e325cba
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 69 deletions.
43 changes: 43 additions & 0 deletions SendItems/Domain/BasePerson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

namespace Denifia.Stardew.SendItems.Domain
{
public class BasePerson : IEquatable<BasePerson>
{
public string Id { get; set; }
public string Name { get; set; }
public string FarmName { get; set; }

public string DisplayText
{
get
{
return $"{Name} ({FarmName} Farm)";
}
}

public string ConsoleSafeName
{
get { return MakeConsoleSave(Name); }
}

public string ConsoleSaveFarmName
{
get { return MakeConsoleSave(FarmName); }
}

private string MakeConsoleSave(string text)
{
if (text.Contains(" "))
{
text = $"\"{text}\"";
}
return text;
}

public bool Equals(BasePerson other)
{
return Id == other.Id;
}
}
}
13 changes: 1 addition & 12 deletions SendItems/Domain/Farmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@

namespace Denifia.Stardew.SendItems.Domain
{
public class Farmer
public class Farmer : BasePerson
{
public string Id { get; set; }
public string Name { get; set; }
public string FarmName { get; set; }
public List<Friend> Friends { get; set; }

public Farmer()
{
Friends = new List<Friend>();
}

public string DisplayText
{
get
{
return $"{Name} ({FarmName} Farm)";
}
}
}
}
17 changes: 1 addition & 16 deletions SendItems/Domain/Friend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,8 @@

namespace Denifia.Stardew.SendItems.Domain
{
public class Friend : IEquatable<Friend>
public class Friend : BasePerson
{
public string Id { get; set; }
public string Name { get; set; }
public string FarmName { get; set; }

public string DisplayText
{
get
{
return $"{Name} ({FarmName} Farm)";
}
}

public bool Equals(Friend other)
{
return Id == other.Id;
}
}
}
4 changes: 2 additions & 2 deletions SendItems/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
22 changes: 5 additions & 17 deletions SendItems/SendItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,16 @@ public override void Entry(IModHelper helper)
Repository.Instance.Init(_container.Resolve<IConfigurationService>());

// Instance classes that do their own thing
_container.Resolve<IFarmerService>();
_container.Resolve<VersionCheckService>();
_container.Resolve<ICommandService>();
_container.Resolve<IPostboxService>();
_container.Resolve<ILetterboxService>();
_container.Resolve<IPostboxInteractionDetector>();
_container.Resolve<ILetterboxInteractionDetector>();
_container.Resolve<IMailDeliveryService>();
_container.Resolve<IMailCleanupService>();
_container.Resolve<IMailScheduleService>();

// Instance classes to be used later
_farmerService = _container.Resolve<IFarmerService>();
_postboxInteractionDetector = _container.Resolve<IPostboxInteractionDetector>();
_letterboxInteractionDetector = _container.Resolve<ILetterboxInteractionDetector>();
_mailDeliveryService = _container.Resolve<IMailDeliveryService>();
_mailCleanupService = _container.Resolve<IMailCleanupService>();

SaveEvents.AfterLoad += AfterSavedGameLoad;
}

private void AfterSavedGameLoad(object sender, EventArgs e)
{
_postboxInteractionDetector.Init();
_letterboxInteractionDetector.Init();

SaveEvents.AfterLoad -= AfterSavedGameLoad;
}
}
}
1 change: 1 addition & 0 deletions SendItems/SendItems.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Domain\BasePerson.cs" />
<Compile Include="Domain\Farmer.cs" />
<Compile Include="Domain\Friend.cs" />
<Compile Include="Domain\GameDateTime.cs" />
Expand Down
14 changes: 10 additions & 4 deletions SendItems/Services/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ public CommandService(
RegisterCommands();

SaveEvents.AfterLoad += AfterSavedGameLoad;
}
SaveEvents.AfterReturnToTitle += AfterReturnToTitle;
}

private void AfterReturnToTitle(object sender, EventArgs e)
{
_savedGameLoaded = false;
}

private void RegisterCommands()
{
Expand Down Expand Up @@ -91,7 +97,7 @@ private void HandleCommand(string command, string[] args)
private void ShowMyDetails(string[] args)
{
_mod.Monitor.Log("This is your \"friend command\". Get your friends to run this command in the SMAPI console to add you as a friend. Each farmer (saved game) has it's own list of friends.", LogLevel.Info);
_mod.Monitor.Log($"{_addFriendCommand} {_farmerService.CurrentFarmer.Id} {_farmerService.CurrentFarmer.Name} {_farmerService.CurrentFarmer.FarmName}", LogLevel.Info);
_mod.Monitor.Log($"{_addFriendCommand} {_farmerService.CurrentFarmer.Id} {_farmerService.CurrentFarmer.ConsoleSafeName} {_farmerService.CurrentFarmer.ConsoleSaveFarmName}", LogLevel.Info);
}

private void ListLocalFarmers(string[] args)
Expand All @@ -103,7 +109,7 @@ private void ListLocalFarmers(string[] args)
_mod.Monitor.Log("<id> <name> <farm name>", LogLevel.Info);
foreach (var farmer in farmers)
{
_mod.Monitor.Log($"{farmer.Id} {farmer.Name} {farmer.FarmName}", LogLevel.Info);
_mod.Monitor.Log($"{farmer.Id} {farmer.ConsoleSafeName} {farmer.ConsoleSaveFarmName}", LogLevel.Info);
}
}
else
Expand Down Expand Up @@ -228,7 +234,7 @@ private void AfterSavedGameLoad(object sender, EventArgs e)
{
_savedGameLoaded = true;
_mod.Monitor.Log($"This is your \"friend command\". Get your friends to run this command in the SMAPI console to add you as a friend...", LogLevel.Info);
_mod.Monitor.Log($"{_addFriendCommand} {_farmerService.CurrentFarmer.Id} {_farmerService.CurrentFarmer.Name} {_farmerService.CurrentFarmer.FarmName}", LogLevel.Alert);
_mod.Monitor.Log($"{_addFriendCommand} {_farmerService.CurrentFarmer.Id} {_farmerService.CurrentFarmer.ConsoleSafeName} {_farmerService.CurrentFarmer.ConsoleSaveFarmName}", LogLevel.Alert);
_mod.Monitor.Log($"They need to be using the Send Items mod too :)", LogLevel.Info);
}

Expand Down
16 changes: 15 additions & 1 deletion SendItems/Services/FarmerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Denifia.Stardew.SendItems.Domain;
using StardewValley;
using System.Linq;
using StardewModdingAPI.Events;
using System;

namespace Denifia.Stardew.SendItems.Services
{
Expand Down Expand Up @@ -33,13 +35,25 @@ public Domain.Farmer CurrentFarmer {
public FarmerService(IConfigurationService configService)
{
_configService = configService;
SaveEvents.AfterReturnToTitle += AfterReturnToTitle;
}

private void AfterReturnToTitle(object sender, EventArgs e)
{
_currentFarmer = null;
}

public void LoadCurrentFarmer()
{
var saves = _configService.GetSavedGames();
var save = saves.FirstOrDefault(x => x.Name == Game1.player.Name && x.FarmName == Game1.player.farmName);
if (save == null) throw new System.Exception("error loading current farmer");
if (save == null)
{
// Happens during a new game creation
return;
//throw new System.Exception("error loading current farmer");
}


var newFarmer = new Domain.Farmer()
{
Expand Down
25 changes: 21 additions & 4 deletions SendItems/Services/LetterboxInteractionDetector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Denifia.Stardew.SendItems.Events;
using Denifia.Stardew.SendItems.Framework;
using StardewModdingAPI.Events;
using StardewValley;
using System;
Expand All @@ -9,7 +10,6 @@ namespace Denifia.Stardew.SendItems.Services
{
public interface ILetterboxInteractionDetector
{
void Init();
}

/// <summary>
Expand All @@ -18,9 +18,26 @@ public interface ILetterboxInteractionDetector
public class LetterboxInteractionDetector : ILetterboxInteractionDetector
{
private const string _locationOfLetterbox = "Farm";
private const string _playerMailKey = "playerMail";

public void Init()
public LetterboxInteractionDetector()
{
SaveEvents.AfterLoad += AfterSavedGameLoad;
SaveEvents.AfterReturnToTitle += AfterReturnToTitle;
}

private void AfterReturnToTitle(object sender, EventArgs e)
{
try
{
ControlEvents.MouseChanged -= MouseChanged;
LocationEvents.CurrentLocationChanged -= CurrentLocationChanged;
}
catch (Exception)
{
}
}

private void AfterSavedGameLoad(object sender, EventArgs e)
{
LocationEvents.CurrentLocationChanged += CurrentLocationChanged;
}
Expand Down Expand Up @@ -57,7 +74,7 @@ private void MouseChanged(object sender, EventArgsMouseStateChanged e)

private bool CanUseLetterbox()
{
return Game1.mailbox != null && Game1.mailbox.Any() && Game1.mailbox.Peek() == _playerMailKey;
return Game1.mailbox != null && Game1.mailbox.Any() && Game1.mailbox.Peek() == ModConstants.PlayerMailKey;
}
}
}
22 changes: 20 additions & 2 deletions SendItems/Services/PostboxInteractionDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Denifia.Stardew.SendItems.Services
{
public interface IPostboxInteractionDetector
{
void Init();

}

/// <summary>
Expand All @@ -19,7 +19,25 @@ public class PostboxInteractionDetector : IPostboxInteractionDetector
{
private const string locationOfPostbox = "Farm";

public void Init()
public PostboxInteractionDetector()
{
SaveEvents.AfterLoad += AfterSavedGameLoad;
SaveEvents.AfterReturnToTitle += AfterReturnToTitle;
}

private void AfterReturnToTitle(object sender, EventArgs e)
{
try
{
ControlEvents.MouseChanged -= MouseChanged;
LocationEvents.CurrentLocationChanged -= CurrentLocationChanged;
}
catch (Exception)
{
}
}

private void AfterSavedGameLoad(object sender, EventArgs e)
{
LocationEvents.CurrentLocationChanged += CurrentLocationChanged;
}
Expand Down
2 changes: 1 addition & 1 deletion SendItems/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ApiUrl": "http://localhost:5000/api",
"Debug": true
"Debug": false
}
10 changes: 5 additions & 5 deletions SendItems/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"Name": "Send Items",
"Author": "Denifia",
"Version": {
"MajorVersion": 0,
"MinorVersion": 2,
"PatchVersion": 0,
"Build": null
"MajorVersion": 1,
"MinorVersion": 0,
"PatchVersion": 1,
"Build": "beta"
},
"MinimumApiVersion": "1.10",
"Description": "Send items to your other farms (saved games) and online friends",
"Description": "Send items to other farmer (saved games and online friends).",
"UniqueID": "Denifia.SendItems",
"EntryDll": "Denifia.Stardew.SendItems.dll"
}
7 changes: 6 additions & 1 deletion SendItems/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[← back to readme](readme.md)

# Release notes
## 0.2.0
## 1.0.1-Beta
* Fixed bug with returning to tile screen
* Fixed bug with friend command extra spaces (issue #27)
* Bumped version because of bad release

## 1.0-Beta
* **Renamed project from "SendLetters" to "Send Items" for clarity**
* Moved local storage into LiteDb (stores data as binary json in the \Mods\SendItems directory)
* Made all web requests run in the background so they don't interfere with the game
Expand Down
2 changes: 1 addition & 1 deletion SendItemsApi/SendItemsApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
<AssemblyName>Denifia.Stardew.SendItemsApi</AssemblyName>
<RootNamespace>Denifia.Stardew.SendItemsApi</RootNamespace>
<Version>0.2.0</Version>
<Version>1.0.1</Version>
<Description>Web Api for the Send Items mod for Stardew Valley</Description>
<Authors>Denifia</Authors>
<Company>Denifia</Company>
Expand Down
7 changes: 5 additions & 2 deletions SendItemsApi/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[← back to readme](readme.md)

# Release notes
## 0.2.0
## 1.0.1
* Bumped version because of bad release

## 1.0-Beta
* All code is now async for performance
* Moved from LiteDb to Azure Table Storage
* Changed mail endpoint paths, names and parameters to be more clear
* Creating mail on the server has changed verbs from POST to PUT
* Added a /api/mail/count endpoint to check how much mail is on the server
* Added a /api/health endpoint that just returns true

## Prior to 0.2.0
## Prior to 1.0-Beta
* Intital cut of api
* No release notes available
2 changes: 1 addition & 1 deletion latest-versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema": 1.0,
"Send Items": "0.2.0",
"Send Items": "1.0.1",
"Purchase Recipes": "0.1.0"
}

0 comments on commit e325cba

Please sign in to comment.