texture_resource.vala 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2012-2024 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. using Gee;
  6. namespace Crown
  7. {
  8. public class TextureResource
  9. {
  10. public static ImportResult import(Project project, string destination_dir, SList<string> filenames)
  11. {
  12. foreach (unowned string filename_i in filenames) {
  13. GLib.File file_src = File.new_for_path(filename_i);
  14. GLib.File file_dst = File.new_for_path(Path.build_filename(destination_dir, file_src.get_basename()));
  15. string resource_filename = project.resource_filename(file_dst.get_path());
  16. string resource_path = ResourceId.normalize(resource_filename);
  17. string resource_name = ResourceId.name(resource_path);
  18. try {
  19. file_src.copy(file_dst, FileCopyFlags.OVERWRITE);
  20. } catch (Error e) {
  21. loge(e.message);
  22. return ImportResult.ERROR;
  23. }
  24. Database db = new Database(project);
  25. Guid texture_id = Guid.new_guid();
  26. db.create(texture_id, "texture");
  27. db.set_property_string(texture_id, "source", resource_path);
  28. db.set_property_bool (texture_id, "generate_mips", true);
  29. db.set_property_bool (texture_id, "normal_map", false);
  30. db.save(project.absolute_path(resource_name) + ".texture", texture_id);
  31. }
  32. return ImportResult.SUCCESS;
  33. }
  34. }
  35. } /* namespace Crown */