mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +01:00
Merge pull request #167 from ms2mml/payload-serialize
This commit is contained in:
commit
671e800bb3
11 changed files with 86 additions and 1 deletions
|
|
@ -51,7 +51,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
|
|||
/// <summary>
|
||||
/// The Lumina instance to use for any necessary data lookups.
|
||||
/// </summary>
|
||||
protected DataManager DataResolver;
|
||||
public DataManager DataResolver;
|
||||
|
||||
// private for now, since subclasses shouldn't interact with this
|
||||
// To force-invalidate it, Dirty can be set to true
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using Dalamud.Data;
|
||||
using Dalamud.Data.TransientSheet;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||
{
|
||||
|
|
@ -34,7 +35,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
}
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
private uint group;
|
||||
|
||||
[JsonProperty]
|
||||
private uint key;
|
||||
|
||||
internal AutoTranslatePayload() { }
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using Dalamud.Data;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||
{
|
||||
|
|
@ -22,6 +23,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <remarks>
|
||||
/// Value is evaluated lazily and cached.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public Item Item
|
||||
{
|
||||
get
|
||||
|
|
@ -57,8 +59,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// Whether or not this item link is for a high-quality version of the item.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public bool IsHQ { get; private set; } = false;
|
||||
|
||||
[JsonProperty]
|
||||
private uint itemId;
|
||||
|
||||
internal ItemPayload() { }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Dalamud.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||
{
|
||||
|
|
@ -20,6 +21,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <remarks>
|
||||
/// Value is evaluated lazily and cached.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public Map Map
|
||||
{
|
||||
get
|
||||
|
|
@ -36,6 +38,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <remarks>
|
||||
/// Value is evaluated lazily and cached.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public TerritoryType TerritoryType
|
||||
{
|
||||
get
|
||||
|
|
@ -70,6 +73,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// The readable y-coordinate position for this map link. This value is approximate and unrounded.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public float YCoord
|
||||
{
|
||||
get
|
||||
|
|
@ -82,6 +86,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// The printable map coordinates for this link. This value tries to match the in-game printable text as closely as possible
|
||||
/// but is an approximation and may be slightly off for some positions.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string CoordinateString
|
||||
{
|
||||
get
|
||||
|
|
@ -102,6 +107,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// The region name for this map link. This corresponds to the upper zone name found in the actual in-game map UI. eg, "La Noscea"
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string PlaceNameRegion
|
||||
{
|
||||
get
|
||||
|
|
@ -115,6 +121,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// The place name for this map link. This corresponds to the lower zone name found in the actual in-game map UI. eg, "Limsa Lominsa Upper Decks"
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string PlaceName
|
||||
{
|
||||
get
|
||||
|
|
@ -129,7 +136,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// </summary>
|
||||
public string DataString => $"m:{TerritoryType.RowId},{Map.RowId},{RawX},{RawY}";
|
||||
|
||||
[JsonProperty]
|
||||
private uint territoryTypeId;
|
||||
|
||||
[JsonProperty]
|
||||
private uint mapId;
|
||||
// there is no Z; it's purely in the text payload where applicable
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using Dalamud.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||
{
|
||||
|
|
@ -14,10 +15,12 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
{
|
||||
public override PayloadType Type => PayloadType.Player;
|
||||
|
||||
[JsonProperty]
|
||||
private string playerName;
|
||||
/// <summary>
|
||||
/// The player's displayed name. This does not contain the server name.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string PlayerName
|
||||
{
|
||||
get { return this.playerName; }
|
||||
|
|
@ -35,6 +38,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <remarks>
|
||||
/// Value is evaluated lazily and cached.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public World World
|
||||
{
|
||||
get
|
||||
|
|
@ -48,8 +52,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// A text representation of this player link matching how it might appear in-game.
|
||||
/// The world name will always be present.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string DisplayedName => $"{PlayerName}{(char)SeIconChar.CrossWorld}{World.Name}";
|
||||
|
||||
[JsonProperty]
|
||||
private uint serverId;
|
||||
|
||||
internal PlayerPayload() { }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -20,6 +21,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
|
||||
public override PayloadType Type => PayloadType.Unknown;
|
||||
|
||||
[JsonProperty]
|
||||
private byte[] data;
|
||||
// this is a bit different from the underlying data
|
||||
// We need to store just the chunk data for decode to behave nicely, but when reading data out
|
||||
|
|
@ -28,6 +30,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// The entire payload byte sequence for this payload.
|
||||
/// The returned data is a clone and modifications will not be persisted.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public byte[] Data
|
||||
{
|
||||
get
|
||||
|
|
@ -38,8 +41,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
}
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
private byte chunkType;
|
||||
|
||||
[JsonConstructor]
|
||||
internal RawPayload(byte chunkType)
|
||||
{
|
||||
this.chunkType = chunkType;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Dalamud.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||
{
|
||||
|
|
@ -20,6 +21,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <remarks>
|
||||
/// Value is evaluated lazily and cached.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public Status Status
|
||||
{
|
||||
get
|
||||
|
|
@ -29,6 +31,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
}
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
private uint statusId;
|
||||
|
||||
internal StatusPayload() { }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -13,11 +14,13 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
public override PayloadType Type => PayloadType.RawText;
|
||||
|
||||
// allow modifying the text of existing payloads on the fly
|
||||
[JsonProperty]
|
||||
private string text;
|
||||
/// <summary>
|
||||
/// The text contained in this payload.
|
||||
/// This may contain SE's special unicode characters.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Text
|
||||
{
|
||||
get { return this.text; }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Dalamud.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||
{
|
||||
|
|
@ -31,6 +32,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <remarks>
|
||||
/// Value is evaluated lazily and cached.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public UIColor UIColor
|
||||
{
|
||||
get
|
||||
|
|
@ -43,6 +45,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// The color key used as a lookup in the UIColor table for this foreground color.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public ushort ColorKey
|
||||
{
|
||||
get { return this.colorKey; }
|
||||
|
|
@ -57,6 +60,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// The Red/Green/Blue values for this foreground color, encoded as a typical hex color.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public uint RGB
|
||||
{
|
||||
get
|
||||
|
|
@ -65,6 +69,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
}
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
private ushort colorKey;
|
||||
|
||||
internal UIForegroundPayload() { }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Dalamud.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||
{
|
||||
|
|
@ -31,6 +32,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <remarks>
|
||||
/// Value is evaluated lazily and cached.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public UIColor UIColor
|
||||
{
|
||||
get
|
||||
|
|
@ -43,6 +45,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// The color key used as a lookup in the UIColor table for this glow color.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public ushort ColorKey
|
||||
{
|
||||
get { return this.colorKey; }
|
||||
|
|
@ -57,6 +60,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
/// <summary>
|
||||
/// The Red/Green/Blue values for this glow color, encoded as a typical hex color.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public uint RGB
|
||||
{
|
||||
get
|
||||
|
|
@ -65,6 +69,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
|||
}
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
private ushort colorKey;
|
||||
|
||||
internal UIGlowPayload() { }
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Dalamud.Data;
|
||||
using Dalamud.Game.Chat.SeStringHandling.Payloads;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Chat.SeStringHandling
|
||||
{
|
||||
|
|
@ -38,6 +40,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
|
|||
/// Creates a new SeString from an ordered list of payloads.
|
||||
/// </summary>
|
||||
/// <param name="payloads">The Payload objects to make up this string.</param>
|
||||
[JsonConstructor]
|
||||
public SeString(List<Payload> payloads)
|
||||
{
|
||||
Payloads = payloads;
|
||||
|
|
@ -100,5 +103,42 @@ namespace Dalamud.Game.Chat.SeStringHandling
|
|||
|
||||
return messageBytes.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the SeString to json
|
||||
/// </summary>
|
||||
/// <returns>An json representation of this object</returns>
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings()
|
||||
{
|
||||
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a SeString from a json. (For testing - not recommended for production use.)
|
||||
/// </summary>
|
||||
/// <param name="json">A serialized SeString produced by ToJson() <see cref="ToJson"/></param>
|
||||
/// <param name="dataManager">An initialized instance of DataManager for Lumina queries.</param>
|
||||
/// <returns>A SeString initialized with values from the json</returns>
|
||||
public static SeString FromJson(string json, DataManager dataManager)
|
||||
{
|
||||
var s = JsonConvert.DeserializeObject<SeString>(json, new JsonSerializerSettings
|
||||
{
|
||||
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
|
||||
});
|
||||
|
||||
foreach(var payload in s.Payloads)
|
||||
{
|
||||
payload.DataResolver = dataManager;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue