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

GDScript: show properties added with _get_property_list() in the code completion popup #25097

Closed
mrcdk opened this issue Jan 18, 2019 · 2 comments · Fixed by #28122
Closed

GDScript: show properties added with _get_property_list() in the code completion popup #25097

mrcdk opened this issue Jan 18, 2019 · 2 comments · Fixed by #28122

Comments

@mrcdk
Copy link
Contributor

mrcdk commented Jan 18, 2019

Godot version:

Godot 3.1 beta 1

I wanted to have some dynamic properties added with _get_property_list() to show in the code completion popup so I wrote this script as an autoload:

tool
extends Node

var layers = Dictionary()

func _init():
	print(get_property_list())
	property_list_changed_notify()
	
func _get_layers():
	var layers = {}
	for i in 20:
		var s = ProjectSettings.get('layer_names/2d_physics/layer_%s' % [i+1])
		if s:
			layers[s] = 1 << i
			
	return layers

func _get(key):
	if layers.has(key):
		return layers[key]
	
	return null
	
func _set(key, value):
	return false
	
func _get_property_list():
	layers = _get_layers()
	var result = []
	for layer in layers.keys():
		result.push_back({
			"name": layer,
			"type": TYPE_INT,
			"usage": PROPERTY_USAGE_SCRIPT_VARIABLE
		})
	return result

It doesn't work so I went to the source code and I think I found why. The code completion calls this function: https://github.com/godotengine/godot/blob/master/modules/gdscript/gdscript.cpp#L239-L264 which doesn't call the script's _get_property_list() function while the function get_property_list() call this one: https://github.com/godotengine/godot/blob/master/modules/gdscript/gdscript.cpp#L1059-L1128 which does call it and returns the property list with the ones added with _get_property_list().

Would it be possible to call GDScriptIntance::get_property_list() from GDScript::get_script_property_list() or would that hurt performance somehow?

@willnationsdev
Copy link
Contributor

I'd be interested in seeing this implemented as well. It's very frustrating considering that a lot of features can only be done using _get_property_list().

@mrcdk
Copy link
Contributor Author

mrcdk commented Apr 17, 2019

I went ahead and tried to implement this in the gdscript editor. What I did does work but I'm not sure if it's going to be the best way to do it.

mrcdk added a commit to mrcdk/godot that referenced this issue Sep 3, 2019
@akien-mga akien-mga added this to the 3.2 milestone Sep 3, 2019
pchasco pushed a commit to pchasco/godot that referenced this issue Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants