Daniele Bartolini vor 5 Jahren
Ursprung
Commit
a23503302d

+ 74 - 73
tools/level_editor/level_editor.vala

@@ -209,13 +209,6 @@ namespace Crown
 		private string _level_resource = "";
 		private bool _create_initial_files = false;
 
-		// Global paths
-		private GLib.File _config_dir;
-		private GLib.File _logs_dir;
-		private GLib.File _log_file;
-		private GLib.FileStream _log_stream;
-		private GLib.File _settings_file;
-
 		// Editor state
 		private double _grid_size;
 		private double _rotation_snap;
@@ -243,7 +236,6 @@ namespace Crown
 		private DataCompiler _data_compiler;
 
 		// Widgets
-		public ConsoleView _console_view;
 		private ProjectBrowser _project_browser;
 		private EditorView _editor_view;
 		private LevelTreeView _level_treeview;
@@ -276,17 +268,6 @@ namespace Crown
 			Object(application_id: "org.crown.level_editor"
 				, flags: GLib.ApplicationFlags.FLAGS_NONE
 				);
-
-			// Global paths
-			_config_dir = GLib.File.new_for_path(GLib.Path.build_filename(GLib.Environment.get_user_config_dir(), "crown"));
-			try { _config_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
-			_logs_dir = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "logs"));
-			try { _logs_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
-
-			_log_file = GLib.File.new_for_path(GLib.Path.build_filename(_logs_dir.get_path(), new GLib.DateTime.now_utc().format("%Y-%m-%d") + ".log"));
-			_settings_file = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "settings.sjson"));
-
-			_log_stream = GLib.FileStream.open(_log_file.get_path(), "a");
 		}
 
 		protected override void startup()
@@ -802,41 +783,6 @@ namespace Crown
 			client.receive_async();
 		}
 
-		public void log(string system, string severity, string message)
-		{
-			GLib.DateTime now = new GLib.DateTime.now_utc();
-			string line = "%s.%06d  %.4s %s: %s\n".printf(now.format("%H:%M:%S")
-				, now.get_microsecond()
-				, severity.ascii_up()
-				, system
-				, message
-				);
-
-			if (_log_stream != null)
-			{
-				_log_stream.puts(line);
-				_log_stream.flush();
-			}
-
-			if (_console_view != null)
-				_console_view.log(severity, line);
-		}
-
-		public void logi(string message)
-		{
-			log("editor", "info", message);
-		}
-
-		public void logw(string message)
-		{
-			log("editor", "warn", message);
-		}
-
-		public void loge(string message)
-		{
-			log("editor", "erro", message);
-		}
-
 		private void send_state()
 		{
 			StringBuilder sb = new StringBuilder();
@@ -1859,30 +1805,74 @@ namespace Crown
 
 			_save_timer_id = GLib.Timeout.add_seconds(minutes*60, save_timeout);
 		}
+	}
+
+	// Global paths
+	public static GLib.File _config_dir;
+	public static GLib.File _logs_dir;
+	public static GLib.File _log_file;
+	public static GLib.File _settings_file;
+
+	public static GLib.FileStream _log_stream;
+	public static ConsoleView _console_view;
+
+	public static void log(string system, string severity, string message)
+	{
+		GLib.DateTime now = new GLib.DateTime.now_utc();
+		string line = "%s.%06d  %.4s %s: %s\n".printf(now.format("%H:%M:%S")
+			, now.get_microsecond()
+			, severity.ascii_up()
+			, system
+			, message
+			);
 
-		public void open_directory(string directory)
+		if (_log_stream != null)
 		{
+			_log_stream.puts(line);
+			_log_stream.flush();
+		}
+
+		if (_console_view != null)
+			_console_view.log(severity, line);
+	}
+
+	public static void logi(string message)
+	{
+		log("editor", "info", message);
+	}
+
+	public static void logw(string message)
+	{
+		log("editor", "warn", message);
+	}
+
+	public static void loge(string message)
+	{
+		log("editor", "erro", message);
+	}
+
+	public void open_directory(string directory)
+	{
 #if CROWN_PLATFORM_LINUX
-			try
-			{
-				GLib.AppInfo.launch_default_for_uri("file://" + directory, null);
-			}
-			catch (Error e)
-			{
-				loge(e.message);
-			}
+		try
+		{
+			GLib.AppInfo.launch_default_for_uri("file://" + directory, null);
+		}
+		catch (Error e)
+		{
+			loge(e.message);
+		}
 #else
-			GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
-			try
-			{
-				sl.spawnv({ "explorer.exe", directory, null });
-			}
-			catch (Error e)
-			{
-				loge(e.message);
-			}
-#endif
+		GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(subprocess_flags());
+		try
+		{
+			sl.spawnv({ "explorer.exe", directory, null });
+		}
+		catch (Error e)
+		{
+			loge(e.message);
 		}
+#endif
 	}
 
 	public static GLib.SubprocessFlags subprocess_flags()
