Note: Merge this commit last, because it will probably cause some merge conflicts, as it moves some files around and changes a good bit of existing code.
This PR adds the activator API and activator plugin, which enables the designing of puzzles.
The basic idea is that there are activators, which emit switch_activated and switch_deactivated signals. There are also activatables, which have activate and deactivate methods that are connected to said signals. The activator plugin allows level designers to make those connections, and the activator manager autoload actually makes those connections in code.
Using the activator plugin
Add an activator and activatable into a scene.
Select/Click on the activator, and a button in the tool bar should show up labeled "Edit Activations".
Clicking on "Edit Activations" will allow you to edit the nodes the activator will activate. Select/Click on an activatable to create the connection. Clicking it again will remove the activation.
When editing activations, you will be able to see the connected activations as yellow lines on screen. You also will not be able to select or edit any other nodes until you click "Edit Activations" again, taking you out of the edit activations mode.
Writing an activator
To create an activator, create a node and add it to the Activator group. This will make it an activator and able to be edited by the activator plugin. Then add the switch_activated signal to the script of the activator. When switch_activated signal is emitted, the activator will activated any connected activatables. Optionally, add the switch_deactivated signal. When the switch_deactivated signal is emitted, the activator will deactivate any connected activatables.
Activators are expected to be Node2Ds, which makes drawing the lines possible.
Writing an activatable
To create an activator, create a node and add it to the Activatable group. This will make it an activatable and able to be used by the activator plugin. Add the activate method to the script of the activatable, and it will be called when one of the connected activators emits switch_activated. add the deactivate method to the script and it will be called when one of the connected activators emits switch_deactivated.
Activatables are expected to be Node2Ds, which makes drawing the lines possible.
Activator internals
Activator connections are managed using object metadata. When modified by the activator plugin, activators will be given a metadata entry of name Activatables and a value of an array of node paths. These node paths are relative to the activator node itself and refer to the activatables that the activator is connected to. The node paths should be automatically changed by the editor if the activatable or activator is moved in the scene tree.
On scene change and the game start, the activator autoload will connect the activator signals to their corresponding activatable methods. This is done when the scene root emits ready, so activators should expect signals to be connected after their _ready has been called.
Existing Activator API implementation
This PR also adds Activator API implementation for some existing dungeon mechanics.
Activators:
Switches
Pressure Plates
Red coins (they emit switch_activated when all of the red coins are collected.)
Activatables:
Locked door (Locked doors are unlocked when activated. They can also be configured to ignore keys)
Moving objects/platforms (See test scene)
Activatable Spawner (Created with this PR, able to spawn anything with an activation, see test scene)
Limitations
There is no way to only connect activations without connecting deactivations. They both are connected no matter what.
There's no way to require several connections to activate and activatable.
Both of these limitations may need to be fixed by creating custom activatables/activators, depending on the needs of level design.
This PR also adds a particle fixer node, which will enable a parent CPUParticles2D on ready and will destroy said parent when the parent is finished emitting particles. Useful for one shot particles.
Note: Merge this commit last, because it will probably cause some merge conflicts, as it moves some files around and changes a good bit of existing code.
This PR adds the activator API and activator plugin, which enables the designing of puzzles.
The basic idea is that there are activators, which emit
switch_activated
andswitch_deactivated
signals. There are also activatables, which haveactivate
anddeactivate
methods that are connected to said signals. The activator plugin allows level designers to make those connections, and the activator manager autoload actually makes those connections in code.Using the activator plugin
Add an activator and activatable into a scene. Select/Click on the activator, and a button in the tool bar should show up labeled "Edit Activations". Clicking on "Edit Activations" will allow you to edit the nodes the activator will activate. Select/Click on an activatable to create the connection. Clicking it again will remove the activation.
When editing activations, you will be able to see the connected activations as yellow lines on screen. You also will not be able to select or edit any other nodes until you click "Edit Activations" again, taking you out of the edit activations mode.
Writing an activator
To create an activator, create a node and add it to the
Activator
group. This will make it an activator and able to be edited by the activator plugin. Then add theswitch_activated
signal to the script of the activator. Whenswitch_activated
signal is emitted, the activator will activated any connected activatables. Optionally, add theswitch_deactivated
signal. When theswitch_deactivated
signal is emitted, the activator will deactivate any connected activatables.Activators are expected to be
Node2D
s, which makes drawing the lines possible.Writing an activatable
To create an activator, create a node and add it to the
Activatable
group. This will make it an activatable and able to be used by the activator plugin. Add theactivate
method to the script of the activatable, and it will be called when one of the connected activators emitsswitch_activated
. add thedeactivate
method to the script and it will be called when one of the connected activators emitsswitch_deactivated
.Activatables are expected to be
Node2D
s, which makes drawing the lines possible.Activator internals
Activator connections are managed using object metadata. When modified by the activator plugin, activators will be given a metadata entry of name
Activatables
and a value of an array of node paths. These node paths are relative to the activator node itself and refer to the activatables that the activator is connected to. The node paths should be automatically changed by the editor if the activatable or activator is moved in the scene tree.On scene change and the game start, the activator autoload will connect the activator signals to their corresponding activatable methods. This is done when the scene root emits
ready
, so activators should expect signals to be connected after their_ready
has been called.Existing Activator API implementation
This PR also adds Activator API implementation for some existing dungeon mechanics.
Activators:
switch_activated
when all of the red coins are collected.)Activatables:
Limitations
Both of these limitations may need to be fixed by creating custom activatables/activators, depending on the needs of level design.
This PR also adds a particle fixer node, which will enable a parent
CPUParticles2D
on ready and will destroy said parent when the parent is finished emitting particles. Useful for one shot particles.