Yaml Inheritance Guide#647
Conversation
|
@RemFexxel If you have time would be great if you could have a look. |
|
Sure. I'll let you know when I've completed my review. |
ArtisticRoomba
left a comment
There was a problem hiding this comment.
Looks good for an inheritance guide. Might want to have another guide on just DataFields as there's some specific behaviors like readonly, required, and serveronly, though the xmldocs for them are already pretty good so I'm indifferent.
RemFexxel
left a comment
There was a problem hiding this comment.
There are a few grammatical mistakes, but the rest of your guide looks good.
| # YAML Inheritance Guide | ||
| ### Inheritance Rules | ||
|
|
||
| There are different ways DataFields get merged or overwritten when inheriting from another prototype in YAML and they can be a little confusing. |
There was a problem hiding this comment.
| There are different ways DataFields get merged or overwritten when inheriting from another prototype in YAML and they can be a little confusing. | |
| There are different ways DataFields get merged or overwritten when inheriting from another prototype in YAML, and they can be a little confusing. |
| name: test item 3 | ||
| description: hampter | ||
|
|
||
| # This time we manually overwrite the inherited rsi. |
There was a problem hiding this comment.
| # This time we manually overwrite the inherited rsi. | |
| # This time we manually overwrite the inherited RSI. |
| name: test item 2 | ||
| description: lizard | ||
|
|
||
| # If we inherit in this order the rsi path will be taken from ParentC first. |
There was a problem hiding this comment.
| # If we inherit in this order the rsi path will be taken from ParentC first. | |
| # If we inherit in this order the RSIpath will be taken from ParentC first. |
| state: icon # this state name is the same for all basic plushie sprites | ||
|
|
||
| # The lizard sprite rsi is inherited first from TestItem1. | ||
| # The rsi is not overwritten by the hampter because it already exists in the first parent. |
There was a problem hiding this comment.
| # The rsi is not overwritten by the hampter because it already exists in the first parent. | |
| # The RSI is not overwritten by the hampter because it already exists in the first parent. |
| sprite: Objects/Fun/Plushies/lizard.rsi | ||
| state: icon # this state name is the same for all basic plushie sprites | ||
|
|
||
| # The lizard sprite rsi is inherited first from TestItem1. |
There was a problem hiding this comment.
| # The lizard sprite rsi is inherited first from TestItem1. | |
| # The lizard sprite RSI is inherited first from TestItem1. |
| components: | ||
| - type: Sprite | ||
| state: icon # all plushie sprites have the same state name | ||
| - type: EmitSoundOnUse # make it squeak when used |
There was a problem hiding this comment.
| - type: EmitSoundOnUse # make it squeak when used | |
| - type: EmitSoundOnUse # Makes the plushie squeak when used. |
| name: bee plushie | ||
| components: | ||
| - type: Sprite | ||
| state: plushie_h # add a state (the sprite path is inherited from BasePlushie) |
There was a problem hiding this comment.
| state: plushie_h # add a state (the sprite path is inherited from BasePlushie) | |
| state: plushie_h # Adds a state (the sprite path is inherited from BasePlushie). |
| This is a simple pointlight that quickly disappears and deletes itself. We use `categories: [HideSpawnMenu]` to make sure it does not show up in the spawn menu, but it can still be spawned through code using the `Spawn(protoId, coords)` method or similar. | ||
| This will also exclude it from several integration tests, which may otherwise fail for such an entity. | ||
|
|
||
| ### Making a prototype inheritable |
There was a problem hiding this comment.
| ### Making a prototype inheritable | |
| ### Making a Prototype Inheritable |
| This will also exclude it from several integration tests, which may otherwise fail for such an entity. | ||
|
|
||
| ### Making a prototype inheritable | ||
| The above examples were all for `EntityPrototype`s, but they work the same for any other type of prototype. You can define your own prototype in C# and make it store DataFields. To make it inheritable in YAML you will have to implement the `IInheritingPrototype` interface. This requires a DataField for the parents and a bool for being abstract. |
There was a problem hiding this comment.
| The above examples were all for `EntityPrototype`s, but they work the same for any other type of prototype. You can define your own prototype in C# and make it store DataFields. To make it inheritable in YAML you will have to implement the `IInheritingPrototype` interface. This requires a DataField for the parents and a bool for being abstract. | |
| The above examples were all for `EntityPrototype`s, but they work the same for any other type of prototype. You can define your own prototype in C# and make it store DataFields. To make it inheritable in YAML, you will have to implement the `IInheritingPrototype` interface. This requires a DataField for the parents and a bool for being abstract. |
There was a problem hiding this comment.
I would also make a short mention of why you would even define your own prototype to begin with (e.g. mention how prototypes are useful as presets).
There was a problem hiding this comment.
This requires a DataField for the parents and a bool for being abstract. ->
This requires a DataField for the ID and parents, and a bool for being abstract.
| - type: inheritanceTest | ||
| parent: Parent | ||
| id: Child | ||
| # neverInheritedField will be the C# default "default value" again |
There was a problem hiding this comment.
| # neverInheritedField will be the C# default "default value" again | |
| # neverInheritedField will be the C# default "default value" again. |
| @@ -0,0 +1,293 @@ | |||
| # YAML Inheritance Guide | |||
There was a problem hiding this comment.
| # YAML Inheritance Guide | |
| # YAML Inheritance Guide | |
| This guide will teach you how inheritance works in YAML prototypes. Inheritance allows "child" prototypes to inherit data from "parent" prototypes, making it easy to copy or change behaviors without needing to type out all data for every single prototype. | |
There was a problem hiding this comment.
Just a quick summary setting expectations for what the doc will contain.
| ``` | ||
|
|
||
|
|
||
| To summarize the inheritance rules: |
There was a problem hiding this comment.
I would put this section before the yaml example. That way you prime the reader for what they will see in the example, rather than show a lot of yaml without it being clear what they should be looking for.
You do this for the next sections and I think they read smoother as a result.
| ``` | ||
|
|
||
| ### Abstract Prototypes | ||
| If you got a base prototype that should not a fully functioning prototype on its own, but used for inheritance, then make sure to mark it as `abstract`. This will make sure it cannot be spawned by any means, it will be hidden from the F5 spawn menu, and will be ignored by integration tests. |
There was a problem hiding this comment.
I would add "only" to but is only used for inheritance. Afaik there is no reason to make something abstract if not for inheritance.
| This will also exclude it from several integration tests, which may otherwise fail for such an entity. | ||
|
|
||
| ### Making a prototype inheritable | ||
| The above examples were all for `EntityPrototype`s, but they work the same for any other type of prototype. You can define your own prototype in C# and make it store DataFields. To make it inheritable in YAML you will have to implement the `IInheritingPrototype` interface. This requires a DataField for the parents and a bool for being abstract. |
There was a problem hiding this comment.
I would also make a short mention of why you would even define your own prototype to begin with (e.g. mention how prototypes are useful as presets).
| This will also exclude it from several integration tests, which may otherwise fail for such an entity. | ||
|
|
||
| ### Making a prototype inheritable | ||
| The above examples were all for `EntityPrototype`s, but they work the same for any other type of prototype. You can define your own prototype in C# and make it store DataFields. To make it inheritable in YAML you will have to implement the `IInheritingPrototype` interface. This requires a DataField for the parents and a bool for being abstract. |
There was a problem hiding this comment.
This requires a DataField for the parents and a bool for being abstract. ->
This requires a DataField for the ID and parents, and a bool for being abstract.
| ``` | ||
|
|
||
| ### AlwaysPushInheritance, NeverPushInheritance | ||
| These two attributes can change the inheritance behaviour for a specific DataField. This works both for DataFields inside Components and inside custom Prototypes. |
There was a problem hiding this comment.
| These two attributes can change the inheritance behaviour for a specific DataField. This works both for DataFields inside Components and inside custom Prototypes. | |
| These two attributes can change the inheritance behaviour for a specific DataField. This works both for DataFields inside Components and inside custom Prototypes. You can find if a DataField has these attributes by looking at it in the C# code. |
I'd move this comment up here instead of the snippet at the bottom.
The first part of the Slarti Guide that I polished up and turned into its own doc.
For the reviewer I recommend to test all of the code in-game to double check that everything is correct and working as intented.