Added page on dynamic layers

This commit is contained in:
thepaperpilot 2022-03-11 09:46:59 -06:00
parent 842044b9af
commit b4dab7a0ce
2 changed files with 15 additions and 1 deletions

View file

@ -62,7 +62,8 @@ module.exports = {
{
text: "Advanced Concepts",
children: [
{ text: "Creating Features", link: "/guide/creating-features" }
{ text: "Creating Features", link: "/guide/creating-features" },
{ text: "Dynamic Layers", link: "/guide/dynamic-layers" }
]
}
],

View file

@ -0,0 +1,13 @@
# Dynamic Layers
You can dynamically add and remove layers using the `addLayer` and `removeLayer` functions. Note that removing a layer does not change the player save data in any way, so you can safely add and remove the same layer. In fact, there is a `reloadLayer` to do just that, which is used for when the structure of a layer changes - e.g., adding a new feature.
If you're going to be procedurally generating layers, all with a similar structure, it might make sense to use a utility function like the following in order to easily access a correctly typed reference to a layer with a given ID:
```ts
function getDynLayer(id: string): DynamicLayer {
const layer = layers[id];
if (!layer) throw "Layer does not exist";
return layer as DynamicLayer; // you might need an "as unknown" after layer
}
```