feat: support emphasis
This commit is contained in:
parent
6f9c96c174
commit
f93beb4133
61
Plugin.cs
61
Plugin.cs
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||||
using Dalamud.Hooking;
|
using Dalamud.Hooking;
|
||||||
@ -12,7 +14,7 @@ using YamlDotNet.Serialization.NamingConventions;
|
|||||||
|
|
||||||
namespace TimePasses;
|
namespace TimePasses;
|
||||||
|
|
||||||
public class Plugin : IDalamudPlugin {
|
public sealed class Plugin : IDalamudPlugin {
|
||||||
[PluginService]
|
[PluginService]
|
||||||
internal static IPluginLog Log { get; set; }
|
internal static IPluginLog Log { get; set; }
|
||||||
|
|
||||||
@ -61,7 +63,7 @@ public class Plugin : IDalamudPlugin {
|
|||||||
await this.Mutex.WaitAsync();
|
await this.Mutex.WaitAsync();
|
||||||
try {
|
try {
|
||||||
this.Data = Plugin.Deserializer.Deserialize<DataFile>(yaml);
|
this.Data = Plugin.Deserializer.Deserialize<DataFile>(yaml);
|
||||||
this.ReplacementPointers.Clear();
|
this.ResetReplacementPointers();
|
||||||
} finally {
|
} finally {
|
||||||
this.Mutex.Release();
|
this.Mutex.Release();
|
||||||
}
|
}
|
||||||
@ -72,11 +74,7 @@ public class Plugin : IDalamudPlugin {
|
|||||||
this.GetBalloonRowHook?.Dispose();
|
this.GetBalloonRowHook?.Dispose();
|
||||||
this.Client.Dispose();
|
this.Client.Dispose();
|
||||||
this.Mutex.Dispose();
|
this.Mutex.Dispose();
|
||||||
foreach (var (_, ptr) in this.ReplacementPointers) {
|
this.ResetReplacementPointers();
|
||||||
Marshal.FreeHGlobal(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ReplacementPointers.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private nint GetBalloonRowDetour(uint rowId) {
|
private nint GetBalloonRowDetour(uint rowId) {
|
||||||
@ -121,13 +119,47 @@ public class Plugin : IDalamudPlugin {
|
|||||||
var lines = text
|
var lines = text
|
||||||
.ReplaceLineEndings("\n")
|
.ReplaceLineEndings("\n")
|
||||||
.Split('\n');
|
.Split('\n');
|
||||||
|
var sb = new StringBuilder();
|
||||||
var seStringBuilder = new SeStringBuilder();
|
var seStringBuilder = new SeStringBuilder();
|
||||||
for (var i = 0; i < lines.Length; i++) {
|
for (var i = 0; i < lines.Length; i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
seStringBuilder.Add(NewLinePayload.Payload);
|
seStringBuilder.Add(NewLinePayload.Payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
seStringBuilder.AddText(lines[i].TrimEnd());
|
var line = lines[i]
|
||||||
|
.TrimEnd()
|
||||||
|
.Replace("<em>", Markers.EmphasisOn.ToString())
|
||||||
|
.Replace("</em>", Markers.EmphasisOff.ToString());
|
||||||
|
|
||||||
|
void Append() {
|
||||||
|
if (sb.Length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
seStringBuilder.AddText(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var ch in lines[i].TrimEnd()) {
|
||||||
|
switch (ch) {
|
||||||
|
case Markers.EmphasisOn: {
|
||||||
|
Append();
|
||||||
|
seStringBuilder.AddItalicsOn();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Markers.EmphasisOff: {
|
||||||
|
Append();
|
||||||
|
seStringBuilder.AddItalicsOff();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
sb.Append(ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Append();
|
||||||
}
|
}
|
||||||
|
|
||||||
var textBytes = seStringBuilder.Encode();
|
var textBytes = seStringBuilder.Encode();
|
||||||
@ -150,6 +182,14 @@ public class Plugin : IDalamudPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResetReplacementPointers() {
|
||||||
|
foreach (var (_, ptr) in this.ReplacementPointers) {
|
||||||
|
Marshal.FreeHGlobal(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ReplacementPointers.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -162,3 +202,8 @@ internal class DataFile {
|
|||||||
public class Definitions {
|
public class Definitions {
|
||||||
public uint[] Quests { get; init; }
|
public uint[] Quests { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static class Markers {
|
||||||
|
internal const char EmphasisOn = '\uf000';
|
||||||
|
internal const char EmphasisOff = '\uf001';
|
||||||
|
}
|
||||||
|
@ -86,7 +86,7 @@ replacements:
|
|||||||
greaterThan: 49
|
greaterThan: 49
|
||||||
text: |-
|
text: |-
|
||||||
Bet beasties never
|
Bet beasties never
|
||||||
give you any trouble.
|
give <em>you</em> any trouble.
|
||||||
- level:
|
- level:
|
||||||
greaterThan: 29
|
greaterThan: 29
|
||||||
text: |-
|
text: |-
|
||||||
|
Loading…
Reference in New Issue
Block a user