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
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions addons/script-ide/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ const OPEN_OUTLINE_POPUP: StringName = SCRIPT_IDE + &"open_outline_popup"
## Editor setting for the 'Open Scripts Popup' shortcut
const OPEN_SCRIPTS_POPUP: StringName = SCRIPT_IDE + &"open_scripts_popup"

#region Preloaded icon resources
const ICON_KEYWORD: Image = preload("icon/keyword.svg")
const ICON_FUNC: Image = preload("icon/func.svg")
const ICON_FUNC_GET: Image = preload("icon/func_get.svg")
const ICON_FUNC_SET: Image = preload("icon/func_set.svg")
const ICON_PROPERTY: Image = preload("icon/property.svg")
const ICON_EXPORT: Image = preload("icon/export.svg")
const ICON_SIGNAL: Image = preload("icon/signal.svg")
const ICON_CONSTANT: Image = preload("icon/constant.svg")
const ICON_CLASS: Image = preload("icon/class.svg")
#endregion

const GETTER: StringName = &"get"
const SETTER: StringName = &"set"
const UNDERSCORE: StringName = &"_"
Expand Down Expand Up @@ -89,15 +101,15 @@ var suppress_settings_sync: bool = false
#region Enter / Exit -> Plugin setup
## Change the Godot script UI and transform into an IDE like UI
func _enter_tree() -> void:
keyword_icon = create_editor_texture(load("res://addons/script-ide/icon/keyword.svg"))
func_icon = create_editor_texture(load("res://addons/script-ide/icon/func.svg"))
func_get_icon = create_editor_texture(load("res://addons/script-ide/icon/func_get.svg"))
func_set_icon = create_editor_texture(load("res://addons/script-ide/icon/func_set.svg"))
property_icon = create_editor_texture(load("res://addons/script-ide/icon/property.svg"))
export_icon = create_editor_texture(load("res://addons/script-ide/icon/export.svg"))
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")))
# ...

func_icon = create_editor_texture(ICON_FUNC)
func_get_icon = create_editor_texture(ICON_FUNC_GET)
func_set_icon = create_editor_texture(ICON_FUNC_SET)
property_icon = create_editor_texture(ICON_PROPERTY)
export_icon = create_editor_texture(ICON_EXPORT)
signal_icon = create_editor_texture(ICON_SIGNAL)
constant_icon = create_editor_texture(ICON_CONSTANT)
class_icon = create_editor_texture(ICON_CLASS)

is_outline_right = get_setting(OUTLINE_POSITION_RIGHT, is_outline_right)
hide_private_members = get_setting(HIDE_PRIVATE_MEMBERS, hide_private_members)
Expand Down