Skip to content

Commit

Permalink
Update conventions.md for ProtoId and new DataField format
Browse files Browse the repository at this point in the history
  • Loading branch information
DrSmugleaf committed Nov 28, 2023
1 parent 9c56471 commit 5a2f5b6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/en/general-development/codebase-info/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ This is so it is clear to others what it is. This is especially true if the same
## Prototypes

### Prototype data-fields
Don't cache prototypes, use prototypeManager to index them when they are needed. You can store them by their ID. When using data-fields that involve prototype ID strings, use custom type serializers. For example, a data-field for a list of prototype IDs should use something like:
Don't cache prototypes, use prototypeManager to index them when they are needed. You can store them by their ID. When using data-fields that involve prototype ID strings, use ProtoId<T>. For example, a data-field for a list of prototype IDs should use something like:
```csharp=
[DataField("exampleTypes", customTypeSerializer: typeof(PrototypeIdListSerializer<ExamplePrototype>))]
public List<string> ExampleTypes = new();
[DataField]
public List<ProtoId<ExamplePrototype>> ExampleTypes = new();
```

### Enums vs Prototypes
Expand All @@ -155,7 +155,7 @@ When specifying sound data fields, use `SoundSpecifier`.
<summary>C# code example (click to expand)</summary>

```csharp=
[DataField("sound", required: true)]
[DataField(required: true)]
public SoundSpecifier Sound { get; } = default!;
```

Expand Down Expand Up @@ -190,7 +190,7 @@ When specifying sprite or texture data fields, use `SpriteSpecifier`.
<summary>C# code example (click to expand)</summary>

```csharp=
[DataField("icon")]
[DataField]
public SpriteSpecifier Icon { get; } = SpriteSpecifier.Invalid;
```

Expand Down

0 comments on commit 5a2f5b6

Please sign in to comment.