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 e99cd65 commit bf6d1ab
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 134 deletions.
32 changes: 14 additions & 18 deletions addons/icon_explorer/internal/scripts/collections/bootstrap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ func _init() -> void:
self.web = "https://github.com/twbs/icons"

# OVERRIDE
func load() -> Array[Icon]:
func load() -> Array:
var dir: DirAccess = DirAccess.open(self._meta_directory())
if !dir:
return []

var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
dir.list_dir_begin()
var file_name: String = dir.get_next()
while file_name != "":
if dir.current_is_dir():
continue
var icon: IconBootstrap = self._load_item(file_name)
if icon != null:
icons.append(icon)
var res: Array = self._load_item(file_name)
if res.size() == 2:
icons.append(res[0])
buffers.append(res[1])
file_name = dir.get_next()

var parser_version: JSON = JSON.new()
Expand All @@ -36,16 +38,16 @@ func load() -> Array[Icon]:
return []
self.version = parser_version.data["version"]

return icons
return [icons, buffers]

func _load_item(file_name: String) -> IconBootstrap:
func _load_item(file_name: String) -> Array:
var icon: IconBootstrap = IconBootstrap.new()
icon.collection = self

var meta: String = FileAccess.get_file_as_string(self._meta_directory().path_join(file_name))
if meta == "":
push_warning("could not read bootstrap meta file '", file_name, "'")
return null
return []

var cur_token: int = 0
for line: String in meta.split("\n"):
Expand All @@ -71,22 +73,16 @@ func _load_item(file_name: String) -> IconBootstrap:

if icon.name == "":
push_warning("bootstrap '", file_name, "' has no name")
return null
return []

icon.icon_path = self.icon_directory().path_join(file_name.get_basename() + ".svg")

var buffer: String = FileAccess.get_file_as_string(icon.icon_path)
var buffer: String = FileAccess.get_file_as_string(icon.icon_path).replace("currentColor", "#ffffff")
if buffer == "":
push_warning("could not load '" + icon.icon_path + "'")
return null
var img: Image = Image.new()
var success: int = img.load_svg_from_string(buffer.replace("currentColor", "#ffffff"), 4.0)
if success != OK:
push_warning("could not load '" + icon.icon_path + "'")
return null
img.fix_alpha_edges()
icon.texture = ImageTexture.create_from_image(img)
return icon
return []

return [icon, buffer]

# OVERRIDE
func install(http: HTTPRequest, _version: String) -> Error:
Expand Down
47 changes: 16 additions & 31 deletions addons/icon_explorer/internal/scripts/collections/font_awesome.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ func _init() -> void:
self.web = "https://github.com/FortAwesome/Font-Awesome"

# OVERRIDE
func load() -> Array[Icon]:
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("Font-Awesome-6.x/js-packages/@fortawesome/fontawesome-free/package.json")))
if res_version != OK:
push_warning("could not parse font awesome package.json: '%s'", [parser_version.get_error_message()])
return []
return [[], []]
self.version = parser_version.data["version"]

var meta_string: String = FileAccess.get_file_as_string(self.directory().path_join("Font-Awesome-6.x/metadata/icons.json"))
var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
var start_idx: int = meta_string.find("\n \"")
var cur: int = 0
var max_items: int = meta_string.count("\n \"")
while start_idx > 0:
var parser: JSON = JSON.new()
var end_idx: int = meta_string.find("\n \"", start_idx + 1)
Expand All @@ -40,34 +39,20 @@ func load() -> Array[Icon]:
push_warning("could not parse font awesome meta: '%s'", [parser.get_error_message()])
continue
var icon_id: String = parser.data.keys()[0]
var meta_data: Dictionary = parser.data.values()[0]
for style: String in meta_data.get("styles", []):
var icon: IconFontAwesome = self._gen_item(icon_id, meta_data, style)
if icon != null:
cur += 1
print(cur, " / ", max_items)
icons.append(icon)
return icons
var item: Dictionary = parser.data.values()[0]
for style: String in item.get("styles", []):
var icon: IconFontAwesome = IconFontAwesome.new()
icon.collection = self
icon.name = item["label"]
icon.icon_path = self.icon_directory().path_join(style + "/" + icon_id + ".svg")

func _gen_item(icon_id: String, item: Dictionary, style: String) -> IconFontAwesome:
var icon: IconFontAwesome = IconFontAwesome.new()
icon.collection = self
icon.name = item["label"]
icon.icon_path = self.icon_directory().path_join(style + "/" + icon_id + ".svg")

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)
var img: Image = Image.new()
var success: int = img.load_svg_from_string(buffer, 4.0)
if success != OK:
push_warning("could not load '" + icon_id + "'")
return null
img.fix_alpha_edges()
icon.texture = ImageTexture.create_from_image(img)
return icon
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)
return [icons, buffers]

# OVERRIDE
func install(http: HTTPRequest, _version: String) -> Error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ func _init() -> void:
self.web = "https://github.com/Templarian/MaterialDesign-SVG"

