diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index 0254e6d..c5bd18f 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -1,6 +1,6 @@ - 1.29.9 + 1.29.10 net8.0-windows enable enable diff --git a/ChatTwo/IpcManager.cs b/ChatTwo/IpcManager.cs index cfeb433..06d653b 100755 --- a/ChatTwo/IpcManager.cs +++ b/ChatTwo/IpcManager.cs @@ -1,6 +1,5 @@ using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; -using Dalamud.Plugin; using Dalamud.Plugin.Ipc; namespace ChatTwo; diff --git a/ChatTwo/MessageManager.cs b/ChatTwo/MessageManager.cs index ea277fe..183ef6c 100644 --- a/ChatTwo/MessageManager.cs +++ b/ChatTwo/MessageManager.cs @@ -103,12 +103,8 @@ internal class MessageManager : IAsyncDisposable LastContentId = contentId; // Drain the PendingSync queue into the PendingAsync queue. - while (true) - { - if (!PendingSync.TryDequeue(out var pending)) - return; + while (PendingSync.TryDequeue(out var pending)) PendingAsync.Enqueue(pending); - } } private void ProcessPendingMessages(CancellationToken token) diff --git a/ChatTwo/MessageStore.cs b/ChatTwo/MessageStore.cs index 7456a65..8be63aa 100644 --- a/ChatTwo/MessageStore.cs +++ b/ChatTwo/MessageStore.cs @@ -8,6 +8,7 @@ using MessagePack; using MessagePack.Formatters; using MessagePack.Resolvers; using Microsoft.Data.Sqlite; + using DalamudUtil = Dalamud.Utility.Util; using Encoding = System.Text.Encoding; @@ -118,11 +119,7 @@ internal class MessageStore : IDisposable private SqliteConnection Connection { get; set; } internal static readonly MessagePackSerializerOptions MsgPackOptions = MessagePackSerializerOptions.Standard - .WithResolver(CompositeResolver.Create( - new IMessagePackFormatter[] { new PayloadMessagePackFormatter(), new SeStringMessagePackFormatter(), }, - new IFormatterResolver[] { StandardResolver.Instance } - ) - ); + .WithResolver(CompositeResolver.Create([new PayloadMessagePackFormatter(), new SeStringMessagePackFormatter()], [StandardResolver.Instance])); internal MessageStore(string dbPath) { diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index 141ff9d..10e4e70 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -27,7 +27,8 @@ using ChatTwoPartyFinderPayload = ChatTwo.Util.PartyFinderPayload; namespace ChatTwo; -public sealed class PayloadHandler { +public sealed class PayloadHandler +{ private const string PopupId = "chat2-context-popup"; private ChatLogWindow LogWindow { get; } @@ -105,35 +106,33 @@ public sealed class PayloadHandler { var contentId = chunk.Message?.ContentId ?? 0; var sender = chunk.Message?.Sender.Select(c => c.Link).FirstOrDefault(p => p is PlayerPayload) as PlayerPayload; - if (ImGui.BeginMenu(Language.Context_Integrations)) + using var menu = ImGuiUtil.Menu(Language.Context_Integrations); + if (!menu.Success) + return; + + var cursor = ImGui.GetCursorPos(); + foreach (var id in registered) { - var cursor = ImGui.GetCursorPos(); - - foreach (var id in registered) + try { - try - { - LogWindow.Plugin.Ipc.Invoke(id, sender, contentId, payload, chunk.Message?.SenderSource, chunk.Message?.ContentSource); - } - catch (Exception ex) - { - Plugin.Log.Error(ex, "Error executing integration"); - } + LogWindow.Plugin.Ipc.Invoke(id, sender, contentId, payload, chunk.Message?.SenderSource, chunk.Message?.ContentSource); } - - if (cursor == ImGui.GetCursorPos()) + catch (Exception ex) { - ImGui.PushStyleColor(ImGuiCol.Text, ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled]); - ImGui.Text("No integrations available"); - ImGui.PopStyleColor(); + Plugin.Log.Error(ex, "Error executing integration"); } + } - ImGui.EndMenu(); + if (cursor == ImGui.GetCursorPos()) + { + using var pushedColor = ImRaii.PushColor(ImGuiCol.Text, ImGui.GetStyle().Colors[(int)ImGuiCol.TextDisabled]); + ImGui.Text("No integrations available"); } } private void ContextFooter(bool didCustomContext, Chunk chunk) { + ImRaii.IEndObject? menu = null; if (didCustomContext) { ImGui.Separator(); @@ -143,7 +142,8 @@ public sealed class PayloadHandler { // // It makes it much more convenient in the majority of cases to // copy the message content without having to open a submenu. - if (!ImGui.BeginMenu(Plugin.PluginName)) + menu = ImGuiUtil.Menu(Plugin.PluginName); + if (!menu.Success) return; } @@ -170,19 +170,11 @@ public sealed class PayloadHandler { WrapperUtil.AddNotification(Language.Context_CopyContentSuccess, NotificationType.Info); } - var col = ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled]; - ImGui.PushStyleColor(ImGuiCol.Text, col); - try - { - ImGui.TextUnformatted(message.Code.Type.Name()); - } - finally - { - ImGui.PopStyleColor(); - } + using var pushedColor = ImRaii.PushColor(ImGuiCol.Text, ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled]); + ImGui.TextUnformatted(message.Code.Type.Name()); } - if (didCustomContext) ImGui.EndMenu(); + menu?.Dispose(); } private static string StringifyMessage(Message? message, bool withSender = false) @@ -191,8 +183,7 @@ public sealed class PayloadHandler { return string.Empty; var chunks = withSender ? message.Sender.Concat(message.Content) : message.Content; - return chunks - .Where(chunk => chunk is TextChunk) + return chunks.Where(chunk => chunk is TextChunk) .Cast() .Select(text => text.Content) .Aggregate(string.Concat); @@ -214,7 +205,8 @@ public sealed class PayloadHandler { } } - internal void Hover(Payload payload) { + internal void Hover(Payload payload) + { var hoverSize = 350f * ImGuiHelpers.GlobalScale; switch (payload) @@ -253,11 +245,12 @@ public sealed class PayloadHandler { { ImGui.SetNextWindowSize(new Vector2(width, -1f)); - using var tooltip = ImRaii.Tooltip(); - using var color = ImRaii.PushColor(ImGuiCol.Text, LogWindow.DefaultText); - using var wrap = ImGuiUtil.TextWrapPos(); - - inside(); + using (ImRaii.Tooltip()) + using (ImGuiUtil.TextWrapPos()) + using (ImRaii.PushColor(ImGuiCol.Text, LogWindow.DefaultText)) + { + inside(); + } } public unsafe void MoveTooltip(AddonEvent type, AddonArgs args) @@ -348,22 +341,20 @@ public sealed class PayloadHandler { private void HoverEventItem(ItemPayload payload) { - if (!Sheets.EventItemSheet.HasRow(payload.RawItemId)) + if (!Sheets.EventItemSheet.TryGetRow(payload.RawItemId, out var itemRow)) return; - var item = Sheets.EventItemSheet.GetRow(payload.RawItemId); - if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(item.Icon)).GetWrapOrDefault() is { } icon) + if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(itemRow.Icon)).GetWrapOrDefault() is { } icon) InlineIcon(icon); - var name = ChunkUtil.ToChunks(item.Name.ToDalamudString(), ChunkSource.None, null); + var name = ChunkUtil.ToChunks(itemRow.Name.ToDalamudString(), ChunkSource.None, null); LogWindow.DrawChunks(name.ToList()); ImGui.Separator(); - if (!Sheets.EventItemHelpSheet.HasRow(payload.RawItemId)) + if (!Sheets.EventItemHelpSheet.TryGetRow(payload.RawItemId, out var itemHelpRow)) return; - var help = Sheets.EventItemHelpSheet.GetRow(payload.RawItemId); - LogWindow.DrawChunks(ChunkUtil.ToChunks(help.Description.ToDalamudString(), ChunkSource.None, null).ToList()); + LogWindow.DrawChunks(ChunkUtil.ToChunks(itemHelpRow.Description.ToDalamudString(), ChunkSource.None, null).ToList()); } private void HoverURI(UriPayload uri) @@ -452,15 +443,14 @@ public sealed class PayloadHandler { return; } - if (!Sheets.ItemSheet.HasRow(payload.ItemId)) + if (!Sheets.ItemSheet.TryGetRow(payload.ItemId, out var itemRow)) return; - var item = Sheets.ItemSheet.GetRow(payload.ItemId); var hq = payload.Kind == ItemPayload.ItemKind.Hq; - if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(item.Icon, hq)).GetWrapOrDefault() is { } icon) + if (Plugin.TextureProvider.GetFromGameIcon(new GameIconLookup(itemRow.Icon, hq)).GetWrapOrDefault() is { } icon) InlineIcon(icon); - var name = item.Name.ToDalamudString(); + var name = itemRow.Name.ToDalamudString(); // hq symbol if (hq) name.Payloads.Add(new TextPayload(" ")); @@ -471,7 +461,7 @@ public sealed class PayloadHandler { ImGui.Separator(); var realItemId = payload.RawItemId; - if (item.EquipSlotCategory.RowId != 0) + if (itemRow.EquipSlotCategory.RowId != 0) { if (ImGui.Selectable(Language.Context_TryOn)) GameFunctions.Context.TryOn(realItemId, 0); @@ -480,7 +470,7 @@ public sealed class PayloadHandler { GameFunctions.Context.OpenItemComparison(realItemId); } - if (item.ItemSearchCategory.Value.Category == 3) + if (itemRow.ItemSearchCategory.Value.Category == 3) if (ImGui.Selectable(Language.Context_SearchRecipes)) GameFunctions.Context.SearchForRecipesUsingItem(payload.ItemId); @@ -580,15 +570,17 @@ public sealed class PayloadHandler { if (validContentId && ImGui.Selectable(Language.Context_InviteToParty)) GameFunctions.Party.InviteInInstance(chunk.Message!.ContentId); } - else if (!inInstance && ImGui.BeginMenu(Language.Context_InviteToParty)) + else if (!inInstance) { - if (ImGui.Selectable(Language.Context_InviteToParty_SameWorld)) - GameFunctions.Party.InviteSameWorld(player.PlayerName, (ushort) world.RowId, chunk.Message?.ContentId ?? 0); + using var menu = ImGuiUtil.Menu(Language.Context_InviteToParty); + if (menu.Success) + { + if (ImGui.Selectable(Language.Context_InviteToParty_SameWorld)) + GameFunctions.Party.InviteSameWorld(player.PlayerName, (ushort)world.RowId, chunk.Message?.ContentId ?? 0); - if (validContentId && ImGui.Selectable(Language.Context_InviteToParty_DifferentWorld)) - GameFunctions.Party.InviteOtherWorld(chunk.Message!.ContentId, (ushort) world.RowId); - - ImGui.EndMenu(); + if (validContentId && ImGui.Selectable(Language.Context_InviteToParty_DifferentWorld)) + GameFunctions.Party.InviteOtherWorld(chunk.Message!.ContentId, (ushort)world.RowId); + } } } @@ -626,8 +618,6 @@ public sealed class PayloadHandler { if (validContentId && ImGui.Selectable(Language.Context_AdventurerPlate)) if (!GameFunctions.GameFunctions.TryOpenAdventurerPlate(chunk.Message!.ContentId)) WrapperUtil.AddNotification(Language.Context_AdventurerPlateError, NotificationType.Warning); - - // View Party Finder 0x2E } private IPlayerCharacter? FindCharacterForPayload(PlayerPayload payload) diff --git a/ChatTwo/Plugin.cs b/ChatTwo/Plugin.cs index e9dab48..001158d 100755 --- a/ChatTwo/Plugin.cs +++ b/ChatTwo/Plugin.cs @@ -28,7 +28,7 @@ public sealed class Plugin : IDalamudPlugin [PluginService] internal static ICommandManager CommandManager { get; private set; } = null!; [PluginService] internal static ICondition Condition { get; private set; } = null!; [PluginService] internal static IDataManager DataManager { get; private set; } = null!; - [PluginService] internal static IFramework Framework { get; set; } = null!; + [PluginService] internal static IFramework Framework { get; private set; } = null!; [PluginService] internal static IGameGui GameGui { get; private set; } = null!; [PluginService] internal static IKeyState KeyState { get; private set; } = null!; [PluginService] internal static IObjectTable ObjectTable { get; private set; } = null!; @@ -115,6 +115,7 @@ public sealed class Plugin : IDalamudPlugin WindowSystem.AddWindow(CommandHelpWindow); WindowSystem.AddWindow(SeStringDebugger); WindowSystem.AddWindow(DebuggerWindow); + FontManager.BuildFonts(); Interface.UiBuilder.DisableCutsceneUiHide = true; @@ -122,7 +123,7 @@ public sealed class Plugin : IDalamudPlugin MessageManager = new MessageManager(this); // requires Ui - // let all the other components register, then initialise commands + // let all the other components register, then initialize commands Commands.Initialise(); if (Interface.Reason is not PluginLoadReason.Boot) @@ -156,6 +157,7 @@ public sealed class Plugin : IDalamudPlugin { Log.Error(ex, "Plugin load threw an error, turning off plugin"); Dispose(); + // Re-throw the exception to fail the plugin load. throw; } diff --git a/ChatTwo/Resources/Language.es.resx b/ChatTwo/Resources/Language.es.resx index 4ec8984..09e4bca 100644 --- a/ChatTwo/Resources/Language.es.resx +++ b/ChatTwo/Resources/Language.es.resx @@ -137,7 +137,7 @@ Mostrar descripción del ítem - Mostrar descripción del ítem cuando el cursor pase sobre el objeto en el {0}. + Mostrar información emergente de los objetos del juego al pasar el cursor sobre ellos en {0}. Mostrar pestañas en la barra lateral @@ -152,10 +152,10 @@ Mostrar mensajes con un estilo más moderno. - 24-hour clock + Reloj 24 horas - Display timestamps as their 24-hour clock version. + Mostrar las marcas de tiempo en formato de reloj de 24 horas. Diseño más moderno y compacto @@ -227,7 +227,7 @@ Modo no leído - Unhide the chat window on activity + Mostrar la ventana de chat en la actividad <Ninguno> @@ -347,10 +347,10 @@ La fuente {0} se utilizará para mostrar el texto japonés. - Italic font + Fuente en cursiva - If enabled, uses the italic font in {0}, else it will use the ingame italic font. + Si está activado, utiliza la fuente cursiva en {0}, de lo contrario usará la fuente cursiva del juego. Especiales @@ -443,7 +443,7 @@ Canales de chat considerados para la actividad - Which chat channels should be considered for activity. Other channels will not restore the chat regardless of which tab they occur in. + Qué canales de chat deben ser considerados para la actividad. Otros canales no restaurarán el chat sin importar en qué pestaña se encuentren. Seleccionar Todo @@ -464,7 +464,7 @@ Otros - Webinterface + Interfaz Web Usar el idioma por defecto de Dalamud @@ -551,16 +551,16 @@ Si esto está habilitado, la lista del Traductor Automático se ordenará alfabéticamente. - Enabled + Habilitado - Enables the webinterface that can be accessed with a browser. + Habilita la interfaz web a la que se puede acceder con un navegador. - Start automatically + Iniciar automáticamente - Webinterface will start alongside the plugin automatically + La interfaz web comenzará junto al plugin automáticamente Sobrescribir estilo @@ -569,22 +569,22 @@ Estilos - Cycle chat tab forwards keybind + Ciclo de la pestaña de chat hacia adelante - Cycle chat tab backwards keybind + Ciclo de la pestaña de chat hacia atrás - Authcode: + Código de autor: - Reset your password and invalidate all session tokens. + Restablecer su contraseña e invalidar todos los tokens de sesión. - Control Panel: + Panel de control: - Active: + Activo: URL: @@ -995,7 +995,7 @@ Mensaje copiado al portapapeles - Unable to find ID for this message, please try another one. + No se puede encontrar el ID de este mensaje, por favor prueba con otro. Copiar enlace al portapapeles @@ -1088,10 +1088,10 @@ Limita la cantidad de líneas de registro que se pueden mostrar en la ventana de chat. Esto puede mejorar ligeramente el rendimiento. - Log line limit for the webinterface + Límite de líneas de registro para la interfaz web - Limits the amount of log lines to show in the webinterface. This will improve loading performance. + Limita la cantidad de líneas de registro a mostrar en la interfaz web. Esto mejorará el rendimiento de la carga. Ha ocurrido un error al cargar el historial del chat. Por favor comprueba los registros del plugin para más informacion para reportar este problema. @@ -1319,57 +1319,57 @@ Se produjo un error al enviar este mensaje privado - Webinterface was stopped. + Interfaz web detenida. - Webinterface failed to stop. Check /xllog for more information. + La interfaz web no se ha detenido. Revisa /xllog para más información. - Stop + Detener - Start + Iniciar - Webinterface was started. + Interfaz web iniciada. - Webinterface failed to start. Check /xllog for more information. + La interfaz web no pudo iniciarse. Revisa /xllog para más información. - Port + Puerto - The port this webinterface will be running on. + Puerto en el que se ejecutará esta interfaz web. - After checking 'Enabled' and clicking 'Start' this will load up Chat2's built-in web interface, which will allow devices on your network to access in-game chat. This feature may be used to allow a phone or another computer to see Chat2 activity, switch channels, and send messages as though you were typing in FFXIV itself. + Después de marcar 'Activado' y hacer clic en 'Iniciar', se cargará la interfaz web integrada de Chat2, que permitirá a los dispositivos de tu red acceder al chat en el juego. Esta función se puede utilizar para permitir que un teléfono u otro equipo vea la actividad de Chat2, cambie de canal, y envíe mensajes como si estuvieras escribiendo en FFXIV. - For reasons of account security, this feature is not intended for use outside of your local network, you have been warned! + Por razones de seguridad de la cuenta, esta característica no está pensada para su uso fuera de su red local, ¡usted ha sido advertido! - Do Not: + No: - - Forward the port used (9000) + Redirijas el puerto usado (9000) - - Share your authentication code with anyone else + Compartas tu código con nadie más - - Expect multi-boxing to work with this (only first client works) + Esperes que el multi-Boeing funcione con esto (solo el primer cliente funciona). - No support will be provided if any of the 'Do Not' clauses aren't respected and adhered to appropriately. + No se proporcionará ningún soporte a las cláusulas de "NO" que no sean respetadas y adheridas apropiadamente. - Unable to resolve hostname. + Incapaz de resolver nombre del host. - Note: This will require at least a semi-modern browser in order to function correctly. + Nota: Esto requerirá al menos un navegador semi moderno para funcionar correctamente - Usage Notice + Aviso de Uso diff --git a/ChatTwo/Resources/Language.fr.resx b/ChatTwo/Resources/Language.fr.resx index ef6a7f1..8067203 100644 --- a/ChatTwo/Resources/Language.fr.resx +++ b/ChatTwo/Resources/Language.fr.resx @@ -1088,10 +1088,10 @@ Limite le nombre de lignes à afficher dans la fenêtre de chat. Cela peut légèrement améliorer les performances. - Log line limit for the webinterface + Nombre de lignes maximum de l'interface web - Limits the amount of log lines to show in the webinterface. This will improve loading performance. + Limite le nombre de lignes à afficher dans l'interface web. Cela améliore la performance des chargements. Une erreur s'est produite lors du chargement de l'historique de la conversation. Veuillez consulter les logs du plugin pour plus d'informations pour signaler ce problème. diff --git a/ChatTwo/Resources/Language.nl.resx b/ChatTwo/Resources/Language.nl.resx index 37c5734..d81d1e6 100644 --- a/ChatTwo/Resources/Language.nl.resx +++ b/ChatTwo/Resources/Language.nl.resx @@ -1088,10 +1088,10 @@ Limiteer het maximum aantal regels die worden getoont in het chatvester. - Log line limit for the webinterface + Regel limiet voor de webinterface - Limits the amount of log lines to show in the webinterface. This will improve loading performance. + Beperkt het aantal regels om weer te geven in de webinterface. Dit zal de laadprestaties verbeteren. Er is een fout opgetreden tijdens het laden van de chatgeschiedenis. Bekijk de plugin logs voor meer informatie om dit probleem te rapporteren. diff --git a/ChatTwo/Resources/Language.zh-Hans.resx b/ChatTwo/Resources/Language.zh-Hans.resx index 4810eb3..3071f5b 100644 --- a/ChatTwo/Resources/Language.zh-Hans.resx +++ b/ChatTwo/Resources/Language.zh-Hans.resx @@ -1088,10 +1088,10 @@ 限制在聊天窗口中显示的日志行数。这可能会稍微提高性能。 - Log line limit for the webinterface + 网页界面日志行数限制 - Limits the amount of log lines to show in the webinterface. This will improve loading performance. + 限制在网页界面中显示的日志行数。可提高加载性能。 加载聊天记录时发生错误。请查看插件日志以获取更多信息以报告此问题。 diff --git a/ChatTwo/Util/AutoTranslate.cs b/ChatTwo/Util/AutoTranslate.cs index 4539b10..1cb9fe4 100644 --- a/ChatTwo/Util/AutoTranslate.cs +++ b/ChatTwo/Util/AutoTranslate.cs @@ -12,7 +12,6 @@ using Lumina.Text.ReadOnly; using Pidgin; using static Pidgin.Parser; using static Pidgin.Parser; -using TextPayload = Lumina.Text.Payloads.TextPayload; namespace ChatTwo.Util; @@ -27,71 +26,28 @@ internal static class AutoTranslate .AtLeastOnceUntil(Lookahead(Char('[').IgnoreResult().Or(End))) .Select(string.Concat) .Labelled("sheetName"); - var numPair = Map( - (first, second) => (ISelectorPart) new IndexRange( - uint.Parse(string.Concat(first)), - uint.Parse(string.Concat(second)) - ), + var numPair = Map(ISelectorPart (first, second) => + new IndexRange(uint.Parse(string.Concat(first)), uint.Parse(string.Concat(second))), Digit.AtLeastOnce().Before(Char('-')), - Digit.AtLeastOnce() - ) + Digit.AtLeastOnce()) .Labelled("numPair"); var singleRow = Digit .AtLeastOnce() .Select(string.Concat) - .Select(num => (ISelectorPart) new SingleRow(uint.Parse(num))); + .Select(ISelectorPart (num) => new SingleRow(uint.Parse(num))); var column = String("col-") .Then(Digit.AtLeastOnce()) .Select(string.Concat) - .Select(num => (ISelectorPart) new ColumnSpecifier(uint.Parse(num))); + .Select(ISelectorPart (num) => new ColumnSpecifier(uint.Parse(num))); var noun = String("noun") - .Select(_ => (ISelectorPart) new NounMarker()); - var selectorItems = OneOf( - Try(numPair), - singleRow, - column, - noun - ) + .Select(ISelectorPart (_) => new NounMarker()); + var selectorItems = OneOf(Try(numPair), singleRow, column, noun) .Separated(Char(',')) .Labelled("selectorItems"); var selector = selectorItems .Between(Char('['), Char(']')) .Labelled("selector"); - return Map( - (name, sel) => (name, sel), - sheetName, - selector.Optional() - ); - } - - private static string TextValue(this Lumina.Text.SeString str) - { - var payloads = str.Payloads - .Select(p => { - if (p is TextPayload text) { - return p.Data[0] == 0x03 - ? text.RawString[1..] - : text.RawString; - } - - if (p.Data.Length <= 1) { - return ""; - } - - if (p.Data[1] == 0x1F) { - return "-"; - } - - if (p.Data.Length > 2 && p.Data[1] == 0x20) { - var value = p.Data.Length > 4 - ? p.Data[3] - 1 - : p.Data[2]; - return ((char) (48 + value)).ToString(); - } - - return ""; - }); - return string.Join("", payloads); + return Map((name, sel) => (name, sel), sheetName, selector.Optional()); } /// @@ -131,7 +87,7 @@ internal static class AutoTranslate var sheet = Plugin.DataManager.Excel.GetSheet(name: sheetName); var columns = new List(); - var rows = new List(); + var rows = new List(); if (selector.HasValue) { columns.Clear(); @@ -179,21 +135,17 @@ internal static class AutoTranslate // See above. for (var i = range.Start.Value; i < range.End.Value; i++) { - if (!sheet.TryGetRow((uint)i, out var rowParser)) continue; + if (!sheet.TryGetRow((uint)i, out var rowParser)) + continue; foreach (var col in columns) { - var rawName = rowParser.RawRow.ReadStringColumn(col)!; - var name = rawName.ToDalamudString(); - var text = name.TextValue; + var rawName = rowParser.RawRow.ReadStringColumn(col); + var name = rawName.ToDalamudString(); + var text = name.TextValue; if (text.Length > 0) { - list.Add(new AutoTranslateEntry( - row.Group, - (uint)i, - text, - name - )); + list.Add(new AutoTranslateEntry(row.Group, (uint)i, text, name)); if (shouldAdd) ValidEntries.Add((row.Group, (uint)i)); @@ -205,12 +157,7 @@ internal static class AutoTranslate else if (lookup is not "@") { var text = row.Text.ToDalamudString(); - list.Add(new AutoTranslateEntry( - row.Group, - row.RowId, - text.TextValue, - text - )); + list.Add(new AutoTranslateEntry(row.Group, row.RowId, text.TextValue, text)); if (shouldAdd) ValidEntries.Add((row.Group, row.RowId)); @@ -271,33 +218,30 @@ internal static class AutoTranslate var start = -1; for (var i = 0; i < bytes.Length; i++) { - if (start != -1) { - if (bytes[i] == '>') - { - var tag = Encoding.UTF8.GetString(bytes[start..(i + 1)]); - var parts = tag[4..^1].Split(',', 2); - if (parts.Length == 2 && uint.TryParse(parts[0], out var group) && uint.TryParse(parts[1], out var key)) - { - var payload = ValidEntries.Contains((group, key)) - ? new AutoTranslatePayload(group, key).Encode() - : []; - - var oldBytes = bytes.ToArray(); - var lengthDiff = payload.Length - (i - start); - bytes = new byte[oldBytes.Length + lengthDiff]; - Array.Copy(oldBytes, bytes, start); - Array.Copy(payload, 0, bytes, start, payload.Length); - Array.Copy(oldBytes, i + 1, bytes, start + payload.Length, oldBytes.Length - (i + 1)); - - i += lengthDiff; - } - - start = -1; - } - else - { + if (start != -1) + { + if (bytes[i] != '>') continue; + + var tag = Encoding.UTF8.GetString(bytes[start..(i + 1)]); + var parts = tag[4..^1].Split(',', 2); + if (parts.Length == 2 && uint.TryParse(parts[0], out var group) && uint.TryParse(parts[1], out var key)) + { + var payload = ValidEntries.Contains((group, key)) + ? new AutoTranslatePayload(group, key).Encode() + : []; + + var oldBytes = bytes.ToArray(); + var lengthDiff = payload.Length - (i - start); + bytes = new byte[oldBytes.Length + lengthDiff]; + Array.Copy(oldBytes, bytes, start); + Array.Copy(payload, 0, bytes, start, payload.Length); + Array.Copy(oldBytes, i + 1, bytes, start + payload.Length, oldBytes.Length - (i + 1)); + + i += lengthDiff; } + + start = -1; } if (i + search.Length < bytes.Length && memcmp(bytes[i..], search, (nuint) search.Length) == 0) @@ -311,9 +255,9 @@ public readonly struct WorkingRawRow(RawRow row) : IExcelRow { public uint RowId => row.RowId; public RawRow RawRow => row; - + static WorkingRawRow IExcelRow.Create(ExcelPage page, uint offset, uint row) => - new(new(page, offset, row)); + new(new RawRow(page, offset, row)); } internal interface ISelectorPart { } diff --git a/ChatTwo/Util/ColourUtil.cs b/ChatTwo/Util/ColourUtil.cs index 7187ff4..a3e7722 100755 --- a/ChatTwo/Util/ColourUtil.cs +++ b/ChatTwo/Util/ColourUtil.cs @@ -4,7 +4,8 @@ using System.Numerics; namespace ChatTwo.Util; internal static class ColourUtil { - internal static (byte r, byte g, byte b, byte a) RgbaToComponents(uint rgba) { + internal static (byte r, byte g, byte b, byte a) RgbaToComponents(uint rgba) + { var r = (byte) ((rgba & 0xFF000000) >> 24); var g = (byte) ((rgba & 0xFF0000) >> 16); var b = (byte) ((rgba & 0xFF00) >> 8); @@ -14,12 +15,14 @@ internal static class ColourUtil { internal static uint RgbaToAbgr(uint rgba) => BinaryPrimitives.ReverseEndianness(rgba); - internal static Vector3 RgbaToVector3(uint rgba) { + internal static Vector3 RgbaToVector3(uint rgba) + { var (r, g, b, _) = RgbaToComponents(rgba); return new Vector3((float) r / 255, (float) g / 255, (float) b / 255); } - internal static uint Vector3ToRgba(Vector3 col) { + internal static uint Vector3ToRgba(Vector3 col) + { return ComponentsToRgba( (byte) Math.Round(col.X * 255), (byte) Math.Round(col.Y * 255), @@ -27,7 +30,8 @@ internal static class ColourUtil { ); } - internal static uint Vector4ToAbgr(Vector4 col) { + internal static uint Vector4ToAbgr(Vector4 col) + { return RgbaToAbgr(ComponentsToRgba( (byte) Math.Round(col.X * 255), (byte) Math.Round(col.Y * 255), diff --git a/ChatTwo/Util/ExtraPayload.cs b/ChatTwo/Util/ExtraPayload.cs index 5430c11..3c8481f 100644 --- a/ChatTwo/Util/ExtraPayload.cs +++ b/ChatTwo/Util/ExtraPayload.cs @@ -24,17 +24,14 @@ public class ColorPayload payload.Enabled = false; return payload; case 0xE9: - { var param = stream.ReadByte(); - var value = (uint) GlobalParametersCache.GetValue(param - 2); + var globalValue = (uint) GlobalParametersCache.GetValue(param - 2); payload.Enabled = true; - payload.UnshiftedColor = value; - payload.Color = ColourUtil.ArgbToRgba(value); + payload.UnshiftedColor = globalValue; + payload.Color = ColourUtil.ArgbToRgba(globalValue); return payload; - } case >= 0xF0 and <= 0xFE: - { // From: https://github.com/NotAdam/Lumina/blob/master/src/Lumina/Text/Expressions/IntegerExpression.cs#L119-L128 uint ShiftAndThrowIfZero(int v, int shift) { @@ -47,21 +44,20 @@ public class ColorPayload } typeByte += 1; - var value = 0u; + var argbValue = 0u; if ((typeByte & 8) != 0) - value |= ShiftAndThrowIfZero(stream.ReadByte(), 24); + argbValue |= ShiftAndThrowIfZero(stream.ReadByte(), 24); else - value |= 0xff000000u; + argbValue |= 0xff000000u; - if( (typeByte & 4) != 0 ) value |= ShiftAndThrowIfZero( stream.ReadByte(), 16 ); - if( (typeByte & 2) != 0 ) value |= ShiftAndThrowIfZero( stream.ReadByte(), 8 ); - if( (typeByte & 1) != 0 ) value |= ShiftAndThrowIfZero( stream.ReadByte(), 0 ); + if( (typeByte & 4) != 0 ) argbValue |= ShiftAndThrowIfZero( stream.ReadByte(), 16 ); + if( (typeByte & 2) != 0 ) argbValue |= ShiftAndThrowIfZero( stream.ReadByte(), 8 ); + if( (typeByte & 1) != 0 ) argbValue |= ShiftAndThrowIfZero( stream.ReadByte(), 0 ); payload.Enabled = true; - payload.Color = ColourUtil.ArgbToRgba(value); + payload.Color = ColourUtil.ArgbToRgba(argbValue); return payload; - } default: return null; } diff --git a/ChatTwo/Util/GlobalParametersCache.cs b/ChatTwo/Util/GlobalParametersCache.cs index f2849e6..1dbb157 100644 --- a/ChatTwo/Util/GlobalParametersCache.cs +++ b/ChatTwo/Util/GlobalParametersCache.cs @@ -12,6 +12,7 @@ public static class GlobalParametersCache { if (index < 0 || index >= Cache.Length) return 0; + return Cache[index]; } @@ -31,9 +32,9 @@ public static class GlobalParametersCache return; ref var gp = ref rtm->TextModule.MacroDecoder.GlobalParameters; - if (Cache.Length != (int)gp.MySize) Cache = new int[gp.MySize]; + for (ulong i = 0; i < gp.MySize; i++) { var p = gp[(long)i]; diff --git a/ChatTwo/Util/IconUtil.cs b/ChatTwo/Util/IconUtil.cs index c7aa2c9..c7f8eac 100755 --- a/ChatTwo/Util/IconUtil.cs +++ b/ChatTwo/Util/IconUtil.cs @@ -137,7 +137,8 @@ public readonly unsafe ref struct GfdFileView -internal static class IconUtil { +internal static class IconUtil +{ private static byte[]? GfdFile; public static unsafe GfdFileView GfdFileView { diff --git a/ChatTwo/Util/ImGuiUtil.cs b/ChatTwo/Util/ImGuiUtil.cs index 52843da..8e24435 100755 --- a/ChatTwo/Util/ImGuiUtil.cs +++ b/ChatTwo/Util/ImGuiUtil.cs @@ -186,15 +186,16 @@ internal static class ImGuiUtil Plugin.FontManager.FontAwesome.Push(); var size = new Vector2(0, 0); if (width > 0) - { - var style = ImGui.GetStyle(); - size.X = width - 2 * style.CellPadding.X; - } + size.X = width - 2 * ImGui.GetStyle().CellPadding.X; + var ret = ImGui.Button(label, size); Plugin.FontManager.FontAwesome.Pop(); if (tooltip != null && ImGui.IsItemHovered()) - ImGui.SetTooltip(tooltip); + { + using var startedTooltip = ImRaii.Tooltip(); + ImGuiHelpers.SafeTextWrapped(tooltip); + } return ret; } @@ -224,11 +225,8 @@ internal static class ImGuiUtil var style = StyleModel.GetConfiguredStyle() ?? StyleModel.GetFromCurrent(); var dalamudOrange = style.BuiltInColors?.DalamudOrange; - var push = dalamudOrange != null; - var color = dalamudOrange ?? Vector4.Zero; - using (TextWrapPos(wrap)) - using (ImRaii.PushColor(ImGuiCol.Text, color, push)) + using (ImRaii.PushColor(ImGuiCol.Text, dalamudOrange ?? Vector4.Zero, dalamudOrange != null)) { ImGui.TextUnformatted(text); } @@ -305,18 +303,17 @@ internal static class ImGuiUtil if (combo) { foreach (var size in FontManager.AxisFontSizeList) - if (ImGui.Selectable($"{size:###.##}pt", currentSize == size)) + if (ImGui.Selectable($"{size:###.##}pt", currentSize.Equals(size))) currentSize = size; } } public static bool Button(string id, FontAwesomeIcon icon, bool disabled) { - var clicked = false; using (ImRaii.Disabled(disabled)) - clicked = ImGuiComponents.IconButton(id, icon); - - return clicked; + { + return ImGuiComponents.IconButton(id, icon); + } } internal static bool CtrlShiftButton(string label, string tooltip = "") @@ -328,7 +325,10 @@ internal static class ImGuiUtil ret = ImGui.Button(label) && ctrlShiftHeld; if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) - ImGui.SetTooltip(tooltip); + { + using var startedTooltip = ImRaii.Tooltip(); + ImGuiHelpers.SafeTextWrapped(tooltip); + } return ret; } @@ -345,15 +345,19 @@ internal static class ImGuiUtil var ret = ImGui.Button(label) && ctrlShiftHeld; if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) - ImGui.SetTooltip(tooltip); + { + using var startedTooltip = ImRaii.Tooltip(); + ImGuiHelpers.SafeTextWrapped(tooltip); + } return ret; } } - internal static bool KeybindInput(string id, ref ConfigKeyBind? keybind) + internal static void KeybindInput(string id, ref ConfigKeyBind? keybind) { var idUint = ImGui.GetID(id); + using var pushedId = ImRaii.PushId(id); if (ImGui.GetStateStorage().GetBool(idUint)) { @@ -387,7 +391,7 @@ internal static class ImGuiUtil { keybind = null; ImGui.GetStateStorage().SetBool(idUint, false); - return false; + return; } foreach (var vk in Enum.GetValues(typeof(VirtualKey)).Cast()) @@ -404,7 +408,7 @@ internal static class ImGuiUtil Key = vk }; ImGui.GetStateStorage().SetBool(idUint, false); - return true; + return; } } else @@ -415,8 +419,6 @@ internal static class ImGuiUtil if (ImGui.Button(text, new Vector2(-1, 0))) ImGui.GetStateStorage().SetBool(idUint, true); } - - return false; } public static void DrawArrows(ref int selected, int min, int max, float spacing, int id = 0) @@ -428,13 +430,15 @@ internal static class ImGuiUtil ImGui.SameLine(0, spacing); using (ImRaii.Disabled(isMin)) { - if (IconButton(FontAwesomeIcon.ArrowLeft, id.ToString())) selected--; + if (IconButton(FontAwesomeIcon.ArrowLeft, id.ToString())) + selected--; } ImGui.SameLine(0, spacing); using (ImRaii.Disabled(isMax)) { - if (IconButton(FontAwesomeIcon.ArrowRight, id+1.ToString())) selected++; + if (IconButton(FontAwesomeIcon.ArrowRight, id+1.ToString())) + selected++; } } @@ -447,7 +451,8 @@ internal static class ImGuiUtil internal static bool TryToImGui(this VirtualKey key, out ImGuiKey result) { - result = key switch { + result = key switch + { VirtualKey.NO_KEY => ImGuiKey.None, VirtualKey.BACK => ImGuiKey.Backspace, VirtualKey.TAB => ImGuiKey.Tab, @@ -561,13 +566,12 @@ internal static class ImGuiUtil return result != 0 || key == VirtualKey.NO_KEY; } - private struct EndUnconditionally(Action endAction, bool success) : ImRaii.IEndObject + public struct EndUnconditionally(Action endAction, bool success) : ImRaii.IEndObject { - private Action EndAction { get; } = endAction; - public bool Success { get; } = success; - public bool Disposed { get; private set; } = false; + private bool Disposed { get; set; } = false; + private Action EndAction { get; } = endAction; public void Dispose() { @@ -594,10 +598,15 @@ internal static class ImGuiUtil return new EndUnconditionally(ImGui.PopTextWrapPos, true); } + public static ImRaii.IEndObject Menu(string label) + { + return new EndUnconditionally(ImGui.EndMenu, ImGui.BeginMenu(label)); + } + public static void ChannelSelector(string headerText, Dictionary chatCodes) { using var channelNode = ImRaii.TreeNode(headerText); - if (!channelNode) + if (!channelNode.Success) return; foreach (var (header, types) in ChatTypeExt.SortOrder) diff --git a/ChatTwo/Util/Lender.cs b/ChatTwo/Util/Lender.cs index 456f9f4..94c48b3 100755 --- a/ChatTwo/Util/Lender.cs +++ b/ChatTwo/Util/Lender.cs @@ -1,23 +1,26 @@ namespace ChatTwo.Util; -internal class Lender { - private readonly Func _ctor; - private readonly List _items = new(); - private int _counter; +internal class Lender +{ + private readonly Func Ctor; + private readonly List Items = []; + private int Counter; - internal Lender(Func ctor) { - _ctor = ctor; + internal Lender(Func ctor) + { + Ctor = ctor; } - internal void ResetCounter() { - _counter = 0; + internal void ResetCounter() + { + Counter = 0; } - internal T Borrow() { - if (_items.Count <= _counter) { - _items.Add(_ctor()); - } + internal T Borrow() + { + if (Items.Count <= Counter) + Items.Add(Ctor()); - return _items[_counter++]; + return Items[Counter++]; } } diff --git a/ChatTwo/Util/Payloads.cs b/ChatTwo/Util/Payloads.cs index f8761ad..d1ec2fb 100755 --- a/ChatTwo/Util/Payloads.cs +++ b/ChatTwo/Util/Payloads.cs @@ -2,38 +2,46 @@ using Dalamud.Game.Text.SeStringHandling; namespace ChatTwo.Util; -internal class PartyFinderPayload : Payload { +internal class PartyFinderPayload : Payload +{ public override PayloadType Type => (PayloadType) 0x50; internal uint Id { get; } - internal PartyFinderPayload(uint id) { + internal PartyFinderPayload(uint id) + { Id = id; } - protected override byte[] EncodeImpl() { + protected override byte[] EncodeImpl() + { throw new NotImplementedException(); } - protected override void DecodeImpl(BinaryReader reader, long endOfStream) { + protected override void DecodeImpl(BinaryReader reader, long endOfStream) + { throw new NotImplementedException(); } } -internal class AchievementPayload : Payload { +internal class AchievementPayload : Payload +{ public override PayloadType Type => (PayloadType) 0x51; internal uint Id { get; } - internal AchievementPayload(uint id) { + internal AchievementPayload(uint id) + { Id = id; } - protected override byte[] EncodeImpl() { + protected override byte[] EncodeImpl() + { throw new NotImplementedException(); } - protected override void DecodeImpl(BinaryReader reader, long endOfStream) { + protected override void DecodeImpl(BinaryReader reader, long endOfStream) + { throw new NotImplementedException(); } } @@ -45,8 +53,8 @@ internal class UriPayload(Uri uri) : Payload public Uri Uri { get; } = uri; + private const string DefaultScheme = "https"; private static readonly string[] ExpectedSchemes = ["http", "https"]; - private static readonly string DefaultScheme = "https"; /// /// Create a URIPayload from a raw URI string. If the URI does not have a @@ -59,18 +67,12 @@ internal class UriPayload(Uri uri) : Payload { ArgumentNullException.ThrowIfNull(rawURI); - // Check for expected scheme ://, if not add https:// - foreach (var scheme in ExpectedSchemes) - { - if (rawURI.StartsWith($"{scheme}://")) - { - return new UriPayload(new Uri(rawURI)); - } - } + // Check for an expected scheme '://', if not add 'https://' + if (ExpectedSchemes.Any(scheme => rawURI.StartsWith($"{scheme}://"))) + return new UriPayload(new Uri(rawURI)); + if (rawURI.Contains("://")) - { throw new UriFormatException($"Unsupported scheme in URL: {rawURI}"); - } return new UriPayload(new Uri($"{DefaultScheme}://{rawURI}")); } @@ -90,7 +92,7 @@ internal class EmotePayload : Payload { public override PayloadType Type => (PayloadType) 0x53; - public string Code; + public string Code = string.Empty; public static EmotePayload ResolveEmote(string code) { diff --git a/ChatTwo/Util/SearchSelector.cs b/ChatTwo/Util/SearchSelector.cs index 3acc6f2..28c87d3 100644 --- a/ChatTwo/Util/SearchSelector.cs +++ b/ChatTwo/Util/SearchSelector.cs @@ -2,6 +2,7 @@ using Dalamud.Interface.Utility; using ImGuiNET; using System.Collections; +using Dalamud.Interface.Utility.Raii; namespace ChatTwo.Util; @@ -58,7 +59,6 @@ public static class SearchSelector public static bool SelectorPopup(string id, out string selected, SelectorPopupOptions? options = null, bool close = false) { - options ??= new SelectorPopupOptions(); var sheet = options.FilteredSheet; selected = string.Empty; @@ -67,12 +67,15 @@ public static class SearchSelector return false; ImGui.SetNextWindowSize(options.Size ?? new Vector2(0, 250 * ImGuiHelpers.GlobalScale)); - if (!ImGui.BeginPopupContextItem(id, options.PopupFlags)) + using var popup = ImRaii.ContextPopupItem(id, options.PopupFlags); + if (!popup.Success) return false; SearchInput(id, sheet, options.SearchPredicate ?? ((row, s) => options.FormatRow(row).Contains(s, StringComparison.CurrentCultureIgnoreCase))); - ImGui.BeginChild("SearchList", Vector2.Zero, true); + using var child = ImRaii.Child("SearchList", Vector2.Zero, true); + if (!child.Success) + return false; var ret = false; var drawSelectable = options.DrawSelectable ?? ((row, selected) => ImGui.Selectable(options.FormatRow(row), selected)); @@ -81,11 +84,12 @@ public static class SearchSelector foreach (var i in clipper.Rows) { var searched = FilteredSearchSheet[i]; - ImGui.PushID(id); - if (!drawSelectable(searched, options.IsSelected(searched))) continue; + using var pushedId = ImRaii.PushId(id); + if (!drawSelectable(searched, options.IsSelected(searched))) + continue; + selected = searched; ret = true; - ImGui.PopID(); } } @@ -93,8 +97,6 @@ public static class SearchSelector if (ret && options.CloseOnSelection) ImGui.CloseCurrentPopup(); - ImGui.EndChild(); - ImGui.EndPopup(); return ret; } } diff --git a/ChatTwo/Util/StringUtil.cs b/ChatTwo/Util/StringUtil.cs index c21b9b7..0e52b06 100755 --- a/ChatTwo/Util/StringUtil.cs +++ b/ChatTwo/Util/StringUtil.cs @@ -2,8 +2,10 @@ using System.Text; namespace ChatTwo.Util; -internal static class StringUtil { - internal static byte[] ToTerminatedBytes(this string s) { +internal static class StringUtil +{ + internal static byte[] ToTerminatedBytes(this string s) + { var utf8 = Encoding.UTF8; var bytes = new byte[utf8.GetByteCount(s) + 1]; utf8.GetBytes(s, 0, s.Length, bytes, 0); @@ -12,7 +14,8 @@ internal static class StringUtil { } // Taken from https://stackoverflow.com/a/4975942 - internal static string BytesToString(long byteCount) { + internal static string BytesToString(long byteCount) + { string[] suf = ["B", "KB", "MB", "GB", "TB", "PB", "EB"]; // Longs run out around EB if (byteCount == 0) return "0" + suf[0]; diff --git a/ChatTwo/Util/TabsUtil.cs b/ChatTwo/Util/TabsUtil.cs index 7749938..833955f 100755 --- a/ChatTwo/Util/TabsUtil.cs +++ b/ChatTwo/Util/TabsUtil.cs @@ -3,7 +3,8 @@ using ChatTwo.Resources; namespace ChatTwo.Util; -internal static class TabsUtil { +internal static class TabsUtil +{ internal static Dictionary AllChannels() { var channels = new Dictionary(); @@ -12,9 +13,11 @@ internal static class TabsUtil { return channels; } - internal static Tab VanillaGeneral => new() { + internal static Tab VanillaGeneral => new() + { Name = Language.Tabs_Presets_General, - ChatCodes = new Dictionary { + ChatCodes = new Dictionary + { // Special [ChatType.Debug] = ChatSourceExt.All, [ChatType.Urgent] = ChatSourceExt.All, @@ -75,11 +78,10 @@ internal static class TabsUtil { }, }; - internal static Tab VanillaEvent => new() { + internal static Tab VanillaEvent => new() + { Name = Language.Tabs_Presets_Event, - ChatCodes = new Dictionary { - [ChatType.NpcDialogue] = ChatSourceExt.All, - }, + ChatCodes = new Dictionary { [ChatType.NpcDialogue] = ChatSourceExt.All, }, }; internal static Dictionary MostlyPlayer => new() diff --git a/ChatTwo/Util/Tokenizer.cs b/ChatTwo/Util/Tokenizer.cs index 9092c7e..82f90ab 100644 --- a/ChatTwo/Util/Tokenizer.cs +++ b/ChatTwo/Util/Tokenizer.cs @@ -36,21 +36,21 @@ public static class Tokenizer static PrecedenceBasedRegexTokenizer() { - TokenDefinitions = new List - { - new(TokenType.CloseParenthesis, "\\)", 1), - new(TokenType.Comma, ",", 1), - new(TokenType.Dot, "\\.", 1), - new(TokenType.QuestionMark, "\\?", 1), - new(TokenType.ExclamationMark, "!", 1), - new(TokenType.Semicolon, ";", 1), - new(TokenType.Whitespace, "\\s", 1), - new(TokenType.Equals, "=", 1), - new(TokenType.OpenParenthesis, "\\(", 1), - new(TokenType.UrlString, URLRegex, 1), - new(TokenType.StringValue, "\\p{IsBasicLatin}", 2), - new(TokenType.Leftover, ".", 3) - }; + TokenDefinitions = + [ + new TokenDefinition(TokenType.CloseParenthesis, "\\)", 1), + new TokenDefinition(TokenType.Comma, ",", 1), + new TokenDefinition(TokenType.Dot, "\\.", 1), + new TokenDefinition(TokenType.QuestionMark, "\\?", 1), + new TokenDefinition(TokenType.ExclamationMark, "!", 1), + new TokenDefinition(TokenType.Semicolon, ";", 1), + new TokenDefinition(TokenType.Whitespace, "\\s", 1), + new TokenDefinition(TokenType.Equals, "=", 1), + new TokenDefinition(TokenType.OpenParenthesis, "\\(", 1), + new TokenDefinition(TokenType.UrlString, URLRegex, 1), + new TokenDefinition(TokenType.StringValue, "\\p{IsBasicLatin}", 2), + new TokenDefinition(TokenType.Leftover, ".", 3) + ]; } public static IEnumerable Tokenize(string lqlText) diff --git a/ChatTwo/Util/WebinterfaceUtil.cs b/ChatTwo/Util/WebinterfaceUtil.cs index 43e1842..faed91b 100644 --- a/ChatTwo/Util/WebinterfaceUtil.cs +++ b/ChatTwo/Util/WebinterfaceUtil.cs @@ -1,6 +1,6 @@ namespace ChatTwo.Util; -public class WebinterfaceUtil +public static class WebinterfaceUtil { private static readonly Random Rng = new();