upload
This commit is contained in:
commit
1c7a8cf25f
579 files changed
+83196
No files matched your search
@@ -0,0 +1,228 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using VibranceHud.Crosshair;
|
||||
using VibranceHud.Display;
|
||||
using VibranceHud.Licensing;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public sealed record CommunityCatalogue(IReadOnlyList<LibraryPreset> Looks, IReadOnlyList<CrosshairLibraryEntry> Crosshairs, IReadOnlyList<DisplayLibraryEntry> Displays, IReadOnlyList<ConfigLibraryEntry> Configs)
|
||||
{
|
||||
public IReadOnlyList<LockedLibraryCard> Locked { get; init; } = Array.Empty<LockedLibraryCard>();
|
||||
|
||||
internal string? Source { get; private init; }
|
||||
|
||||
internal string ReadWith { get; private init; } = "";
|
||||
|
||||
public static readonly CommunityCatalogue Empty = new CommunityCatalogue(Array.Empty<LibraryPreset>(), Array.Empty<CrosshairLibraryEntry>(), Array.Empty<DisplayLibraryEntry>(), Array.Empty<ConfigLibraryEntry>());
|
||||
|
||||
public const int MaxNameLength = 48;
|
||||
|
||||
public const int MaxBlurbLength = 60;
|
||||
|
||||
private const string FallbackGame = "Other";
|
||||
|
||||
private const string CommunityGlyph = "custom";
|
||||
|
||||
private const string LookKind = "look";
|
||||
|
||||
private const string CrosshairKind = "crosshair";
|
||||
|
||||
private const string DisplayKind = "display";
|
||||
|
||||
private const string ConfigKind = "config";
|
||||
|
||||
private const string LookPrefix = "PX-";
|
||||
|
||||
private const string CrosshairPrefix = "PXC-";
|
||||
|
||||
private const string DisplayPrefix = "PXM-";
|
||||
|
||||
private const string ConfigPrefix = "PXF-";
|
||||
|
||||
internal CommunityCatalogue ReadAgainIfTheCodesMoved()
|
||||
{
|
||||
if (Source != null && !(CodesKey(ServedCodes.Current) == ReadWith))
|
||||
{
|
||||
return Parse(Source);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private static string CodesKey(ShareCodeFormat? format)
|
||||
{
|
||||
if (format == null || format.Withheld)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
int[] source = new int[16]
|
||||
{
|
||||
format.ChecksumModulus, format.ChecksumWeightStep, format.ChecksumWeightOffset, format.ChecksumIndexOffset, format.MaxVibrance, format.MaxSaturation, format.MinBrightness, format.MaxBrightness, format.MinGamma, format.MaxGamma,
|
||||
format.MinContrast, format.MaxContrast, format.MinTemperature, format.MaxTemperature, format.MinGrade, format.MaxGrade
|
||||
};
|
||||
IEnumerable<string> values = from l in format.BodyLengths
|
||||
orderby l.Key
|
||||
select l.Key.ToString(CultureInfo.InvariantCulture) + ":" + l.Value.ToString(CultureInfo.InvariantCulture);
|
||||
return format.Alphabet + "|" + format.Prefix + "|" + string.Join(",", values) + "|" + string.Join(",", source.Select((int n) => n.ToString(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
|
||||
public static CommunityCatalogue Parse(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
string readWith = CodesKey(ServedCodes.Current);
|
||||
List<LibraryPreset> looks = new List<LibraryPreset>();
|
||||
List<CrosshairLibraryEntry> crosshairs = new List<CrosshairLibraryEntry>();
|
||||
List<DisplayLibraryEntry> displays = new List<DisplayLibraryEntry>();
|
||||
List<ConfigLibraryEntry> configs = new List<ConfigLibraryEntry>();
|
||||
List<LockedLibraryCard> locked = new List<LockedLibraryCard>();
|
||||
try
|
||||
{
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(json);
|
||||
if (jsonDocument.RootElement.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
if (!jsonDocument.RootElement.TryGetProperty("presets", out var value))
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
if (value.ValueKind != JsonValueKind.Array)
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
foreach (JsonElement item in value.EnumerateArray())
|
||||
{
|
||||
try
|
||||
{
|
||||
Read(item, looks, crosshairs, displays, configs, locked);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
return new CommunityCatalogue(looks, crosshairs, displays, configs)
|
||||
{
|
||||
Source = json,
|
||||
ReadWith = readWith,
|
||||
Locked = locked
|
||||
};
|
||||
}
|
||||
|
||||
private static void Read(JsonElement entry, List<LibraryPreset> looks, List<CrosshairLibraryEntry> crosshairs, List<DisplayLibraryEntry> displays, List<ConfigLibraryEntry> configs, List<LockedLibraryCard> locked)
|
||||
{
|
||||
if (entry.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string text = Text(entry, "kind");
|
||||
string text2 = Text(entry, "code");
|
||||
string name = Clip(Text(entry, "name"), 48, "Untitled");
|
||||
string author = Clip(Text(entry, "author"), 48, "Anonymous");
|
||||
string blurb = Clip(Text(entry, "blurb"), 60, "");
|
||||
string game = Game(Text(entry, "game"));
|
||||
string communityId = Text(entry, "id");
|
||||
ConfigCode.Parts parts;
|
||||
if (text2.Length == 0)
|
||||
{
|
||||
string text3 = KnownKind(text);
|
||||
if (text3 != null)
|
||||
{
|
||||
locked.Add(new LockedLibraryCard(text3, name, author, game, blurb)
|
||||
{
|
||||
CommunityId = communityId
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (string.Equals(text, "look", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (text2.StartsWith("PX-", StringComparison.Ordinal) && !text2.StartsWith("PXC-", StringComparison.Ordinal) && ProfileCode.TryDecode(text2, out var profile))
|
||||
{
|
||||
looks.Add(new LibraryPreset(name, author, game, blurb, LookFrom(profile, name, blurb))
|
||||
{
|
||||
CommunityId = communityId
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (string.Equals(text, "crosshair", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (text2.StartsWith("PXC-", StringComparison.Ordinal) && CrosshairCode.TryDecode(text2, out CrosshairConfig crosshair))
|
||||
{
|
||||
crosshairs.Add(new CrosshairLibraryEntry(name, author, game, blurb, crosshair)
|
||||
{
|
||||
CommunityId = communityId
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (string.Equals(text, "display", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (text2.StartsWith("PXM-", StringComparison.Ordinal) && MonitorCode.TryDecode(text2, out var mode))
|
||||
{
|
||||
displays.Add(new DisplayLibraryEntry(name, author, game, blurb, mode)
|
||||
{
|
||||
CommunityId = communityId
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (string.Equals(text, "config", StringComparison.OrdinalIgnoreCase) && text2.StartsWith("PXF-", StringComparison.Ordinal) && ConfigCode.TryDecode(text2, out parts))
|
||||
{
|
||||
configs.Add(new ConfigLibraryEntry(name, author, game, blurb, parts)
|
||||
{
|
||||
CommunityId = communityId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static DisplayPreset LookFrom(ProfileCode profile, string name, string blurb)
|
||||
{
|
||||
return new DisplayPreset(name, blurb, profile.Saturation, profile.Vibrance, profile.Brightness, profile.Gamma, profile.Contrast, profile.Temperature, "custom", "", profile.Highlights, profile.Shadows, NightVision: false, profile.ColourVision, 0, 0, 0, 0, null, profile.Hue, profile.RedGain, profile.GreenGain, profile.BlueGain, profile.Formula, profile.Darken, profile.DarkenHue, profile.HueTurn, profile.HueTurnAmount, profile.HueComplement);
|
||||
}
|
||||
|
||||
private static string? KnownKind(string kind)
|
||||
{
|
||||
return new string[4] { "look", "crosshair", "display", "config" }.FirstOrDefault((string k) => string.Equals(k, kind, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static string Text(JsonElement entry, string field)
|
||||
{
|
||||
if (!entry.TryGetProperty(field, out var value) || value.ValueKind != JsonValueKind.String)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return value.GetString() ?? "";
|
||||
}
|
||||
|
||||
private static string Clip(string value, int max, string fallback)
|
||||
{
|
||||
value = value.Trim();
|
||||
if (value.Length == 0)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
if (value.Length > max)
|
||||
{
|
||||
return value.Substring(0, max);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static string Game(string game)
|
||||
{
|
||||
game = Clip(game, 48, "Other");
|
||||
if (!string.Equals(game, "All", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return game;
|
||||
}
|
||||
return "Other";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using A;
|
||||
using VibranceHud.Licensing;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class CommunityPresetService
|
||||
{
|
||||
internal sealed record LibraryAsker(string Serial, string HardwareId, string? BuildId);
|
||||
|
||||
private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(8.0);
|
||||
|
||||
internal static string PublicWallUrl => ActivationEndpoint.Origin + "/api/presets/public?version=" + Uri.EscapeDataString(AppVersion);
|
||||
|
||||
internal static string AppVersion { get; } = ReadAppVersion();
|
||||
|
||||
internal static string CachePath => Path.Combine(SettingsStore.DefaultDirectory, "community-presets.json");
|
||||
|
||||
private static string ReadAppVersion()
|
||||
{
|
||||
Assembly assembly = typeof(CommunityPresetService).Assembly;
|
||||
return PlainVersion(assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion, assembly.GetName().Version);
|
||||
}
|
||||
|
||||
internal static string PlainVersion(string? informational, Version? assemblyVersion)
|
||||
{
|
||||
Match match = Regex.Match(informational?.Trim() ?? "", "^(\\d+)\\.(\\d+)\\.(\\d+)");
|
||||
if (match.Success)
|
||||
{
|
||||
return int.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture) + "." + int.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture) + "." + int.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
Version version = assemblyVersion ?? new Version(0, 0, 0);
|
||||
return version.Major + "." + version.Minor + "." + Math.Max(version.Build, 0);
|
||||
}
|
||||
|
||||
public static CommunityCatalogue Cached()
|
||||
{
|
||||
return Cached(CachePath);
|
||||
}
|
||||
|
||||
internal static CommunityCatalogue Cached(string cachePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.Exists(cachePath) ? CommunityCatalogue.Parse(File.ReadAllText(cachePath)) : CommunityCatalogue.Empty;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return CommunityCatalogue.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static Task<CommunityCatalogue?> FetchAsync(CancellationToken cancel = default(CancellationToken))
|
||||
{
|
||||
return FetchAsync(null, CachePath, WhoIsAskingNow(), cancel);
|
||||
}
|
||||
|
||||
private static LibraryAsker? WhoIsAskingNow()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static LibraryAsker? WhoIsAsking(string? serial)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static LibraryAsker? WhoIsAsking(string? serial, string? hardwareId, string? buildId)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(serial) && !string.IsNullOrWhiteSpace(hardwareId))
|
||||
{
|
||||
return new LibraryAsker(serial, hardwareId, buildId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static string PaidWallUrl(LibraryAsker who)
|
||||
{
|
||||
return ActivationEndpoint.LibraryUrl + "?serial=" + Uri.EscapeDataString(who.Serial) + "&hwid=" + Uri.EscapeDataString(who.HardwareId) + (!string.IsNullOrWhiteSpace(who.BuildId) ? ("&build_id=" + Uri.EscapeDataString(who.BuildId)) : "") + "&version=" + Uri.EscapeDataString(AppVersion);
|
||||
}
|
||||
|
||||
internal static Task<CommunityCatalogue?> FetchAsync(HttpMessageHandler? transport, string cachePath, CancellationToken cancel = default(CancellationToken))
|
||||
{
|
||||
return FetchAsync(transport, cachePath, null, cancel);
|
||||
}
|
||||
|
||||
internal static async Task<CommunityCatalogue?> FetchAsync(HttpMessageHandler? transport, string cachePath, LibraryAsker? who, CancellationToken cancel = default(CancellationToken), Func<Action, bool>? acceptResponse = null)
|
||||
{
|
||||
string json = null;
|
||||
try
|
||||
{
|
||||
using HttpClient client = ((transport == null) ? new HttpClient() : new HttpClient(transport, disposeHandler: false));
|
||||
client.Timeout = Timeout;
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("PlexusX");
|
||||
if ((object)who != null)
|
||||
{
|
||||
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, PaidWallUrl(who));
|
||||
using HttpResponseMessage answer = await client.SendAsync(request, cancel).ConfigureAwait(continueOnCapturedContext: false);
|
||||
int statusCode = (int)answer.StatusCode;
|
||||
if (answer.IsSuccessStatusCode)
|
||||
{
|
||||
json = await answer.Content.ReadAsStringAsync(cancel).ConfigureAwait(continueOnCapturedContext: false);
|
||||
}
|
||||
else if (statusCode != 403 && statusCode != 401)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (json == null)
|
||||
{
|
||||
json = await client.GetStringAsync(PublicWallUrl, cancel).ConfigureAwait(continueOnCapturedContext: false);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CommunityCatalogue catalogue = CommunityCatalogue.Parse(json);
|
||||
if (catalogue.Source == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (acceptResponse != null)
|
||||
{
|
||||
if (!acceptResponse(Remember))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Remember();
|
||||
}
|
||||
return catalogue;
|
||||
void Remember()
|
||||
{
|
||||
if (catalogue.Looks.Count > 0 || catalogue.Crosshairs.Count > 0)
|
||||
{
|
||||
Save(json, cachePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Save(string json, string cachePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cachePath));
|
||||
string text = cachePath + ".tmp";
|
||||
File.WriteAllText(text, json);
|
||||
File.Move(text, cachePath, overwrite: true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using VibranceHud.Crosshair;
|
||||
using VibranceHud.Display;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class ConfigCode
|
||||
{
|
||||
public sealed record Parts(ProfileCode? Look, CrosshairConfig? Crosshair, MonitorCode? Mode);
|
||||
|
||||
public const string Prefix = "PXF-";
|
||||
|
||||
private const char Separator = '.';
|
||||
|
||||
public static string Encode(ProfileCode? look, CrosshairConfig? crosshair, MonitorCode? mode)
|
||||
{
|
||||
if (!look.HasValue && crosshair == null && !mode.HasValue)
|
||||
{
|
||||
throw new ArgumentException("A config has to carry at least one of the three.");
|
||||
}
|
||||
string[] value = new string[3]
|
||||
{
|
||||
(!look.HasValue) ? "" : ProfileCode.Encode(look.Value),
|
||||
(crosshair == null) ? "" : CrosshairCode.Encode(crosshair),
|
||||
(!mode.HasValue) ? "" : MonitorCode.Encode(mode.Value)
|
||||
};
|
||||
return "PXF-" + string.Join('.', value);
|
||||
}
|
||||
|
||||
public static bool TryDecode(string? code, out Parts parts)
|
||||
{
|
||||
parts = new Parts(null, null, null);
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text = new string((from ch in ShareCodeText.Normalize(code)
|
||||
where !char.IsWhiteSpace(ch)
|
||||
select ch).ToArray());
|
||||
if (!text.StartsWith("PXF-", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string[] array = text.Substring("PXF-".Length).Split('.');
|
||||
if (array.Length != 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ProfileCode? look = null;
|
||||
CrosshairConfig crosshairConfig = null;
|
||||
MonitorCode? mode = null;
|
||||
if (array[0].Length > 0)
|
||||
{
|
||||
if (!ProfileCode.TryDecode(array[0], out var profile))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
look = profile;
|
||||
}
|
||||
if (array[1].Length > 0)
|
||||
{
|
||||
if (!CrosshairCode.TryDecode(array[1], out CrosshairConfig crosshair))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
crosshairConfig = crosshair;
|
||||
}
|
||||
if (array[2].Length > 0)
|
||||
{
|
||||
if (!MonitorCode.TryDecode(array[2], out var mode2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mode = mode2;
|
||||
}
|
||||
if (!look.HasValue && crosshairConfig == null && !mode.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
parts = new Parts(look, crosshairConfig, mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<string> Describe(Parts parts)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
if (parts.Look.HasValue)
|
||||
{
|
||||
list.Add("Colour");
|
||||
}
|
||||
if (parts.Crosshair != null)
|
||||
{
|
||||
list.Add("Crosshair");
|
||||
}
|
||||
MonitorCode? mode = parts.Mode;
|
||||
if (mode.HasValue)
|
||||
{
|
||||
list.Add(mode.GetValueOrDefault().Label());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class ConfigLibrary
|
||||
{
|
||||
public static readonly IReadOnlyList<ConfigLibraryEntry> All = Array.Empty<ConfigLibraryEntry>();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using VibranceHud.Crosshair;
|
||||
using VibranceHud.Display;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public sealed record ConfigLibraryEntry(string Name, string Author, string Game, string Blurb, ConfigCode.Parts Setup)
|
||||
{
|
||||
public string? CommunityId { get; init; }
|
||||
|
||||
public string Code => ConfigCode.Encode(Setup.Look, Setup.Crosshair, Setup.Mode);
|
||||
|
||||
public DisplayPreset? Look
|
||||
{
|
||||
get
|
||||
{
|
||||
ProfileCode? look = Setup.Look;
|
||||
if (look.HasValue)
|
||||
{
|
||||
ProfileCode valueOrDefault = look.GetValueOrDefault();
|
||||
return CommunityCatalogue.LookFrom(valueOrDefault, Name, Blurb);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public CrosshairConfig? Crosshair => Setup.Crosshair;
|
||||
|
||||
public MonitorCode? Mode => Setup.Mode;
|
||||
|
||||
public bool ChangesTheScreenMode => Setup.Mode.HasValue;
|
||||
|
||||
public string Summary()
|
||||
{
|
||||
return string.Join(" · ", ConfigCode.Describe(Setup));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class CrosshairLibrary
|
||||
{
|
||||
public static readonly IReadOnlyList<CrosshairLibraryEntry> All = Array.Empty<CrosshairLibraryEntry>();
|
||||
|
||||
public static IReadOnlyList<string> Games => new string[1] { "All" }.Concat(All.Select((CrosshairLibraryEntry e) => e.Game).Distinct()).ToList();
|
||||
|
||||
public static IReadOnlyList<CrosshairLibraryEntry> ForGame(string game)
|
||||
{
|
||||
if (!string.Equals(game, "All", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return All.Where((CrosshairLibraryEntry e) => string.Equals(e.Game, game, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
}
|
||||
return All;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VibranceHud.Crosshair;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public sealed record CrosshairLibraryEntry(string Name, string Author, string Game, string Blurb, CrosshairConfig Crosshair)
|
||||
{
|
||||
public string? CommunityId { get; init; }
|
||||
|
||||
public string Code => CrosshairCode.Encode(Crosshair);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class DisplayLibrary
|
||||
{
|
||||
public static readonly IReadOnlyList<DisplayLibraryEntry> All = Array.Empty<DisplayLibraryEntry>();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using VibranceHud.Display;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public sealed record DisplayLibraryEntry(string Name, string Author, string Game, string Blurb, MonitorCode Mode)
|
||||
{
|
||||
public string? CommunityId { get; init; }
|
||||
|
||||
public string Code => MonitorCode.Encode(Mode);
|
||||
|
||||
public string Summary()
|
||||
{
|
||||
return Mode.Label() + " · " + Mode.Scaling.Label();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public sealed record LibraryPreset(string Name, string Author, string Game, string Blurb, DisplayPreset Look)
|
||||
{
|
||||
public string? CommunityId { get; init; }
|
||||
|
||||
public string Code => ProfileCode.Encode(new ProfileCode(Look.Vibrance, Look.Saturation, Look.Brightness, Look.Gamma, Look.Contrast, Look.Temperature, Look.Highlights, Look.Shadows, Look.ColourVision).WithDepth(Look.Depth()));
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public enum LinkAction
|
||||
{
|
||||
None,
|
||||
Apply
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class LinkInbox
|
||||
{
|
||||
private static readonly object Gate = new object();
|
||||
|
||||
private static string? _waiting;
|
||||
|
||||
private static Action<string>? _handler;
|
||||
|
||||
public static Action<string>? Handler
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
return _handler;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
string waiting;
|
||||
lock (Gate)
|
||||
{
|
||||
_handler = value;
|
||||
waiting = _waiting;
|
||||
_waiting = null;
|
||||
}
|
||||
if (value != null && waiting != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
value(waiting);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static string? WaitingForTest
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
return _waiting;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Offer(string? link)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(link))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Action<string> handler;
|
||||
lock (Gate)
|
||||
{
|
||||
handler = _handler;
|
||||
if (handler == null)
|
||||
{
|
||||
_waiting = link;
|
||||
return;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
handler(link);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ResetForTest()
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
_waiting = null;
|
||||
_handler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public sealed record LockedLibraryCard(string Kind, string Name, string Author, string Game, string Blurb)
|
||||
{
|
||||
public string? CommunityId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public readonly record struct PlexusLink(LinkAction Action, string Code);
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class PlexusLinks
|
||||
{
|
||||
public const string Scheme = "plexusx";
|
||||
|
||||
internal const int MaxCodeChars = 2048;
|
||||
|
||||
private const string ApplyPrefix = "apply/";
|
||||
|
||||
public static PlexusLink Parse(string? link)
|
||||
{
|
||||
PlexusLink result = new PlexusLink(LinkAction.None, "");
|
||||
if (string.IsNullOrWhiteSpace(link))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
string text = link.Trim();
|
||||
if (text.Length > 2080)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (!text.StartsWith("plexusx://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
string text2 = text.Substring("plexusx".Length + 3);
|
||||
text2 = text2.TrimEnd('/');
|
||||
if (!text2.StartsWith("apply/", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
string stringToUnescape = text2.Substring("apply/".Length);
|
||||
try
|
||||
{
|
||||
stringToUnescape = Uri.UnescapeDataString(stringToUnescape);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return result;
|
||||
}
|
||||
stringToUnescape = stringToUnescape.Trim();
|
||||
if (stringToUnescape.Length == 0 || stringToUnescape.Length > 2048)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return new PlexusLink(LinkAction.Apply, stringToUnescape);
|
||||
}
|
||||
|
||||
public static string For(string code)
|
||||
{
|
||||
return "plexusx://apply/" + Uri.EscapeDataString(code ?? "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VibranceHud.Presets;
|
||||
|
||||
public static class PresetLibrary
|
||||
{
|
||||
public const string Everything = "All";
|
||||
|
||||
public static readonly IReadOnlyList<LibraryPreset> All = Array.Empty<LibraryPreset>();
|
||||
|
||||
public static IReadOnlyList<string> Games => new string[1] { "All" }.Concat(All.Select((LibraryPreset p) => p.Game).Distinct()).ToList();
|
||||
|
||||
public static IReadOnlyList<LibraryPreset> ForGame(string game)
|
||||
{
|
||||
if (!string.Equals(game, "All", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return All.Where((LibraryPreset p) => string.Equals(p.Game, game, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
}
|
||||
return All;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user