# OVERRIDE
func load() -> Array[Icon]:
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("MaterialDesign-SVG-master/package.json")))
if res_version != OK:
push_warning("could not parse MDI package.json: '%s'", [parser_version.get_error_message()])
return []
return [[], PackedStringArray()]
self.version = parser_version.data["version"]

var parser: JSON = JSON.new()
var res: int = parser.parse(FileAccess.get_file_as_string(self.directory().path_join("MaterialDesign-SVG-master/meta.json")))
if res != OK:
push_warning("could not parse MDI meta.json: '%s'", [parser.get_error_message()])
return []
return [[], PackedStringArray()]

var icon_path: String = self.icon_directory()
var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
for item: Dictionary in parser.data:
var icon: IconMaterialDesign = IconMaterialDesign.new()
icon.collection = self
Expand All @@ -47,15 +48,9 @@ func load() -> Array[Icon]:
continue
# patch to white color
buffer = '<svg fill="#FFFFFF"' + buffer.substr(4)
var img: Image = Image.new()
var success: int = img.load_svg_from_string(buffer, 4.0)
if success != OK:
push_warning("could not load '" + icon.icon_path + "'")
continue
img.fix_alpha_edges()
icon.texture = ImageTexture.create_from_image(img)
icons.append(icon)
return icons
buffers.append(buffer)
return [icons, buffers]

# OVERRIDE
func install(http: HTTPRequest, _version: String) -> Error:
Expand Down
37 changes: 17 additions & 20 deletions addons/icon_explorer/internal/scripts/collections/simple_icons.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,39 @@ func _init() -> void:
self.web = "https://github.com/simple-icons/simple-icons"

# OVERRIDE
func load() -> Array[Icon]:
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 []
return [[], []]
self.version = parser_version.data["version"]

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:
push_warning("could not parse simple icons simple-icons.json: '%s'", [parser.get_error_message()])
return []
return [[], []]

var icons: Array[Icon] = []
var buffers: PackedStringArray = PackedStringArray()
for item: Dictionary in parser.data.get("icons", []):
var icon: IconSimpleIcons = self._load_item(item)
if icon == null:
var arr_res: Array = self._load_item(item)
if arr_res.size() == 0:
continue
icons.append(icon)
icons.append(arr_res[0])
buffers.append(arr_res[1])
for dup: Dictionary in item.get("aliases", {}).get("dup", []):
var dup_item: Dictionary = item.duplicate(true)
dup_item.merge(dup, true)
icon = self._load_item(item)
if icon != null:
icons.append(icon)
arr_res = self._load_item(item)
if arr_res.size() == 2:
icons.append(arr_res[0])
buffers.append(arr_res[1])

return icons
return [icons, buffers]

func _load_item(item: Dictionary) -> IconSimpleIcons:
func _load_item(item: Dictionary) -> Array:
var icon: IconSimpleIcons = IconSimpleIcons.new()
icon.collection = self
icon.name = item["title"]
Expand All @@ -63,17 +66,11 @@ func _load_item(item: Dictionary) -> IconSimpleIcons:
var buffer: String = FileAccess.get_file_as_string(icon.icon_path)
if buffer == "":
push_warning("could not load '" + icon.icon_path + "'")
return null
return []
# patch to white color
buffer = '<svg fill="#FFFFFF"' + buffer.substr(4)
var img: Image = Image.new()
var success: int = img.load_svg_from_string(buffer, 4.0)
if success != OK:
push_warning("could not load '" + icon.icon_path + "'")
return null
img.fix_alpha_edges()
icon.texture = ImageTexture.create_from_image(img)
return icon

return [icon, buffer]

# OVERRIDE
func install(http: HTTPRequest, _version: String) -> Error:
Expand Down
18 changes: 7 additions & 11 deletions addons/icon_explorer/internal/scripts/collections/tabler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ func _init() -> void:
self.web = "https://github.com/tabler/tabler-icons"

# OVERRIDE
func load() -> Array[Icon]:
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("tabler-icons-master/package.json")))
if res_version != OK:
push_warning("could not parse tabler icons package.json: '%s'", [parser_version.get_error_message()])
return []
return [[], []]
self.version = parser_version.data["version"]

var parser: JSON = JSON.new()
var res: int = parser.parse(FileAccess.get_file_as_string(self.directory().path_join("tabler-icons-master/tags.json")))
if res != OK:
push_warning("could not parse tabler icons tags.json: '%s'", [parser.get_error_message()])
return []
return [[], []]

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
Expand All @@ -43,15 +44,10 @@ func load() -> Array[Icon]:
if buffer == "":
push_warning("could not load '" + icon.icon_path + "'")
continue
var img: Image = Image.new()
var success: int = img.load_svg_from_string(buffer.replace("currentColor", "#ffffff"), 4.0)
if success != OK:
push_warning("could not load '" + icon.icon_path + "'")
continue
img.fix_alpha_edges()
icon.texture = ImageTexture.create_from_image(img)
buffer = buffer.replace("currentColor", "#ffffff")
icons.append(icon)
return icons
buffers.append(buffer)
return [icons, buffers]

# OVERRIDE
func install(http: HTTPRequest, _version: String) -> Error:
Expand Down
Loading

0 comments on commit bf6d1ab

Please sign in to comment.