-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cooldown overview and extra servers.
- Loading branch information
1 parent
c0af0de
commit 88ea508
Showing
27 changed files
with
694 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
|
||
namespace NewWorldCompanion.Entities | ||
{ | ||
public class CooldownTimer | ||
{ | ||
public string Name { get; set; } = string.Empty; | ||
public TimeSpan Duration { get; set; } = TimeSpan.FromHours(24); | ||
public DateTime StartTime { get; set; } = DateTime.Now; | ||
|
||
[JsonIgnore] | ||
public bool Ready | ||
{ | ||
get { return DateTime.Now > StartTime + Duration; } | ||
} | ||
|
||
[JsonIgnore] | ||
public TimeSpan RemainingTime | ||
{ | ||
get | ||
{ | ||
TimeSpan remainder = Duration - (DateTime.Now - StartTime); | ||
return remainder > TimeSpan.Zero ? remainder : TimeSpan.Zero; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Prism.Events; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NewWorldCompanion.Events | ||
{ | ||
public class PriceServerListUpdatedEvent : PubSubEvent | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using NewWorldCompanion.Entities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NewWorldCompanion.Interfaces | ||
{ | ||
public interface ICooldownManager | ||
{ | ||
List<CooldownTimer> CooldownTimers | ||
{ | ||
get; | ||
} | ||
|
||
void AddCooldown(CooldownTimer cooldownTimer); | ||
void RemoveCooldown(CooldownTimer cooldownTimer); | ||
|
||
void SaveCooldowns(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using NewWorldCompanion.Entities; | ||
using NewWorldCompanion.Interfaces; | ||
using Prism.Events; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace NewWorldCompanion.Services | ||
{ | ||
public class CooldownManager : ICooldownManager | ||
{ | ||
private readonly IEventAggregator _eventAggregator; | ||
|
||
private List<CooldownTimer> _cooldownTimers = new List<CooldownTimer>(); | ||
|
||
// Start of Constructor region | ||
|
||
#region Constructor | ||
|
||
public CooldownManager(IEventAggregator eventAggregator) | ||
{ | ||
// Init IEventAggregator | ||
_eventAggregator = eventAggregator; | ||
|
||
// Init cooldowns | ||
LoadCooldowns(); | ||
} | ||
|
||
#endregion | ||
|
||
// Start of Properties region | ||
|
||
#region Properties | ||
|
||
public List<CooldownTimer> CooldownTimers { get => _cooldownTimers; } | ||
|
||
#endregion | ||
|
||
// Start of Events region | ||
|
||
#region Events | ||
|
||
#endregion | ||
|
||
// Start of Methods region | ||
|
||
#region Methods | ||
|
||
public void AddCooldown(CooldownTimer cooldownTimer) | ||
{ | ||
_cooldownTimers.Add(cooldownTimer); | ||
} | ||
|
||
public void RemoveCooldown(CooldownTimer cooldownTimer) | ||
{ | ||
_cooldownTimers.Remove(cooldownTimer); | ||
} | ||
|
||
private void LoadCooldowns() | ||
{ | ||
_cooldownTimers.Clear(); | ||
|
||
string fileName = "Config/Cooldowns.json"; | ||
if (File.Exists(fileName)) | ||
{ | ||
using FileStream stream = File.OpenRead(fileName); | ||
_cooldownTimers = JsonSerializer.Deserialize<List<CooldownTimer>>(stream) ?? new List<CooldownTimer>(); | ||
} | ||
|
||
// Sort list | ||
_cooldownTimers.Sort((x, y) => | ||
{ | ||
int result = x.RemainingTime - y.RemainingTime > TimeSpan.Zero ? 1 : -1; | ||
return result != 0 ? result : string.Compare(x.Name, y.Name, StringComparison.Ordinal); | ||
}); | ||
|
||
SaveCooldowns(); | ||
} | ||
|
||
public void SaveCooldowns() | ||
{ | ||
string fileName = "Config/Cooldowns.json"; | ||
string path = Path.GetDirectoryName(fileName) ?? string.Empty; | ||
Directory.CreateDirectory(path); | ||
|
||
using FileStream stream = File.Create(fileName); | ||
var options = new JsonSerializerOptions { WriteIndented = true }; | ||
JsonSerializer.Serialize(stream, CooldownTimers, options); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.