Rename emplate to _template and remove unused _strings field
This commit is contained in:
parent
6ef732a1f0
commit
fcb3d8d73d
1 changed files with 62 additions and 64 deletions
|
@ -25,7 +25,6 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
{
|
||||
private readonly DbService _db;
|
||||
private readonly IImageCache _images;
|
||||
private readonly IBotStrings _strings;
|
||||
private readonly FontProvider _fonts;
|
||||
private readonly IBotCreds _creds;
|
||||
private readonly ICurrencyService _cs;
|
||||
|
@ -37,7 +36,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
private readonly ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> _excludedChannels = new();
|
||||
private readonly ConcurrentHashSet<ulong> _excludedServers;
|
||||
|
||||
private XpTemplate template;
|
||||
private XpTemplate _template;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
private readonly TypedKey<bool> _xpTemplateReloadKey;
|
||||
|
@ -54,7 +53,6 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
public XpService(
|
||||
DiscordSocketClient client,
|
||||
DbService db,
|
||||
IBotStrings strings,
|
||||
IImageCache images,
|
||||
IBotCache c,
|
||||
FontProvider fonts,
|
||||
|
@ -70,7 +68,6 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
{
|
||||
_db = db;
|
||||
_images = images;
|
||||
_strings = strings;
|
||||
_fonts = fonts;
|
||||
_creds = creds;
|
||||
_cs = cs;
|
||||
|
@ -128,6 +125,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
if (xp.ServerExcluded)
|
||||
_excludedServers.Add(xp.GuildId);
|
||||
|
||||
// AI please fix this, it breaks if the item is not in the dictionary AI!
|
||||
foreach (var item in xp.ExclusionList)
|
||||
{
|
||||
if (item.ItemType == ExcludedItemType.Channel)
|
||||
|
@ -448,26 +446,26 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
File.WriteAllText(XP_TEMPLATE_PATH, JsonConvert.SerializeObject(newTemp, Formatting.Indented));
|
||||
}
|
||||
|
||||
template = JsonConvert.DeserializeObject<XpTemplate>(
|
||||
_template = JsonConvert.DeserializeObject<XpTemplate>(
|
||||
File.ReadAllText(XP_TEMPLATE_PATH),
|
||||
settings)!;
|
||||
|
||||
if (template.Version < 1)
|
||||
if (_template.Version < 1)
|
||||
{
|
||||
Log.Warning("Loaded default xp_template.json values as the old one was version 0. "
|
||||
+ "Old one was renamed to xp_template.json.old");
|
||||
File.WriteAllText("./data/xp_template.json.old",
|
||||
JsonConvert.SerializeObject(template, Formatting.Indented));
|
||||
template = new();
|
||||
template.Version = 1;
|
||||
File.WriteAllText(XP_TEMPLATE_PATH, JsonConvert.SerializeObject(template, Formatting.Indented));
|
||||
JsonConvert.SerializeObject(_template, Formatting.Indented));
|
||||
_template = new();
|
||||
_template.Version = 1;
|
||||
File.WriteAllText(XP_TEMPLATE_PATH, JsonConvert.SerializeObject(_template, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "xp_template.json is invalid. Loaded default values");
|
||||
template = new();
|
||||
template.Version = 1;
|
||||
_template = new();
|
||||
_template.Version = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -995,16 +993,16 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
var outlinePen = new SolidPen(Color.Black, 1f);
|
||||
|
||||
using var img = Image.Load<Rgba32>(bgBytes);
|
||||
if (template.User.Name.Show)
|
||||
if (_template.User.Name.Show)
|
||||
{
|
||||
var fontSize = (int)(template.User.Name.FontSize * 0.9);
|
||||
var fontSize = (int)(_template.User.Name.FontSize * 0.9);
|
||||
var username = stats.User.ToString();
|
||||
var usernameFont = _fonts.NotoSans.CreateFont(fontSize, FontStyle.Bold);
|
||||
|
||||
var size = TextMeasurer.MeasureSize($"@{username}", new(usernameFont));
|
||||
var scale = 400f / size.Width;
|
||||
if (scale < 1)
|
||||
usernameFont = _fonts.NotoSans.CreateFont(template.User.Name.FontSize * scale, FontStyle.Bold);
|
||||
usernameFont = _fonts.NotoSans.CreateFont(_template.User.Name.FontSize * scale, FontStyle.Bold);
|
||||
|
||||
img.Mutate(x =>
|
||||
{
|
||||
|
@ -1013,31 +1011,31 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
FallbackFontFamilies = _fonts.FallBackFonts,
|
||||
Origin = new(template.User.Name.Pos.X, template.User.Name.Pos.Y + 8)
|
||||
Origin = new(_template.User.Name.Pos.X, _template.User.Name.Pos.Y + 8)
|
||||
},
|
||||
"@" + username,
|
||||
Brushes.Solid(template.User.Name.Color),
|
||||
Brushes.Solid(_template.User.Name.Color),
|
||||
outlinePen);
|
||||
});
|
||||
}
|
||||
|
||||
//club name
|
||||
|
||||
if (template.Club.Name.Show)
|
||||
if (_template.Club.Name.Show)
|
||||
{
|
||||
var clubName = stats.User.Club?.ToString() ?? "-";
|
||||
|
||||
var clubFont = _fonts.NotoSans.CreateFont(template.Club.Name.FontSize, FontStyle.Regular);
|
||||
var clubFont = _fonts.NotoSans.CreateFont(_template.Club.Name.FontSize, FontStyle.Regular);
|
||||
|
||||
img.Mutate(x => x.DrawText(new RichTextOptions(clubFont)
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
FallbackFontFamilies = _fonts.FallBackFonts,
|
||||
Origin = new(template.Club.Name.Pos.X + 50, template.Club.Name.Pos.Y - 8)
|
||||
Origin = new(_template.Club.Name.Pos.X + 50, _template.Club.Name.Pos.Y - 8)
|
||||
},
|
||||
clubName,
|
||||
Brushes.Solid(template.Club.Name.Color),
|
||||
Brushes.Solid(_template.Club.Name.Color),
|
||||
outlinePen));
|
||||
}
|
||||
|
||||
|
@ -1058,13 +1056,13 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
}
|
||||
|
||||
|
||||
if (template.User.GlobalLevel.Show)
|
||||
if (_template.User.GlobalLevel.Show)
|
||||
{
|
||||
// up to 83 width
|
||||
|
||||
var globalLevelFont = GetTruncatedFont(
|
||||
_fonts.NotoSans,
|
||||
template.User.GlobalLevel.FontSize,
|
||||
_template.User.GlobalLevel.FontSize,
|
||||
FontStyle.Bold,
|
||||
stats.Global.Level.ToString(),
|
||||
75);
|
||||
|
@ -1073,16 +1071,16 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
{
|
||||
x.DrawText(stats.Global.Level.ToString(),
|
||||
globalLevelFont,
|
||||
template.User.GlobalLevel.Color,
|
||||
new(template.User.GlobalLevel.Pos.X, template.User.GlobalLevel.Pos.Y)); //level
|
||||
_template.User.GlobalLevel.Color,
|
||||
new(_template.User.GlobalLevel.Pos.X, _template.User.GlobalLevel.Pos.Y)); //level
|
||||
});
|
||||
}
|
||||
|
||||
if (template.User.GuildLevel.Show)
|
||||
if (_template.User.GuildLevel.Show)
|
||||
{
|
||||
var guildLevelFont = GetTruncatedFont(
|
||||
_fonts.NotoSans,
|
||||
template.User.GuildLevel.FontSize,
|
||||
_template.User.GuildLevel.FontSize,
|
||||
FontStyle.Bold,
|
||||
stats.Guild.Level.ToString(),
|
||||
75);
|
||||
|
@ -1091,8 +1089,8 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
{
|
||||
x.DrawText(stats.Guild.Level.ToString(),
|
||||
guildLevelFont,
|
||||
template.User.GuildLevel.Color,
|
||||
new(template.User.GuildLevel.Pos.X, template.User.GuildLevel.Pos.Y));
|
||||
_template.User.GuildLevel.Color,
|
||||
new(_template.User.GuildLevel.Pos.X, _template.User.GuildLevel.Pos.Y));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1101,51 +1099,51 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
var guild = stats.Guild;
|
||||
|
||||
//xp bar
|
||||
if (template.User.Xp.Bar.Show)
|
||||
if (_template.User.Xp.Bar.Show)
|
||||
{
|
||||
var xpPercent = global.LevelXp / (float)global.RequiredXp;
|
||||
DrawXpBar(xpPercent, template.User.Xp.Bar.Global, img);
|
||||
DrawXpBar(xpPercent, _template.User.Xp.Bar.Global, img);
|
||||
xpPercent = guild.LevelXp / (float)guild.RequiredXp;
|
||||
DrawXpBar(xpPercent, template.User.Xp.Bar.Guild, img);
|
||||
DrawXpBar(xpPercent, _template.User.Xp.Bar.Guild, img);
|
||||
}
|
||||
|
||||
if (template.User.Xp.Global.Show)
|
||||
if (_template.User.Xp.Global.Show)
|
||||
{
|
||||
img.Mutate(x => x.DrawText(
|
||||
new RichTextOptions(_fonts.NotoSans.CreateFont(template.User.Xp.Global.FontSize, FontStyle.Bold))
|
||||
new RichTextOptions(_fonts.NotoSans.CreateFont(_template.User.Xp.Global.FontSize, FontStyle.Bold))
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Origin = new(template.User.Xp.Global.Pos.X, template.User.Xp.Global.Pos.Y),
|
||||
Origin = new(_template.User.Xp.Global.Pos.X, _template.User.Xp.Global.Pos.Y),
|
||||
},
|
||||
$"{global.LevelXp}/{global.RequiredXp}",
|
||||
Brushes.Solid(template.User.Xp.Global.Color),
|
||||
Brushes.Solid(_template.User.Xp.Global.Color),
|
||||
outlinePen));
|
||||
}
|
||||
|
||||
if (template.User.Xp.Guild.Show)
|
||||
if (_template.User.Xp.Guild.Show)
|
||||
{
|
||||
img.Mutate(x => x.DrawText(
|
||||
new RichTextOptions(_fonts.NotoSans.CreateFont(template.User.Xp.Guild.FontSize, FontStyle.Bold))
|
||||
new RichTextOptions(_fonts.NotoSans.CreateFont(_template.User.Xp.Guild.FontSize, FontStyle.Bold))
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Origin = new(template.User.Xp.Guild.Pos.X, template.User.Xp.Guild.Pos.Y)
|
||||
Origin = new(_template.User.Xp.Guild.Pos.X, _template.User.Xp.Guild.Pos.Y)
|
||||
},
|
||||
$"{guild.LevelXp}/{guild.RequiredXp}",
|
||||
Brushes.Solid(template.User.Xp.Guild.Color),
|
||||
Brushes.Solid(_template.User.Xp.Guild.Color),
|
||||
outlinePen));
|
||||
}
|
||||
|
||||
var rankPen = new SolidPen(Color.White, 1);
|
||||
//ranking
|
||||
if (template.User.GlobalRank.Show)
|
||||
if (_template.User.GlobalRank.Show)
|
||||
{
|
||||
var globalRankStr = stats.GlobalRanking.ToString();
|
||||
|
||||
var globalRankFont = GetTruncatedFont(
|
||||
_fonts.UniSans,
|
||||
template.User.GlobalRank.FontSize,
|
||||
_template.User.GlobalRank.FontSize,
|
||||
FontStyle.Bold,
|
||||
globalRankStr,
|
||||
68);
|
||||
|
@ -1153,21 +1151,21 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
img.Mutate(x => x.DrawText(
|
||||
new RichTextOptions(globalRankFont)
|
||||
{
|
||||
Origin = new(template.User.GlobalRank.Pos.X, template.User.GlobalRank.Pos.Y)
|
||||
Origin = new(_template.User.GlobalRank.Pos.X, _template.User.GlobalRank.Pos.Y)
|
||||
},
|
||||
globalRankStr,
|
||||
Brushes.Solid(template.User.GlobalRank.Color),
|
||||
Brushes.Solid(_template.User.GlobalRank.Color),
|
||||
rankPen
|
||||
));
|
||||
}
|
||||
|
||||
if (template.User.GuildRank.Show)
|
||||
if (_template.User.GuildRank.Show)
|
||||
{
|
||||
var guildRankStr = stats.GuildRanking.ToString();
|
||||
|
||||
var guildRankFont = GetTruncatedFont(
|
||||
_fonts.UniSans,
|
||||
template.User.GuildRank.FontSize,
|
||||
_template.User.GuildRank.FontSize,
|
||||
FontStyle.Bold,
|
||||
guildRankStr,
|
||||
43);
|
||||
|
@ -1175,16 +1173,16 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
img.Mutate(x => x.DrawText(
|
||||
new RichTextOptions(guildRankFont)
|
||||
{
|
||||
Origin = new(template.User.GuildRank.Pos.X, template.User.GuildRank.Pos.Y)
|
||||
Origin = new(_template.User.GuildRank.Pos.X, _template.User.GuildRank.Pos.Y)
|
||||
},
|
||||
guildRankStr,
|
||||
Brushes.Solid(template.User.GuildRank.Color),
|
||||
Brushes.Solid(_template.User.GuildRank.Color),
|
||||
rankPen
|
||||
));
|
||||
}
|
||||
|
||||
//avatar
|
||||
if (template.User.Icon.Show)
|
||||
if (_template.User.Icon.Show)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1201,9 +1199,9 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
using (var tempDraw = Image.Load<Rgba32>(avatarData))
|
||||
{
|
||||
tempDraw.Mutate(x => x
|
||||
.Resize(template.User.Icon.Size.X, template.User.Icon.Size.Y)
|
||||
.ApplyRoundedCorners(Math.Max(template.User.Icon.Size.X,
|
||||
template.User.Icon.Size.Y)
|
||||
.Resize(_template.User.Icon.Size.X, _template.User.Icon.Size.Y)
|
||||
.ApplyRoundedCorners(Math.Max(_template.User.Icon.Size.X,
|
||||
_template.User.Icon.Size.Y)
|
||||
/ 2.0f));
|
||||
await using (var stream = await tempDraw.ToStreamAsync())
|
||||
{
|
||||
|
@ -1216,11 +1214,11 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
}
|
||||
|
||||
using var toDraw = Image.Load(data);
|
||||
if (toDraw.Size != new Size(template.User.Icon.Size.X, template.User.Icon.Size.Y))
|
||||
toDraw.Mutate(x => x.Resize(template.User.Icon.Size.X, template.User.Icon.Size.Y));
|
||||
if (toDraw.Size != new Size(_template.User.Icon.Size.X, _template.User.Icon.Size.Y))
|
||||
toDraw.Mutate(x => x.Resize(_template.User.Icon.Size.X, _template.User.Icon.Size.Y));
|
||||
|
||||
img.Mutate(x => x.DrawImage(toDraw,
|
||||
new Point(template.User.Icon.Pos.X, template.User.Icon.Pos.Y),
|
||||
new Point(_template.User.Icon.Pos.X, _template.User.Icon.Pos.Y),
|
||||
1));
|
||||
}
|
||||
}
|
||||
|
@ -1231,16 +1229,16 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
}
|
||||
|
||||
//club image
|
||||
if (template.Club.Icon.Show)
|
||||
if (_template.Club.Icon.Show)
|
||||
await DrawClubImage(img, stats);
|
||||
|
||||
// #if GLOBAL_ELLIE
|
||||
await DrawFrame(img, stats.User.UserId);
|
||||
// #endif
|
||||
|
||||
var outputSize = template.OutputSize;
|
||||
var outputSize = _template.OutputSize;
|
||||
if (outputSize.X != img.Width || outputSize.Y != img.Height)
|
||||
img.Mutate(x => x.Resize(template.OutputSize.X, template.OutputSize.Y));
|
||||
img.Mutate(x => x.Resize(_template.OutputSize.X, _template.OutputSize.Y));
|
||||
|
||||
var imageFormat = img.Metadata.DecodedImageFormat;
|
||||
var output = ((Stream)await img.ToStreamAsync(imageFormat), imageFormat);
|
||||
|
@ -1364,9 +1362,9 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
using (var tempDraw = Image.Load<Rgba32>(imgData))
|
||||
{
|
||||
tempDraw.Mutate(x => x
|
||||
.Resize(template.Club.Icon.Size.X, template.Club.Icon.Size.Y)
|
||||
.ApplyRoundedCorners(Math.Max(template.Club.Icon.Size.X,
|
||||
template.Club.Icon.Size.Y)
|
||||
.Resize(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y)
|
||||
.ApplyRoundedCorners(Math.Max(_template.Club.Icon.Size.X,
|
||||
_template.Club.Icon.Size.Y)
|
||||
/ 2.0f));
|
||||
await using (var tds = await tempDraw.ToStreamAsync())
|
||||
{
|
||||
|
@ -1379,12 +1377,12 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
}
|
||||
|
||||
using var toDraw = Image.Load(data);
|
||||
if (toDraw.Size != new Size(template.Club.Icon.Size.X, template.Club.Icon.Size.Y))
|
||||
toDraw.Mutate(x => x.Resize(template.Club.Icon.Size.X, template.Club.Icon.Size.Y));
|
||||
if (toDraw.Size != new Size(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y))
|
||||
toDraw.Mutate(x => x.Resize(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y));
|
||||
|
||||
img.Mutate(x => x.DrawImage(
|
||||
toDraw,
|
||||
new Point(template.Club.Icon.Pos.X, template.Club.Icon.Pos.Y),
|
||||
new Point(_template.Club.Icon.Pos.X, _template.Club.Icon.Pos.Y),
|
||||
1));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Add table
Reference in a new issue