Struct GridLocation
Handles translating coordinates to/from grid coordinates.
[JsonConverter(typeof(GridLocationConverter))]
[TypeConverter(typeof(GridLocationTypeConverter))]
public readonly struct GridLocation : ITranslationArgument, IEquatable<GridLocation>, IComparable<GridLocation>, IFormattable
- Implements
- Inherited Members
- Extension Methods
Constructors
GridLocation(byte, byte, byte)
Create a grid location from an X-coordinate, a Y-coordinate, and a subgrid index.
[JsonConstructor]
public GridLocation(byte x, byte y, byte index)
Parameters
Exceptions
GridLocation(char, byte, byte)
Create a grid location from an X-coordinate letter, a Y-coordinate, and a subgrid index.
public GridLocation(char x, byte y, byte index)
Parameters
Exceptions
GridLocation(in Vector3)
Create a GridLocation from any given point inside a grid and subgrid.
public GridLocation(in Vector3 pos)
Parameters
posVector3
Exceptions
- NotSupportedException
Not ran on an active server.
Fields
BorderPercentage
What percentage of the image is border for the grid?
public const float BorderPercentage = 0.033333335
Field Value
OptimalGridSizeWorldScale
The preferred distance between grids in meters. This will be scaled slightly to ensure the grid looks squared.
public const int OptimalGridSizeWorldScale = 150
Field Value
SubgridAmount
Square root of the amount of subgrids in a grid. Ex. in a 3x3 = 9 subgrid, this value will be 3.
public const int SubgridAmount = 3
Field Value
Remarks
Must be within the interval [1, 9].
Properties
Center
The center of the referenced grid or sub-grid.
[JsonIgnore]
[JsonIgnore]
public Vector2 Center { get; }
Property Value
- Vector2
Exceptions
- NotSupportedException
Not ran on an active server.
Index
The sub-grid index of in the current grid.
[JsonPropertyName("index")]
[JsonProperty("index")]
public byte Index { get; }
Property Value
IsChecked
Was this grid location verified to be a valid location? This will always be true unless the GridLocation hasn't been initialized by a constructor.
[JsonIgnore]
[JsonIgnore]
public bool IsChecked { get; }
Property Value
IsValid
Is this a valid GridLocation? This will always be true unless the GridLocation hasn't been initialized by a constructor.
[JsonIgnore]
[JsonIgnore]
public bool IsValid { get; }
Property Value
LetterX
The captialized letter of the current X coordinate of the grid.
[JsonIgnore]
[JsonIgnore]
public char LetterX { get; }
Property Value
X
The X coordinate of the grid.
[JsonPropertyName("x")]
[JsonProperty("x")]
public byte X { get; }
Property Value
Y
The Y coordinate of the grid.
[JsonPropertyName("y")]
[JsonProperty("y")]
public byte Y { get; }
Property Value
Methods
CompareTo(GridLocation)
Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.
public int CompareTo(GridLocation other)
Parameters
otherGridLocation
Returns
Equals(object?)
Check if two locations are in the same grid and sub-grid.
public override bool Equals(object? obj)
Parameters
objobject
Returns
Equals(GridLocation)
Check if two locations are in the same grid and sub-grid.
public bool Equals(GridLocation other)
Parameters
otherGridLocation
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetLegacyBorderSize(ELevelSize)
Get the size of the map's border based on a legacy size.
public static int GetLegacyBorderSize(ELevelSize size)
Parameters
sizeELevelSize
Returns
GetLegacyGridSize(ELevelSize)
Get the ideal grid size from a legacy size.
public static int GetLegacyGridSize(ELevelSize size)
Parameters
sizeELevelSize
Returns
GetLegacyMapSize(ELevelSize)
Get the size of the map's image (and total size) based on a legacy size.
public static int GetLegacyMapSize(ELevelSize size)
Parameters
sizeELevelSize
Returns
GetLegacySizeFromMapSize(int)
Get the expected legacy size from a map's image size (or total size), or null if it doesn't match any legacy sizes.
public static ELevelSize? GetLegacySizeFromMapSize(int mapSize)
Parameters
mapSizeint
Returns
- ELevelSize?
GetMapMetrics(ELevelSize, out int, out double, out double)
Only works with maps without a cartography volume.
public static void GetMapMetrics(ELevelSize size, out int gridSize, out double sectionWidth, out double borderSize)
Parameters
GetMapMetrics(int, int, out int, out int, out double, out double, out double)
Only works with maps with a cartography volume.
public static void GetMapMetrics(int imgSizeX, int imgSizeY, out int gridSizeX, out int gridSizeY, out double sectionWidthX, out double sectionWidthY, out double borderSize)
Parameters
imgSizeXintimgSizeYintgridSizeXintgridSizeYintsectionWidthXdoublesectionWidthYdoubleborderSizedouble
Remarks
Used by grid generator in Discord bot.
GridEquals(GridLocation)
Check if two locations are in the same grid.
public bool GridEquals(GridLocation other)
Parameters
otherGridLocation
Returns
Parse(ReadOnlySpan<char>)
Parse a case-insensitive string representing a GridLocation, ignoring whitespace.
public static GridLocation Parse(ReadOnlySpan<char> value)
Parameters
valueReadOnlySpan<char>
Returns
Exceptions
Parse(ReadOnlySpan<char>, IFormatProvider?)
Parse a case-insensitive string representing a GridLocation, ignoring whitespace.
[Obsolete]
public static GridLocation Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
Parameters
sReadOnlySpan<char>providerIFormatProvider
Returns
Exceptions
Parse(string, IFormatProvider?)
Parse a case-insensitive string representing a GridLocation, ignoring whitespace.
[Obsolete]
public static GridLocation Parse(string s, IFormatProvider? provider)
Parameters
sstringproviderIFormatProvider
Returns
Exceptions
ReadLocation(ByteReader)
Read a location from a DanielWillett.SpeedBytes.ByteReader.
public static GridLocation ReadLocation(ByteReader reader)
Parameters
readerByteReader
Returns
ToString()
Convert this grid location to a string representation, formatted like A1-1.
public override string ToString()
Returns
ToString(byte, byte, byte)
Convert a grid location with the given x, y, and index to a string representation, formatted like A1-1.
public static string ToString(byte x, byte y, byte index)
Parameters
Returns
ToString(string?, IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format to use.
-or-
A null reference (Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Convert this grid location to a string representation, formatted like A1-1.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destinationSpan<char>charsWrittenintformatReadOnlySpan<char>providerIFormatProvider
Returns
TryParse(ReadOnlySpan<char>, IFormatProvider?, out GridLocation)
Parse a case-insensitive string representing a GridLocation, ignoring whitespace.
[Obsolete]
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out GridLocation result)
Parameters
sReadOnlySpan<char>providerIFormatProviderresultGridLocation
Returns
- bool
Trueif a valid GridLocation was parsed, otherwise false.
TryParse(ReadOnlySpan<char>, out GridLocation)
Parse a case-insensitive string representing a GridLocation, ignoring whitespace.
public static bool TryParse(ReadOnlySpan<char> value, out GridLocation location)
Parameters
valueReadOnlySpan<char>locationGridLocation
Returns
- bool
Trueif a valid GridLocation was parsed, otherwise false.
TryParse(string?, IFormatProvider?, out GridLocation)
Parse a case-insensitive string representing a GridLocation, ignoring whitespace.
[Obsolete]
public static bool TryParse(string? s, IFormatProvider? provider, out GridLocation result)
Parameters
sstringproviderIFormatProviderresultGridLocation
Returns
- bool
Trueif a valid GridLocation was parsed, otherwise false.
Write(ByteWriter)
Write this location to a DanielWillett.SpeedBytes.ByteWriter.
public void Write(ByteWriter writer)
Parameters
writerByteWriter
WriteLocation(ByteWriter, GridLocation)
Write a location to a DanielWillett.SpeedBytes.ByteWriter.
public static void WriteLocation(ByteWriter writer, GridLocation gridLocation)
Parameters
writerByteWritergridLocationGridLocation
Operators
operator ==(GridLocation, GridLocation)
Check if two locations are in the same grid and sub-grid.
public static bool operator ==(GridLocation left, GridLocation right)
Parameters
leftGridLocationrightGridLocation
Returns
operator >(GridLocation, GridLocation)
Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.
public static bool operator >(GridLocation left, GridLocation right)
Parameters
leftGridLocationrightGridLocation
Returns
operator >=(GridLocation, GridLocation)
Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.
public static bool operator >=(GridLocation left, GridLocation right)
Parameters
leftGridLocationrightGridLocation
Returns
operator !=(GridLocation, GridLocation)
Check if two locations are in the same grid and sub-grid.
public static bool operator !=(GridLocation left, GridLocation right)
Parameters
leftGridLocationrightGridLocation
Returns
operator <(GridLocation, GridLocation)
Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.
public static bool operator <(GridLocation left, GridLocation right)
Parameters
leftGridLocationrightGridLocation
Returns
operator <=(GridLocation, GridLocation)
Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.
public static bool operator <=(GridLocation left, GridLocation right)
Parameters
leftGridLocationrightGridLocation