Phazorknight / Cogito

Immersive Sim Template Project for GODOT 4
MIT License
902 stars 101 forks source link

Lightzone Switch component #88

Closed kk1201 closed 7 months ago

kk1201 commented 7 months ago

I noticed that the lightzone script didn't have any functionality to respond to light switch events. I added a LightzoneSwitchComponent.gd script to solve this. Parenting it to a LightzoneComponent and connecting the switched signal from a Cogito_Switch.gd node to the _on_switched function, this should should make the parent lightzone automatically follow the switch's state by enabling and disabling the Area3D::monitoring property.

Reason Small change, follows composition, I think it makes sense for it to be included in the template since it's a big feature of a lot of immersive sims, allows for new gameplay and level design options :)

No side effects Will only affect lightzones, and not connecting the signal or setting the switchable flag to false will make the lightzone behave as previously. CogitoSwitch.gd::is_on initial state is respected. I added a LightzoneSwitchComponent to the LightzoneComponent prefab and added a LightzoneComponent child to the CeilingLamp prefab as an example but feel free to make me restore them to their previous state.

Downsides Uses get_parent(), which violates pure composition. However the use-case is incredibly obvious based on the name and documentation, and it shouldn't pollute anything else, so I feel like using it in this limited scope makes sense.


https://github.com/Phazorknight/Cogito/assets/149746050/a2699cb9-14d0-4613-9b53-e7327fd567bd