Skip to content

Commit

Permalink
[icon_explorer] Add 1.3.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Dec 30, 2024
1 parent f526c7f commit d6cdd4e
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 61 deletions.
25 changes: 8 additions & 17 deletions addons/icon_explorer/internal/ext/font_awesome/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,16 @@ func color_icon(buffer: String, color: String) -> String:

# OVERRIDE
func load() -> Array:
var meta_string: String = FileAccess.get_file_as_string(self.directory().path_join("Font-Awesome-6.x/metadata/icons.json"))
var parser: JSON = JSON.new()
var res: int = parser.parse(FileAccess.get_file_as_string(self.directory().path_join("Font-Awesome-6.x/metadata/icons.json")))
if res != OK:
push_warning("could not parse font awesome meta: '%s'", [parser.get_error_message()])
return [[], PackedStringArray()]

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 end_idx: int = meta_string.find("\n \"", start_idx + 1)
var meta: String
if end_idx != -1:
meta = "{" + meta_string.substr(start_idx, end_idx - start_idx - 1) + "}"
else:
meta = "{" + meta_string.substr(start_idx) + "}"
start_idx = end_idx
var res: int = parser.parse(meta)
if res != OK:
push_warning("could not parse font awesome meta: '%s'", [parser.get_error_message()])
continue
var icon_id: String = parser.data.keys()[0]
var item: Dictionary = parser.data.values()[0]
for icon_id: String in parser.data:
var item: Dictionary = parser.data[icon_id]
for style: String in item.get("styles", []):
var icon: IconFontAwesome = IconFontAwesome.new()
icon.collection = self
Expand Down
58 changes: 32 additions & 26 deletions addons/icon_explorer/internal/ext/icon_tabler/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends "res://addons/icon_explorer/internal/scripts/collection.gd"
const IconTabler := preload("res://addons/icon_explorer/internal/ext/icon_tabler/icon.gd")
const ZipUnpacker := preload("res://addons/icon_explorer/internal/scripts/tools/zip_unpacker.gd")

const _DOWNLOAD_FILE: String = "https://github.com/tabler/tabler-icons/archive/master.zip"
const _DOWNLOAD_FILE: String = "https://github.com/tabler/tabler-icons/archive/main.zip"

func _init() -> void:
self.name = "tabler Icons"
Expand All @@ -19,35 +19,37 @@ func color_icon(buffer: String, color: String) -> String:
# OVERRIDE
func load() -> Array:
var parser: JSON = JSON.new()
var res: int = parser.parse(FileAccess.get_file_as_string(self.directory().path_join("tabler-icons-master/tags.json")))
var res: int = parser.parse(FileAccess.get_file_as_string(self.directory().path_join("icons.json")))
if res != OK:
push_warning("could not parse tabler icons tags.json: '%s'", [parser.get_error_message()])
push_warning("could not parse tabler icons icons.json: '%s'", [parser.get_error_message()])
return [[], PackedStringArray()]

var icon_path: String = self.icon_directory()
var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
for item: Dictionary in parser.data.values():
var icon: IconTabler = IconTabler.new()
icon.collection = self
icon.svg_size = Vector2i(24, 24)
icon.colorable = true
icon.name = item["name"]
icon.icon_path = icon_path.path_join(icon.name + ".svg")

icon.category = item.get("category", "")
icon.tags = item.get("tags", PackedStringArray())
icon.version = item.get("version", "")

var buffer: String = FileAccess.get_file_as_string(icon.icon_path)
if buffer == "":
push_warning("could not load '" + icon.icon_path + "'")
continue
icons.append(icon)
buffers.append(self.color_icon(buffer, "FFFFFF"))
for style: String in item.get("styles", []):
var icon: IconTabler = IconTabler.new()
icon.collection = self
icon.svg_size = Vector2i(24, 24)
icon.colorable = true
icon.name = item["name"]
icon.icon_path = icon_path.path_join(style + "/" + item["name"] + ".svg")

