gmuGADIG / FetchQuest

woof woof (Game created by GMU GADIG in Fall 2024)
8 stars 0 forks source link

Activator API #152

Open micycle8778 opened 3 days ago

micycle8778 commented 3 days ago

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". 1 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. 2

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:

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.