-
Notifications
You must be signed in to change notification settings - Fork 31
/
import_worker.gd
58 lines (49 loc) · 1.84 KB
/
import_worker.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This file is part of Unidot Importer. See LICENSE.txt for full MIT license.
# Copyright (c) 2021-present Lyuma <xn.lyuma@gmail.com> and contributors
# SPDX-License-Identifier: MIT
@tool
extends "./thread_worker.gd"
const tarfile := preload("./tarfile.gd")
const package_file := preload("./package_file.gd")
var stage2: bool = false
var guid_to_pkgasset: Dictionary
var stage2_dict_lock := Mutex.new()
var stage2_extra_asset_dict: Dictionary
func set_stage2(pkg_guid_to_pkgasset: Dictionary):
stage2 = true
guid_to_pkgasset = pkg_guid_to_pkgasset
stage2_extra_asset_dict = {}
class ThreadWork:
var asset: package_file.PkgAsset
var tmpdir: String
var output_path: String
var extra: Variant
var did_fail: bool
var is_loaded: bool
# asset: package_file.PkgAsset object
func push_asset(asset: package_file.PkgAsset, tmpdir: String, extra: Variant = null):
var tw = ThreadWork.new()
tw.asset = asset
tw.tmpdir = tmpdir
tw.extra = extra
if asset.parsed_meta != null:
asset.parsed_meta.log_debug(0, "Enqueue asset " + str(asset.guid) + " " + str(asset.pathname))
else:
print("Enqueue asset " + str(asset.guid) + " " + str(asset.pathname))
self.push_work_obj(tw)
func _run_single_item(tw_: Object, thread_subdir: String):
var tw: ThreadWork = tw_ as ThreadWork
asset_processing_started.emit(tw)
if stage2:
asset_adapter.preprocess_asset_stage2(tw.asset, tw.tmpdir, guid_to_pkgasset, stage2_dict_lock, stage2_extra_asset_dict)
asset_processing_finished.emit(tw)
else:
tw.output_path = asset_adapter.preprocess_asset(asset_database, tw.asset, tw.tmpdir, thread_subdir)
# It has not yet been added to the database, so do not use rename()
if tw.output_path == "":
tw.did_fail = true
else:
if tw.asset.parsed_meta != null:
tw.asset.parsed_meta.path = tw.output_path
tw.asset.pathname = tw.output_path
asset_processing_finished.emit(tw)