Created resources, trivia reloading on start, cleanup

This commit is contained in:
Master Kwoth
2016-01-28 10:09:07 +01:00
parent 073d67c1ed
commit ecb1667ef8
90 changed files with 24190 additions and 296 deletions

View File

@@ -36,7 +36,7 @@ public class Cards
public CARD_SUIT suit;
public int number;
public string Path
public string Name
{
get
{
@@ -44,13 +44,13 @@ public class Cards
if (number <= 10 && number > 1)
{
str += number;
str += "_"+number;
}
else
{
str += GetName().ToLower();
}
return @"./images/cards/" + str + "_of_" + suit.ToString().ToLower() + ".jpg";
return str + "_of_" + suit.ToString().ToLower();
}
}

View File

@@ -7,6 +7,8 @@ using Discord.Commands;
using Discord;
using Discord.Legacy;
using NadekoBot.Modules;
using System.IO;
using System.Drawing;
namespace NadekoBot.Extensions
{
@@ -184,5 +186,37 @@ namespace NadekoBot.Extensions
public static int GiB(this int value) => value.MiB() * 1024;
public static int GB(this int value) => value.MB() * 1000;
public static Stream ToStream(this System.Drawing.Image img, System.Drawing.Imaging.ImageFormat format = null) {
if (format == null)
format = System.Drawing.Imaging.ImageFormat.Jpeg;
MemoryStream stream = new MemoryStream();
img.Save(stream, format);
stream.Position = 0;
return stream;
}
/// <summary>
/// Merges Images into 1 Image and returns a bitmap.
/// </summary>
/// <param name="images">The Images you want to merge.</param>
/// <returns>Merged bitmap</returns>
public static Bitmap Merge(this IEnumerable<Image> images) {
if (images.Count() == 0) return null;
int width = images.Sum(i => i.Width);
int height = images.First().Height;
Bitmap bitmap = new Bitmap(width, height);
var r = new Random();
int offsetx = 0;
foreach (var img in images) {
Bitmap bm = new Bitmap(img);
for (int w = 0; w < img.Width; w++) {
for (int h = 0; h < img.Height; h++) {
bitmap.SetPixel(w + offsetx, h, bm.GetPixel(w, h));
}
}
offsetx += img.Width;
}
return bitmap;
}
}
}

View File

@@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
namespace NadekoBot
{
class ImageHandler
{
/// <summary>
/// Merges Images into 1 Image and returns a bitmap.
/// </summary>
/// <param name="images">The Images you want to merge.</param>
/// <returns>Merged bitmap</returns>
public static Bitmap MergeImages(IEnumerable<Image> images)
{
if (images.Count() == 0) return null;
int width = images.Sum(i => i.Width);
int height = images.First().Height;
Bitmap bitmap = new Bitmap(width, height);
var r = new Random();
int offsetx = 0;
foreach (var img in images)
{
Bitmap bm = new Bitmap(img);
for (int w = 0; w < img.Width; w++)
{
for (int h = 0; h < img.Height; h++)
{
bitmap.SetPixel(w + offsetx, h, bm.GetPixel(w, h));
}
}
offsetx += img.Width;
}
return bitmap;
}
public static Stream ImageToStream(Image img,ImageFormat format) {
MemoryStream stream = new MemoryStream();
img.Save(stream, format);
stream.Position = 0;
return stream;
}
}
}

View File

@@ -149,6 +149,7 @@ namespace NadekoBot
stopwatch = new Stopwatch();
timeout.Elapsed += (s, e) => { TimeUp(); };
TriviaQuestionsPool.Instance.Reload();
LoadNextRound();
}
@@ -353,22 +354,7 @@ namespace NadekoBot
public TriviaQuestionsPool()
{
_r = new Random();
pool = new List<TriviaQuestion>();
JArray arr = JArray.Parse(File.ReadAllText("questions.txt"));
foreach (var item in arr)
{
TriviaQuestion tq;
tq = new TriviaQuestion((string)item["Question"], (string)item["Answer"]);
if (item?["Category"] != null)
{
tq.Category = item["Category"].ToString();
}
pool.Add(tq);
}
Reload();
}
@@ -386,5 +372,22 @@ namespace NadekoBot
}
return tq;
}
internal void Reload() {
_r = new Random();
pool = new List<TriviaQuestion>();
JArray arr = JArray.Parse(Properties.Resources.questions);
foreach (var item in arr) {
TriviaQuestion tq;
tq = new TriviaQuestion((string)item["Question"], (string)item["Answer"]);
if (item?["Category"] != null) {
tq.Category = item["Category"].ToString();
}
pool.Add(tq);
}
}
}
}