Files
armorpaint/base/sources/ts/import_asset.ts
T

92 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-03-13 23:50:11 +01:00
2024-04-07 09:52:45 +02:00
let _import_asset_drop_x: f32;
let _import_asset_drop_y: f32;
let _import_asset_show_box: bool;
let _import_asset_hdr_as_envmap: bool;
let _import_asset_done: ()=>void;
2024-03-13 23:50:11 +01:00
function import_asset_run(path: string, drop_x: f32 = -1.0, drop_y: f32 = -1.0, show_box: bool = true, hdr_as_envmap: bool = true, done: ()=>void = null) {
2024-03-20 16:13:54 +01:00
if (starts_with(path, "cloud")) {
2024-09-06 21:11:46 +02:00
///if (arm_android || arm_ios)
2024-04-07 09:52:45 +02:00
console_toast(tr("Downloading"));
2024-03-13 23:50:11 +01:00
///end
2024-04-07 09:52:45 +02:00
_import_asset_drop_x = drop_x;
_import_asset_drop_y = drop_y;
_import_asset_show_box = show_box;
_import_asset_hdr_as_envmap = hdr_as_envmap;
_import_asset_done = done;
file_cache_cloud(path, function (abs: string) {
if (abs == null) {
return;
}
import_asset_run(abs, _import_asset_drop_x, _import_asset_drop_y, _import_asset_show_box, _import_asset_hdr_as_envmap, _import_asset_done);
});
2024-03-13 23:50:11 +01:00
return;
}
if (path_is_mesh(path)) {
2024-12-11 00:19:37 +01:00
///if is_forge
2025-08-07 19:43:11 +02:00
project_import_mesh_box(path, false, false, tab_meshes_import_mesh_done);
2024-12-11 00:19:37 +01:00
///else
2024-03-13 23:50:11 +01:00
show_box ? project_import_mesh_box(path) : import_mesh_run(path);
2024-12-11 00:19:37 +01:00
///end
2024-03-20 16:13:54 +01:00
if (drop_x > 0) {
ui_box_click_to_hide = false; // Prevent closing when going back to window after drag and drop
}
2024-03-13 23:50:11 +01:00
}
else if (path_is_texture(path)) {
import_texture_run(path, hdr_as_envmap);
// Place image node
let x0: i32 = ui_nodes_wx;
let x1: i32 = ui_nodes_wx + ui_nodes_ww;
if (ui_nodes_show && drop_x > x0 && drop_x < x1) {
let asset_index: i32 = 0;
for (let i: i32 = 0; i < project_assets.length; ++i) {
if (project_assets[i].file == path) {
asset_index = i;
break;
}
}
ui_nodes_accept_asset_drag(asset_index);
2024-03-14 23:58:24 +01:00
ui_nodes_get_nodes().nodes_drag = false;
2024-03-13 23:50:11 +01:00
ui_nodes_hwnd.redraws = 2;
}
2025-08-07 19:43:11 +02:00
if (context_raw.tool == tool_type_t.COLORID && project_asset_names.length == 1) {
2024-03-13 23:50:11 +01:00
ui_header_handle.redraws = 2;
context_raw.ddirty = 2;
}
}
else if (path_is_project(path)) {
import_arm_run_project(path);
}
else if (path_is_plugin(path)) {
import_plugin_run(path);
}
else if (path_is_gimp_color_palette(path)) {
2024-11-08 23:46:39 +01:00
// import_gpl_run(path, false);
2024-03-13 23:50:11 +01:00
}
else if (path_is_font(path)) {
import_font_run(path);
}
else if (path_is_folder(path)) {
2024-03-14 15:31:22 +01:00
import_folder_run(path);
2024-03-13 23:50:11 +01:00
}
else {
if (context_enable_import_plugin(path)) {
import_asset_run(path, drop_x, drop_y, show_box);
}
else {
2025-01-19 20:35:39 +01:00
console_error(strings_unknown_asset_format());
2024-03-13 23:50:11 +01:00
}
}
2024-03-20 16:13:54 +01:00
if (done != null) {
done();
}
2024-03-13 23:50:11 +01:00
}