image errors will now show error image
This commit is contained in:
parent
ea31da7a52
commit
378897de81
@ -31,7 +31,7 @@ namespace NadekoBot.Commands {
|
|||||||
try {
|
try {
|
||||||
//get role
|
//get role
|
||||||
string role = ResolvePos(e.GetArg("position"));
|
string role = ResolvePos(e.GetArg("position"));
|
||||||
var name = e.GetArg("champ").Replace(" ","");
|
var name = e.GetArg("champ").Replace(" ", "");
|
||||||
|
|
||||||
var allData = JArray.Parse(await Classes.SearchHelper.GetResponseAsync($"http://api.champion.gg/champion/{name}?api_key={NadekoBot.creds.LOLAPIKey}"));
|
var allData = JArray.Parse(await Classes.SearchHelper.GetResponseAsync($"http://api.champion.gg/champion/{name}?api_key={NadekoBot.creds.LOLAPIKey}"));
|
||||||
JToken data = null;
|
JToken data = null;
|
||||||
@ -92,7 +92,7 @@ namespace NadekoBot.Commands {
|
|||||||
//get skill order data<API_KEY>
|
//get skill order data<API_KEY>
|
||||||
|
|
||||||
var orderArr = (data["skills"]["mostGames"]["order"] as JArray);
|
var orderArr = (data["skills"]["mostGames"]["order"] as JArray);
|
||||||
|
|
||||||
//todo save this for at least 1 hour
|
//todo save this for at least 1 hour
|
||||||
Image img = Image.FromFile("data/lol/bg.png");
|
Image img = Image.FromFile("data/lol/bg.png");
|
||||||
using (Graphics g = Graphics.FromImage(img)) {
|
using (Graphics g = Graphics.FromImage(img)) {
|
||||||
@ -104,7 +104,7 @@ namespace NadekoBot.Commands {
|
|||||||
var normalFont = new Font("Monaco", 8, FontStyle.Regular);
|
var normalFont = new Font("Monaco", 8, FontStyle.Regular);
|
||||||
var smallFont = new Font("Monaco", 7, FontStyle.Regular);
|
var smallFont = new Font("Monaco", 7, FontStyle.Regular);
|
||||||
//draw champ image
|
//draw champ image
|
||||||
g.DrawImage(Image.FromFile($"data/lol/champions/{name}.png"), new Rectangle(margin, margin, imageSize, imageSize));
|
g.DrawImage(GetImage(name), new Rectangle(margin, margin, imageSize, imageSize));
|
||||||
//draw champ name
|
//draw champ name
|
||||||
g.DrawString($"{data["key"]}", new Font("Times New Roman", 25, FontStyle.Regular), Brushes.WhiteSmoke, margin + imageSize + margin, margin);
|
g.DrawString($"{data["key"]}", new Font("Times New Roman", 25, FontStyle.Regular), Brushes.WhiteSmoke, margin + imageSize + margin, margin);
|
||||||
//draw champ surname
|
//draw champ surname
|
||||||
@ -146,7 +146,7 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
|
|||||||
int smallImgSize = 50;
|
int smallImgSize = 50;
|
||||||
|
|
||||||
for (int i = 0; i < counters.Length; i++) {
|
for (int i = 0; i < counters.Length; i++) {
|
||||||
g.DrawImage(Image.FromFile("data/lol/champions/" + counters[i] + ".png"),
|
g.DrawImage(GetImage(counters[i]),
|
||||||
new Rectangle(i * (smallImgSize + margin) + margin, img.Height - smallImgSize - margin,
|
new Rectangle(i * (smallImgSize + margin) + margin, img.Height - smallImgSize - margin,
|
||||||
smallImgSize,
|
smallImgSize,
|
||||||
smallImgSize));
|
smallImgSize));
|
||||||
@ -156,7 +156,7 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
|
|||||||
|
|
||||||
for (int i = 0; i < countered.Length; i++) {
|
for (int i = 0; i < countered.Length; i++) {
|
||||||
int j = countered.Length - i;
|
int j = countered.Length - i;
|
||||||
g.DrawImage(Image.FromFile("data/lol/champions/" + countered[i] + ".png"),
|
g.DrawImage(GetImage(countered[i]),
|
||||||
new Rectangle(img.Width - (j * (smallImgSize + margin) + margin), img.Height - smallImgSize - margin,
|
new Rectangle(img.Width - (j * (smallImgSize + margin) + margin), img.Height - smallImgSize - margin,
|
||||||
smallImgSize,
|
smallImgSize,
|
||||||
smallImgSize));
|
smallImgSize));
|
||||||
@ -168,7 +168,7 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
|
|||||||
var inverse_i = 5 - i;
|
var inverse_i = 5 - i;
|
||||||
var j = inverse_i % 3 + 1;
|
var j = inverse_i % 3 + 1;
|
||||||
var k = inverse_i / 3;
|
var k = inverse_i / 3;
|
||||||
g.DrawImage(Image.FromFile("data/lol/items/" + items[i] + ".png"),
|
g.DrawImage(GetImage(items[i], GetImageType.Item),
|
||||||
new Rectangle(img.Width - (j * (smallImgSize + margin) + margin), 92 + k * (smallImgSize + margin),
|
new Rectangle(img.Width - (j * (smallImgSize + margin) + margin), 92 + k * (smallImgSize + margin),
|
||||||
smallImgSize,
|
smallImgSize,
|
||||||
smallImgSize));
|
smallImgSize));
|
||||||
@ -182,6 +182,24 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
enum GetImageType {
|
||||||
|
Champion,
|
||||||
|
Item
|
||||||
|
}
|
||||||
|
private Image GetImage(string id, GetImageType imageType = GetImageType.Champion) {
|
||||||
|
try {
|
||||||
|
switch (imageType) {
|
||||||
|
case GetImageType.Champion:
|
||||||
|
return Image.FromFile($"data/lol/champions/{id}.png");
|
||||||
|
case GetImageType.Item:
|
||||||
|
default:
|
||||||
|
return Image.FromFile($"data/lol/items/{id}.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
return Image.FromFile("data/lol/_ERROR.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string ResolvePos(string pos) {
|
private string ResolvePos(string pos) {
|
||||||
if (string.IsNullOrWhiteSpace(pos))
|
if (string.IsNullOrWhiteSpace(pos))
|
||||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue
Block a user