# WeaponTuning class

> 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.

Namespace `EvilEngine.Formats.Records`, assembly `EvilEngine.Formats`. Engine commit 4ff877b1.

```csharp
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](/docs/plugins/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](#mistakes), and every key nothing read is listed as [unread](#unread), so the server can note both once by the weapon and key. A behaviour reads its tuning when it's made:

```csharp
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");
}
```

## Members

### Empty (field)

```csharp
public static readonly WeaponTuning Empty
```

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

### Path (property)

```csharp
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)

```csharp
public IEnumerable<string> Keys { get; }
```

The table's keys, in order.

### Count (property)

```csharp
public int Count { get; }
```

How many keys the table has.

### Unread (property)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
public bool Has(string key)
```

Whether the table has a key, without reading it.

### Raw (method)

```csharp
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)

```csharp
public double Number(string key, double fallback)
```

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

### Integer (method)

```csharp
public int Integer(string key, int fallback)
```

A key as a whole number, or the fallback.

### Bool (method)

```csharp
public bool Bool(string key, bool fallback)
```

A key as `true` or `false`, or the fallback.

### String (method)

```csharp
public string String(string key, string fallback)
```

```csharp
public string? String(string key)
```

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

### Choice (method)

```csharp
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)

```csharp
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)

```csharp
public ContentId? Id(string key)
```

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

### RequiredId (method)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
public bool Equals(WeaponTuning? other)
```

```csharp
public override bool Equals(object? obj)
```

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

### GetHashCode (method)

```csharp
public override int GetHashCode()
```

A hash over the keys, matching [Equals](#equals).
