blackears / cyclopsLevelBuilder

A Godot plugin to let you block in levels inside the Godot editor.
MIT License
920 stars 36 forks source link

Nuke class_names everywhere #133

Closed fauxhaus closed 4 months ago

fauxhaus commented 4 months ago

I was working on adding this plugin into a larger project with a bunch of existing class_name nodes, when I started to observe an instability in Godot's class_name system. For whatever reason, I had to manually go through most of this plugin's scripts and resave them and reload the editor numerous times, eventually allowing Godot's parser to finally untangle the nest of class dependencies throughout the plugin. This was an issue present in my project and other plugins as well.

A workaround I used in my own project was to remove class_names in the majority of my scripts, instead preloading the types in each file that needed them.

An example of this with action_popup_menu.gd:

@tool
extends PopupMenu
# no class_name here

## Script types
const CyclopsAction = preload("res://addons/cyclops_level_builder/actions/cyclops_action.gd")

var action_map:Dictionary = {}

func _ready():
    id_pressed.connect(on_id_pressed)

func add_action_item(action:CyclopsAction):
    ...

The advantages of this:

The main disadvantage is that this requires manually defining types everywhere, which puts more burden on active development. However, I think the benefits of the cleanup for devs using the plugin are worth it.

If this seems worth pursuing, I can whip up a quick Python script to automatically refactor the plugin for this.

blackears commented 4 months ago

I'm not going to do this. I know that GDScript has a very problematic handling of class names at the moment, but I'd rather stick with strong class naming conventions and hope that this improves in the future. I really do not like dynamically typed languages and am strongly typing things as much as I can. You can strip out the class names in your branch of the project if you feel this improves things, but I will not be doing this in the main project.

blackears commented 4 months ago

I had another look at your code. It looks a bit like how Python's import statement works. While I suppose this offers some safety, it would be a lot more work to keep consistent.

There has been some discussion about namespaces being added to GDScript, and I'm hoping that will resolve a lot of issues like this when it happens.