icon.category = item.get("category", "")
icon.tags = item.get("tags", PackedStringArray())
icon.version = item.get("version", "")
icon.style = style

var buffer: String = FileAccess.get_file_as_string(icon.icon_path)
if buffer == "":
push_warning("could not load '" + icon.icon_path + "'")
continue
icons.append(icon)
buffers.append(self.color_icon(buffer, "FFFFFF"))

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(FileAccess.get_file_as_string(self.directory().path_join("tabler-icons-master/package.json")))
var res_version: int = parser_version.parse(FileAccess.get_file_as_string(self.directory().path_join("tabler-icons-main/package.json")))
if res_version != OK:
push_warning("could not parse tabler icons package.json: '%s'", [parser_version.get_error_message()])
return [[], PackedStringArray()]
Expand All @@ -65,11 +67,15 @@ func install(http: HTTPRequest, _version: String) -> Error:
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

http.download_file = self.directory().path_join("icons.json")
downloader.await_request("https://cdn.jsdelivr.net/npm/@tabler/icons@latest/icons.json")
if downloader.result != HTTPRequest.RESULT_SUCCESS:
return Error.FAILED

var unzipper: ZipUnpacker = ZipUnpacker.new(zip_path, self.directory(), [
"tabler-icons-master/package.json",
"tabler-icons-master/icons/",
"tabler-icons-master/tags.json",
"tabler-icons-master/LICENSE",
"tabler-icons-main/package.json",
"tabler-icons-main/icons/",
"tabler-icons-main/LICENSE",
])
if !unzipper.unpack_mt(maxi(OS.get_processor_count() / 2, 1)):
return Error.FAILED
Expand Down Expand Up @@ -97,4 +103,4 @@ func update_latest_version(http: HTTPRequest) -> void:

