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

Changed icon retrieval to use preload(), and made the paths local. #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

BunkWire2X8
Copy link

I wanted to use this rather useful plugin with the Godot Global Project framework, but the problem is that it always retrieves the icon files from a predetermined "res://addons/script-ide/icon/" path. This is unfortunate, due to how the framework doesn't add editor-only addons into the "res://addons/" directory, making this normally incompatible.

This is a small edit that fixes that. Using preload(), I have these icon resources instead be retrieved from a more local relative path, which could also be argued to be a slight optimization on top of making the addon more compatible.

signal_icon = create_editor_texture(load("res://addons/script-ide/icon/signal.svg"))
constant_icon = create_editor_texture(load("res://addons/script-ide/icon/constant.svg"))
class_icon = create_editor_texture(load("res://addons/script-ide/icon/class.svg"))
keyword_icon = create_editor_texture(ICON_KEYWORD)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a safe change. Although I would prefer loading them here, as before.

My reasoning for this was, that we do not really want to preload those icons, as we will never use them. We will use a slightly different texture, made by create_editor_texture.

So if you can revert the load -> preload change while keeping the relative path, I will accept this PR. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I mainly used preload() to begin with because it allows easy use of relative paths, but since preload() is not ideal for this use case, I've now committed a change so that it now uses load() again, and concatenates the file path with the script's current base directory. It's slightly less efficient than from back when it used absolute paths, but I think it's probably fine, since this only happens on startup.

# ...
func _enter_tree() -> void:
	var script_path: String = get_script().get_path().get_base_dir()
	
	keyword_icon = create_editor_texture(load(script_path.path_join("icon/keyword.svg")))
	func_icon = create_editor_texture(load(script_path.path_join("icon/func.svg")))
	func_get_icon = create_editor_texture(load(script_path.path_join("icon/func_get.svg")))
	func_set_icon = create_editor_texture(load(script_path.path_join("icon/func_set.svg")))
	property_icon = create_editor_texture(load(script_path.path_join("icon/property.svg")))
	export_icon = create_editor_texture(load(script_path.path_join("icon/export.svg")))
	signal_icon = create_editor_texture(load(script_path.path_join("icon/signal.svg")))
	constant_icon = create_editor_texture(load(script_path.path_join("icon/constant.svg")))
	class_icon = create_editor_texture(load(script_path.path_join("icon/class.svg")))
# ...

Due to `load()` not having built-in support for relative paths, unlike `preload()`, I use `get_script().get_path().get_base_dir()` and `String.path_join()` to concatenate the relative icon paths with the script's current base directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants