added prices to .nczoom

.nc resized to 250x125
This commit is contained in:
Toastie 2025-03-30 15:38:40 +13:00
parent 57a5993064
commit c058d180ae
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
5 changed files with 101 additions and 49 deletions
src/EllieBot
Modules/Games/NCanvas
_common/Services/Impl
data
strings

View file

@ -35,17 +35,22 @@ public partial class Games
public async Task NCanvas()
{
var pixels = await _service.GetCanvas();
var image = new Image<Rgba32>(_service.GetWidth(), _service.GetHeight());
var w = _service.GetWidth();
var h = _service.GetHeight();
var image = new Image<Rgba32>(w * 2, h * 2);
Parallel.For(0,
image.Height,
h * 2,
y =>
{
var pixelAccessor = image.DangerousGetPixelRowMemory(y);
var row = pixelAccessor.Span;
for (int x = 0; x < image.Width; x++)
for (var x = 0; x < image.Width; x += 2)
{
row[x] = new Rgba32(pixels[(y * image.Width) + x]);
var pi = pixels[(y / 2 * w) + x / 2];
row[x] = new Rgba32(pi);
row[x + 1] = new Rgba32(pi);
}
});
@ -106,11 +111,13 @@ public partial class Games
const float fontSize = 30;
var posFont = _fonts.NotoSans.CreateFont(fontSize, FontStyle.Bold);
var priceFont = _fonts.Symbola.CreateFont(25, FontStyle.Bold);
var size = TextMeasurer.MeasureSize("wwww", new TextOptions(posFont));
var scale = 100f / size.Width;
if (scale < 1)
posFont = _fonts.NotoSans.CreateFont(fontSize * scale, FontStyle.Bold);
var outlinePen = new SolidPen(SixLabors.ImageSharp.Color.Black, 1f);
var outlinePen = new SolidPen(SixLabors.ImageSharp.Color.Black, 0.5f);
Parallel.For(0,
pixels.Length,
@ -131,11 +138,23 @@ public partial class Games
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Origin = new(startX + 50, startY + 50)
Origin = new(startX + 50, startY + 30)
},
((kwum)pix.Position).ToString().PadLeft(2, '2'),
Brushes.Solid(SixLabors.ImageSharp.Color.White),
outlinePen);
x.DrawText(new RichTextOptions(priceFont)
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Origin = new(startX + 50, startY + 80)
},
// "", Brushes.Solid(SixLabors.ImageSharp.Color.White), outlinePen);
pix.Price + "💵",
// CurrencyHelper.N(pix.Price, Culture, _gcs.Data.Currency.Sign),
Brushes.Solid(SixLabors.ImageSharp.Color.White),
outlinePen);
});
});

View file

@ -20,8 +20,8 @@ public sealed class NCanvasService : INCanvasService, IReadyExecutor, IEService
private readonly ICurrencyService _cs;
private readonly QuestService _quests;
public const int CANVAS_WIDTH = 500;
public const int CANVAS_HEIGHT = 350;
public const int CANVAS_WIDTH = 250;
public const int CANVAS_HEIGHT = 125;
public const int INITIAL_PRICE = 3;
public NCanvasService(
@ -45,9 +45,36 @@ public sealed class NCanvasService : INCanvasService, IReadyExecutor, IEService
await using var uow = _db.GetDbContext();
if (await uow.GetTable<NCPixel>().CountAsyncLinqToDB() > 0)
var count = await uow.GetTable<NCPixel>().CountAsync();
if (count == CANVAS_WIDTH * CANVAS_HEIGHT)
return;
var oldWidth = 500;
var oldHeight = 250;
if (count == oldWidth * oldHeight)
{
await uow.GetTable<NCPixel>()
.Where(x => x.Position % (oldWidth * 2) % 2 != 0 // x is odd
|| (x.Position / oldWidth) % 2 != 0) // or y is odd
.DeleteAsync();
await uow.GetTable<NCPixel>()
.Where(x => x.Position % (oldWidth * 2) % 2 == 0
&& (x.Position / oldWidth) % 2 == 0)
.UpdateAsync(old => new()
{
Position = (old.Position % oldWidth) / 2
+ ((old.Position / oldWidth) / 2) * CANVAS_WIDTH,
Price = INITIAL_PRICE,
Text = old.Text,
OwnerId = old.OwnerId,
Color = old.Color,
});
return;
}
await ResetAsync();
}

View file

@ -6,6 +6,7 @@ namespace EllieBot.Services;
public class FontProvider : IEService
{
public FontFamily NotoSans { get; }
public FontFamily Symbola { get; }
public List<FontFamily> FallBackFonts { get; }
private readonly FontCollection _fonts;
@ -14,6 +15,7 @@ public class FontProvider : IEService
_fonts = new();
NotoSans = _fonts.Add("data/fonts/NotoSans-Bold.ttf");
Symbola = _fonts.Add("data/fonts/Symbola-10.24.ttf");
FallBackFonts = new();
@ -27,7 +29,9 @@ public class FontProvider : IEService
FallBackFonts.AddRange(_fonts.AddCollection(Path.Combine(fontsfolder, "msgothic.ttc")));
FallBackFonts.AddRange(_fonts.AddCollection(Path.Combine(fontsfolder, "segoe.ttc")));
}
catch { }
catch
{
}
}
// any fonts present in data/fonts should be added as fallback fonts

View file

@ -4315,7 +4315,8 @@
"Aliases": [
".ncsetpixel",
".ncsp",
".ncs"
".ncs",
".ncset"
],
"Description": "Sets a pixel's color and text on the nCanvas.\nYou must specify the position of the pixel to set in alphanumeric format.\nYou can obtain alphanumeric position of the pixel by using `nczoom` or `ncp <x> <y>`",
"Usage": [

View file

@ -1484,6 +1484,7 @@ ncsetpixel:
- ncsetpixel
- ncsp
- ncs
- ncset
nczoom:
- nczoom
- ncz