Skip to content

Commit

Permalink
[plugin|licenses] Do not override engine methods
Browse files Browse the repository at this point in the history
Fixes: #5
  • Loading branch information
IceflowRE committed Sep 24, 2023
1 parent 11ebeb2 commit 7f09625
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
52 changes: 32 additions & 20 deletions addons/licenses/component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ class License:
## Web present of the license
var web: String

func get_property_list() -> Array:
var properties: Array = super.get_property_list()
for property in properties:
if property["name"] == "text":
property["hint"] = PROPERTY_HINT_MULTILINE_TEXT
if property["name"] == "file":
property["hint"] = PROPERTY_HINT_FILE
return properties
func _get_property_list() -> Array[Dictionary]:
return [
{
"name": "text",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_MULTILINE_TEXT,
},
{
"name": "file",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_FILE,
}
]

## Either returns the license text or loads the text from file or a message that the text could not be loaded.
func get_license_text() -> String:
Expand Down Expand Up @@ -75,18 +80,25 @@ var web: String
var paths: PackedStringArray = []
var licenses: Array[License] = []

func get_property_list() -> Array:
var properties: Array = super.get_property_list()
for property in properties:
if property["name"] == "paths":
property["hint"] = PROPERTY_HINT_FILE
# allow files too (inofficial)
property["hint_text"] = "*"
if property["name"] == "description":
property["hint"] = PROPERTY_HINT_MULTILINE_TEXT
if property["name"] == "licenses":
property["constructor"] = License.new
return properties
func _get_property_list() -> Array:
return [
{
"name": "paths",
"type": TYPE_PACKED_STRING_ARRAY,
"hint": PROPERTY_HINT_FILE,
"hint_text": "*",
},
{
"name": "description",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_MULTILINE_TEXT,
},
{
"name": "licenses",
"type": TYPE_ARRAY,
"constructor": License.new,
},
]

func serialize() -> Dictionary:
var licenses: Array[Dictionary] = []
Expand Down
7 changes: 5 additions & 2 deletions addons/licenses/internal/handler/object.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
extends "base.gd"

const Utils := preload("../utils.gd")

func _init(tree_: Tree, item_: TreeItem, value_: Variant, property_: Dictionary) -> void:
super._init(tree_, item_, value_, property_)
self.item.set_text(0, self.property["name"].capitalize())
self.item.set_selectable(1, false)
for prop in self.value.get_property_list():
# ignore private variables and ignore non supported types

for prop in Utils.get_updated_property_list(self.value):
# ignore private variables and ignore non supported types and already added items
if prop["name"].begins_with("_"):
continue
self.tree._add_item(self.item, self.value.get(prop["name"]), prop)
Expand Down
10 changes: 10 additions & 0 deletions addons/licenses/internal/utils.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
static func get_updated_property_list(object: Object) -> Array:
var properties: Array = object.get_property_list()
var patched_properties: Array = object._get_property_list()
properties = properties.slice(0, properties.size() - patched_properties.size())
for p_prop_idx in range(patched_properties.size()):
for prop_idx in range(properties.size()):
if properties[prop_idx]["name"] == patched_properties[p_prop_idx]["name"]:
properties[prop_idx] = patched_properties[p_prop_idx]
break
return properties

0 comments on commit 7f09625

Please sign in to comment.