Skip to content

Commit

Permalink
Merge pull request #59 from Gml-Launcher/1.0.2
Browse files Browse the repository at this point in the history
Update to v1.0.2
  • Loading branch information
GamerVII-NET authored Dec 5, 2024
2 parents e2215d6 + bb7c722 commit 802038a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 74 deletions.
138 changes: 66 additions & 72 deletions src/Gml.Launcher/Core/Services/SkinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,81 +42,75 @@ public static byte[] GetCloak(string cloakPath, int size)
return memoryStream.ToArray();
}

public static byte[] GetFront(Stream skinStream, int size)
{
using var inputImage = Image.Load(skinStream);

var scaleFactor = inputImage.Width / 64;

var croppedHead = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(8 * scaleFactor, 8 * scaleFactor, 8 * scaleFactor, 8 * scaleFactor)));

var croppedBody = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(20 * scaleFactor, 20 * scaleFactor, 8 * scaleFactor, 12 * scaleFactor)));

var croppedLeg = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(4 * scaleFactor, 20 * scaleFactor, 4 * scaleFactor, 12 * scaleFactor)));

var croppedArm = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(44 * scaleFactor, 20 * scaleFactor, 4 * scaleFactor, 12 * scaleFactor)));

var newWidth = croppedArm.Width * 2 + croppedBody.Width;
var newHeight = croppedHead.Height + croppedBody.Height + croppedArm.Height;

var combinedImage = new Image<Rgba32>(newWidth, newHeight);

combinedImage.Mutate(context =>
{
var headPosition = new Rectangle(croppedArm.Width, 0, croppedHead.Width, croppedHead.Height);
var bodyPosition = new Rectangle(headPosition.X, croppedHead.Height, croppedBody.Width, croppedBody.Height);

var leftArmPosition = new Rectangle(0, bodyPosition.Y, croppedArm.Width, croppedArm.Height);
var rightArmPosition = new Rectangle(leftArmPosition.Width + bodyPosition.Width, leftArmPosition.Y,
leftArmPosition.Width, leftArmPosition.Height);

var leftLegPosition = new Rectangle(leftArmPosition.Width, headPosition.Height + bodyPosition.Height,
croppedLeg.Width, croppedLeg.Height);
var rightLegPosition = new Rectangle(leftArmPosition.Width + leftLegPosition.Width,
headPosition.Height + bodyPosition.Height, leftLegPosition.Width, leftLegPosition.Height);

context.DrawImage(croppedHead, new Point(headPosition.X, headPosition.Y), 1f);
context.DrawImage(croppedBody, new Point(bodyPosition.X, bodyPosition.Y), 1f);
context.DrawImage(croppedArm, new Point(leftArmPosition.X, leftArmPosition.Y), 1f);
context.DrawImage(croppedArm, new Point(rightArmPosition.X, rightArmPosition.Y), 1f);
context.DrawImage(croppedLeg, new Point(leftLegPosition.X, leftLegPosition.Y), 1f);
context.DrawImage(croppedLeg, new Point(rightLegPosition.X, rightLegPosition.Y), 1f);

// context.DrawImage(croppedArm, new Point(0, 8 * scaleFactor), 1f);
// context.DrawImage(croppedLeg, new Point(200, 200), 1f);
});

using var memoryStream = new MemoryStream();
if (inputImage.Metadata.DecodedImageFormat != null)
combinedImage.Save(memoryStream, inputImage.Metadata.DecodedImageFormat);
else
combinedImage.Save(memoryStream, new PngEncoder());

// var image = ResizeImage(size, inputImage, combinedImage);

if (size != combinedImage.Width)
{
var scaleSize = GetScaleSize(size, combinedImage.Width);

if (scaleSize != 0)
combinedImage = combinedImage.Clone(ctx => ctx.Resize(combinedImage.Width * scaleSize,
combinedImage.Height * scaleSize, KnownResamplers.Box));
}

using var resizeMemoryStream = new MemoryStream();

if (inputImage.Metadata.DecodedImageFormat != null)
combinedImage.Save(resizeMemoryStream, inputImage.Metadata.DecodedImageFormat);
else
combinedImage.Save(resizeMemoryStream, new PngEncoder());
public static byte[] GetFront(Stream skinStream, int size) {
using var inputImage = Image.Load(skinStream);

var scaleFactor = inputImage.Width / 64;

var croppedHead = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(8 * scaleFactor, 8 * scaleFactor, 8 * scaleFactor, 8 * scaleFactor)));
var croppedBody = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(20 * scaleFactor, 20 * scaleFactor, 8 * scaleFactor, 12 * scaleFactor)));
var croppedLeg = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(4 * scaleFactor, 20 * scaleFactor, 4 * scaleFactor, 12 * scaleFactor)));
var croppedArm = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(44 * scaleFactor, 20 * scaleFactor, 4 * scaleFactor, 12 * scaleFactor)));

