Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
358 changes: 205 additions & 153 deletions tools/level_editor/level_editor.vala

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tools/level_editor/project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum ImportResult
CANCEL, ///< User cancelled the import.
}

public delegate void Import(ImportResult result);
public delegate void Import(ImportResult result, string? primary_resource_path = null);

public enum ProjectFlags
{
Expand Down Expand Up @@ -625,7 +625,7 @@ public class Project
paths.sort((a, b) => {
int ext_a = a.last_index_of_char('.');
int ext_b = b.last_index_of_char('.');
return strcmp(a[ext_a : a.length], b[ext_b : b.length]);
return strcmp(a[ext_a: a.length], b[ext_b: b.length]);
});

while (paths.size != 0) {
Expand Down
22 changes: 20 additions & 2 deletions tools/resource/font_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,26 @@ public class FontImportDialog : Gtk.Window

public void on_import()
{
_import_result(FontResource.do_import(this, _project, _destination_dir, _filenames));
destroy();
ImportResult res = FontResource.do_import(this, _project, _destination_dir, _filenames);

string? primary_path = null; // Track primary_path
if (res == ImportResult.SUCCESS) {
GLib.File file_src = File.new_for_path(_filenames.nth_data(0));
string resource_basename = _filenames.length() == 1
? _font_name.value + "." + _font_type
: file_src.get_basename();

GLib.File file_dst = File.new_for_path(Path.build_filename(_destination_dir, resource_basename));

string resource_filename = _project.resource_filename(file_dst.get_path());
string resource_path = ResourceId.normalize(resource_filename);
string resource_name = ResourceId.name(resource_path);

primary_path = ResourceId.path(OBJECT_TYPE_FONT, resource_name);
}

_import_result(res, primary_path);
// FontResource.do_import() already calls FontImportDialog.destroy()
}
}

Expand Down
15 changes: 11 additions & 4 deletions tools/resource/mesh_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ namespace MeshResource
}
}

public static ImportResult do_import(Database database, string destination_dir, SList<string> filenames)
public static ImportResult do_import(Database database, string destination_dir, SList<string> filenames, out string? primary_path)
{
primary_path = null; // Track primary_path
Project project = database._project;

foreach (unowned string filename_i in filenames) {
GLib.File file_src = File.new_for_path(filename_i);

GLib.File file_dst = File.new_for_path(Path.build_filename(destination_dir, file_src.get_basename()));

string resource_filename = project.resource_filename(file_dst.get_path());
string resource_path = ResourceId.normalize(resource_filename);
string resource_name = ResourceId.name(resource_path);
Expand Down Expand Up @@ -167,6 +168,8 @@ namespace MeshResource
loge(e.message);
return ImportResult.ERROR;
}

primary_path = ResourceId.path(OBJECT_TYPE_UNIT, resource_name);
}

return ImportResult.SUCCESS;
Expand All @@ -187,12 +190,16 @@ namespace MeshResource
}

ImportResult res = ImportResult.SUCCESS;
string? primary_path = null;

if (mesh_filenames != null)
res = MeshResource.do_import(database, destination_dir, mesh_filenames);
res = MeshResource.do_import(database, destination_dir, mesh_filenames, out primary_path);

// .fbx files call import_result from FBXImportDialog, while mixed (.mesh + .fbx) batches are not supported.
if (res == ImportResult.SUCCESS && fbx_filenames != null)
FBXImporter.import(import_result, database, destination_dir, fbx_filenames, parent_window);
else
import_result(res);
import_result(res, primary_path);
}

} /* namespace MeshResource */
Expand Down
15 changes: 14 additions & 1 deletion tools/resource/mesh_resource_fbx.vala
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,20 @@ public class FBXImportDialog : Gtk.Window
res = ImportResult.ERROR;
}
}
_import_result(res);

