Typereaders will be autoloaded when module loads

This commit is contained in:
Master Kwoth
2017-10-09 02:52:46 +02:00
parent 72f36270dc
commit f3513779b7
60 changed files with 316 additions and 140 deletions

View File

@ -11,6 +11,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman
public class Hangman : IDisposable
{
public string TermType { get; }
public TermPool TermPool { get; }
public HangmanObject Term { get; }
public string ScrambledWord => "`" + String.Concat(Term.Word.Select(c =>
@ -56,10 +57,11 @@ namespace NadekoBot.Modules.Games.Common.Hangman
public Task EndedTask => _endingCompletionSource.Task;
public Hangman(string type)
public Hangman(string type, TermPool tp = null)
{
this.TermType = type.Trim().ToLowerInvariant().ToTitleCase();
this.Term = TermPool.GetTerm(type);
this.TermPool = tp ?? new TermPool();
this.Term = this.TermPool.GetTerm(type);
}
private void AddError()

View File

@ -5,27 +5,35 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NLog;
namespace NadekoBot.Modules.Games.Common.Hangman
{
public class TermPool
{
const string termsPath = "data/hangman3.json";
public static IReadOnlyDictionary<string, HangmanObject[]> Data { get; } = new Dictionary<string, HangmanObject[]>();
static TermPool()
private readonly Logger _log;
public IReadOnlyDictionary<string, HangmanObject[]> Data { get; } = new Dictionary<string, HangmanObject[]>();
public TermPool()
{
_log = LogManager.GetCurrentClassLogger();
try
{
Data = JsonConvert.DeserializeObject<Dictionary<string, HangmanObject[]>>(File.ReadAllText(termsPath));
Data = Data.ToDictionary(
x => x.Key.ToLowerInvariant(),
x => x.Value);
}
catch (Exception)
catch (Exception ex)
{
//ignored
_log.Warn(ex);
}
}
public static HangmanObject GetTerm(string type)
public HangmanObject GetTerm(string type)
{
type = type?.Trim().ToLowerInvariant();
var rng = new NadekoRandom();
if (type == "random")