Skip to content

Commit

Permalink
Allow to specify compression settings for hs build codes (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: Sobrinth <hey@sobrinth.net>
Co-authored-by: Plenyx <1507236+Plenyx@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 16, 2022
1 parent de08d90 commit ec2f293
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 33 deletions.
3 changes: 3 additions & 0 deletions AppSettings/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ private static ApplicationSettings DeserialiseFromFile(string loadLocation)

[JsonProperty("upload")]
internal ApplicationSettingsUpload Upload { get; set; } = new ApplicationSettingsUpload();

[JsonProperty("buildCodes")]
internal ApplicationSettingsBuildCodes BuildCodes { get; set; } = new();
#endregion
}
}
12 changes: 12 additions & 0 deletions AppSettings/ApplicationSettingsBuildCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;
using static Hardstuck.GuildWars2.BuildCodes.V2.Static;

namespace PlenBotLogUploader.AppSettings
{
internal sealed class ApplicationSettingsBuildCodes
{
[JsonProperty("demoteRunes")] internal bool DemoteRunes { get; set; } = true;
[JsonProperty("demoteSigils")] internal bool DemoteSigils { get; set; } = true;
[JsonProperty("compression")] internal CompressionOptions Compression { get; set; } = CompressionOptions.ALL;
}
}
34 changes: 24 additions & 10 deletions Forms/FormGW2API.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions Forms/FormGW2API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,46 @@ private void ButtonGetHardStuckCode_Click(object sender, EventArgs e)
var trueApiKey = ApplicationSettings.Current.GW2APIs.Find(x => x.Characters.Contains(mainLink.MumbleReader.Data.Identity.Name));
if (trueApiKey is null)
{
foreach (var apiKey in ApplicationSettings.Current.GW2APIs.Where(x => x.Valid))
using var httpClientController = new HttpClientController();
var settings = ApplicationSettings.Current;
foreach (var apiKey in settings.GW2APIs.Where(x => x.Valid))
{
await apiKey.GetCharacters(httpClientController, true);
await apiKey.GetCharacters(httpClientController);
}
var trueApiKey = settings.GW2APIs.Find(x => x.Characters.Contains(mainLink.MumbleReader.Data.Identity.Name));
if (trueApiKey is null)
{
foreach (var apiKey in settings.GW2APIs.Where(x => x.Valid))
{
await apiKey.GetCharacters(httpClientController, true);
}
trueApiKey = settings.GW2APIs.Find(x => x.Characters.Contains(mainLink.MumbleReader.Data.Identity.Name));
}
try
{
var code = await APILoader.LoadBuildCodeFromCurrentCharacter(trueApiKey.APIKey);
if (settings.BuildCodes.DemoteRunes)
{
code.Rune = Static.LegendaryToSuperior(code.Rune);
}
if (settings.BuildCodes.DemoteSigils)
{
code.WeaponSet1.Sigil1 = Static.LegendaryToSuperior(code.WeaponSet1.Sigil1);
code.WeaponSet1.Sigil2 = Static.LegendaryToSuperior(code.WeaponSet1.Sigil2);
code.WeaponSet2.Sigil1 = Static.LegendaryToSuperior(code.WeaponSet2.Sigil1);
code.WeaponSet2.Sigil2 = Static.LegendaryToSuperior(code.WeaponSet2.Sigil2);
}
Static.Compress(code, settings.BuildCodes.Compression);
mainLink.AddToText($"https://hardstuck.gg/gw2/builds/?b={TextLoader.WriteBuildCode(code)}");
}
catch (InvalidAccessTokenException)
{
mainLink.AddToText("GW2 API access token is not valid.");
}
catch (MissingScopesException)
{
var missingScopes = APILoader.ValidateScopes(trueApiKey.APIKey);
mainLink.AddToText($"GW2 API access token is missing the following required scopes: {string.Join(", ", missingScopes)}.");
}
trueApiKey = ApplicationSettings.Current.GW2APIs.Find(x => x.Characters.Contains(mainLink.MumbleReader.Data.Identity.Name));
}
Expand Down Expand Up @@ -114,5 +151,10 @@ private void ButtonGetHardStuckCode_Click(object sender, EventArgs e)
}
});
}

private void ButtonBuildCodeCompressionSettings_Click(object sender, EventArgs e)
{
(new FormHsBuildCodeCompressionSettings()).ShowDialog();
}
}
}
108 changes: 108 additions & 0 deletions Forms/FormHsBuildCodeCompressionSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Forms/FormHsBuildCodeCompressionSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using PlenBotLogUploader.AppSettings;
using System;
using System.Windows.Forms;
using static Hardstuck.GuildWars2.BuildCodes.V2.Static;

namespace PlenBotLogUploader
{
public partial class FormHsBuildCodeCompressionSettings : Form
{
public FormHsBuildCodeCompressionSettings()
{
InitializeComponent();
Icon = Properties.Resources.AppIcon;

var settings = ApplicationSettings.Current.BuildCodes;
checkBoxDemoteRunes.Checked = settings.DemoteRunes;
checkBoxDemoteSigils.Checked = settings.DemoteSigils;
foreach (var option in Enum.GetValues<CompressionOptions>())
{
if ((option == CompressionOptions.ALL) || (option == CompressionOptions.NONE))
{
continue;
}
checkboxListCompressionOptions.Items.Add(option, settings.Compression.HasFlag(option));
}
}

private void CheckBoxDemoteRunes_CheckedChanged(object s, EventArgs e) => ApplicationSettings.Current.BuildCodes.DemoteRunes = checkBoxDemoteRunes.Checked;
private void CheckBoxDemoteSigils_CheckedChanged(object s, EventArgs e) => ApplicationSettings.Current.BuildCodes.DemoteSigils = checkBoxDemoteSigils.Checked;

private void CheckboxListCompressionOptions_ItemCheck(object s, ItemCheckEventArgs e)
{
var compressionOption = (CompressionOptions)checkboxListCompressionOptions.Items[e.Index];

if (e.NewValue == CheckState.Checked)
{
ApplicationSettings.Current.BuildCodes.Compression |= compressionOption;
}
else
{
ApplicationSettings.Current.BuildCodes.Compression &= ~compressionOption;
}
}
}
}
Loading

0 comments on commit ec2f293

Please sign in to comment.