oh yeah woo yeah
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Kehyeedra/Kehyeedra3/Helpers.cs

157 lines
4.2 KiB

using ImageMagick;
using Kehyeedra3.Services.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kehyeedra3
{
public static class Helpers
{
public static async Task<(MagickImageCollection cardCollection, MagickFormat outFormatEnum, string outFormat)> MakeFishCardAsync(Fish fish, ulong currentXp, ulong floorXp, ulong nextLevelXp, string levelUp, int weight, ulong xp, int dcatch)
{
string path = Path.Combine(Environment.CurrentDirectory, "btextures");
string fpath = Path.Combine(path, "fish");
string[] vowels = new string[] { "a", "e", "i", "o", "u" };
string label = $"You caught a{(vowels.Contains((fish.Name[0].ToString()).ToLower()) ? "n" : "")} {fish.Name}.\n{weight / 100d}kg {fish.Rarity} fish.\n\nYou gain {xp}xp.\n{levelUp.Replace("*", "")}.";
if (dcatch != 1)
{
label = $"You caught {dcatch} {fish.Name}.\n{weight / 100d}kg {fish.Rarity} fish.\n\nYou gain {xp}xp.\n{levelUp.Replace("*", "")}.";
}
if (levelUp.Contains("reach"))
{
label = label.Replace("\nYou gain", "\n\nYou gain");
}
string tier = "";
switch (fish.Tier)
{
case FishTier.T1:
{
tier = "tier1";
}
break;
case FishTier.T2:
{
tier = "tier2";
}
break;
case FishTier.T3:
{
tier = "tier3";
}
break;
case FishTier.T4:
{
tier = "tier4";
}
break;
}
if (fish.Rarity == FishRarity.Unreasonable)
{
tier = "tieru";
}
try
{
MagickImage tempCard = new MagickImage(Path.Combine(path, "background.png"));
DrawableFont font = new DrawableFont(Path.Combine(path, "COMIC.TTF"));
using (MagickImage frame = new MagickImage(Path.Combine(path, "scover.png"), new MagickReadSettings //cover
{
BackgroundColor = MagickColors.None
}))
{
tempCard.Composite(frame, CompositeOperator.Over);
}
//draw to tempcard
{
using (MagickImage frame = new MagickImage(Path.Combine(path, "frame.png"), new MagickReadSettings //frame
{
BackgroundColor = MagickColors.None
}))
{
tempCard.Composite(frame, CompositeOperator.Over);
}
using (MagickImage stats = new MagickImage($"label:" + label, new MagickReadSettings
{
BackgroundColor = MagickColors.None,
FillColor = MagickColors.White,
FontPointsize = 14,
Font = font.Family,
TextAntiAlias = false,
StrokeAntiAlias = false
}))
{
tempCard.Composite(stats, 139, 5, CompositeOperator.Over);
}
//draw progressbar
if (currentXp != 0)
{
using (MagickImage xpBar = new MagickImage(Path.Combine(path, "xpbar.png"), new MagickReadSettings //xpbar
{
BackgroundColor = MagickColors.None
}))
{
using (var mask = new MagickImage("xc:none", xpBar.Width, xpBar.Height))
{
var h = (int)currentXp.Remap(floorXp, nextLevelXp, 5, 128);
mask.Draw(new DrawableFillColor(MagickColors.White), new DrawableRectangle(0, 128, xpBar.Width, 128 - h));
xpBar.Composite(mask, CompositeOperator.CopyAlpha);
}
tempCard.Composite(xpBar, 405, 5, CompositeOperator.Over);
}
}
}
MagickImageCollection cardCollection = await Extensions.GifPngMergeAsync(
tempCard,
Path.Combine(fpath, fish.Texture),
new Rectangle(10, 10, 128, 128),
PixelInterpolateMethod.Nearest,
true
);
tempCard.Dispose();
foreach(var card in cardCollection)
{
using (MagickImage frame = new MagickImage(Path.Combine(path, $"{tier}.png"), new MagickReadSettings //tier glow
{
BackgroundColor = MagickColors.None
}))
{
card.Composite(frame, 5, 5, CompositeOperator.Over);
}
}
MagickFormat outFormat = MagickFormat.Png;
if (cardCollection.Count > 1)
{
outFormat = MagickFormat.Gif;
}
return (cardCollection, outFormat, outFormat.ToString().ToLowerInvariant());
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return (null, MagickFormat.Png, MagickFormat.Png.ToString().ToLowerInvariant());
}
}
}