Class Helper
Class Helper
Namespace: SwiftlyS2.Shared
Assembly: SwiftlyS2.CS2.dll
public static class HelperInheritance
Inherited Members
- object.Equals(object?)
- object.Equals(object?, object?)
- object.GetHashCode()
- object.GetType()
- object.MemberwiseClone()
- object.ReferenceEquals(object?, object?)
- object.ToString()
Methods
AsProtobuf<T>(nint, bool)
Convert the pointer to the protobuf class.
public static T AsProtobuf<T>(nint ptr, bool manuallyAllocated) where T : ITypedProtobuf<T>Parameters
- ptr nint — The pointer to the protobuf class.
- manuallyAllocated bool — Whether the pointer is manually allocated.
Returns
- T — The protobuf class.
Type Parameters
- T — The protobuf class to convert to.
AsSchema<T>(nint)
Convert the pointer to the schema class.
public static T AsSchema<T>(nint ptr) where T : ISchemaClass<T>Parameters
- ptr nint — The pointer to the schema class.
Returns
- T — The schema class.
Type Parameters
- T — The schema class to convert to.
Colored(string)
Replace the color codes in the text with the corresponding color codes.
public static string Colored(this string text)Parameters
- text string — The text to replace the color codes in.
Returns
- string — The text with the color codes replaced.
EstimateTextWidth(string)
Estimates the display width of a text string based on character types.
public static float EstimateTextWidth(string text)Parameters
- text string — The text string to measure.
Returns
- float — The estimated display width in relative units.
GetCharWidth(char)
Estimates the display width of a character based on its type. Inspired by: https://github.com/spectreconsole/wcwidth
public static float GetCharWidth(char c)Parameters
- c char — The character to measure.
Returns
- float — The estimated display width in relative units.
GetSchemaSize<T>()
Get the size of a schema class.
public static int GetSchemaSize<T>() where T : ISchemaClass<T>Returns
- int — The size of the schema class.
Type Parameters
- T — The schema class to get the size of.
ParseHexColor(string, bool)
Parses a hex color string and returns the RGBA color components.
public static (int? r, int? g, int? b, int? a) ParseHexColor(string hexColor, bool alphaFirst = false)Parameters
- hexColor string — The hex color string to parse.
- alphaFirst bool — Whether alpha component comes first (ARGB format). Default is false (RGBA format).
Returns
- (int? r, int? g, int? b, int? a) — Color components (R, G, B, A) or nulls if invalid. Alpha defaults to 255 for RGB format.