-
Notifications
You must be signed in to change notification settings - Fork 22
Add mod storage modes and patch support #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace WheelWizard.GameBanana.Domain; | ||
|
|
||
| public class GameBananaTag | ||
| { | ||
| public string Title { get; set; } = string.Empty; | ||
| public string Value { get; set; } = string.Empty; | ||
| } | ||
|
|
||
| public sealed class GameBananaTagListJsonConverter : JsonConverter<List<GameBananaTag>> | ||
| { | ||
| public override List<GameBananaTag> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| if (reader.TokenType == JsonTokenType.Null) | ||
| return []; | ||
|
|
||
| if (reader.TokenType != JsonTokenType.StartArray) | ||
| throw new JsonException($"Expected StartArray token, but got {reader.TokenType}."); | ||
|
|
||
| var tags = new List<GameBananaTag>(); | ||
|
|
||
| while (reader.Read()) | ||
| { | ||
| if (reader.TokenType == JsonTokenType.EndArray) | ||
| return tags; | ||
|
|
||
| switch (reader.TokenType) | ||
| { | ||
| case JsonTokenType.String: | ||
| var tagText = reader.GetString() ?? string.Empty; | ||
| tags.Add(new() { Title = tagText, Value = tagText }); | ||
| break; | ||
| case JsonTokenType.StartObject: | ||
| using (var tagDocument = JsonDocument.ParseValue(ref reader)) | ||
| { | ||
| var root = tagDocument.RootElement; | ||
| tags.Add( | ||
| new() | ||
| { | ||
| Title = root.TryGetProperty("_sTitle", out var title) ? title.GetString() ?? string.Empty : string.Empty, | ||
| Value = root.TryGetProperty("_sValue", out var value) ? value.GetString() ?? string.Empty : string.Empty, | ||
| } | ||
| ); | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| using (JsonDocument.ParseValue(ref reader)) { } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| throw new JsonException("Unexpected end of GameBanana tag payload."); | ||
| } | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, List<GameBananaTag> value, JsonSerializerOptions options) | ||
| { | ||
| writer.WriteStartArray(); | ||
|
|
||
| foreach (var tag in value) | ||
| { | ||
| writer.WriteStartObject(); | ||
| writer.WriteString("_sTitle", tag.Title); | ||
| writer.WriteString("_sValue", tag.Value); | ||
| writer.WriteEndObject(); | ||
| } | ||
|
|
||
| writer.WriteEndArray(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using WheelWizard.GameBanana.Domain; | ||
| using WheelWizard.Resources.Languages; | ||
| using WheelWizard.Settings; | ||
|
|
||
| namespace WheelWizard.Services; | ||
|
|
||
| public enum ModStorageSystem | ||
| { | ||
| MyStuff, | ||
| Patches, | ||
| } | ||
|
|
||
| public static class ModStorageSystemHelper | ||
| { | ||
| public static ModStorageSystem GetCurrent(ISettingsManager settingsManager) | ||
| { | ||
| return settingsManager.Get<bool>(settingsManager.USE_PATCHES_SYSTEM) ? ModStorageSystem.Patches : ModStorageSystem.MyStuff; | ||
| } | ||
|
|
||
| public static string GetDisplayName(ModStorageSystem storageSystem) => | ||
| storageSystem == ModStorageSystem.Patches ? "Patches" : Common.PageTitle_Mods; | ||
|
|
||
| public static string GetClearFolderPrompt(ModStorageSystem storageSystem) | ||
| { | ||
| if (storageSystem == ModStorageSystem.MyStuff) | ||
| return Phrases.Question_LaunchClearModsFound_Extra; | ||
|
|
||
| //todo: translation lol | ||
| return "You are about to launch the game without mods. Do you want to clear your Patches folder?"; | ||
| } | ||
|
Comment on lines
+20
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Address missing localization for Patches display strings. Lines 21 and 29 contain hardcoded English strings ("Patches" and the prompt text) while Would you like me to help identify all the required localization keys and open an issue to track this? 🤖 Prompt for AI Agents |
||
|
|
||
| public static string GetTargetFolderPath(ModStorageSystem storageSystem, bool isBeta = false) | ||
| { | ||
| if (storageSystem == ModStorageSystem.Patches) | ||
| return isBeta ? PathManager.RrBetaPatchesFolderPath : PathManager.PatchesFolderPath; | ||
|
|
||
| return isBeta ? PathManager.RrBetaMyStuffFolderPath : PathManager.MyStuffFolderPath; | ||
| } | ||
|
|
||
| public static string GetInactiveFolderPath(ModStorageSystem storageSystem, bool isBeta = false) | ||
| { | ||
| var inactiveStorageSystem = storageSystem == ModStorageSystem.Patches ? ModStorageSystem.MyStuff : ModStorageSystem.Patches; | ||
| return GetTargetFolderPath(inactiveStorageSystem, isBeta); | ||
| } | ||
|
|
||
| public static bool UsesPatches(IEnumerable<GameBananaTag>? tags) => tags?.Any(tag => IsPatchesTag(tag.Title)) == true; | ||
|
|
||
| public static bool IsPatchesTag(string? tagTitle) | ||
| { | ||
| var normalizedTitle = tagTitle?.Trim(); | ||
| if (string.IsNullOrWhiteSpace(normalizedTitle)) | ||
| return false; | ||
|
|
||
| var titleOnly = normalizedTitle.Split(':', 2)[0].Trim(); | ||
| return ( | ||
| titleOnly.Equals("patch", StringComparison.OrdinalIgnoreCase) || titleOnly.Equals("patches", StringComparison.OrdinalIgnoreCase) | ||
| ); | ||
| } | ||
|
patchzyy marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.