fix: DI in payloads

This commit is contained in:
goat 2020-07-25 21:21:51 +02:00
parent 26631682cd
commit 1fffc18da9
9 changed files with 45 additions and 27 deletions

View file

@ -75,9 +75,9 @@ namespace Dalamud.Injector {
Thread.Sleep(1000); Thread.Sleep(1000);
#if NO #if DEBUG
// Inject exception handler // Inject exception handler
NativeInject(process); //NativeInject(process);
#endif #endif
} }

View file

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Dalamud.Data;
using Dalamud.Data.TransientSheet; using Dalamud.Data.TransientSheet;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads namespace Dalamud.Game.Chat.SeStringHandling.Payloads
@ -41,14 +42,15 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Creates a new auto-translate payload. /// Creates a new auto-translate payload.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="group">The group id for this message.</param> /// <param name="group">The group id for this message.</param>
/// <param name="key">The key/row id for this message. Which table this is in depends on the group id and details the Completion table.</param> /// <param name="key">The key/row id for this message. Which table this is in depends on the group id and details the Completion table.</param>
/// <remarks> /// <remarks>
/// This table is somewhat complicated in structure, and so using this constructor may not be very nice. /// This table is somewhat complicated in structure, and so using this constructor may not be very nice.
/// There is probably little use to create one of these, however. /// There is probably little use to create one of these, however.
/// </remarks> /// </remarks>
public AutoTranslatePayload(uint group, uint key) public AutoTranslatePayload(DataManager data, uint group, uint key) {
{ this.DataResolver = data;
this.group = group; this.group = group;
this.key = key; this.key = key;
} }

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Dalamud.Data;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads namespace Dalamud.Game.Chat.SeStringHandling.Payloads
@ -65,13 +66,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Creates a payload representing an interactable item link for the specified item. /// Creates a payload representing an interactable item link for the specified item.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="itemId">The id of the item.</param> /// <param name="itemId">The id of the item.</param>
/// <param name="isHQ">Whether or not the link should be for the high-quality variant of the item.</param> /// <param name="isHQ">Whether or not the link should be for the high-quality variant of the item.</param>
/// <param name="displayNameOverride">An optional name to include in the item link. Typically this should /// <param name="displayNameOverride">An optional name to include in the item link. Typically this should
/// be left as null, or set to the normal item name. Actual overrides are better done with the subsequent /// be left as null, or set to the normal item name. Actual overrides are better done with the subsequent
/// TextPayload that is a part of a full item link in chat.</param> /// TextPayload that is a part of a full item link in chat.</param>
public ItemPayload(uint itemId, bool isHQ, string displayNameOverride = null) public ItemPayload(DataManager data, uint itemId, bool isHQ, string displayNameOverride = null) {
{ this.DataResolver = data;
this.itemId = itemId; this.itemId = itemId;
this.IsHQ = isHQ; this.IsHQ = isHQ;
this.displayName = displayNameOverride; this.displayName = displayNameOverride;

View file

@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{ {
@ -137,13 +138,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Creates an interactable MapLinkPayload from a human-readable position. /// Creates an interactable MapLinkPayload from a human-readable position.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="territoryTypeId">The id of the TerritoryType entry for this link.</param> /// <param name="territoryTypeId">The id of the TerritoryType entry for this link.</param>
/// <param name="mapId">The id of the Map entry for this link.</param> /// <param name="mapId">The id of the Map entry for this link.</param>
/// <param name="niceXCoord">The human-readable x-coordinate for this link.</param> /// <param name="niceXCoord">The human-readable x-coordinate for this link.</param>
/// <param name="niceYCoord">The human-readable y-coordinate for this link.</param> /// <param name="niceYCoord">The human-readable y-coordinate for this link.</param>
/// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param> /// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param>
public MapLinkPayload(uint territoryTypeId, uint mapId, float niceXCoord, float niceYCoord, float fudgeFactor = 0.05f) public MapLinkPayload(DataManager data, uint territoryTypeId, uint mapId, float niceXCoord, float niceYCoord, float fudgeFactor = 0.05f) {
{ this.DataResolver = data;
this.territoryTypeId = territoryTypeId; this.territoryTypeId = territoryTypeId;
this.mapId = mapId; this.mapId = mapId;
// this fudge is necessary basically to ensure we don't shift down a full tenth // this fudge is necessary basically to ensure we don't shift down a full tenth
@ -156,12 +158,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Creates an interactable MapLinkPayload from a raw position. /// Creates an interactable MapLinkPayload from a raw position.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="territoryTypeId">The id of the TerritoryType entry for this link.</param> /// <param name="territoryTypeId">The id of the TerritoryType entry for this link.</param>
/// <param name="mapId">The id of the Map entry for this link.</param> /// <param name="mapId">The id of the Map entry for this link.</param>
/// <param name="rawX">The internal raw x-coordinate for this link.</param> /// <param name="rawX">The internal raw x-coordinate for this link.</param>
/// <param name="rawY">The internal raw y-coordinate for this link.</param> /// <param name="rawY">The internal raw y-coordinate for this link.</param>
public MapLinkPayload(uint territoryTypeId, uint mapId, int rawX, int rawY) public MapLinkPayload(DataManager data, uint territoryTypeId, uint mapId, int rawX, int rawY)
{ {
this.DataResolver = data;
this.territoryTypeId = territoryTypeId; this.territoryTypeId = territoryTypeId;
this.mapId = mapId; this.mapId = mapId;
RawX = rawX; RawX = rawX;

View file

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{ {
@ -56,10 +57,11 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Create a PlayerPayload link for the specified player. /// Create a PlayerPayload link for the specified player.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="playerName">The player's displayed name.</param> /// <param name="playerName">The player's displayed name.</param>
/// <param name="serverId">The player's home server id.</param> /// <param name="serverId">The player's home server id.</param>
public PlayerPayload(string playerName, uint serverId) public PlayerPayload(DataManager data, string playerName, uint serverId) {
{ this.DataResolver = data;
this.playerName = playerName; this.playerName = playerName;
this.serverId = serverId; this.serverId = serverId;
} }

View file

@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{ {
@ -35,9 +36,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Creates a new StatusPayload for the given status id. /// Creates a new StatusPayload for the given status id.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="statusId">The id of the Status for this link.</param> /// <param name="statusId">The id of the Status for this link.</param>
public StatusPayload(uint statusId) public StatusPayload(DataManager data, uint statusId) {
{ this.DataResolver = data;
this.statusId = statusId; this.statusId = statusId;
} }

View file

@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{ {
@ -13,7 +14,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Payload representing disabling foreground color on following text. /// Payload representing disabling foreground color on following text.
/// </summary> /// </summary>
public static UIForegroundPayload UIForegroundOff => new UIForegroundPayload(0); // TODO Make this work with DI
public static UIForegroundPayload UIForegroundOff => new UIForegroundPayload(null, 0);
public override PayloadType Type => PayloadType.UIForeground; public override PayloadType Type => PayloadType.UIForeground;
@ -70,9 +72,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Creates a new UIForegroundPayload for the given UIColor key. /// Creates a new UIForegroundPayload for the given UIColor key.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="colorKey"></param> /// <param name="colorKey"></param>
public UIForegroundPayload(ushort colorKey) public UIForegroundPayload(DataManager data, ushort colorKey) {
{ this.DataResolver = data;
this.colorKey = colorKey; this.colorKey = colorKey;
} }

View file

@ -2,6 +2,7 @@ using Lumina.Excel.GeneratedSheets;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Dalamud.Data;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{ {
@ -13,7 +14,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Payload representing disabling glow color on following text. /// Payload representing disabling glow color on following text.
/// </summary> /// </summary>
public static UIGlowPayload UIGlowOff => new UIGlowPayload(0); // TODO Make this work with DI
public static UIGlowPayload UIGlowOff => new UIGlowPayload(null, 0);
public override PayloadType Type => PayloadType.UIGlow; public override PayloadType Type => PayloadType.UIGlow;
@ -70,9 +72,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
/// <summary> /// <summary>
/// Creates a new UIForegroundPayload for the given UIColor key. /// Creates a new UIForegroundPayload for the given UIColor key.
/// </summary> /// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
/// <param name="colorKey"></param> /// <param name="colorKey"></param>
public UIGlowPayload(ushort colorKey) public UIGlowPayload(DataManager data, ushort colorKey) {
{ this.DataResolver = data;
this.colorKey = colorKey; this.colorKey = colorKey;
} }

View file

@ -60,9 +60,9 @@ namespace Dalamud.Game.Chat.SeStringHandling
// TODO: probably a cleaner way to build these than doing the bulk+insert // TODO: probably a cleaner way to build these than doing the bulk+insert
var payloads = new List<Payload>(new Payload[] var payloads = new List<Payload>(new Payload[]
{ {
new UIForegroundPayload(0x0225), new UIForegroundPayload(this.data, 0x0225),
new UIGlowPayload(0x0226), new UIGlowPayload(this.data, 0x0226),
new ItemPayload(itemId, isHQ), new ItemPayload(this.data, itemId, isHQ),
// arrow goes here // arrow goes here
new TextPayload(displayName), new TextPayload(displayName),
RawPayload.LinkTerminator RawPayload.LinkTerminator
@ -88,7 +88,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
public SeString CreateMapLink(uint territoryId, uint mapId, int rawX, int rawY) public SeString CreateMapLink(uint territoryId, uint mapId, int rawX, int rawY)
{ {
var mapPayload = new MapLinkPayload(territoryId, mapId, rawX, rawY); var mapPayload = new MapLinkPayload(this.data, territoryId, mapId, rawX, rawY);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}"; var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List<Payload>(new Payload[] var payloads = new List<Payload>(new Payload[]
@ -114,7 +114,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
/// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns> /// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns>
public SeString CreateMapLink(uint territoryId, uint mapId, float xCoord, float yCoord, float fudgeFactor = 0.05f) public SeString CreateMapLink(uint territoryId, uint mapId, float xCoord, float yCoord, float fudgeFactor = 0.05f)
{ {
var mapPayload = new MapLinkPayload(territoryId, mapId, xCoord, yCoord, fudgeFactor); var mapPayload = new MapLinkPayload(this.data, territoryId, mapId, xCoord, yCoord, fudgeFactor);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}"; var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List<Payload>(new Payload[] var payloads = new List<Payload>(new Payload[]
@ -163,12 +163,12 @@ namespace Dalamud.Game.Chat.SeStringHandling
/// with the appropriate glow and coloring. /// with the appropriate glow and coloring.
/// </summary> /// </summary>
/// <returns>A list of all the payloads required to insert the link marker.</returns> /// <returns>A list of all the payloads required to insert the link marker.</returns>
public static List<Payload> TextArrowPayloads() public List<Payload> TextArrowPayloads()
{ {
return new List<Payload>(new Payload[] return new List<Payload>(new Payload[]
{ {
new UIForegroundPayload(0x01F4), new UIForegroundPayload(this.data, 0x01F4),
new UIGlowPayload(0x01F5), new UIGlowPayload(this.data, 0x01F5),
new TextPayload($"{(char)SeIconChar.LinkMarker}"), new TextPayload($"{(char)SeIconChar.LinkMarker}"),
UIGlowPayload.UIGlowOff, UIGlowPayload.UIGlowOff,
UIForegroundPayload.UIForegroundOff UIForegroundPayload.UIForegroundOff