string? primary_path = null; // Track primary_path
if (res == ImportResult.SUCCESS && _filenames.size > 0) {
GLib.File file_dst;
string resource_path;

get_destination_file(out file_dst, _destination_dir, File.new_for_path(_filenames[0]));
get_resource_path(out resource_path, file_dst, _project);
string resource_name = ResourceId.name(resource_path);

primary_path = ResourceId.path(OBJECT_TYPE_UNIT, resource_name);
}

_import_result(res, primary_path);
close();
}

Expand Down
9 changes: 6 additions & 3 deletions tools/resource/sound_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ public struct SoundResource
return _db.save(project.absolute_path(resource_name) + "." + OBJECT_TYPE_SOUND, _id);
}

public static void import(Import import_result, Database database, string destination_dir, SList<string> filenames)
public static void import(Import import_result, Database database, string destination_dir, SList<string> filenames, Gtk.Window? parent_window)
{
Project project = database._project;
string? primary_path = null; // Track primary_path

foreach (unowned string filename_i in filenames) {
GLib.File file_src = File.new_for_path(filename_i);

GLib.File file_dst = File.new_for_path(Path.build_filename(destination_dir, file_src.get_basename()));

string resource_filename = project.resource_filename(file_dst.get_path());
string resource_path = ResourceId.normalize(resource_filename);
string resource_name = ResourceId.name(resource_path);
Expand All @@ -53,9 +54,11 @@ public struct SoundResource
import_result(ImportResult.ERROR);
return;
}

primary_path = ResourceId.path(OBJECT_TYPE_SOUND, resource_name);
}

import_result(ImportResult.SUCCESS);
import_result(ImportResult.SUCCESS, primary_path);
}
}

Expand Down
20 changes: 19 additions & 1 deletion tools/resource/sprite_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,25 @@ public class SpriteImportDialog : Gtk.Window

public void on_import()
{
_import_result(SpriteResource.do_import(this, _project, _destination_dir, _filenames));
ImportResult res = SpriteResource.do_import(this, _project, _destination_dir, _filenames);

string? primary_path = null; // Track primary_path
if (res == ImportResult.SUCCESS) {
GLib.File file_src = File.new_for_path(_filenames.nth_data(0));
string resource_basename = _filenames.length() == 1
? _unit_name.value + "." + _image_type
: file_src.get_basename();

GLib.File file_dst = File.new_for_path(Path.build_filename(_destination_dir, resource_basename));

string resource_filename = _project.resource_filename(file_dst.get_path());
string resource_path = ResourceId.normalize(resource_filename);
string resource_name = ResourceId.name(resource_path);

primary_path = ResourceId.path(OBJECT_TYPE_UNIT, resource_name);
}

_import_result(res, primary_path);
close();
}
}
Expand Down
9 changes: 6 additions & 3 deletions tools/resource/texture_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ public struct TextureResource
return _db.save(project.absolute_path(resource_name) + "." + OBJECT_TYPE_TEXTURE, _id);
}

public static void import(Import import_result, Database database, string destination_dir, SList<string> filenames)
public static void import(Import import_result, Database database, string destination_dir, SList<string> filenames, Gtk.Window? parent_window)
{
Project project = database._project;
string? primary_path = null; // Track primary_path

foreach (unowned string filename_i in filenames) {
GLib.File file_src = File.new_for_path(filename_i);

GLib.File file_dst = File.new_for_path(Path.build_filename(destination_dir, file_src.get_basename()));

string resource_filename = project.resource_filename(file_dst.get_path());
string resource_path = ResourceId.normalize(resource_filename);
string resource_name = ResourceId.name(resource_path);
Expand All @@ -119,9 +120,11 @@ public struct TextureResource
Database db = new Database(project);
var texture_resource = TextureResource.color_map(db, Guid.new_guid(), resource_path);
texture_resource.save(project, resource_name);

primary_path = ResourceId.path(OBJECT_TYPE_TEXTURE, resource_name);
}

import_result(ImportResult.SUCCESS);
import_result(ImportResult.SUCCESS, primary_path);
}
}

Expand Down