Skip to content

Commit

Permalink
tools: pass ProjectStore instead of Project
Browse files Browse the repository at this point in the history
It'll become useful in later commits.
  • Loading branch information
dbartolini committed Feb 10, 2025
1 parent e14e98f commit ad88720
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
5 changes: 4 additions & 1 deletion tools/level_editor/level_editor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,10 @@ public class LevelEditorApplication : Gtk.Application
{
string? destination_dir = param == null ? null : param.get_string();

ImportResult ec = _project.import(destination_dir, on_import_result, this.active_window);
ImportResult ec = _project.import(destination_dir
, on_import_result
, _project_store
);
if (ec != ImportResult.CALLBACK)
on_import_result(ec);
}
Expand Down
16 changes: 11 additions & 5 deletions tools/level_editor/project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public class Project
{
public const string LEVEL_EDITOR_TEST_NAME = "_level_editor_test";

public delegate ImportResult ImporterDelegate(Project project, string destination_dir, SList<string> filenames, Import import_result);
public delegate ImportResult ImporterDelegate(ProjectStore project_store
, string destination_dir
, SList<string> filenames
, Import import_result
);

[Compact]
public struct ImporterData
Expand Down Expand Up @@ -518,8 +522,10 @@ public class Project
return Path.build_filename(prefix, resource_path);
}

public static ImportResult import_all_extensions(Project project, string destination_dir, SList<string> filenames, Import import_result)
public static ImportResult import_all_extensions(ProjectStore project_store, string destination_dir, SList<string> filenames, Import import_result)
{
Project project = project_store._project;

Gee.ArrayList<string> paths = new Gee.ArrayList<string>();
foreach (var item in filenames)
paths.add(item);
Expand Down Expand Up @@ -559,7 +565,7 @@ public class Project
foreach (var item in importables)
importables_list.append(item);

result = importer.delegate(project, destination_dir, importables_list, import_result);
result = importer.delegate(project_store, destination_dir, importables_list, import_result);
}

return result;
Expand Down Expand Up @@ -647,7 +653,7 @@ public class Project
return find_importer_for_extension(type) != null;
}

public ImportResult import(string? destination_dir, Import import_result, Gtk.Window? parent_window = null)
public ImportResult import(string? destination_dir, Import import_result, ProjectStore project_store, Gtk.Window? parent_window = null)
{
Gtk.FileChooserDialog src = new Gtk.FileChooserDialog("Import..."
, parent_window
Expand Down Expand Up @@ -708,7 +714,7 @@ public class Project
if (importer == null)
importer = _all_extensions_importer_data.delegate;

return importer(this, out_dir, filenames, import_result);
return importer(project_store, out_dir, filenames, import_result);
}

public void delete_tree(GLib.File file) throws Error
Expand Down
3 changes: 2 additions & 1 deletion tools/resource/font_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace Crown
{
public class FontResource
{
public static ImportResult import(Project project, string destination_dir, SList<string> filenames)
public static ImportResult import(ProjectStore project_store, string destination_dir, SList<string> filenames)
{
Project project = project_store._project;
Hashtable importer_settings = null;
string importer_settings_path = null;
string font_path;
Expand Down
10 changes: 6 additions & 4 deletions tools/resource/mesh_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ namespace MeshResource
}
}

public static ImportResult do_import(Project project, string destination_dir, SList<string> filenames)
public static ImportResult do_import(ProjectStore project_store, string destination_dir, SList<string> filenames)
{
Project project = project_store._project;

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

Expand Down Expand Up @@ -198,7 +200,7 @@ namespace MeshResource
return ImportResult.SUCCESS;
}

public static ImportResult import(Project project, string destination_dir, SList<string> filenames, Import import_result)
public static ImportResult import(ProjectStore project_store, string destination_dir, SList<string> filenames, Import import_result)
{
SList<string> fbx_filenames = new SList<string>();
SList<string> mesh_filenames = new SList<string>();
Expand All @@ -214,9 +216,9 @@ namespace MeshResource

ImportResult res = ImportResult.SUCCESS;
if (mesh_filenames != null)
res = MeshResource.do_import(project, destination_dir, mesh_filenames);
res = MeshResource.do_import(project_store, destination_dir, mesh_filenames);
if (res == ImportResult.SUCCESS && fbx_filenames != null)
res = FBXImporter.import(project, destination_dir, fbx_filenames, import_result);
res = FBXImporter.import(project_store, destination_dir, fbx_filenames, import_result);
return res;
}

Expand Down
8 changes: 4 additions & 4 deletions tools/resource/mesh_resource_fbx.vala
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public class FBXImportDialog : Gtk.Window
public Gtk.Button _cancel;
public Gtk.HeaderBar _header_bar;

public FBXImportDialog(Project project, string destination_dir, GLib.SList<string> filenames, Import import_result)
public FBXImportDialog(ProjectStore project_store, string destination_dir, GLib.SList<string> filenames, Import import_result)
{
_project = project;
_project = project_store._project;
_destination_dir = destination_dir;
_filenames = new Gee.ArrayList<string>();
foreach (var f in filenames)
Expand Down Expand Up @@ -621,9 +621,9 @@ public class FBXImporter
return ImportResult.SUCCESS;
}

public static ImportResult import(Project project, string destination_dir, GLib.SList<string> filenames, Import import_result)
public static ImportResult import(ProjectStore project_store, string destination_dir, GLib.SList<string> filenames, Import import_result)
{
FBXImportDialog dialog = new FBXImportDialog(project, destination_dir, filenames, import_result);
FBXImportDialog dialog = new FBXImportDialog(project_store, destination_dir, filenames, import_result);
dialog.show_all();
dialog.present();
return ImportResult.CALLBACK;
Expand Down
4 changes: 3 additions & 1 deletion tools/resource/sound_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ namespace Crown
{
public class SoundResource
{
public static ImportResult import(Project project, string destination_dir, SList<string> filenames)
public static ImportResult import(ProjectStore project_store, string destination_dir, SList<string> filenames)
{
Project project = project_store._project;

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

Expand Down
3 changes: 2 additions & 1 deletion tools/resource/sprite_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace Crown
{
public class SpriteResource
{
public static ImportResult import(Project project, string destination_dir, SList<string> filenames)
public static ImportResult import(ProjectStore project_store, string destination_dir, SList<string> filenames)
{
Project project = project_store._project;
Hashtable importer_settings = null;
string importer_settings_path = null;
string image_path;
Expand Down
4 changes: 3 additions & 1 deletion tools/resource/texture_resource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ public struct TextureResource
_db.save(project.absolute_path(resource_name) + ".texture", _id);
}

public static ImportResult import(Project project, string destination_dir, SList<string> filenames)
public static ImportResult import(ProjectStore project_store, string destination_dir, SList<string> filenames)
{
Project project = project_store._project;

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

Expand Down

0 comments on commit ad88720

Please sign in to comment.