Skip to content

Commit

Permalink
Resume now shows block list
Browse files Browse the repository at this point in the history
  • Loading branch information
lllggghhhaaa committed Jan 12, 2024
1 parent ceb20c5 commit e3ef138
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<PublishSingleFile>true</PublishSingleFile>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions WaxMapArt.Avalonia/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<TextBlock x:Name="resGenMethod" FontSize="10" Text="Generation method:"/>
<TextBlock x:Name="resDithering" FontSize="10" Text="Dithering:"/>
<TextBlock x:Name="resElapsed" FontSize="10" Text="Elapsed time:"/>
<TextBlock x:Name="resBlocks" FontSize="10" Text="Used blocks:"/>
</StackPanel>
</StackPanel>
</StackPanel>
Expand Down
21 changes: 18 additions & 3 deletions WaxMapArt.Avalonia/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading.Tasks;
using Avalonia;
using System.Diagnostics;
using System.Text;

namespace WaxMapArt.Avalonia.Views;

Expand Down Expand Up @@ -160,7 +161,7 @@ public async void PreviewClick(object sender, RoutedEventArgs args)

_generatorWatch.Stop();

UpdateResume(ctx);
UpdateResume(ctx, output.BlockList);
}

public async void GenerateClick(object sender, RoutedEventArgs args)
Expand Down Expand Up @@ -208,20 +209,34 @@ public async void GenerateClick(object sender, RoutedEventArgs args)

_generatorWatch.Stop();

UpdateResume(ctx);
UpdateResume(ctx, output.CountBlocks());
}

public void UpdateResume(MainViewModel ctx)
public void UpdateResume(MainViewModel ctx, Dictionary<BlockInfo, int> blockList)
{
var size = ctx.MapSize;

StringBuilder sb = new StringBuilder("Used Blocks: \n");
foreach (var (info, count) in blockList)
{
int packs = count / 64;
int rem = count % 64;
double shulkers = Math.Truncate(packs / 27f * 100) / 100;

string packCount = packs > 0 ? $"{packs} packs + {rem}" : count.ToString();
string id = info.BlockId.Replace("minecraft:", "");

sb.Append($" {id}: {count} ({packCount} blocks) ({shulkers}SB)\n");
}

resPalette.Text = $"Palette: {_palettes.ElementAt(ctx.PaletteIndex).Value.Name}";
resWidth.Text = $"Width: {size.X}";
resHeight.Text = $"Height: {size.Y}";
resMethod.Text = $"Comparison method: {Enum.GetName(ctx.Comparison)}";
resGenMethod.Text = $"Generation method: {Enum.GetName(ctx.Generate)}";
resDithering.Text = $"Dithering: {Enum.GetName(ctx.Dithering)}";
resElapsed.Text = $"Elapsed time: {_generatorWatch.Elapsed:m\\:ss\\.fff}";
resBlocks.Text = sb.ToString();
}

public async Task<string?> SaveFile(FilePickerSaveOptions options, Stream stream)
Expand Down
4 changes: 2 additions & 2 deletions WaxMapArt.Bot/Commands/ArtCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ await ctx.EditResponseAsync(new DiscordWebhookBuilder()
Stream outStream = await output.Image.SaveAsStreamAsync(new PngEncoder());

StringBuilder sb = new StringBuilder("Blocks: \n");
foreach (var (mapId, count) in output.BlockList)
foreach (var (info, count) in output.BlockList)
{
int packs = count / 64;
int rem = count % 64;
double shulkers = Math.Truncate(packs / 27f * 100) / 100;

string packCount = packs > 0 ? $"{packs} packs + {rem}" : count.ToString();
string id = palette.Value.Colors[mapId.ToString()].BlockId;
string id = info.BlockId;

sb.Append($" {id}: {count} ({packCount} blocks) ({shulkers}SB)\n");
}
Expand Down
18 changes: 9 additions & 9 deletions WaxMapArt/Preview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Preview
public PreviewOutput GeneratePreviewStaircase(Image<Rgb24> input)
{
var size = MapSize * 128;
var usedBlocks = new ConcurrentBag<int>();
var usedBlocks = new ConcurrentBag<BlockInfo>();
var outImage = new Image<Rgb24>(size.X, size.Y);
var pImage = new ImageProcessor(size, Dithering).Process(input);

Expand All @@ -45,14 +45,14 @@ public PreviewOutput GeneratePreviewStaircase(Image<Rgb24> input)
outImage[x, y] = nearest.ToRgb24();
var info = colors.Find(blockColor => blockColor.Color.IsEquals(nearest)).Info;

usedBlocks.Add(info.MapId);
if (info.GeneratorProperties.NeedSupport) usedBlocks.Add(ColorPalette.PlaceholderBlock.MapId);
usedBlocks.Add(info);
if (info.GeneratorProperties.NeedSupport) usedBlocks.Add(ColorPalette.PlaceholderBlock);
}
});

outImage.Mutate(ctx => ctx.Resize(OutputSize.X, OutputSize.Y));

var blockCount = new Dictionary<int, int> { { ColorPalette.PlaceholderBlock.MapId, size.X } };
var blockCount = new Dictionary<BlockInfo, int> { { ColorPalette.PlaceholderBlock, size.X } };
foreach (var block in usedBlocks)
{
if (blockCount.ContainsKey(block)) blockCount[block]++;
Expand All @@ -66,7 +66,7 @@ public PreviewOutput GeneratePreviewStaircase(Image<Rgb24> input)
public PreviewOutput GeneratePreviewFlat(Image<Rgb24> input)
{
var size = MapSize * 128;
var usedBlocks = new ConcurrentBag<int>();
var usedBlocks = new ConcurrentBag<BlockInfo>();
var outImage = new Image<Rgb24>(size.X, size.Y);
var pImage = new ImageProcessor(size, Dithering).Process(input);

Expand All @@ -82,15 +82,15 @@ public PreviewOutput GeneratePreviewFlat(Image<Rgb24> input)
var nearest = inputColor.Nearest(colors.Select(blockColor => blockColor.Color), Method);

outImage[x, y] = nearest.ToRgb24();
int id = colors.Find(blockColor => blockColor.Color.IsEquals(nearest)).Info.MapId;
var info = colors.Find(blockColor => blockColor.Color.IsEquals(nearest)).Info;

usedBlocks.Add(id);
usedBlocks.Add(info);
}
});

outImage.Mutate(ctx => ctx.Resize(OutputSize.X, OutputSize.Y));

var blockCount = new Dictionary<int, int>();
var blockCount = new Dictionary<BlockInfo, int>();

foreach (var block in usedBlocks)
{
Expand All @@ -102,4 +102,4 @@ public PreviewOutput GeneratePreviewFlat(Image<Rgb24> input)
}
}

public record struct PreviewOutput(Image<Rgb24> Image, Dictionary<int, int> BlockList);
public record struct PreviewOutput(Image<Rgb24> Image, Dictionary<BlockInfo, int> BlockList);

0 comments on commit e3ef138

Please sign in to comment.