small racing game im working on
Diffstat (limited to 'ui/editor/items.gd')
| -rw-r--r-- | ui/editor/items.gd | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/ui/editor/items.gd b/ui/editor/items.gd index b16a36e..298c79f 100644 --- a/ui/editor/items.gd +++ b/ui/editor/items.gd @@ -11,9 +11,7 @@ const icon_table = { -1: preload("res://ui/assets/folder.png") } -var thread: Thread = Thread.new() - -static func get_thumb(f: FileItem) -> Array: +static func get_thumb(f: FileItem) -> Variant: var thumb: Texture2D = icon_table[-1] if f is WeakLink: thumb = icon_table[f.type] @@ -21,10 +19,10 @@ static func get_thumb(f: FileItem) -> Array: 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 [thumb, hsh] - return [thumb] + return hsh + return thumb ## doesnt care about failures & processes multiple files. ## the size of the output may not equal the size of the input, @@ -54,17 +52,11 @@ 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.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] + var thumb = Items.get_thumb(file) + if thumb is PackedByteArray: 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()) @@ -74,12 +66,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, need[2]) + var e := Thumbnail.save(t, Globals.THUMBS % file.resource_name, hash) if e != OK: push_error("err when thumbnailing %s: %d" % [file.resource_name, e]) - if item_count > need[0]: # may have switched dirs - set_item_icon(need[0], ImageTexture.create_from_image(t)) - , Thread.PRIORITY_LOW) + 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) func _get_drag_data(at_position: Vector2) -> Variant: var index := get_item_at_position(at_position) @@ -107,8 +99,3 @@ 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() |