From b4dab7a0ced7de3d610b5d14547b131d6d7b5bd2 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Fri, 11 Mar 2022 09:46:59 -0600 Subject: [PATCH] Added page on dynamic layers --- docs/.vitepress/config.js | 3 ++- docs/guide/dynamic-layers.md | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 docs/guide/dynamic-layers.md diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 942a2214..0bf76cab 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -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" } ] } ], diff --git a/docs/guide/dynamic-layers.md b/docs/guide/dynamic-layers.md new file mode 100644 index 00000000..2653809d --- /dev/null +++ b/docs/guide/dynamic-layers.md @@ -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 +} +```