Skip to content

Commit

Permalink
[*] Update snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Jan 9, 2024
1 parent bf6d1ab commit d98ea9c
Show file tree
Hide file tree
Showing 24 changed files with 201 additions and 69 deletions.
6 changes: 6 additions & 0 deletions addons/icon_explorer/internal/scripts/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var license: String
var license_text: String
var web: String

## scale at what the icon will be loaded, aim for 128px size
var svg_scale: float

# is set on registering it at the IconDatabase
var _id: int = -1
# set value on installing from 0 - 100
Expand All @@ -31,16 +34,19 @@ func is_installed() -> bool:
return DirAccess.dir_exists_absolute(self.icon_directory())

# VIRTUAL
# called in a thread
func load() -> Array[Icon]:
assert(false, "virtual function")
return []

# VIRTUAL
# called in a thread
func install(http: HTTPRequest, version: String) -> Error:
assert(false, "virtual function")
return Error.FAILED

# VIRTUAL
# called in a thread
func remove() -> Error:
if Io.rrm_dir(self.directory()):
return Error.OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func _init() -> void:
self.author = "The Bootstrap Authors"
self.license = "MIT"
self.web = "https://github.com/twbs/icons"
self.svg_scale = 8.0

# OVERRIDE
func load() -> Array:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func _init() -> void:
self.author = "The Font Awesome Team"
self.license = "CC BY 4.0"
self.web = "https://github.com/FortAwesome/Font-Awesome"
self.svg_scale = 0.25

# OVERRIDE
func load() -> Array:
Expand All @@ -25,8 +26,8 @@ func load() -> Array:
var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
var start_idx: int = meta_string.find("\n \"")
var parser: JSON = JSON.new()
while start_idx > 0:
var parser: JSON = JSON.new()
var end_idx: int = meta_string.find("\n \"", start_idx + 1)
var meta: String
if end_idx != -1:
Expand All @@ -49,9 +50,9 @@ func load() -> Array:
icon.style = style
icon.aliases = item.get("aliases", {}).get("names", PackedStringArray())
icon.search_terms = item.get("search", {}).get("terms", PackedStringArray())
var buffer: String = '<svg fill="#FFFFFF"' + item["svg"][style]["raw"].substr(4)
icons.append(icon)
buffers.append(buffer)
buffers.append('<svg fill="#FFFFFF"' + item["svg"][style]["raw"].substr(4))

return [icons, buffers]

# OVERRIDE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ var tags: PackedStringArray
var categories: PackedStringArray
var version_added: String

func is_filtered(keyword: String) -> bool:
func match(keyword: String) -> int:
var name_match: int = self.get_name_match(keyword)
if name_match != 0:
return name_match
for tag: String in self.tags:
if tag.to_lower().contains(keyword):
return true
return 7
for category: String in self.categories:
if category.to_lower().contains(keyword):
return true
return super.is_filtered(keyword)
return 5
return 0
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ var style: String
var aliases: PackedStringArray
var search_terms: PackedStringArray

func is_filtered(keyword: String) -> bool:
func match(keyword: String) -> int:
var name_match: int = self.get_name_match(keyword)
if name_match != 0:
return name_match
for alias: String in self.aliases:
if alias.to_lower().contains(keyword):
return true
return 7
for term: String in self.search_terms:
if term.to_lower().contains(keyword):
return true
return super.is_filtered(keyword) || self.style.to_lower().contains(keyword)
return 5
if self.style.to_lower().contains(keyword):
return 3
return 0
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ var version: String
var deprecated: bool


func is_filtered(keyword: String) -> bool:
func match(keyword: String) -> int:
var name_match: int = self.get_name_match(keyword)
if name_match != 0:
return name_match
for alias: String in self.aliases:
if alias.to_lower().contains(keyword):
return true
return 7
for tag: String in self.tags:
if tag.to_lower().contains(keyword):
return true
return super.is_filtered(keyword) || self.author.to_lower().contains(keyword) || keyword == "deprecated" && self.deprecated
return 7
if keyword == "deprecated" && self.deprecated:
return 1
return 0
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ var license_link: String
var guidelines: String


func is_filtered(keyword: String) -> bool:
func match(keyword: String) -> int:
var name_match: int = self.get_name_match(keyword)
if name_match != 0:
return name_match
for alias: String in self.aliases:
if alias.to_lower().contains(keyword):
return true
return super.is_filtered(keyword) || self.hex.to_html().to_lower().contains(keyword)
return 7
if self.hex.to_html().to_lower() == keyword || "#"+self.hex.to_html().to_lower() == keyword:
return 1
return 0
11 changes: 8 additions & 3 deletions addons/icon_explorer/internal/scripts/collections/icon_tabler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ var category: String
var tags: PackedStringArray
var version: String

func is_filtered(keyword: String) -> bool:
func match(keyword: String) -> int:
var name_match: int = self.get_name_match(keyword)
if name_match != 0:
return name_match
for tag: String in self.tags:
if tag.to_lower().contains(keyword):
return true
return super.is_filtered(keyword) || self.category.to_lower().contains(keyword)
return 7
if self.category.to_lower().contains(keyword):
return 5
return 0
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func _init() -> void:
self.author = "Austin Andrews"
self.license = "Apache 2.0"
self.web = "https://github.com/Templarian/MaterialDesign-SVG"
self.svg_scale = 5.33333

# OVERRIDE
func load() -> Array:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func _init() -> void:
self.author = ""
self.license = "CC0 1.0 Universal / Others"
self.web = "https://github.com/simple-icons/simple-icons"
self.svg_scale = 5.33333

