Scripting API

Scripting API

FieldKinds

Class in Abyss.Core, from Abyss.Core.

Sizes for FieldKind.

public static class FieldKinds

Methods

SizeOf

public static int SizeOf(this FieldKind kind)

Size of one value of this kind, in bytes.

Parameters

  • kind

Writable

public static bool Writable(this FieldKind kind)

Whether a value of this kind can be written: every kind but FieldKind.Entity.

Parameters

  • kind

ClrType

public static Type ClrType(this FieldKind kind)

The CLR type a field of this kind holds, for checking a caller's type argument.

Parameters

  • kind

Decode

public static FieldValue Decode(this FieldKind kind, ReadOnlySpan<byte> bytes)

Reads one value of this kind.

Parameters

  • kind: The kind to read as.
  • bytes: At least FieldKinds.SizeOf bytes of the field's storage.

Every field kind the engine describes is a number, and that is what makes a generic inspector possible at all. A tool that has never heard of the component it is showing cannot have a typed path per field; what it can do is read a number, show it, and write a number back. The one kind that is not really a number — a boolean — is carried as zero or one so that the same path works for it too, and a caller that wants a checkbox asks the kind rather than the value.

A whole number is read as the whole number it is, every one of the 64 bits of an FieldKind.I64 or a FieldKind.U64, where a double past 2^53 would skip it; see FieldValue.

Encode

public static void Encode(this FieldKind kind, FieldValue value, Span<byte> bytes)

Writes a value into one value of this kind.

Parameters

  • kind: The kind to write as.
  • value: The value to store.
  • bytes: At least FieldKinds.SizeOf bytes of the field's storage.

Integers are clamped rather than cast. A double past an integer's range is undefined behavior as a cast in C and saturating in .NET, and neither is what a person dragging a value wants: a counter that wrapped to its minimum because a drag went one pixel too far would be a memorable bug. Clamping at least keeps the value where the person pointed. A whole value is written as itself, every bit of it; a fraction into an integer is cut toward zero, as it always was.

Roundtrip

public static FieldValue Roundtrip(this FieldKind kind, FieldValue value)

What a value becomes once this kind has stored it.

Parameters

  • kind: The kind that would store it.
  • value: The value.

Storing a value is lossy and the loss is knowable. 0.1 written into an FieldKind.F32 reads back as 0.100000001490116, and 3.7 written into an FieldKind.I32 reads back as 3. Anything comparing what it asked for against what the world now reports has to compare against this rather than against the original, or it will conclude that a write it made perfectly correctly never landed.