var secondLayerHead = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(40 * scaleFactor, 8 * scaleFactor, 8 * scaleFactor, 8 * scaleFactor)));
var secondLayerBody = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(20 * scaleFactor, 36 * scaleFactor, 8 * scaleFactor, 12 * scaleFactor)));
var secondLayerLeg = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(4 * scaleFactor, 52 * scaleFactor, 4 * scaleFactor, 12 * scaleFactor)));
var secondLayerArm = inputImage.Clone(ctx =>
ctx.Crop(new Rectangle(44 * scaleFactor, 52 * scaleFactor, 4 * scaleFactor, 12 * scaleFactor)));

var newWidth = croppedArm.Width * 2 + croppedBody.Width;
var newHeight = croppedHead.Height + croppedBody.Height + croppedArm.Height;

var combinedImage = new Image<Rgba32>(newWidth, newHeight);

combinedImage.Mutate(context => {
var headPosition = new Rectangle(croppedArm.Width, 0, croppedHead.Width, croppedHead.Height);
var bodyPosition = new Rectangle(headPosition.X, croppedHead.Height, croppedBody.Width, croppedBody.Height);

var leftArmPosition = new Rectangle(0, bodyPosition.Y, croppedArm.Width, croppedArm.Height);
var rightArmPosition = new Rectangle(leftArmPosition.Width + bodyPosition.Width, leftArmPosition.Y,
leftArmPosition.Width, leftArmPosition.Height);

var leftLegPosition = new Rectangle(leftArmPosition.Width, headPosition.Height + bodyPosition.Height,
croppedLeg.Width, croppedLeg.Height);
var rightLegPosition = new Rectangle(leftArmPosition.Width + leftLegPosition.Width,
headPosition.Height + bodyPosition.Height, leftLegPosition.Width, leftLegPosition.Height);

context.DrawImage(croppedHead, new Point(headPosition.X, headPosition.Y), 1f);
context.DrawImage(croppedBody, new Point(bodyPosition.X, bodyPosition.Y), 1f);
context.DrawImage(croppedArm, new Point(leftArmPosition.X, leftArmPosition.Y), 1f);
context.DrawImage(croppedArm, new Point(rightArmPosition.X, rightArmPosition.Y), 1f);
context.DrawImage(croppedLeg, new Point(leftLegPosition.X, leftLegPosition.Y), 1f);
context.DrawImage(croppedLeg, new Point(rightLegPosition.X, rightLegPosition.Y), 1f);

context.DrawImage(secondLayerHead, new Point(headPosition.X, headPosition.Y), 1f);
context.DrawImage(secondLayerBody, new Point(bodyPosition.X, bodyPosition.Y), 1f);
context.DrawImage(secondLayerArm, new Point(leftArmPosition.X, leftArmPosition.Y), 1f);
context.DrawImage(secondLayerArm, new Point(rightArmPosition.X, rightArmPosition.Y), 1f);
context.DrawImage(secondLayerLeg, new Point(leftLegPosition.X, leftLegPosition.Y), 1f);
context.DrawImage(secondLayerLeg, new Point(rightLegPosition.X, rightLegPosition.Y), 1f);
});

if (size != combinedImage.Width) {
var scaleSize = GetScaleSize(size, combinedImage.Width);
if (scaleSize != 0)
combinedImage = combinedImage.Clone(ctx => ctx.Resize(combinedImage.Width * scaleSize,
combinedImage.Height * scaleSize, KnownResamplers.Box));
}

return resizeMemoryStream.ToArray();
using var memoryStream = new MemoryStream();
combinedImage.Save(memoryStream, new PngEncoder());
return memoryStream.ToArray();
}


public static byte[] GetBack(string skinPath, int size, bool includeCloak = false)
{
using var inputImage = Image.Load(skinPath);
Expand Down
34 changes: 32 additions & 2 deletions src/Gml.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ namespace Gml.Launcher;
internal class Program
{
[STAThread]
#if DEBUG
public static void Main(string[] args)
{
try
{
Debug.WriteLine($"[Gml][{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] Application started");
InitializeSentry();
RxApp.DefaultExceptionHandler = Observer.Create<Exception>(GlobalExceptionHandler);
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
catch (Exception exception)
{
SentrySdk.CaptureException(exception);
Console.WriteLine(exception);
}
}
#else
public static void Main(string[] args)
{
try
Expand All @@ -30,12 +48,25 @@ public static void Main(string[] args)
Console.WriteLine(exception);
}
}
#endif

private static void GlobalExceptionHandler(Exception exception)
{
SentrySdk.CaptureException(exception);
}

#if DEBUG
public static AppBuilder BuildAvaloniaApp()
{
Debug.WriteLine($"[Gml][{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] Configuring launcher");
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.RegisterServices([])
.LogToTrace()
.UseReactiveUI();
}
#else
public static AppBuilder BuildAvaloniaApp(string[] args)
{
Debug.WriteLine($"[Gml][{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] Configuring launcher");
Expand All @@ -46,8 +77,7 @@ public static AppBuilder BuildAvaloniaApp(string[] args)
.LogToTrace()
.UseReactiveUI();
}


#endif

private static void InitializeSentry()
{
Expand Down

0 comments on commit 802038a

Please sign in to comment.