en-kig / componentable

Split your Godot project's logic into components (little pieces of code) to better maintenance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Componentable

A Godot Plugin to create generic components to your project's logic to make better maintenance

Works only on Godot 4.x versions


Table of Contents


πŸ“Ÿ What is Componentable?

The main goal of the Componentable is to create components to some classes to share responsibility between nodes.

Why use Components?

Structure Comparation with componentable and without

With this you can split the logic in many scripts with low code, and you can customize some behaviours for many nodes with same scene

Componentable properties

Example of selection of components on Componentable


Componentable Flow

The componentable flow is the componentable will always be required, so when you create a component will always have a variable with the componentable as value, but componentable can call the component but the component could not exist.


πŸ”§ Installation

  • You can search "Componentable" on Godot Assets Library
  • You can download this repo, copy and paste the addons/componentable into your project's folder

πŸ“ Getting Started

Creating a Componentable

To start just select a node and in the inspector click on Create Componentable

Inspector with a Create Componentable Button

Then will be create a Component Script for your node, and your node will be ready to have components

In this example, the Component Script created will be PlayerComponent, because de class_name of the script in this node is Progress.

Node don't need to have a script, componentable can be used with build-in types


Creating a Component

Just create a Script with a class_name and extends PlayerComponent, then you can place the behaviour you want inside this component.

in the PlayerComponent we have:

class_name PlayerComponent extends Node

@export var active = true
@export var player: Player

so we can access the player using the player variable.


So for in our component example Glowing will make the player glow with:

class_name Glowing extends PlayerComponent

func _ready():
	if active: # active is a variable inside PlayerComponent to make some enabling behaviours
		create_tween().tween_property(player, "modulate:a", 0, 1)

then you select the Componentable node you can select the component


This list of components will show all components that is from this node type and node parent types

when selected a component will show up as a node in components node of your Componentable


Alt text

Here you can see that we have two variables player that will be automatic assign as the Componentable Node, and the active variable, that will disable the behavior in your logic.

You can make more exported variables to create more customization to your component


Getting a Component from a Node

When you want to get a component from a Componentable, you can use:

var glowing: Glowing = Component.find(self, "Glowing")

If you want to get a component from a other node, you can use:

var glowing: Glowing = Component.find(player, "Glowing")

Just remember the component can be null


Adding or removing component in runtime

To add a component to a componentable in runtime you can use:

Component.subscribe(node, "ComponentName")

and to remove a component you can use:

Component.unsubscribe(node, "ComponentName")

Some others functions

Component.componentable(node) # will create a Component Script if don't exists to this node, and define this node as a componentable

Component.uncomponentable(node) # will make this node not a Componentable any more

Component.is_componentable(node) # return true if this node is a componentable

Component.has(node, "component") # return true if this componentable have this component

Component.get_all(node) # return all components in this componentable

πŸ€” FAQ

  • Why you created that? Cuz is so boring to create an Item with a custom name in Bukkit, it's more than 4 lines, and I'm lazy
  • I Found a BUG! Click here and open an issue
  • Can I help with the project? Sure! just send your PR :D
  • Can I contact you? Yep, send email to contact@gump.dev

About

Split your Godot project's logic into components (little pieces of code) to better maintenance

License:MIT License


Languages

Language:GDScript 100.0%