# OVERRIDE
func icon_directory() -> String:
return self.directory().path_join("tabler-icons-master/icons/")
return self.directory().path_join("tabler-icons-main/icons/")
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ const ListField := preload("res://addons/icon_explorer/internal/ui/detail_panel/
@export var _category: TextField
@export var _tags: ListField
@export var _version: TextField
@export var _style: TextField

func display(icon: IconTabler) -> void:
self._tags.set_items(icon.tags)
self._category.text = icon.category
self._version.text = icon.version
self._style.text = icon.style
18 changes: 9 additions & 9 deletions addons/icon_explorer/internal/ext/icon_tabler/details_panel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[ext_resource type="Script" path="res://addons/icon_explorer/internal/ext/icon_tabler/details_panel.gd" id="1_te45c"]
[ext_resource type="PackedScene" uid="uid://b64tcvn5sw03h" path="res://addons/icon_explorer/internal/ui/detail_panel/text_field.tscn" id="2_u3ntg"]

[node name="tabler" type="VBoxContainer" node_paths=PackedStringArray("_category", "_tags", "_version")]
[node name="tabler" type="VBoxContainer" node_paths=PackedStringArray("_category", "_tags", "_version", "_style")]
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 136.0
Expand All @@ -13,20 +13,20 @@ script = ExtResource("1_te45c")
_category = NodePath("category")
_tags = NodePath("tags")
_version = NodePath("version_added")
_style = NodePath("style")

[node name="category" parent="." node_paths=PackedStringArray("_label", "_button") instance=ExtResource("2_u3ntg")]
[node name="category" parent="." instance=ExtResource("2_u3ntg")]
layout_mode = 2
_label = NodePath("margin_container/h_box_container/label")
_button = NodePath("margin_container/h_box_container/button")
title = "Category"

[node name="tags" parent="." node_paths=PackedStringArray("_list") instance=ExtResource("1_muhea")]
[node name="tags" parent="." instance=ExtResource("1_muhea")]
layout_mode = 2
_list = NodePath("margin_container/item_list")
title = "Tags"

[node name="version_added" parent="." node_paths=PackedStringArray("_label", "_button") instance=ExtResource("2_u3ntg")]
[node name="style" parent="." instance=ExtResource("2_u3ntg")]
layout_mode = 2
title = "Style"

[node name="version_added" parent="." instance=ExtResource("2_u3ntg")]
layout_mode = 2
_label = NodePath("margin_container/h_box_container/label")
_button = NodePath("margin_container/h_box_container/button")
title = "Version added"
3 changes: 3 additions & 0 deletions addons/icon_explorer/internal/ext/icon_tabler/icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends "res://addons/icon_explorer/internal/scripts/icon.gd"
var category: String
var tags: PackedStringArray
var version: String
var style: String

func match(keyword: String) -> int:
var name_match: int = self.get_name_match(keyword)
Expand All @@ -13,4 +14,6 @@ func match(keyword: String) -> int:
return 7
if self.category.to_lower().contains(keyword):
return 5
if self.style.to_lower().contains(keyword):
return 3
return 0
20 changes: 13 additions & 7 deletions addons/icon_explorer/internal/ext/simple_icons/collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func _title_to_slug(title: String) -> String:

# OVERRIDE
func load() -> Array:
var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(FileAccess.get_file_as_string(self.directory().path_join("simple-icons-master/package.json")))
if res_version != OK:
push_warning("could not parse simple icons package.json: '%s'", [parser_version.get_error_message()])
return [[], PackedStringArray()]

var parser: JSON = JSON.new()
var res: int = parser.parse(FileAccess.get_file_as_string(self.directory().path_join("simple-icons-master/_data/simple-icons.json")))
if res != OK:
Expand All @@ -61,7 +67,13 @@ func load() -> Array:

var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
for item: Dictionary in parser.data.get("icons", []):

var raw_icons: Array = []
if parser_version.data["version"].begins_with("14."):
raw_icons = parser.data
else:
raw_icons = parser.data.get("icons", [])
for item: Dictionary in raw_icons:
var arr_res: Array = self._load_item(item)
if arr_res.size() == 0:
continue
Expand All @@ -75,13 +87,7 @@ func load() -> Array:
icons.append(arr_res[0])
buffers.append(arr_res[1])

var parser_version: JSON = JSON.new()
var res_version: int = parser_version.parse(FileAccess.get_file_as_string(self.directory().path_join("simple-icons-master/package.json")))
if res_version != OK:
push_warning("could not parse simple icons package.json: '%s'", [parser_version.get_error_message()])
return [[], PackedStringArray()]
self.version = parser_version.data["version"]

return [icons, buffers]

func _load_item(item: Dictionary) -> Array:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func _on_button_clicked(item: TreeItem, _column: int, id: int, _mouse_button_ind
if self._http_request != null:
self._http_request.queue_free()
self._http_request = HTTPRequest.new()
self._http_request.use_threads = true
self._http_request.download_chunk_size = 4 * 65536
self.add_child(self._http_request, true)
self.db.install(coll, self._http_request, "")
ButtonId.REMOVE:
Expand Down
2 changes: 1 addition & 1 deletion addons/icon_explorer/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name="Icon Explorer"
description="Explore icon collections."
author="Iceflower S"
version="1.3.0"
version="1.4.0"
script="plugin.gd"
license="MIT"
repository="https://github.com/kenyoni-software/godot-addons"
Expand Down
9 changes: 8 additions & 1 deletion doc/docs/addons/icon_explorer.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ As popup:

## Changelog

### 1.3.0
### 1.4.0

- Require Godot 4.4
- Use OS temporary directory for downloads

### 1.3.0

- Support Tabler Icons 3 (you might need to reinstall this collection)
- Support Simple Icons 14
- Improve download speed and reduce installation time
- Improve Font Awesome icon loading

### 1.2.0

- Require Godot 4.3
Expand Down

0 comments on commit d6cdd4e

Please sign in to comment.