Skip to content

Commit

Permalink
Minor Fix for LGPE trade bot code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
bdawg1989 committed Jun 12, 2024
1 parent 0b02674 commit c274fe0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 51 deletions.
8 changes: 8 additions & 0 deletions SysBot.Pokemon.Discord/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:SysBot.Pokemon.Discord.DiscordTradeNotifier`1.CreateLGLinkCodeSpriteEmbed(System.Collections.Generic.List{SysBot.Pokemon.Pictocodes})~System.ValueTuple{System.String,Discord.Embed}")]
103 changes: 52 additions & 51 deletions SysBot.Pokemon.Discord/Helpers/DiscordTradeNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using Discord;
using Discord.WebSocket;
using PKHeX.Core;
using PKHeX.Core.AutoMod;
using PKHeX.Drawing.PokeSprite;
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Linq;
using Color = Discord.Color;

Expand Down Expand Up @@ -154,59 +160,54 @@ private void SendNotificationZ3(SeedSearchResult r)

public static (string, Embed) CreateLGLinkCodeSpriteEmbed(List<Pictocodes> lgcode)
{
#if WINDOWS
List<System.Drawing.Image> spritearray = new List<System.Drawing.Image>();

foreach (Pictocodes cd in lgcode)
{
var showdown = new ShowdownSet(cd.ToString());
var sav = SaveUtil.GetBlankSAV(EntityContext.Gen7b, "pip");
PKM pk = sav.GetLegalFromSet(showdown).Created;

System.Drawing.Image png = pk.Sprite();
var destRect = new Rectangle(-40, -65, 137, 130);
var destImage = new Bitmap(137, 130);
destImage.SetResolution(png.HorizontalResolution, png.VerticalResolution);

using (var graphics = Graphics.FromImage(destImage))
List<System.Drawing.Image> spritearray = new List<System.Drawing.Image>();
foreach (Pictocodes cd in lgcode)
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.DrawImage(png, destRect, 0, 0, png.Width, png.Height, GraphicsUnit.Pixel);
var showdown = new ShowdownSet(cd.ToString());
var sav = SaveUtil.GetBlankSAV(EntityContext.Gen7b, "pip");
PKM pk = sav.GetLegalFromSet(showdown).Created;
System.Drawing.Image png = pk.Sprite();
var destRect = new Rectangle(-40, -65, 137, 130);
var destImage = new Bitmap(137, 130);
destImage.SetResolution(png.HorizontalResolution, png.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.DrawImage(png, destRect, 0, 0, png.Width, png.Height, GraphicsUnit.Pixel);
}
png = destImage;
spritearray.Add(png);
}
png = destImage;
spritearray.Add(png);
}

if (spritearray.Count == 0)
throw new InvalidOperationException("No sprites available.");

int outputImageWidth = spritearray[0].Width + 20;
int outputImageHeight = spritearray[0].Height - 65;
Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, PixelFormat.Format32bppArgb);
if (spritearray.Count == 0)
throw new InvalidOperationException("No sprites available.");
int outputImageWidth = spritearray[0].Width + 20;
int outputImageHeight = spritearray[0].Height - 65;
Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, PixelFormat.Format32bppArgb);
using (Graphics graphics = Graphics.FromImage(outputImage))
{
graphics.DrawImage(spritearray[0], new Rectangle(0, 0, spritearray[0].Width, spritearray[0].Height),
new Rectangle(new Point(), spritearray[0].Size), GraphicsUnit.Pixel);
if (spritearray.Count > 1)
{
graphics.DrawImage(spritearray[1], new Rectangle(50, 0, spritearray[1].Width, spritearray[1].Height),
new Rectangle(new Point(), spritearray[1].Size), GraphicsUnit.Pixel);
}

using (Graphics graphics = Graphics.FromImage(outputImage))
{
graphics.DrawImage(spritearray[0], new Rectangle(0, 0, spritearray[0].Width, spritearray[0].Height),
new Rectangle(new Point(), spritearray[0].Size), GraphicsUnit.Pixel);
if (spritearray.Count > 1)
graphics.DrawImage(spritearray[1], new Rectangle(50, 0, spritearray[1].Width, spritearray[1].Height),
new Rectangle(new Point(), spritearray[1].Size), GraphicsUnit.Pixel);
if (spritearray.Count > 2)
graphics.DrawImage(spritearray[2], new Rectangle(100, 0, spritearray[2].Width, spritearray[2].Height),
new Rectangle(new Point(), spritearray[2].Size), GraphicsUnit.Pixel);
}
System.Drawing.Image finalembedpic = outputImage;
var filename = $"{Directory.GetCurrentDirectory()}//finalcode.png";
finalembedpic.Save(filename);
filename = Path.GetFileName($"{Directory.GetCurrentDirectory()}//finalcode.png");
Embed returnembed = new EmbedBuilder().WithTitle($"{lgcode[0]}, {lgcode[1]}, {lgcode[2]}").WithImageUrl($"attachment://{filename}").Build();
return (filename, returnembed);
#else
throw new PlatformNotSupportedException("This code requires a Windows platform.");
#endif
if (spritearray.Count > 2)
{
graphics.DrawImage(spritearray[2], new Rectangle(100, 0, spritearray[2].Width, spritearray[2].Height),
new Rectangle(new Point(), spritearray[2].Size), GraphicsUnit.Pixel);
}
}
System.Drawing.Image finalembedpic = outputImage;
var filename = $"{Directory.GetCurrentDirectory()}//finalcode.png";
finalembedpic.Save(filename);
filename = Path.GetFileName($"{Directory.GetCurrentDirectory()}//finalcode.png");
Embed returnembed = new EmbedBuilder().WithTitle($"{lgcode[0]}, {lgcode[1]}, {lgcode[2]}").WithImageUrl($"attachment://{filename}").Build();
return (filename, returnembed);
}
}

0 comments on commit c274fe0

Please sign in to comment.