small racing game im working on
Diffstat (limited to 'ui/editor/items.gd')
-rw-r--r--ui/editor/items.gd35
1 files changed, 24 insertions, 11 deletions
diff --git a/ui/editor/items.gd b/ui/editor/items.gd
index 298c79f..b16a36e 100644
--- a/ui/editor/items.gd
+++ b/ui/editor/items.gd
@@ -11,7 +11,9 @@ const icon_table = {
-1: preload("res://ui/assets/folder.png")
}
-static func get_thumb(f: FileItem) -> Variant:
+var thread: Thread = Thread.new()
+
+static func get_thumb(f: FileItem) -> Array:
var thumb: Texture2D = icon_table[-1]
if f is WeakLink:
thumb = icon_table[f.type]
@@ -19,10 +21,10 @@ static func get_thumb(f: FileItem) -> Variant:
var hsh: PackedByteArray = f.hash_s()
var img := Thumbnail._load(Globals.THUMBS % f.resource_name, hsh)
if img:
- return ImageTexture.create_from_image(img)
+ return [ImageTexture.create_from_image(img)]
else:
- return hsh
- return thumb
+ return [thumb, hsh]
+ return [thumb]
## doesnt care about failures & processes multiple files.
## the size of the output may not equal the size of the input,
@@ -52,11 +54,17 @@ func open_dir(dir: DirRes):
var needing_thumbs := []
for i in dir.files.size():
var file := dir.files[i]
- var thumb = Items.get_thumb(file)
- if thumb is PackedByteArray:
+ var thumb := Items.get_thumb(file)
+ if thumb.size() > 1:
+ needing_thumbs.append([i, file, thumb[-1]])
+ set_item_tooltip(add_item(file.resource_name, thumb[0]), file.description)
+ if thread.is_started():
+ thread.wait_to_finish()
+ thread.start(func():
+ for need in needing_thumbs:
+ var file: WeakLink = need[1]
match file.type:
WeakLink.Type.Scene:
- var hash: PackedByteArray = thumb;
var n: Block = file.scene.instantiate()
n.making_thumbnail = true
n.add_child(preload("res://scenes/sun.tscn").instantiate())
@@ -66,12 +74,12 @@ func open_dir(dir: DirRes):
var world := World3D.new()
world.environment = preload("res://default_env.tres")
var t := await Thumbnail.create_thumb(self, n, Vector2(64,64), world)
- var e := Thumbnail.save(t, Globals.THUMBS % file.resource_name, hash)
+ var e := Thumbnail.save(t, Globals.THUMBS % file.resource_name, need[2])
if e != OK:
push_error("err when thumbnailing %s: %d" % [file.resource_name, e])
- set_item_tooltip(add_item(file.resource_name, ImageTexture.create_from_image(t)), file.description)
- continue
- set_item_tooltip(add_item(file.resource_name, thumb), file.description)
+ if item_count > need[0]: # may have switched dirs
+ set_item_icon(need[0], ImageTexture.create_from_image(t))
+ , Thread.PRIORITY_LOW)
func _get_drag_data(at_position: Vector2) -> Variant:
var index := get_item_at_position(at_position)
@@ -99,3 +107,8 @@ func make_drag_preview(textures: Array[Texture2D]) -> Control:
preview.over_viewport()
, CONNECT_ONE_SHOT | CONNECT_DEFERRED)
return preview
+
+
+func _on_tree_exiting() -> void:
+ if thread.is_started():
+ thread.wait_to_finish()