@@ -1898,6 +1888,17 @@ namespace Crown
 	{
 		Intl.setlocale(LocaleCategory.ALL, "C");
 
+		// Global paths
+		_config_dir = GLib.File.new_for_path(GLib.Path.build_filename(GLib.Environment.get_user_config_dir(), "crown"));
+		try { _config_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
+		_logs_dir = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "logs"));
+		try { _logs_dir.make_directory(); } catch (Error e) { /* Nobody cares */ }
+
+		_log_file = GLib.File.new_for_path(GLib.Path.build_filename(_logs_dir.get_path(), new GLib.DateTime.now_utc().format("%Y-%m-%d") + ".log"));
+		_settings_file = GLib.File.new_for_path(GLib.Path.build_filename(_config_dir.get_path(), "settings.sjson"));
+
+		_log_stream = GLib.FileStream.open(_log_file.get_path(), "a");
+
 		LevelEditorApplication app = new LevelEditorApplication();
 		return app.run(args);
 	}

+ 5 - 10
tools/level_editor/project_browser.vala

@@ -239,8 +239,7 @@ namespace Crown
 								}
 								catch (Error e)
 								{
-									Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
-									((LevelEditorApplication)app).loge(e.message);
+									loge(e.message);
 								}
 							}
 
@@ -274,8 +273,7 @@ namespace Crown
 								}
 								catch (Error e)
 								{
-									Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
-									((LevelEditorApplication)app).loge(e.message);
+									loge(e.message);
 								}
 							});
 							menu.add(mi);
@@ -298,8 +296,7 @@ namespace Crown
 							}
 							catch (Error e)
 							{
-								Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
-								((LevelEditorApplication)app).loge(e.message);
+								loge(e.message);
 							}
 						});
 						menu.add(mi);
@@ -313,8 +310,7 @@ namespace Crown
 								_tree_view.model.get_value(parent, ProjectStore.Column.NAME, out parent_name);
 
 								GLib.File file = GLib.File.new_for_path(GLib.Path.build_filename(_project.source_dir(), (string)parent_name));
-								Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
-								((LevelEditorApplication)app).open_directory(file.get_path());
+								open_directory(file.get_path());
 							}
 						});
 						menu.add(mi);
@@ -362,8 +358,7 @@ namespace Crown
 							}
 							catch (Error e)
 							{
-								Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
-								((LevelEditorApplication)app).loge(e.message);
+								loge(e.message);
 							}
 						}
 					}

+ 6 - 4
tools/level_editor/sprite_import_dialog.vala

@@ -146,11 +146,13 @@ public class SpriteImportDialog : Gtk.Dialog
 		this.border_width = 18;
 		this.title = "Import Sprite...";
 
-		try {
+		try
+		{
 			_pixbuf = new Gdk.Pixbuf.from_file(png);
-		} catch(GLib.Error err) {
-			Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
-			((LevelEditorApplication)app).loge("Pixbuf.from_file: error");
+		}
+		catch (GLib.Error e)
+		{
+			loge(e.message);
 		}
 
 		// Create checkered pattern