瀏覽代碼

Attempt to replace IDs with human-readable names when logging to ConsoleView

Daniele Bartolini 8 年之前
父節點
當前提交
788282059a
共有 3 個文件被更改,包括 23 次插入3 次删除
  1. 1 1
      tools/level_editor/level_editor.vala
  2. 7 0
      tools/level_editor/project.vala
  3. 15 2
      tools/widgets/console_view.vala

+ 1 - 1
tools/level_editor/level_editor.vala

@@ -242,7 +242,7 @@ namespace Crown
 			_resource_compiler = new ResourceCompiler(_compiler);
 
 			// Widgets
-			_console_view = new ConsoleView(_engine);
+			_console_view = new ConsoleView(_engine, _project);
 			_level_treeview = new LevelTreeView(_db, _level);
 			_level_layers_treeview = new LevelLayersTreeView(_db, _level);
 			_properties_view = new PropertiesView(_level);

+ 7 - 0
tools/level_editor/project.vala

@@ -85,6 +85,13 @@ namespace Crown
 			}
 		}
 
+		public string id_to_name(string id)
+		{
+			Hashtable index = SJSON.load(Path.build_filename(_data_dir.get_path(), "data_index.sjson"));
+			Value? name = index[id];
+			return name != null ? (string)name : id;
+		}
+
 		public Database files()
 		{
 			return _files;

+ 15 - 2
tools/widgets/console_view.vala

@@ -52,19 +52,21 @@ namespace Crown
 		// Data
 		private EntryHistory _entry_history;
 		private ConsoleClient _console_client;
+		private Project _project;
 
 		// Widgets
 		private Gtk.ScrolledWindow _scrolled_window;
 		private Gtk.TextView _text_view;
 		private Gtk.Entry _entry;
 
-		public ConsoleView(ConsoleClient client)
+		public ConsoleView(ConsoleClient client, Project project)
 		{
 			Object(orientation: Gtk.Orientation.VERTICAL, spacing: 0);
 
 			// Data
 			_entry_history = new EntryHistory(256);
 			_console_client = client;
+			_project = project;
 
 			// Widgets
 			Pango.FontDescription fd = new Pango.FontDescription();
@@ -156,7 +158,18 @@ namespace Crown
 
 		public void log(string system, string text, string severity)
 		{
-			string line = system + ": " + text + "\n";
+			string msg = text;
+
+			// Replace IDs with human-readable names
+			int id_index = text.index_of("#ID(");
+			if (id_index != -1)
+			{
+				string id = text.substring(id_index + 4, 33);
+				string name = _project.id_to_name(id);
+				msg = text.replace("#ID(%s)".printf(id), "'%s'".printf(name));
+			}
+
+			string line = system + ": " + msg + "\n";
 			Gtk.TextBuffer buffer = _text_view.buffer;
 			Gtk.TextIter end_iter;
 			buffer.get_end_iter(out end_iter);