Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify and seperate class_name into two functionalties #3329

Closed
Shadowblitz16 opened this issue Sep 22, 2021 · 10 comments
Closed

modify and seperate class_name into two functionalties #3329

Shadowblitz16 opened this issue Sep 22, 2021 · 10 comments

Comments

@Shadowblitz16
Copy link

Describe the project you are working on

Space ship game

Describe the problem or limitation you are having in your project

  • I want to use class_name to register a whole scene as createable
  • I need a way to name derived node's without them being in the node creation dialog.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

  • rename class_name to class and allow a optional : at the end
  • add scene keyword to register a whole scene
  • allow optional exporting of classes, and scenes

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

# for just the node, with this script.. extend Node, name it MyCustomClass and export it to node creation dialog as MyCustomClass
export class MyCustomNode extends Node

# for this node and all its children, with this script.. extend Node, name it MyCustomClass and export it to node creation dialog as MyCustomClass
export scene MyCustomClass extends Node

  • export would export it to the resource or node creation dialog depending on whether its a resource or node
  • class treats it as a new class
  • scene treats it as a new composite node

If this enhancement will not be used often, can it be worked around with a few lines of script?

  • The scene keyword would be used to register a whole scene as a type.

    • It basically would be a way to link the scene and scripts together in a type,
    • It would still have to be attached to a scene and saved before it's registered
  • The class keyword would reduce the amount of keywords in GDScript

  • The optional export keyword would be used either at the end of a class, scene, property or field

    • It reduces needs for checks in GDScript parser
    • It allows separation of named scenes / classes and the exporting them to the creation dialogs

Is there a reason why this should be core and not an add-on in the asset library?

  • It helps with static typing a bit and improves code.
  • Its currently not possible to separate class name's from whether they show up in the creation dialogs.
  • Its currently not possible to register a whole scene as a type without creating and setting up the children node's through script.
@Shadowblitz16
Copy link
Author

Note I am sure how it would translate to 4.0 please let me know what you think.

@zinnschlag
Copy link

# for this node and all its children, with this script.. extend Node, name it MyCustomClass and export it to node creation dialog as MyCustomClass
export scene MyCustomClass extends Node

I assume you mean to name a Scene as MyCustomClass. How is that supposed to work? How is Godot to know which scene is meant?

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Sep 22, 2021

@zinnschlag It would be registered when you add the script to the node.

I would guess it would be added on some sort of script added signal and removed on some sort of script removed signal.
When the scene is freed from memory it would unregister the script

This means you would have to not only attach the script but also have to save the scene or keep it open in the editor.

@zinnschlag
Copy link

But a script can be attached to nodes in more than one scene. If you have a script S that is attached to both the root nodes of scene A and scene B, which scene is it then?

@YuriSizov
Copy link
Contributor

@zinnschlag To save you the trouble, it's the same basic idea they've been asking for across several other proposals, like #2612. The aim is to somehow make scenes into types instead of scripts. Which would imply exclusive, one-to-one binding.

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Sep 22, 2021

@zinnschlag Yes it would take the node the script was attached and basically package it as a type with all its node's and script's attached to those node's.

I'm not saying it would be a actual new type but the idea is depending on the keywords you use you can register it as a global name and you can export it to the creation dialogs.

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Sep 22, 2021

@pycbouh part of this issue covers this #1047
Also the other part of what I am suggesting isn't necessarily making scenes into types, It more of just a way to package scenes under a name in the node creation dialog.

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Sep 23, 2021

The scene keyword would probably be better as a annotation in 4.0 like willnationsdev's I just don't like the idea of having to hard code a file path that might change.

@dalexeev
Copy link
Member

  • scene treats it as a new composite node

The same script can be attached to multiple scenes, so Godot cannot guess which scene is needed. You need to explicitly specify the path to the scene in the script, we already discussed this in #1935.

@Shadowblitz16
Copy link
Author

Closing in favor of #1047
As much as I dislike the fact that scenes can't by dynamically linked to the script (for now) I agree with @dalexeev 's statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants