NadekoBot/NadekoBot.Core/Services/Impl/ImagesService.cs

102 lines
4.0 KiB
C#
Raw Normal View History

2017-02-25 15:35:09 +00:00
using NLog;
using System;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
namespace NadekoBot.Core.Services.Impl
{
public class ImagesService : IImagesService
{
private readonly Logger _log;
2017-02-25 15:35:09 +00:00
private const string _basePath = "data/images/";
2017-02-25 15:35:09 +00:00
private const string _headsPath = _basePath + "coins/heads.png";
private const string _tailsPath = _basePath + "coins/tails.png";
2017-02-25 15:35:09 +00:00
private const string _currencyImagesPath = _basePath + "currency";
private const string _diceImagesPath = _basePath + "dice";
2017-03-21 12:12:47 +00:00
private const string _slotBackgroundPath = _basePath + "slots/background2.png";
2017-02-25 15:35:09 +00:00
private const string _slotNumbersPath = _basePath + "slots/numbers/";
private const string _slotEmojisPath = _basePath + "slots/emojis/";
2017-02-25 15:35:09 +00:00
private const string _wifeMatrixPath = _basePath + "rategirl/wifematrix.png";
private const string _rategirlDot = _basePath + "rategirl/dot.png";
private const string _xpCardPath = _basePath + "xp/xp.png";
2017-10-15 09:48:29 +00:00
private const string _ripPath = _basePath + "rip/rip.png";
private const string _ripFlowersPath = _basePath + "rip/rose_overlay.png";
public ImmutableArray<byte> Heads { get; private set; }
public ImmutableArray<byte> Tails { get; private set; }
public ImmutableArray<(string, ImmutableArray<byte>)> Currency { get; private set; }
public ImmutableArray<ImmutableArray<byte>> Dice { get; private set; }
public ImmutableArray<byte> SlotBackground { get; private set; }
public ImmutableArray<ImmutableArray<byte>> SlotNumbers { get; private set; }
public ImmutableArray<ImmutableArray<byte>> SlotEmojis { get; private set; }
public ImmutableArray<byte> WifeMatrix { get; private set; }
2017-02-23 12:40:43 +00:00
public ImmutableArray<byte> RategirlDot { get; private set; }
public ImmutableArray<byte> XpCard { get; private set; }
2017-10-15 09:48:29 +00:00
public ImmutableArray<byte> Rip { get; private set; }
public ImmutableArray<byte> FlowerCircle { get; private set; }
2017-05-22 23:59:31 +00:00
public ImagesService()
{
_log = LogManager.GetCurrentClassLogger();
2017-05-22 23:59:31 +00:00
this.Reload();
}
public void Reload()
{
try
{
2017-02-25 15:35:09 +00:00
Heads = File.ReadAllBytes(_headsPath).ToImmutableArray();
Tails = File.ReadAllBytes(_tailsPath).ToImmutableArray();
2017-02-25 15:35:09 +00:00
Currency = Directory.GetFiles(_currencyImagesPath)
.Select(x => (Path.GetFileName(x), File.ReadAllBytes(x).ToImmutableArray()))
.ToImmutableArray();
2017-02-25 15:35:09 +00:00
Dice = Directory.GetFiles(_diceImagesPath)
.OrderBy(x => int.Parse(Path.GetFileNameWithoutExtension(x)))
.Select(x => File.ReadAllBytes(x).ToImmutableArray())
.ToImmutableArray();
2017-02-25 15:35:09 +00:00
SlotBackground = File.ReadAllBytes(_slotBackgroundPath).ToImmutableArray();
2017-02-25 15:35:09 +00:00
SlotNumbers = Directory.GetFiles(_slotNumbersPath)
.OrderBy(f => int.Parse(Path.GetFileNameWithoutExtension(f)))
.Select(x => File.ReadAllBytes(x).ToImmutableArray())
.ToImmutableArray();
2017-02-25 15:35:09 +00:00
SlotEmojis = Directory.GetFiles(_slotEmojisPath)
2017-02-10 12:03:15 +00:00
.OrderBy(f => int.Parse(Path.GetFileNameWithoutExtension(f)))
.Select(x => File.ReadAllBytes(x).ToImmutableArray())
.ToImmutableArray();
WifeMatrix = File.ReadAllBytes(_wifeMatrixPath).ToImmutableArray();
2017-02-23 12:40:43 +00:00
RategirlDot = File.ReadAllBytes(_rategirlDot).ToImmutableArray();
XpCard = File.ReadAllBytes(_xpCardPath).ToImmutableArray();
2017-10-15 09:48:29 +00:00
Rip = File.ReadAllBytes(_ripPath).ToImmutableArray();
FlowerCircle = File.ReadAllBytes(_ripFlowersPath).ToImmutableArray();
}
catch (Exception ex)
{
_log.Error(ex);
throw;
}
2017-05-22 23:59:31 +00:00
}
}
}