StyleCop: everything else

This commit is contained in:
Raymond Lynch 2021-05-30 07:10:00 -04:00
parent f64c9b8321
commit 595fd3f1e4
134 changed files with 16346 additions and 6202 deletions

View file

@ -1,8 +1,9 @@
using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.IO;
using Dalamud.Data;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json;
namespace Dalamud.Game.Text.SeStringHandling.Payloads
@ -12,140 +13,19 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
/// </summary>
public class MapLinkPayload : Payload
{
public override PayloadType Type => PayloadType.MapLink;
private Map map;
/// <summary>
/// The Map specified for this map link.
/// </summary>
/// <remarks>
/// Value is evaluated lazily and cached.
/// </remarks>
[JsonIgnore]
public Map Map
{
get
{
this.map ??= this.DataResolver.GetExcelSheet<Map>().GetRow(this.mapId);
return this.map;
}
}
private TerritoryType territoryType;
/// <summary>
/// The TerritoryType specified for this map link.
/// </summary>
/// <remarks>
/// Value is evaluated lazily and cached.
/// </remarks>
[JsonIgnore]
public TerritoryType TerritoryType
{
get
{
this.territoryType ??= this.DataResolver.GetExcelSheet<TerritoryType>().GetRow(this.territoryTypeId);
return this.territoryType;
}
}
/// <summary>
/// The internal x-coordinate for this map position.
/// </summary>
public int RawX { get; private set; }
/// <summary>
/// The internal y-coordinate for this map position.
/// </summary>
public int RawY { get; private set; }
// these could be cached, but this isn't really too egregious
/// <summary>
/// The readable x-coordinate position for this map link. This value is approximate and unrounded.
/// </summary>
public float XCoord
{
get
{
return ConvertRawPositionToMapCoordinate(RawX, Map.SizeFactor);
}
}
/// <summary>
/// The readable y-coordinate position for this map link. This value is approximate and unrounded.
/// </summary>
[JsonIgnore]
public float YCoord
{
get
{
return ConvertRawPositionToMapCoordinate(RawY, Map.SizeFactor);
}
}
/// <summary>
/// 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
{
// this truncates the values to one decimal without rounding, which is what the game does
// the fudge also just attempts to correct the truncated/displayed value for rounding/fp issues
// TODO: should this fudge factor be the same as in the ctor? currently not since that is customizable
const float fudge = 0.02f;
var x = Math.Truncate((XCoord+fudge) * 10.0f) / 10.0f;
var y = Math.Truncate((YCoord+fudge) * 10.0f) / 10.0f;
// the formatting and spacing the game uses
return $"( {x.ToString("0.0")} , {y.ToString("0.0")} )";
}
}
private string placeNameRegion;
/// <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
{
this.placeNameRegion ??= TerritoryType.PlaceNameRegion.Value?.Name;
return this.placeNameRegion;
}
}
private string placeName;
/// <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
{
this.placeName ??= TerritoryType.PlaceName.Value?.Name;
return this.placeName;
}
}
/// <summary>
/// The data string for this map link, for use by internal game functions that take a string variant and not a binary payload.
/// </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
internal MapLinkPayload() { }
/// <summary>
/// Initializes a new instance of the <see cref="MapLinkPayload"/> class.
/// Creates an interactable MapLinkPayload from a human-readable position.
/// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
@ -154,18 +34,20 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
/// <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="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param>
public MapLinkPayload(DataManager data, 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.mapId = mapId;
// this fudge is necessary basically to ensure we don't shift down a full tenth
// because essentially values are truncated instead of rounded, so 3.09999f will become
// 3.0f and not 3.1f
RawX = this.ConvertMapCoordinateToRawPosition(niceXCoord + fudgeFactor, Map.SizeFactor);
RawY = this.ConvertMapCoordinateToRawPosition(niceYCoord + fudgeFactor, Map.SizeFactor);
this.RawX = this.ConvertMapCoordinateToRawPosition(niceXCoord + fudgeFactor, this.Map.SizeFactor);
this.RawY = this.ConvertMapCoordinateToRawPosition(niceYCoord + fudgeFactor, this.Map.SizeFactor);
}
/// <summary>
/// Initializes a new instance of the <see cref="MapLinkPayload"/> class.
/// Creates an interactable MapLinkPayload from a raw position.
/// </summary>
/// <param name="data">DataManager instance needed to resolve game data.</param>
@ -178,27 +60,121 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
this.DataResolver = data;
this.territoryTypeId = territoryTypeId;
this.mapId = mapId;
RawX = rawX;
RawY = rawY;
this.RawX = rawX;
this.RawY = rawY;
}
/// <summary>
/// Initializes a new instance of the <see cref="MapLinkPayload"/> class.
/// Creates an interactable MapLinkPayload from a human-readable position.
/// </summary>
internal MapLinkPayload()
{
}
/// <inheritdoc/>
public override PayloadType Type => PayloadType.MapLink;
/// <summary>
/// Gets the Map specified for this map link.
/// </summary>
/// <remarks>
/// The value is evaluated lazily and cached.
/// </remarks>
[JsonIgnore]
public Map Map => this.map ??= this.DataResolver.GetExcelSheet<Map>().GetRow(this.mapId);
/// <summary>
/// Gets the TerritoryType specified for this map link.
/// </summary>
/// <remarks>
/// The value is evaluated lazily and cached.
/// </remarks>
[JsonIgnore]
public TerritoryType TerritoryType => this.territoryType ??= this.DataResolver.GetExcelSheet<TerritoryType>().GetRow(this.territoryTypeId);
/// <summary>
/// Gets the internal x-coordinate for this map position.
/// </summary>
public int RawX { get; private set; }
/// <summary>
/// Gets the internal y-coordinate for this map position.
/// </summary>
public int RawY { get; private set; }
// these could be cached, but this isn't really too egregious
/// <summary>
/// Gets the readable x-coordinate position for this map link. This value is approximate and unrounded.
/// </summary>
public float XCoord => this.ConvertRawPositionToMapCoordinate(this.RawX, this.Map.SizeFactor);
/// <summary>
/// Gets the readable y-coordinate position for this map link. This value is approximate and unrounded.
/// </summary>
[JsonIgnore]
public float YCoord => this.ConvertRawPositionToMapCoordinate(this.RawY, this.Map.SizeFactor);
// there is no Z; it's purely in the text payload where applicable
/// <summary>
/// Gets 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
{
// this truncates the values to one decimal without rounding, which is what the game does
// the fudge also just attempts to correct the truncated/displayed value for rounding/fp issues
// TODO: should this fudge factor be the same as in the ctor? currently not since that is customizable
const float fudge = 0.02f;
var x = Math.Truncate((this.XCoord + fudge) * 10.0f) / 10.0f;
var y = Math.Truncate((this.YCoord + fudge) * 10.0f) / 10.0f;
// the formatting and spacing the game uses
return $"( {x:0.0} , {y:0.0} )";
}
}
/// <summary>
/// Gets 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 => this.placeNameRegion ??= this.TerritoryType.PlaceNameRegion.Value?.Name;
/// <summary>
/// Gets 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 => this.placeName ??= this.TerritoryType.PlaceName.Value?.Name;
/// <summary>
/// Gets the data string for this map link, for use by internal game functions that take a string variant and not a binary payload.
/// </summary>
public string DataString => $"m:{this.TerritoryType.RowId},{this.Map.RowId},{this.RawX},{this.RawY}";
/// <inheritdoc/>
public override string ToString()
{
return $"{Type} - TerritoryTypeId: {territoryTypeId}, MapId: {mapId}, RawX: {RawX}, RawY: {RawY}, display: {PlaceName} {CoordinateString}";
return $"{this.Type} - TerritoryTypeId: {this.territoryTypeId}, MapId: {this.mapId}, RawX: {this.RawX}, RawY: {this.RawY}, display: {this.PlaceName} {this.CoordinateString}";
}
/// <inheritdoc/>
protected override byte[] EncodeImpl()
{
var packedTerritoryAndMapBytes = MakePackedInteger(this.territoryTypeId, this.mapId);
var xBytes = MakeInteger(unchecked((uint)RawX));
var yBytes = MakeInteger(unchecked((uint)RawY));
var xBytes = MakeInteger(unchecked((uint)this.RawX));
var yBytes = MakeInteger(unchecked((uint)this.RawY));
var chunkLen = 4 + packedTerritoryAndMapBytes.Length + xBytes.Length + yBytes.Length;
var bytes = new List<byte>()
{
START_BYTE,
(byte)SeStringChunkType.Interactable, (byte)chunkLen, (byte)EmbeddedInfoType.MapPositionLink
(byte)SeStringChunkType.Interactable, (byte)chunkLen, (byte)EmbeddedInfoType.MapPositionLink,
};
bytes.AddRange(packedTerritoryAndMapBytes);
@ -211,6 +187,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
return bytes.ToArray();
}
/// <inheritdoc/>
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
{
// for debugging for now
@ -221,8 +198,8 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
try
{
(this.territoryTypeId, this.mapId) = GetPackedIntegers(reader);
RawX = unchecked((int)GetInteger(reader));
RawY = unchecked((int)GetInteger(reader));
this.RawX = unchecked((int)GetInteger(reader));
this.RawY = unchecked((int)GetInteger(reader));
// the Z coordinate is never in this chunk, just the text (if applicable)
// seems to always be FF 01
@ -237,6 +214,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
}
#region ugliness
// from https://github.com/xivapi/ffxiv-datamining/blob/master/docs/MapCoordinates.md
// extra 1/1000 because that is how the network ints are done
private float ConvertRawPositionToMapCoordinate(int pos, float scale)
@ -257,6 +235,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads
return (int)scaledPos;
}
#endregion
}
}