Skip to content
EvilEngine.Formats.Records

WeaponTuning class

public sealed class WeaponTuning : IEquatable<WeaponTuning>

A weapon record’s tuning table, the numbers and choices its behaviour reads. Its keys are free: a behaviour decides which it reads and what they mean, as evil.weapons does for its firearms, launchers, melee and beams (Making weapons). A record’s tuning merges key by key over its base’s, tables into tables.

Every read takes a fallback and never throws. A value of the wrong kind falls back and is kept as a mistake, and every key nothing read is listed as unread, so the server can note both once by the weapon and key. A behaviour reads its tuning when it’s made:

sealed class ChainLightning(WeaponRecord record) : IWeaponBehaviour
{
    readonly double reach = record.Tuning.Number("reach", 6);
    readonly string mode = record.Tuning.Choice("mode", "arc", "arc", "fork");
    readonly (double R, double G, double B, double A) colour = record.Tuning.Colour("colour", "#80c0ff");
}
Assembly
EvilEngine.Formats
Commit
4ff877b1

Members

Empty field

public static readonly WeaponTuning Empty

Tuning with no keys, what a record without a tuning table has.

Path property

public string Path { get; }

Where this table is in the record, tuning. or tuning.recoil., which every mistake and unread key is named by.

Keys property

public IEnumerable<string> Keys { get; }

The table’s keys, in order.

Count property

public int Count { get; }

How many keys the table has.

Unread property

public IReadOnlyList<string> Unread { get; }

Every key, nested ones included, that nothing has read yet, each by its full path such as tuning.recoil.yaw.

Mistakes property

public IReadOnlyList<string> Mistakes { get; }

Every read so far that found the wrong kind of value, each saying what was there, what was wanted and what was used instead, once each.

Of method

public static WeaponTuning Of(IEnumerable<KeyValuePair<string, object>> values)

Tuning made in code from pairs of keys and values: numbers, strings, flags, lists, and dictionaries or other tuning for tables.

Has method

public bool Has(string key)

Whether the table has a key, without reading it.

Raw method

public object? Raw(string key)

A key’s value as it is: a long, double, bool, string, an object[] list or a nested WeaponTuning, or null.

Number method

public double Number(string key, double fallback)

A key as a number, whole or not, or the fallback.

Integer method

public int Integer(string key, int fallback)

A key as a whole number, or the fallback.

Bool method

public bool Bool(string key, bool fallback)

A key as true or false, or the fallback.

String method

public string String(string key, string fallback)
public string? String(string key)

A key as a string, or the fallback, or null without one.

Choice method

public string Choice(string key, string fallback, params string[] choices)

A key as one of a set of strings, or the fallback when it’s missing or none of them.

Colour method

public (double, double, double, double) Colour(string key, string fallback)

A key as a #rrggbb or #rrggbbaa colour, red, green, blue and alpha from 0 to 1, or the fallback’s.

Id method

public ContentId? Id(string key)

A key as a namespace:object id, or null.

RequiredId method

public ContentId? RequiredId(string key)

A key as an id the behaviour can’t do without: missing, it’s kept as a mistake that names it, and null comes back.

Numbers method

public IReadOnlyList<double> Numbers(string key, params double[] fallback)

A key as a list of numbers, a single number as a list of one, or the fallback.

Range method

public (double, double) Range(string key, double low, double high)

A key as a low and a high, from two numbers or one used for both, or the fallback’s.

Strings method

public IReadOnlyList<string> Strings(string key)

A key as a list of strings, a single string as a list of one, or none.

Table method

public WeaponTuning Table(string key)

A key as a nested table, or an empty one at that path, so a behaviour reads Table("recoil").Number("pitch", 0) whether or not it’s there.

Tables method

public IReadOnlyList<WeaponTuning> Tables(string key)

A key as a list of tables, a single table as a list of one, or none.

Over method

public WeaponTuning Over(WeaponTuning under)

This tuning over another, its keys winning and tables merging key by key, as a record’s tuning over its base’s.

Equals method

public bool Equals(WeaponTuning? other)
public override bool Equals(object? obj)

Whether two tunings hold the same keys and values, nested tables and lists compared by value.

GetHashCode method

public override int GetHashCode()

A hash over the keys, matching Equals.