# OVERRIDE
func load() -> Array:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func _init() -> void:
self.author = "Paweł Kuna"
self.license = "MIT"
self.web = "https://github.com/tabler/tabler-icons"
self.svg_scale = 5.33333

# OVERRIDE
func load() -> Array:
Expand Down
6 changes: 3 additions & 3 deletions addons/icon_explorer/internal/scripts/database.gd
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func load() -> void:
self._processing_thread = Thread.new()
self._processing_thread.start(self._load)

# thread function
func _load() -> void:
var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
Expand All @@ -136,18 +137,17 @@ func _load_done(icons: Array[Icon], buffers: PackedStringArray) -> void:
var start_time: float = Time.get_unix_time_from_system()
for idx: int in range(icons.size()):
if idx % 50 == 0:
print("loaded ", idx, " / ", icons.size())
self._load_progress = float(idx + 1) / icons.size() * 100.0
await self._scene_tree.process_frame
_load_texture(icons[idx], buffers[idx])
self._icons.append_array(icons)
print("load textures in: ", "%.1f" % (Time.get_unix_time_from_system() - start_time), "s")
self.loaded.emit()


static func _load_texture(icon: Icon, buffer: String) -> void:
#print("loading ", icon.name)
var img: Image = Image.new()
var success: int = img.load_svg_from_string(buffer, 4.0)
var success: int = img.load_svg_from_string(buffer, icon.collection.svg_scale)
if success != OK:
push_warning("could not load '" + icon.icon_path + "'")
return
Expand Down
34 changes: 29 additions & 5 deletions addons/icon_explorer/internal/scripts/icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@ extends RefCounted

const Collection := preload("res://addons/icon_explorer/internal/scripts/collection.gd")

var texture: Texture2D
var name: String
var icon_path: String
var collection: Collection
var texture: Texture2D
var icon_path: String

# used by the GUI to sort multiple icons, cached value to optimize sorting
var sort_priority: int

# VIRTUAL
# returns true if found by this filter
func is_filtered(keyword: String) -> bool:
return self.name.to_lower().contains(keyword) || self.collection.name.to_lower().contains(keyword)
# return a value between 0 and 10
# 10:
# - keyword is contained in name
# 7:
# - keyword is part of an alias
# 5:
# - keyword is part of category or search term
# 0:
# - will not be displayed
func match(keyword: String) -> int:
return 0

# return either 10, 9 or 0
func get_name_match(keyword: String) -> int:
if self.name.to_lower() == keyword:
return 10
if self.name.to_lower().contains(keyword):
return 9
if self.name.similarity(keyword) > 0.8:
return 9
return 0

static func compare(lhs, rhs) -> bool:
return lhs.sort_priority > rhs.sort_priority || (lhs.sort_priority == rhs.sort_priority && lhs.name.to_lower() < rhs.name.to_lower())
4 changes: 4 additions & 0 deletions addons/icon_explorer/internal/ui/detail_panel/detail_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const TextField := preload("res://addons/icon_explorer/internal/ui/detail_panel/
@export var _icon: TextureRect
@export var _name: Label
@export var _collection: Label
@export var _size: Label

var _cur_icon: Icon

Expand Down Expand Up @@ -60,3 +61,6 @@ func _on_filepath_selected(path: String) -> void:
var err: Error = DirAccess.copy_absolute(self._cur_icon.icon_path, path)
if err != OK:
push_error(err)
return
if Engine.is_editor_hint():
EditorInterface.get_resource_filesystem().scan()
12 changes: 11 additions & 1 deletion addons/icon_explorer/internal/ui/detail_panel/detail_panel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_brt2g"]

[node name="detail_panel" type="Control" node_paths=PackedStringArray("_detail_container", "_hint_container", "_detail_tabs", "_icon", "_name", "_collection")]
[node name="detail_panel" type="Control" node_paths=PackedStringArray("_detail_container", "_hint_container", "_detail_tabs", "_icon", "_name", "_collection", "_size")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
Expand All @@ -29,6 +29,7 @@ _detail_tabs = NodePath("detail_container/panel_container2/v_box_container/scrol
_icon = NodePath("detail_container/panel_container2/v_box_container/preview/icon")
_name = NodePath("detail_container/panel_container2/v_box_container/name")
_collection = NodePath("detail_container/panel_container/toolbar/collection")
_size = NodePath("detail_container/panel_container2/v_box_container/size")

[node name="detail_container" type="VBoxContainer" parent="."]
layout_mode = 1
Expand Down Expand Up @@ -65,6 +66,11 @@ size_flags_vertical = 3

[node name="v_box_container" type="VBoxContainer" parent="detail_container/panel_container2"]
layout_mode = 2
theme_override_constants/separation = 0

[node name="size" type="Label" parent="detail_container/panel_container2/v_box_container"]
layout_mode = 2
text = "16x1600000"

[node name="preview" type="PanelContainer" parent="detail_container/panel_container2/v_box_container"]
layout_mode = 2
Expand Down Expand Up @@ -122,6 +128,10 @@ layout_mode = 2
visible = false
layout_mode = 2

[node name="v_box_container" type="VBoxContainer" parent="detail_container/panel_container2/v_box_container/scroll_container"]
layout_mode = 2
theme_override_constants/separation = 0

[node name="panel_container" type="PanelContainer" parent="detail_container/panel_container2/v_box_container"]
layout_mode = 2

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@tool
#@tool
extends VBoxContainer

@export var title: String:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@tool
#@tool
extends VBoxContainer

@export var title: String:
Expand Down
Loading

0 comments on commit d98ea9c

Please sign in to comment.