migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
986 stars 55 forks source link

Extending #initSwiftExtension macro to support type registration at editor level #464

Closed sekimondre closed 2 months ago

sekimondre commented 2 months ago

Motivation

Currently, the #initSwiftExtension macro only registers types at a .scene initialization level. If you need to expose types that run on editor time (e.g. plugin code), you have to resort to the default boilerplate initialization code, and manually register your editor classes:

func setupScene (level: GDExtension.InitializationLevel) {
    switch level {
    case .editor:
        register(type: ToolThatWillRunOnEditor.self)
    case .scene:
        // gameplay classes
    default:
        break
    }
}

Solution

Extending the #initSwiftExtension to separately register classes on .editor init level.

#initSwiftExtension(
    cdecl: "swift_entry_point",
    editorTypes: [/* editor level classes */],
    sceneTypes: [/* scene level classes */]
)

Questions

  1. Considering that this change is dealing with exposing types at different GDExtension.InitializationLevel times, is there any interest in also allowing type registration at .core and .servers levels?
  2. Or any reason not to support it?