2019-06-19 18:45:36 +02:00
|
|
|
|
2019-11-20 16:36:08 +01:00
|
|
|
class ImportAsset {
|
2019-06-19 18:45:36 +02:00
|
|
|
|
2024-01-17 18:53:31 +01:00
|
|
|
static run = (path: string, dropX = -1.0, dropY = -1.0, showBox = true, hdrAsEnvmap = true, done: ()=>void = null) => {
|
2021-01-11 21:58:15 +01:00
|
|
|
|
|
|
|
|
if (path.startsWith("cloud")) {
|
2024-01-17 18:53:31 +01:00
|
|
|
let doCacheCloud = () => {
|
|
|
|
|
File.cacheCloud(path, (abs: string) => {
|
2022-12-13 10:57:31 +01:00
|
|
|
if (abs == null) return;
|
2024-01-17 18:53:31 +01:00
|
|
|
ImportAsset.run(abs, dropX, dropY, showBox, hdrAsEnvmap, done);
|
2022-12-13 10:57:31 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-17 18:53:31 +01:00
|
|
|
///if (krom_android || krom_ios)
|
|
|
|
|
Base.notifyOnNextFrame(() => {
|
2022-12-13 10:57:31 +01:00
|
|
|
Console.toast(tr("Downloading"));
|
2023-12-12 14:57:44 +01:00
|
|
|
Base.notifyOnNextFrame(doCacheCloud);
|
2021-07-13 13:47:56 +02:00
|
|
|
});
|
2024-01-17 18:53:31 +01:00
|
|
|
///else
|
2022-12-13 10:57:31 +01:00
|
|
|
doCacheCloud();
|
2024-01-17 18:53:31 +01:00
|
|
|
///end
|
2022-12-13 10:57:31 +01:00
|
|
|
|
2021-07-13 13:47:56 +02:00
|
|
|
return;
|
2021-01-11 21:58:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-11 15:35:00 +01:00
|
|
|
if (Path.isMesh(path)) {
|
2019-12-03 22:07:08 +01:00
|
|
|
showBox ? Project.importMeshBox(path) : ImportMesh.run(path);
|
2019-11-21 14:24:29 +01:00
|
|
|
if (dropX > 0) UIBox.clickToHide = false; // Prevent closing when going back to window after drag and drop
|
2019-06-19 18:45:36 +02:00
|
|
|
}
|
2019-11-11 15:35:00 +01:00
|
|
|
else if (Path.isTexture(path)) {
|
2021-02-15 15:06:59 +01:00
|
|
|
ImportTexture.run(path, hdrAsEnvmap);
|
2019-06-19 18:45:36 +02:00
|
|
|
// Place image node
|
2024-01-21 15:18:44 +01:00
|
|
|
let x0 = UINodes.wx;
|
|
|
|
|
let x1 = UINodes.wx + UINodes.ww;
|
|
|
|
|
if (UINodes.show && dropX > x0 && dropX < x1) {
|
2024-01-17 18:53:31 +01:00
|
|
|
let assetIndex = 0;
|
|
|
|
|
for (let i = 0; i < Project.assets.length; ++i) {
|
2020-03-24 14:32:34 +01:00
|
|
|
if (Project.assets[i].file == path) {
|
|
|
|
|
assetIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-21 15:18:44 +01:00
|
|
|
UINodes.acceptAssetDrag(assetIndex);
|
|
|
|
|
UINodes.getNodes().nodesDrag = false;
|
|
|
|
|
UINodes.hwnd.redraws = 2;
|
2019-06-19 18:45:36 +02:00
|
|
|
}
|
2023-04-20 00:38:27 +02:00
|
|
|
|
2024-01-17 18:53:31 +01:00
|
|
|
///if is_paint
|
|
|
|
|
if (Context.raw.tool == WorkspaceTool.ToolColorId && Project.assetNames.length == 1) {
|
2024-01-21 15:18:44 +01:00
|
|
|
UIHeader.headerHandle.redraws = 2;
|
2023-02-27 21:13:25 +01:00
|
|
|
Context.raw.ddirty = 2;
|
2022-03-09 10:14:39 +01:00
|
|
|
}
|
2024-01-17 18:53:31 +01:00
|
|
|
///end
|
2019-06-19 18:45:36 +02:00
|
|
|
}
|
2019-11-11 15:35:00 +01:00
|
|
|
else if (Path.isProject(path)) {
|
2019-06-20 11:23:01 +02:00
|
|
|
ImportArm.runProject(path);
|
2019-06-19 18:45:36 +02:00
|
|
|
}
|
2019-11-11 15:35:00 +01:00
|
|
|
else if (Path.isPlugin(path)) {
|
2019-10-10 14:27:17 +02:00
|
|
|
ImportPlugin.run(path);
|
|
|
|
|
}
|
2022-04-01 17:21:18 +02:00
|
|
|
else if (Path.isGimpColorPalette(path)) {
|
|
|
|
|
ImportGpl.run(path, false);
|
|
|
|
|
}
|
2024-01-17 18:53:31 +01:00
|
|
|
///if is_paint
|
2023-04-20 00:38:27 +02:00
|
|
|
else if (Path.isFont(path)) {
|
|
|
|
|
ImportFont.run(path);
|
|
|
|
|
}
|
|
|
|
|
else if (Path.isFolder(path)) {
|
|
|
|
|
ImportFolder.run(path);
|
|
|
|
|
}
|
2024-01-17 18:53:31 +01:00
|
|
|
///end
|
2019-06-19 18:45:36 +02:00
|
|
|
else {
|
2023-04-18 14:33:50 +02:00
|
|
|
if (Context.enableImportPlugin(path)) {
|
2024-01-17 18:53:31 +01:00
|
|
|
ImportAsset.run(path, dropX, dropY, showBox);
|
2021-01-08 15:18:41 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2021-05-06 16:44:25 +02:00
|
|
|
Console.error(Strings.error1());
|
2021-01-08 15:18:41 +01:00
|
|
|
}
|
2019-06-19 18:45:36 +02:00
|
|
|
}
|
2021-07-17 14:30:30 +02:00
|
|
|
|
|
|
|
|
if (done != null) done();
|
2019-06-19 18:45:36 +02:00
|
|
|
}
|
|
|
|
|
}
|