Przeglądaj źródła

tools/*: code-style: fix brace style

Daniele Bartolini 3 lat temu
rodzic
commit
c71486bb7e

+ 1 - 2
tools/api/engine_api.vala

@@ -52,8 +52,7 @@ namespace DeviceApi
 	public string command(string[] args)
 	{
 		StringBuilder sb = new StringBuilder();
-		for (int i = 0; i < args.length; ++i)
-		{
+		for (int i = 0; i < args.length; ++i) {
 			string arg = args[i].replace("\\", "\\\\").replace("\"", "\\\"");
 			sb.append("\"%s\",".printf(arg));
 		}

+ 11 - 22
tools/core/console_client.vala

@@ -22,15 +22,13 @@ public class ConsoleClient : GLib.Object
 
 	public new void connect(string address, int port)
 	{
-		try
-		{
+		try {
 			GLib.SocketClient client = new GLib.SocketClient();
 			_connection = client.connect(new InetSocketAddress.from_string(address, port), null);
 			if (_connection != null)
 				connected(address, port);
 		}
-		catch (Error e)
-		{
+		catch (Error e) {
 			// Ignore
 		}
 	}
@@ -40,8 +38,7 @@ public class ConsoleClient : GLib.Object
 	public async int connect_async(string address, int port, int num_tries, int interval)
 	{
 		int tries;
-		for (tries = 0; tries < num_tries; ++tries)
-		{
+		for (tries = 0; tries < num_tries; ++tries) {
 			this.connect(address, port);
 			if (this.is_connected())
 				break;
@@ -53,17 +50,14 @@ public class ConsoleClient : GLib.Object
 
 	public void close()
 	{
-		try
-		{
-			if (_connection != null)
-			{
+		try {
+			if (_connection != null) {
 				_connection.close();
 				_connection = null;
 				disconnected();
 			}
 		}
-		catch (Error e)
-		{
+		catch (Error e) {
 			loge(e.message);
 		}
 	}
@@ -79,8 +73,7 @@ public class ConsoleClient : GLib.Object
 		if (!is_connected())
 			return;
 
-		try
-		{
+		try {
 			// FIXME: Add bit conversion utils
 			uint32 len = json.length;
 			uint8* ptr = (uint8*)(&len);
@@ -92,8 +85,7 @@ public class ConsoleClient : GLib.Object
 			_connection.output_stream.write_all(header, out bytes_read);
 			_connection.output_stream.write_all(json.data, out bytes_read);
 		}
-		catch (Error e)
-		{
+		catch (Error e) {
 			loge(e.message);
 		}
 	}
@@ -111,14 +103,12 @@ public class ConsoleClient : GLib.Object
 
 	private void on_read(Object? obj, AsyncResult ar)
 	{
-		try
-		{
+		try {
 			InputStream input_stream = (InputStream)obj;
 			uint8[] header = input_stream.read_bytes_async.end(ar).get_data();
 
 			// Connection closed gracefully
-			if (header.length == 0)
-			{
+			if (header.length == 0) {
 				close();
 				return;
 			}
@@ -136,8 +126,7 @@ public class ConsoleClient : GLib.Object
 			if (input_stream.read_all(data, out bytes_read))
 				message_received(this, data);
 		}
-		catch (Error e)
-		{
+		catch (Error e) {
 			if (e.code == 44) // An existing connection was forcibly closed by the remote host.
 				close();
 		}

+ 50 - 125
tools/core/database.vala

@@ -463,8 +463,7 @@ public class Database
 		string old_db = db_key;
 		string k = db_key;
 
-		if (k == "" && json.has_key("type"))
-		{
+		if (k == "" && json.has_key("type")) {
 			// The "type" key defines object type only if it appears
 			// in the root of a JSON object (k == "").
 			if (!has_property(id, "type"))
@@ -472,8 +471,7 @@ public class Database
 		}
 
 		string[] keys = json.keys.to_array();
-		foreach (string key in keys)
-		{
+		foreach (string key in keys) {
 			if (key == "id")
 				continue;
 
@@ -481,21 +479,16 @@ public class Database
 
 			k += k == "" ? key : ("." + key);
 
-			if (val.holds(typeof(Hashtable)))
-			{
+			if (val.holds(typeof(Hashtable))) {
 				Hashtable ht = (Hashtable)val;
 				decode_object(id, k, ht);
-			}
-			else if (val.holds(typeof(ArrayList)))
-			{
+			} else if (val.holds(typeof(ArrayList))) {
 				ArrayList<Value?> arr = (ArrayList<Value?>)val;
 				if (arr.size > 0 && arr[0].holds(typeof(double)))
 					set_property_internal(0, id, k, decode_value(val));
 				else
 					decode_set(id, key, arr);
-			}
-			else
-			{
+			} else {
 				set_property_internal(0, id, k, decode_value(val));
 			}
 
@@ -508,8 +501,7 @@ public class Database
 		// Set should be created even if it is empty.
 		create_empty_set(0, owner_id, key);
 
-		for (int i = 0; i < json.size; ++i)
-		{
+		for (int i = 0; i < json.size; ++i) {
 			Hashtable obj = (Hashtable)json[i];
 			Guid obj_id = Guid.parse((string)obj["id"]);
 			create_internal(0, obj_id);
@@ -520,8 +512,7 @@ public class Database
 
 	private Value? decode_value(Value? value)
 	{
-		if (value.holds(typeof(ArrayList)))
-		{
+		if (value.holds(typeof(ArrayList))) {
 			ArrayList<Value?> al = (ArrayList<Value?>)value;
 			if (al.size == 3)
 				return Vector3((double)al[0], (double)al[1], (double)al[2]);
@@ -529,20 +520,14 @@ public class Database
 				return Quaternion((double)al[0], (double)al[1], (double)al[2], (double)al[3]);
 			else
 				assert(false);
-		}
-		else if (value.holds(typeof(string)))
-		{
+		} else if (value.holds(typeof(string))) {
 			Guid id;
 			if (Guid.try_parse((string)value, out id))
 				return id;
 			return value;
-		}
-		else if (value == null || value.holds(typeof(bool)) || value.holds(typeof(double)))
-		{
+		} else if (value == null || value.holds(typeof(bool)) || value.holds(typeof(double))) {
 			return value;
-		}
-		else
-		{
+		} else {
 			assert(false);
 		}
 
@@ -556,22 +541,18 @@ public class Database
 			obj["id"] = id.to_string();
 
 		string[] keys = db.keys.to_array();
-		foreach (string key in keys)
-		{
+		foreach (string key in keys) {
 			// Since null-key is equivalent to non-existent key, skip serialization.
 			if (db[key] == null)
 				continue;
 
 			string[] foo = key.split(".");
 			Hashtable x = obj;
-			if (foo.length > 1)
-			{
-				for (int i = 0; i < foo.length - 1; ++i)
-				{
+			if (foo.length > 1) {
+				for (int i = 0; i < foo.length - 1; ++i) {
 					string f = foo[i];
 
-					if (x.has_key(f))
-					{
+					if (x.has_key(f)) {
 						x = (Hashtable)x[f];
 						continue;
 					}
@@ -591,17 +572,14 @@ public class Database
 	{
 		assert(is_valid_value(value) || value.holds(typeof(HashSet)));
 
-		if (value.holds(typeof(Vector3)))
-		{
+		if (value.holds(typeof(Vector3))) {
 			Vector3 v = (Vector3)value;
 			ArrayList<Value?> arr = new Gee.ArrayList<Value?>();
 			arr.add(v.x);
 			arr.add(v.y);
 			arr.add(v.z);
 			return arr;
-		}
-		else if (value.holds(typeof(Quaternion)))
-		{
+		} else if (value.holds(typeof(Quaternion))) {
 			Quaternion q = (Quaternion)value;
 			ArrayList<Value?> arr = new Gee.ArrayList<Value?>();
 			arr.add(q.x);
@@ -609,24 +587,17 @@ public class Database
 			arr.add(q.z);
 			arr.add(q.w);
 			return arr;
-		}
-		else if (value.holds(typeof(Guid)))
-		{
+		} else if (value.holds(typeof(Guid))) {
 			Guid id = (Guid)value;
 			return id.to_string();
-		}
-		else if (value.holds(typeof(HashSet)))
-		{
+		} else if (value.holds(typeof(HashSet))) {
 			HashSet<Guid?> hs = (HashSet<Guid?>)value;
 			ArrayList<Value?> arr = new Gee.ArrayList<Value?>();
-			foreach (Guid id in hs)
-			{
+			foreach (Guid id in hs) {
 				arr.add(encode_object(id, get_data(id)));
 			}
 			return arr;
-		}
-		else
-		{
+		} else {
 			return value;
 		}
 	}
@@ -704,14 +675,11 @@ public class Database
 
 		HashMap<string, Value?> ob = get_data(id);
 
-		if (!ob.has_key(key))
-		{
+		if (!ob.has_key(key)) {
 			HashSet<Guid?> hs = new HashSet<Guid?>(Guid.hash_func, Guid.equal_func);
 			hs.add(item_id);
 			ob[key] = hs;
-		}
-		else
-		{
+		} else {
 			((HashSet<Guid?>)ob[key]).add(item_id);
 		}
 
@@ -776,21 +744,16 @@ public class Database
 		HashMap<string, Value?> o = get_data(id);
 		string[] keys = o.keys.to_array();
 
-		foreach (string key in keys)
-		{
+		foreach (string key in keys) {
 			Value? value = o[key];
-			if (value.holds(typeof(HashSet)))
-			{
+			if (value.holds(typeof(HashSet))) {
 				HashSet<Guid?> hs = (HashSet<Guid?>)value;
 				Guid?[] ids = hs.to_array();
-				foreach (Guid item_id in ids)
-				{
+				foreach (Guid item_id in ids) {
 					remove_from_set(id, key, item_id);
 					destroy(item_id);
 				}
-			}
-			else
-			{
+			} else {
 				set_property_null(id, key);
 			}
 		}
@@ -809,8 +772,7 @@ public class Database
 		assert(is_valid_value(null));
 
 		HashMap<string, Value?> ob = get_data(id);
-		if (ob.has_key(key) && ob[key] != null)
-		{
+		if (ob.has_key(key) && ob[key] != null) {
 			if (ob[key].holds(typeof(bool)))
 				_undo.write_set_property_bool_action(id, key, (bool)ob[key]);
 			if (ob[key].holds(typeof(double)))
@@ -823,9 +785,7 @@ public class Database
 				_undo.write_set_property_vector3_action(id, key, (Vector3)ob[key]);
 			if (ob[key].holds(typeof(Quaternion)))
 				_undo.write_set_property_quaternion_action(id, key, (Quaternion)ob[key]);
-		}
-		else
-		{
+		} else {
 			_undo.write_set_property_null_action(id, key);
 		}
 
@@ -1076,21 +1036,16 @@ public class Database
 
 		HashMap<string, Value?> ob = get_data(id);
 		string[] keys = ob.keys.to_array();
-		foreach (string key in keys)
-		{
+		foreach (string key in keys) {
 			Value? val = ob[key];
-			if (val.holds(typeof(HashSet)))
-			{
+			if (val.holds(typeof(HashSet))) {
 				HashSet<Guid?> hs = (HashSet<Guid?>)val;
-				foreach (Guid j in hs)
-				{
+				foreach (Guid j in hs) {
 					Guid x = Guid.new_guid();
 					duplicate(j, x);
 					add_to_set(new_id, key, x);
 				}
-			}
-			else
-			{
+			} else {
 				if (ob[key] == null)
 					set_property_null(new_id, key);
 				if (ob[key].holds(typeof(bool)))
@@ -1122,21 +1077,16 @@ public class Database
 	{
 		HashMap<string, Value?> ob = get_data(id);
 		string[] keys = ob.keys.to_array();
-		foreach (string key in keys)
-		{
+		foreach (string key in keys) {
 			Value? value = ob[key];
-			if (value.holds(typeof(HashSet)))
-			{
+			if (value.holds(typeof(HashSet))) {
 				HashSet<Guid?> hs = (HashSet<Guid?>)value;
-				foreach (Guid j in hs)
-				{
+				foreach (Guid j in hs) {
 					db.create(j, object_type(j));
 					copy_deep(db, j, "");
 					db.add_to_set(id, new_key + (new_key == "" ? "" : ".") + key, j);
 				}
-			}
-			else
-			{
+			} else {
 				string kk = new_key + (new_key == "" ? "" : ".") + key;
 
 				if (ob[key] == null)
@@ -1199,11 +1149,9 @@ public class Database
 	{
 		int dir = undo == _undo ? -1 : 1;
 
-		while (undo.size() != size)
-		{
+		while (undo.size() != size) {
 			uint32 type = undo.peek_type();
-			if (type == Action.CREATE)
-			{
+			if (type == Action.CREATE) {
 				Action t = undo.read_action();
 				assert(t == Action.CREATE);
 
@@ -1213,9 +1161,7 @@ public class Database
 				redo.write_destroy_action(id, obj_type);
 				create_internal(dir, id);
 				set_object_type(id, obj_type);
-			}
-			else if (type == Action.DESTROY)
-			{
+			} else if (type == Action.DESTROY) {
 				Action t = undo.read_action();
 				assert(t == Action.DESTROY);
 
@@ -1224,17 +1170,14 @@ public class Database
 
 				redo.write_create_action(id, obj_type);
 				destroy_internal(dir, id);
-			}
-			else if (type == Action.SET_PROPERTY_NULL)
-			{
+			} else if (type == Action.SET_PROPERTY_NULL) {
 				Action t = undo.read_action();
 				assert(t == Action.SET_PROPERTY_NULL);
 
 				Guid id = undo.read_guid();
 				string key = undo.read_string();
 
-				if (has_property(id, key))
-				{
+				if (has_property(id, key)) {
 					if (get_data(id)[key].holds(typeof(bool)))
 						redo.write_set_property_bool_action(id, key, get_property_bool(id, key));
 					if (get_data(id)[key].holds(typeof(double)))
@@ -1247,15 +1190,11 @@ public class Database
 						redo.write_set_property_vector3_action(id, key, get_property_vector3(id, key));
 					if (get_data(id)[key].holds(typeof(Quaternion)))
 						redo.write_set_property_quaternion_action(id, key, get_property_quaternion(id, key));
-				}
-				else
-				{
+				} else {
 					redo.write_set_property_null_action(id, key);
 				}
 				set_property_internal(dir, id, key, null);
-			}
-			else if (type == Action.SET_PROPERTY_BOOL)
-			{
+			} else if (type == Action.SET_PROPERTY_BOOL) {
 				Action t = undo.read_action();
 				assert(t == Action.SET_PROPERTY_BOOL);
 
@@ -1268,9 +1207,7 @@ public class Database
 				else
 					redo.write_set_property_null_action(id, key);
 				set_property_internal(dir, id, key, val);
-			}
-			else if (type == Action.SET_PROPERTY_DOUBLE)
-			{
+			} else if (type == Action.SET_PROPERTY_DOUBLE) {
 				Action t = undo.read_action();
 				assert(t == Action.SET_PROPERTY_DOUBLE);
 
@@ -1283,9 +1220,7 @@ public class Database
 				else
 					redo.write_set_property_null_action(id, key);
 				set_property_internal(dir, id, key, val);
-			}
-			else if (type == Action.SET_PROPERTY_STRING)
-			{
+			} else if (type == Action.SET_PROPERTY_STRING) {
 				Action t = undo.read_action();
 				assert(t == Action.SET_PROPERTY_STRING);
 
@@ -1298,9 +1233,7 @@ public class Database
 				else
 					redo.write_set_property_null_action(id, key);
 				set_property_internal(dir, id, key, val);
-			}
-			else if (type == Action.SET_PROPERTY_GUID)
-			{
+			} else if (type == Action.SET_PROPERTY_GUID) {
 				Action t = undo.read_action();
 				assert(t == Action.SET_PROPERTY_GUID);
 
@@ -1313,9 +1246,7 @@ public class Database
 				else
 					redo.write_set_property_null_action(id, key);
 				set_property_internal(dir, id, key, val);
-			}
-			else if (type == Action.SET_PROPERTY_VECTOR3)
-			{
+			} else if (type == Action.SET_PROPERTY_VECTOR3) {
 				Action t = undo.read_action();
 				assert(t == Action.SET_PROPERTY_VECTOR3);
 
@@ -1328,9 +1259,7 @@ public class Database
 				else
 					redo.write_set_property_null_action(id, key);
 				set_property_internal(dir, id, key, val);
-			}
-			else if (type == Action.SET_PROPERTY_QUATERNION)
-			{
+			} else if (type == Action.SET_PROPERTY_QUATERNION) {
 				Action t = undo.read_action();
 				assert(t == Action.SET_PROPERTY_QUATERNION);
 
@@ -1343,9 +1272,7 @@ public class Database
 				else
 					redo.write_set_property_null_action(id, key);
 				set_property_internal(dir, id, key, val);
-			}
-			else if (type == Action.ADD_TO_SET)
-			{
+			} else if (type == Action.ADD_TO_SET) {
 				Action t = undo.read_action();
 				assert(t == Action.ADD_TO_SET);
 
@@ -1355,9 +1282,7 @@ public class Database
 
 				redo.write_remove_from_set_action(id, key, item_id);
 				add_to_set_internal(dir, id, key, item_id);
-			}
-			else if (type == Action.REMOVE_FROM_SET)
-			{
+			} else if (type == Action.REMOVE_FROM_SET) {
 				Action t = undo.read_action();
 				assert(t == Action.REMOVE_FROM_SET);
 

+ 22 - 55
tools/core/json/json.vala

@@ -114,21 +114,15 @@ public class JSON
 	static void write_string(string s, StringBuilder builder)
 	{
 		builder.append_c('"');
-		for (int i = 0; i < s.length; ++i)
-		{
+		for (int i = 0; i < s.length; ++i) {
 			uint8 c = s[i];
-			if (c == '"' || c == '\\')
-			{
+			if (c == '"' || c == '\\') {
 				builder.append_c('\\');
 				builder.append_c((char)c);
-			}
-			else if (c == '\n')
-			{
+			} else if (c == '\n') {
 				builder.append_c('\\');
 				builder.append_c('n');
-			}
-			else
-			{
+			} else {
 				builder.append_c((char)c);
 			}
 		}
@@ -139,8 +133,7 @@ public class JSON
 	{
 		bool write_comma = false;
 		builder.append("[ ");
-		foreach (Value? item in a)
-		{
+		foreach (Value? item in a) {
 			if (write_comma)
 				builder.append(", ");
 			write(item, builder, indentation + 1);
@@ -153,8 +146,7 @@ public class JSON
 	{
 		builder.append_c('{');
 		bool write_comma = false;
-		foreach (var de in t.entries)
-		{
+		foreach (var de in t.entries) {
 			if (write_comma)
 				builder.append(", ");
 			write_new_line(builder, indentation);
@@ -169,8 +161,7 @@ public class JSON
 
 	static void skip_whitespace(uint8[] json, ref int index)
 	{
-		while (index < json.length)
-		{
+		while (index < json.length) {
 			uint8 c = json[index];
 			if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == ',')
 				++index;
@@ -182,8 +173,7 @@ public class JSON
 	static void consume(uint8[] json, ref int index, string consume)
 	{
 		skip_whitespace(json, ref index);
-		for (int i = 0; i < consume.length; ++i)
-		{
+		for (int i = 0; i < consume.length; ++i) {
 			if (json[index] != consume[i])
 				assert(false);
 			++index;
@@ -194,39 +184,24 @@ public class JSON
 	{
 		uint8 c = next(json, ref index);
 
-		if (c == '{')
-		{
+		if (c == '{') {
 			return parse_object(json, ref index);
-		}
-		else if (c == '[')
-		{
+		} else if (c == '[') {
 			return parse_array(json, ref index);
-		}
-		else if (c == '"')
-		{
+		} else if (c == '"') {
 			return parse_string(json, ref index);
-		}
-		else if (c == '-' || c >= '0' && c <= '9')
-		{
+		} else if (c == '-' || c >= '0' && c <= '9') {
 			return parse_number(json, ref index);
-		}
-		else if (c == 't')
-		{
+		} else if (c == 't') {
 			consume(json, ref index, "true");
 			return true;
-		}
-		else if (c == 'f')
-		{
+		} else if (c == 'f') {
 			consume(json, ref index, "false");
 			return false;
-		}
-		else if (c == 'n')
-		{
+		} else if (c == 'n') {
 			consume(json, ref index, "null");
 			return null;
-		}
-		else
-		{
+		} else {
 			assert(false);
 			return null;
 		}
@@ -244,8 +219,7 @@ public class JSON
 		consume(json, ref index, "{");
 		skip_whitespace(json, ref index);
 
-		while (next(json, ref index) != '}')
-		{
+		while (next(json, ref index) != '}') {
 			string key = parse_string(json, ref index);
 			consume(json, ref index, ":");
 			if (key.has_suffix("_binary"))
@@ -261,8 +235,7 @@ public class JSON
 	{
 		ArrayList<Value?> a = new ArrayList<Value?>();
 		consume(json, ref index, "[");
-		while (next(json, ref index) != ']')
-		{
+		while (next(json, ref index) != ']') {
 			Value? value = parse(json, ref index);
 			a.add(value);
 		}
@@ -275,20 +248,14 @@ public class JSON
 		ArrayList<uint8> s = new ArrayList<uint8>();
 
 		consume(json, ref index, "\"");
-		while (true)
-		{
+		while (true) {
 			uint8 c = json[index];
 			++index;
-			if (c == '"')
-			{
+			if (c == '"') {
 				break;
-			}
-			else if (c != '\\')
-			{
+			} else if (c != '\\') {
 				s.add(c);
-			}
-			else
-			{
+			} else {
 				uint8 q = json[index];
 				++index;
 				if (q == '"' || q == '\\' || q == '/')

+ 14 - 39
tools/core/json/sjson.vala

@@ -226,20 +226,15 @@ public class SJSON
 	static void skip_comment(uint8 [] json, ref int index)
 	{
 		uint8 next = json[index + 1];
-		if (next == '/')
-		{
+		if (next == '/') {
 			while (index + 1 < json.length && json[index] != '\n')
 				++index;
 			++index;
-		}
-		else if (next == '*')
-		{
+		} else if (next == '*') {
 			while (index + 2 < json.length && (json[index] != '*' || json[index + 1] != '/'))
 				++index;
 			index += 2;
-		}
-		else
-		{
+		} else {
 			GLib.assert(false);
 		}
 	}
@@ -277,39 +272,24 @@ public class SJSON
 	{
 		uint8 c = next(json, ref index);
 
-		if (c == '{')
-		{
+		if (c == '{') {
 			return parse_object(json, ref index);
-		}
-		else if (c == '[')
-		{
+		} else if (c == '[') {
 			return parse_array(json, ref index);
-		}
-		else if (c == '"')
-		{
+		} else if (c == '"') {
 			return parse_string(json, ref index);
-		}
-		else if (c == '-' || c >= '0' && c <= '9')
-		{
+		} else if (c == '-' || c >= '0' && c <= '9') {
 			return parse_number(json, ref index);
-		}
-		else if (c == 't')
-		{
+		} else if (c == 't') {
 			consume(json, ref index, "true");
 			return true;
-		}
-		else if (c == 'f')
-		{
+		} else if (c == 'f') {
 			consume(json, ref index, "false");
 			return false;
-		}
-		else if (c == 'n')
-		{
+		} else if (c == 'n') {
 			consume(json, ref index, "null");
 			return null;
-		}
-		else
-		{
+		} else {
 			GLib.assert(false);
 			return null;
 		}
@@ -357,16 +337,11 @@ public class SJSON
 		while (true) {
 			uint8 c = json[index];
 			++index;
-			if (c == '"')
-			{
+			if (c == '"') {
 				break;
-			}
-			else if (c != '\\')
-			{
+			} else if (c != '\\') {
 				s.add(c);
-			}
-			else
-			{
+			} else {
 				uint8 q = json[index];
 				++index;
 				if (q == '"' || q == '\\' || q == '/')

+ 6 - 15
tools/core/math/quaternion.vala

@@ -70,35 +70,28 @@ public struct Quaternion
 		// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
 		double tr = m.x.x + m.y.y + m.z.z;
 
-		if (tr > 0.0)
-		{
+		if (tr > 0.0) {
 			double sq = Math.sqrt(1.0 + tr) * 0.5;
 			double inv = 0.25 / sq;
 			this.w = sq;
 			this.x = (m.y.z - m.z.y) * inv;
 			this.y = (m.z.x - m.x.z) * inv;
 			this.z = (m.x.y - m.y.x) * inv;
-		}
-		else if ((m.x.x > m.y.y) && (m.x.x > m.z.z))
-		{
+		} else if ((m.x.x > m.y.y) && (m.x.x > m.z.z)) {
 			double sq = Math.sqrt(1.0 + m.x.x - m.y.y - m.z.z) * 0.5;
 			double inv = 0.25 / sq;
 			this.x = sq;
 			this.w = (m.y.z - m.z.y) * inv;
 			this.y = (m.x.y + m.y.x) * inv;
 			this.z = (m.z.x + m.x.z) * inv;
-		}
-		else if (m.y.y > m.z.z)
-		{
+		} else if (m.y.y > m.z.z) {
 			double sq = Math.sqrt(1.0 + m.y.y - m.x.x - m.z.z) * 0.5;
 			double inv = 0.25 / sq;
 			this.y = sq;
 			this.w = (m.z.x - m.x.z) * inv;
 			this.x = (m.x.y + m.y.x) * inv;
 			this.z = (m.y.z + m.z.y) * inv;
-		}
-		else
-		{
+		} else {
 			double sq = Math.sqrt(1.0 + m.z.z - m.x.x - m.y.y) * 0.5;
 			double inv = 0.25 / sq;
 			this.z = sq;
@@ -144,15 +137,13 @@ public struct Quaternion
 	{
 		// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
 		double test = x*y + z*w;
-		if (test > 0.499)
-		{ // singularity at north pole
+		if (test > 0.499) { // singularity at north pole
 			double rx = 0.0;
 			double ry = 2.0 * Math.atan2(x, w);
 			double rz = Math.PI*0.5;
 			return Vector3(rx, ry, rz);
 		}
-		if (test < -0.499)
-		{ // singularity at south pole
+		if (test < -0.499) { // singularity at south pole
 			double rx = +0.0;
 			double ry = -2.0 * Math.atan2(x, w);
 			double rz = -Math.PI*0.5;

+ 12 - 24
tools/level_editor/editor_view.vala

@@ -44,8 +44,7 @@ public class EditorView : Gtk.EventBox
 
 	private string key_to_string(uint k)
 	{
-		switch (k)
-		{
+		switch (k) {
 		case Gdk.Key.w:     return "w";
 		case Gdk.Key.a:     return "a";
 		case Gdk.Key.s:     return "s";
@@ -104,8 +103,7 @@ public class EditorView : Gtk.EventBox
 		this.focus_out_event.connect(on_event_box_focus_out_event);
 		this.size_allocate.connect(on_size_allocate);
 
-		if (input_enabled)
-		{
+		if (input_enabled) {
 			this.button_release_event.connect(on_button_release);
 			this.button_press_event.connect(on_button_press);
 			this.key_press_event.connect(on_key_press);
@@ -140,14 +138,12 @@ public class EditorView : Gtk.EventBox
 		if (ev.button == Gdk.BUTTON_PRIMARY)
 			str += LevelEditorApi.mouse_up((int)ev.x, (int)ev.y);
 
-		if (camera_modifier_pressed())
-		{
+		if (camera_modifier_pressed()) {
 			if (!_mouse_left || !_mouse_middle || !_mouse_right)
 				str += "LevelEditor:camera_drag_start('idle')";
 		}
 
-		if (str.length != 0)
-		{
+		if (str.length != 0) {
 			_client.send_script(str);
 			_client.send(DeviceApi.frame());
 		}
@@ -170,8 +166,7 @@ public class EditorView : Gtk.EventBox
 			, _mouse_right
 			);
 
-		if (camera_modifier_pressed())
-		{
+		if (camera_modifier_pressed()) {
 			if (_mouse_left)
 				str += "LevelEditor:camera_drag_start('tumble')";
 			if (_mouse_middle)
@@ -183,8 +178,7 @@ public class EditorView : Gtk.EventBox
 		if (ev.button == Gdk.BUTTON_PRIMARY)
 			str += LevelEditorApi.mouse_down((int)ev.x, (int)ev.y);
 
-		if (str.length != 0)
-		{
+		if (str.length != 0) {
 			_client.send_script(str);
 			_client.send(DeviceApi.frame());
 		}
@@ -195,8 +189,7 @@ public class EditorView : Gtk.EventBox
 	{
 		string str = "";
 
-		if (ev.keyval == Gdk.Key.Escape)
-		{
+		if (ev.keyval == Gdk.Key.Escape) {
 			LevelEditorApplication app = (LevelEditorApplication)((Gtk.Window)this.get_toplevel()).application;
 			app.activate_last_tool_before_place();
 		}
@@ -210,16 +203,14 @@ public class EditorView : Gtk.EventBox
 		if (ev.keyval == Gdk.Key.Left)
 			str += "LevelEditor:key_down(\"move_left\")";
 
-		if (_keys.has_key(ev.keyval))
-		{
+		if (_keys.has_key(ev.keyval)) {
 			if (!_keys[ev.keyval])
 				str += LevelEditorApi.key_down(key_to_string(ev.keyval));
 
 			_keys[ev.keyval] = true;
 		}
 
-		if (str.length != 0)
-		{
+		if (str.length != 0) {
 			_client.send_script(str);
 			_client.send(DeviceApi.frame());
 		}
@@ -233,16 +224,14 @@ public class EditorView : Gtk.EventBox
 		if ((ev.keyval == Gdk.Key.Alt_L || ev.keyval == Gdk.Key.Alt_R))
 			str += "LevelEditor:camera_drag_start('idle')";
 
-		if (_keys.has_key(ev.keyval))
-		{
+		if (_keys.has_key(ev.keyval)) {
 			if (_keys[ev.keyval])
 				str += LevelEditorApi.key_up(key_to_string(ev.keyval));
 
 			_keys[ev.keyval] = false;
 		}
 
-		if (str.length != 0)
-		{
+		if (str.length != 0) {
 			_client.send_script(str);
 			_client.send(DeviceApi.frame());
 		}
@@ -290,8 +279,7 @@ public class EditorView : Gtk.EventBox
 		_client.send(DeviceApi.resize(_allocation.width, _allocation.height));
 
 		// Ensure there is some delay between the last resize() and the last frame().
-		if (_resize_timer_id == 0)
-		{
+		if (_resize_timer_id == 0) {
 			_resize_timer_id = GLib.Timeout.add_full(GLib.Priority.DEFAULT, 200, () => {
 					_client.send(DeviceApi.frame());
 					_resize_timer_id = 0;

+ 41 - 90
tools/level_editor/level.vala

@@ -120,29 +120,24 @@ public class Level
 		Guid[] units = {};
 		Guid[] sounds = {};
 
-		foreach (Guid id in ids)
-		{
+		foreach (Guid id in ids) {
 			if (_db.object_type(id) == OBJECT_TYPE_UNIT)
 				units += id;
 			else if (_db.object_type(id) == OBJECT_TYPE_SOUND_SOURCE)
 				sounds += id;
 		}
 
-		if (units.length > 0)
-		{
+		if (units.length > 0) {
 			_db.add_restore_point((int)ActionType.DESTROY_UNIT, units);
-			foreach (Guid id in units)
-			{
+			foreach (Guid id in units) {
 				_db.remove_from_set(_id, "units", id);
 				_db.destroy(id);
 			}
 		}
 
-		if (sounds.length > 0)
-		{
+		if (sounds.length > 0) {
 			_db.add_restore_point((int)ActionType.DESTROY_SOUND, sounds);
-			foreach (Guid id in sounds)
-			{
+			foreach (Guid id in sounds) {
 				_db.remove_from_set(_id, "sounds", id);
 				_db.destroy(id);
 			}
@@ -163,8 +158,7 @@ public class Level
 
 	public void duplicate_selected_objects()
 	{
-		if (_selection.size > 0)
-		{
+		if (_selection.size > 0) {
 			Guid[] ids = new Guid[_selection.size];
 			// FIXME
 			{
@@ -198,16 +192,12 @@ public class Level
 	public void duplicate_objects(Guid[] ids, Guid[] new_ids)
 	{
 		_db.add_restore_point((int)ActionType.DUPLICATE_OBJECTS, new_ids);
-		for (int i = 0; i < ids.length; ++i)
-		{
+		for (int i = 0; i < ids.length; ++i) {
 			_db.duplicate(ids[i], new_ids[i]);
 
-			if (_db.object_type(ids[i]) == OBJECT_TYPE_UNIT)
-			{
+			if (_db.object_type(ids[i]) == OBJECT_TYPE_UNIT) {
 				_db.add_to_set(_id, "units", new_ids[i]);
-			}
-			else if (_db.object_type(ids[i]) == OBJECT_TYPE_SOUND_SOURCE)
-			{
+			} else if (_db.object_type(ids[i]) == OBJECT_TYPE_SOUND_SOURCE) {
 				_db.add_to_set(_id, "sounds", new_ids[i]);
 			}
 		}
@@ -221,23 +211,19 @@ public class Level
 		_db.create(id, OBJECT_TYPE_UNIT);
 		_db.set_property_string(id, "editor.name", "unit_%04u".printf(_num_units++));
 
-		if (name != null)
-		{
+		if (name != null) {
 			_project.load_unit(name);
 			_db.set_property_string(id, "prefab", name);
 		}
 
 		Unit unit = new Unit(_db, id);
 		Guid component_id;
-		if (unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM))
-		{
+		if (unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM)) {
 			unit.set_component_property_vector3   (component_id, "data.position", pos);
 			unit.set_component_property_quaternion(component_id, "data.rotation", rot);
 			unit.set_component_property_vector3   (component_id, "data.scale", scl);
 			unit.set_component_property_string    (component_id, "type", OBJECT_TYPE_TRANSFORM);
-		}
-		else
-		{
+		} else {
 			_db.set_property_vector3   (id, "position", pos);
 			_db.set_property_quaternion(id, "rotation", rot);
 			_db.set_property_vector3   (id, "scale", scl);
@@ -263,32 +249,25 @@ public class Level
 	{
 		_db.add_restore_point((int)ActionType.MOVE_OBJECTS, ids);
 
-		for (int i = 0; i < ids.length; ++i)
-		{
+		for (int i = 0; i < ids.length; ++i) {
 			Guid id = ids[i];
 			Vector3 pos = positions[i];
 			Quaternion rot = rotations[i];
 			Vector3 scl = scales[i];
 
-			if (_db.object_type(id) == OBJECT_TYPE_UNIT)
-			{
+			if (_db.object_type(id) == OBJECT_TYPE_UNIT) {
 				Unit unit = new Unit(_db, id);
 				Guid component_id;
-				if (unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM))
-				{
+				if (unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM)) {
 					unit.set_component_property_vector3   (component_id, "data.position", pos);
 					unit.set_component_property_quaternion(component_id, "data.rotation", rot);
 					unit.set_component_property_vector3   (component_id, "data.scale", scl);
-				}
-				else
-				{
+				} else {
 					_db.set_property_vector3   (id, "position", pos);
 					_db.set_property_quaternion(id, "rotation", rot);
 					_db.set_property_vector3   (id, "scale", scl);
 				}
-			}
-			else if (_db.object_type(id) == OBJECT_TYPE_SOUND_SOURCE)
-			{
+			} else if (_db.object_type(id) == OBJECT_TYPE_SOUND_SOURCE) {
 				_db.set_property_vector3   (id, "position", pos);
 				_db.set_property_quaternion(id, "rotation", rot);
 			}
@@ -488,14 +467,10 @@ public class Level
 	private void send_spawn_objects(Guid[] ids)
 	{
 		StringBuilder sb = new StringBuilder();
-		for (int i = 0; i < ids.length; ++i)
-		{
-			if (_db.object_type(ids[i]) == OBJECT_TYPE_UNIT)
-			{
+		for (int i = 0; i < ids.length; ++i) {
+			if (_db.object_type(ids[i]) == OBJECT_TYPE_UNIT) {
 				generate_spawn_unit_commands(new Guid[] { ids[i] }, sb);
-			}
-			else if (_db.object_type(ids[i]) == OBJECT_TYPE_SOUND_SOURCE)
-			{
+			} else if (_db.object_type(ids[i]) == OBJECT_TYPE_SOUND_SOURCE) {
 				generate_spawn_sound_commands(new Guid[] { ids[i] }, sb);
 			}
 		}
@@ -556,8 +531,7 @@ public class Level
 
 	private void generate_spawn_unit_commands(Guid[] unit_ids, StringBuilder sb)
 	{
-		foreach (Guid unit_id in unit_ids)
-		{
+		foreach (Guid unit_id in unit_ids) {
 			Unit unit = new Unit(_db, unit_id);
 
 			if (unit.has_prefab())
@@ -566,8 +540,7 @@ public class Level
 			sb.append(LevelEditorApi.spawn_empty_unit(unit_id));
 
 			Guid component_id;
-			if (unit.has_component(out component_id, "transform"))
-			{
+			if (unit.has_component(out component_id, "transform")) {
 				string s = LevelEditorApi.add_tranform_component(unit_id
 					, component_id
 					, unit.get_component_property_vector3   (component_id, "data.position")
@@ -576,8 +549,7 @@ public class Level
 					);
 				sb.append(s);
 			}
-			if (unit.has_component(out component_id, "camera"))
-			{
+			if (unit.has_component(out component_id, "camera")) {
 				string s = LevelEditorApi.add_camera_component(unit_id
 					, component_id
 					, unit.get_component_property_string(component_id, "data.projection")
@@ -587,8 +559,7 @@ public class Level
 					);
 				sb.append(s);
 			}
-			if (unit.has_component(out component_id, "mesh_renderer"))
-			{
+			if (unit.has_component(out component_id, "mesh_renderer")) {
 				string s = LevelEditorApi.add_mesh_renderer_component(unit_id
 					, component_id
 					, unit.get_component_property_string(component_id, "data.mesh_resource")
@@ -598,8 +569,7 @@ public class Level
 					);
 				sb.append(s);
 			}
-			if (unit.has_component(out component_id, "sprite_renderer"))
-			{
+			if (unit.has_component(out component_id, "sprite_renderer")) {
 				string s = LevelEditorApi.add_sprite_renderer_component(unit_id
 					, component_id
 					, unit.get_component_property_string(component_id, "data.sprite_resource")
@@ -610,8 +580,7 @@ public class Level
 					);
 				sb.append(s);
 			}
-			if (unit.has_component(out component_id, "light"))
-			{
+			if (unit.has_component(out component_id, "light")) {
 				string s = LevelEditorApi.add_light_component(unit_id
 					, component_id
 					, unit.get_component_property_string (component_id, "data.type")
@@ -627,8 +596,7 @@ public class Level
 
 	private void generate_spawn_sound_commands(Guid[] sound_ids, StringBuilder sb)
 	{
-		foreach (Guid id in sound_ids)
-		{
+		foreach (Guid id in sound_ids) {
 			string s = LevelEditorApi.spawn_sound(id
 				, _db.get_property_string    (id, "name")
 				, _db.get_property_vector3   (id, "position")
@@ -643,8 +611,7 @@ public class Level
 
 	private void undo_redo_action(bool undo, int id, Guid[] data)
 	{
-		switch (id)
-		{
+		switch (id) {
 		case (int)ActionType.SPAWN_UNIT:
 			if (undo)
 				send_destroy_objects(data);
@@ -673,44 +640,34 @@ public class Level
 				send_destroy_objects(data);
 			break;
 
-		case (int)ActionType.MOVE_OBJECTS:
-		{
+		case (int)ActionType.MOVE_OBJECTS: {
 			Guid[] ids = data;
 
 			Vector3[] positions = new Vector3[ids.length];
 			Quaternion[] rotations = new Quaternion[ids.length];
 			Vector3[] scales = new Vector3[ids.length];
 
-			for (int i = 0; i < ids.length; ++i)
-			{
-				if (_db.object_type(ids[i]) == OBJECT_TYPE_UNIT)
-				{
+			for (int i = 0; i < ids.length; ++i) {
+				if (_db.object_type(ids[i]) == OBJECT_TYPE_UNIT) {
 					Guid unit_id = ids[i];
 
 					Unit unit = new Unit(_db, unit_id);
 					Guid component_id;
-					if (unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM))
-					{
+					if (unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM)) {
 						positions[i] = unit.get_component_property_vector3   (component_id, "data.position");
 						rotations[i] = unit.get_component_property_quaternion(component_id, "data.rotation");
 						scales[i]    = unit.get_component_property_vector3   (component_id, "data.scale");
-					}
-					else
-					{
+					} else {
 						positions[i] = _db.get_property_vector3   (unit_id, "position");
 						rotations[i] = _db.get_property_quaternion(unit_id, "rotation");
 						scales[i]    = _db.get_property_vector3   (unit_id, "scale");
 					}
-				}
-				else if (_db.object_type(ids[i]) == OBJECT_TYPE_SOUND_SOURCE)
-				{
+				} else if (_db.object_type(ids[i]) == OBJECT_TYPE_SOUND_SOURCE) {
 					Guid sound_id = ids[i];
 					positions[i] = _db.get_property_vector3   (sound_id, "position");
 					rotations[i] = _db.get_property_quaternion(sound_id, "rotation");
 					scales[i]    = Vector3(1.0, 1.0, 1.0);
-				}
-				else
-				{
+				} else {
 					assert(false);
 				}
 			}
@@ -721,8 +678,7 @@ public class Level
 			break;
 		}
 
-		case (int)ActionType.DUPLICATE_OBJECTS:
-		{
+		case (int)ActionType.DUPLICATE_OBJECTS: {
 			Guid[] new_ids = data;
 			if (undo)
 				send_destroy_objects(new_ids);
@@ -735,8 +691,7 @@ public class Level
 			object_editor_name_changed(data[0], object_editor_name(data[0]));
 			break;
 
-		case (int)ActionType.SET_LIGHT:
-		{
+		case (int)ActionType.SET_LIGHT: {
 			Guid unit_id = data[0];
 
 			Unit unit = new Unit(_db, unit_id);
@@ -756,8 +711,7 @@ public class Level
 			break;
 		}
 
-		case (int)ActionType.SET_MESH:
-		{
+		case (int)ActionType.SET_MESH: {
 			Guid unit_id = data[0];
 
 			Unit unit = new Unit(_db, unit_id);
@@ -774,8 +728,7 @@ public class Level
 			break;
 		}
 
-		case (int)ActionType.SET_SPRITE:
-		{
+		case (int)ActionType.SET_SPRITE: {
 			Guid unit_id = data[0];
 
 			Unit unit = new Unit(_db, unit_id);
@@ -795,8 +748,7 @@ public class Level
 			break;
 		}
 
-		case (int)ActionType.SET_CAMERA:
-		{
+		case (int)ActionType.SET_CAMERA: {
 			Guid unit_id = data[0];
 
 			Unit unit = new Unit(_db, unit_id);
@@ -823,8 +775,7 @@ public class Level
 			selection_changed(_selection);
 			break;
 
-		case (int)ActionType.SET_SOUND:
-		{
+		case (int)ActionType.SET_SOUND: {
 			Guid sound_id = data[0];
 
 			_client.send_script(LevelEditorApi.set_sound_range(sound_id

Plik diff jest za duży
+ 122 - 269
tools/level_editor/level_editor.vala


+ 14 - 30
tools/level_editor/level_tree_view.vala

@@ -159,20 +159,15 @@ public class LevelTreeView : Gtk.Box
 
 	private bool on_button_pressed(Gdk.EventButton ev)
 	{
-		if (ev.button == Gdk.BUTTON_SECONDARY)
-		{
+		if (ev.button == Gdk.BUTTON_SECONDARY) {
 			Gtk.TreePath path;
 			Gtk.TreeViewColumn column;
-			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, out column, null, null))
-			{
-				if (!_tree_selection.path_is_selected(path))
-				{
+			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, out column, null, null)) {
+				if (!_tree_selection.path_is_selected(path)) {
 					_tree_selection.unselect_all();
 					_tree_selection.select_path(path);
 				}
-			}
-			else // Clicked on empty space.
-			{
+			} else { // Clicked on empty space.
 				return Gdk.EVENT_PROPAGATE;
 			}
 
@@ -203,8 +198,7 @@ public class LevelTreeView : Gtk.Box
 					dg.skip_taskbar_hint = true;
 					dg.show_all();
 
-					if (dg.run() == (int)ResponseType.OK)
-					{
+					if (dg.run() == (int)ResponseType.OK) {
 						string cur_name = "";
 						string new_name = "";
 						Guid object_id = GUID_ZERO;
@@ -259,11 +253,9 @@ public class LevelTreeView : Gtk.Box
 
 	private bool on_button_released(Gdk.EventButton ev)
 	{
-		if (ev.button == Gdk.BUTTON_PRIMARY)
-		{
+		if (ev.button == Gdk.BUTTON_PRIMARY) {
 			Gtk.TreePath path;
-			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null))
-			{
+			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null)) {
 				Gtk.TreeIter iter;
 				_tree_view.model.get_iter(out iter, path);
 
@@ -318,10 +310,8 @@ public class LevelTreeView : Gtk.Box
 				Value id;
 				model.get_value(iter, Column.GUID, out id);
 
-				foreach (Guid? guid in selection)
-				{
-					if ((Guid)id == guid)
-					{
+				foreach (Guid? guid in selection) {
+					if ((Guid)id == guid) {
 						_tree_selection.select_iter(iter);
 						return false;
 					}
@@ -345,8 +335,7 @@ public class LevelTreeView : Gtk.Box
 				model.get_value(iter, Column.GUID, out guid);
 				Guid guid_model = (Guid)guid;
 
-				if (guid_model == object_id)
-				{
+				if (guid_model == object_id) {
 					Gtk.TreeIter iter_filter;
 					Gtk.TreeIter iter_model;
 					_tree_sort.convert_iter_to_child_iter(out iter_filter, iter);
@@ -429,19 +418,15 @@ public class LevelTreeView : Gtk.Box
 		HashSet<Guid?> units  = _db.get_property_set(_level._id, "units", new HashSet<Guid?>());
 		HashSet<Guid?> sounds = _db.get_property_set(_level._id, "sounds", new HashSet<Guid?>());
 
-		foreach (Guid unit in units)
-		{
+		foreach (Guid unit in units) {
 			Unit u = new Unit(_level._db, unit);
 
 			int item_type = LevelTreeView.ItemType.UNIT;
 			Gtk.TreeIter tree_iter = units_iter;
-			if (u.is_light())
-			{
+			if (u.is_light()) {
 				item_type = LevelTreeView.ItemType.LIGHT;
 				tree_iter = lights_iter;
-			}
-			else if (u.is_camera())
-			{
+			} else if (u.is_camera()) {
 				item_type = LevelTreeView.ItemType.CAMERA;
 				tree_iter = cameras_iter;
 			}
@@ -459,8 +444,7 @@ public class LevelTreeView : Gtk.Box
 				, -1
 				);
 		}
-		foreach (Guid sound in sounds)
-		{
+		foreach (Guid sound in sounds) {
 			Gtk.TreeIter iter;
 			_tree_store.insert_with_values(out iter
 				, sounds_iter

+ 12 - 25
tools/level_editor/panel_new_project.vala

@@ -54,8 +54,7 @@ public class PanelNewProject : Gtk.Viewport
 			});
 
 		_button_create.clicked.connect(() => {
-				if (_entry_name.text == "")
-				{
+				if (_entry_name.text == "") {
 					_label_message.label = "Choose project name";
 					return;
 				}
@@ -63,19 +62,16 @@ public class PanelNewProject : Gtk.Viewport
 				GLib.File location = _file_chooser_button_location.get_file();
 				string? source_dir = location.get_path();
 
-				if (source_dir == null)
-				{
+				if (source_dir == null) {
 					_label_message.label = "Location is not valid";
 					return;
 				}
-				if (GLib.FileUtils.test(source_dir, FileTest.IS_REGULAR))
-				{
+				if (GLib.FileUtils.test(source_dir, FileTest.IS_REGULAR)) {
 					_label_message.label = "Location must be an empty directory";
 					return;
 				}
 
-				if (!is_directory_empty(source_dir))
-				{
+				if (!is_directory_empty(source_dir)) {
 					_label_message.label = "Location must be an empty directory";
 					return;
 				}
@@ -97,30 +93,25 @@ public class PanelNewProject : Gtk.Viewport
 	public void fill_templates_list(string path)
 	{
 		GLib.File file = GLib.File.new_for_path(path);
-		try
-		{
+		try {
 			FileEnumerator enumerator = file.enumerate_children("standard::*"
 				, FileQueryInfoFlags.NOFOLLOW_SYMLINKS
 				);
-			for (GLib.FileInfo? info = enumerator.next_file(); info != null ; info = enumerator.next_file())
-			{
+			for (GLib.FileInfo? info = enumerator.next_file(); info != null ; info = enumerator.next_file()) {
 				GLib.File source_dir = GLib.File.new_for_path(GLib.Path.build_filename(path, info.get_name()));
 				_combo_box_map_template.append(source_dir.get_path(), info.get_name());
 			}
 		}
-		catch (GLib.Error e)
-		{
+		catch (GLib.Error e) {
 			loge(e.message);
 		}
 	}
 
 	public void copy_recursive(GLib.File dst, GLib.File src, GLib.FileCopyFlags flags = GLib.FileCopyFlags.NONE)
 	{
-		try
-		{
+		try {
 			GLib.FileType src_type = src.query_file_type(GLib.FileQueryInfoFlags.NONE);
-			if (src_type == GLib.FileType.DIRECTORY)
-			{
+			if (src_type == GLib.FileType.DIRECTORY) {
 				if (dst.query_exists() == false)
 					dst.make_directory();
 				src.copy_attributes(dst, flags);
@@ -128,21 +119,17 @@ public class PanelNewProject : Gtk.Viewport
 				string dst_path = dst.get_path();
 				string src_path = src.get_path();
 				GLib.FileEnumerator enum = src.enumerate_children(GLib.FileAttribute.STANDARD_NAME, GLib.FileQueryInfoFlags.NONE);
-				for (GLib.FileInfo? info = enum.next_file(); info != null; info = enum.next_file())
-				{
+				for (GLib.FileInfo? info = enum.next_file(); info != null; info = enum.next_file()) {
 					copy_recursive(GLib.File.new_for_path(GLib.Path.build_filename(dst_path, info.get_name()))
 						, GLib.File.new_for_path(GLib.Path.build_filename(src_path, info.get_name()))
 						, flags
 						);
 				}
-			}
-			else if (src_type == GLib.FileType.REGULAR)
-			{
+			} else if (src_type == GLib.FileType.REGULAR) {
 				src.copy(dst, flags);
 			}
 		}
-		catch (Error e)
-		{
+		catch (Error e) {
 			loge(e.message);
 		}
 	}

+ 1 - 2
tools/level_editor/panel_projects_list.vala

@@ -135,8 +135,7 @@ public class PanelProjectsList : Gtk.ScrolledWindow
 	public void on_recent_project_touched(string source_dir, string mtime)
 	{
 		_list_projects.foreach((row) => {
-				if (row.get_data<string>("source_dir") == source_dir)
-				{
+				if (row.get_data<string>("source_dir") == source_dir) {
 					row.set_data("mtime", mtime);
 					return;
 				}

+ 25 - 52
tools/level_editor/project.vala

@@ -265,14 +265,10 @@ public class Project
 	{
 		string path = Path.build_filename(_source_dir.get_path(), directory + "/" + name + ".lua");
 		FileStream fs = FileStream.open(path, "wb");
-		if (fs != null)
-		{
-			if (empty)
-			{
+		if (fs != null) {
+			if (empty) {
 				fs.puts("\n");
-			}
-			else
-			{
+			} else {
 				string text = "local Behavior = Behavior or {}"
 					+ "\nlocal Data = Data or {}"
 					+ "\n"
@@ -322,8 +318,7 @@ public class Project
 	{
 		string path = Path.build_filename(_source_dir.get_path(), directory + "/" + name + ".unit");
 		FileStream fs = FileStream.open(path, "wb");
-		if (fs != null)
-		{
+		if (fs != null) {
 			fs.puts("\ncomponents = [");
 			fs.puts("\n]");
 			fs.puts("\n");
@@ -374,13 +369,11 @@ public class Project
 
 	public void delete_garbage()
 	{
-		try
-		{
+		try {
 			_level_editor_test_level.delete();
 			_level_editor_test_package.delete();
 		}
-		catch (GLib.Error e)
-		{
+		catch (GLib.Error e) {
 			// Ignored
 		}
 	}
@@ -394,12 +387,10 @@ public class Project
 	public void delete_resource(string type, string name)
 	{
 		GLib.File file = GLib.File.new_for_path(filename(type, name));
-		try
-		{
+		try {
 			file.delete();
 		}
-		catch (Error e)
-		{
+		catch (Error e) {
 			loge(e.message);
 		}
 	}
@@ -412,8 +403,7 @@ public class Project
 		string index_path = Path.build_filename(_data_dir.get_path(), "data_index.sjson");
 		Hashtable index = SJSON.load_from_path(index_path);
 		Value? name = index[resource_id];
-		if (name != null)
-		{
+		if (name != null) {
 			resource_name = (string)name;
 			return true;
 		}
@@ -459,8 +449,7 @@ public class Project
 
 	public void remove_file(string path)
 	{
-		if (!_map.has_key(path))
-		{
+		if (!_map.has_key(path)) {
 			logw("remove_file: map does not contain path: %s".printf(path));
 			return;
 		}
@@ -530,8 +519,7 @@ public class Project
 			});
 
 		int success = 0;
-		while (paths.size != 0 && success == 0)
-		{
+		while (paths.size != 0 && success == 0) {
 			// Find importer for the first file in the list of selected filenames.
 			ImporterData? importer = project.find_importer_for_path(paths[0]);
 			if (importer == null)
@@ -540,14 +528,11 @@ public class Project
 			// Create the list of all filenames importable by importer.
 			Gee.ArrayList<string> importables = new Gee.ArrayList<string>();
 			var cur = paths.list_iterator();
-			for (var has_next = cur.next(); has_next; has_next = cur.next())
-			{
+			for (var has_next = cur.next(); has_next; has_next = cur.next()) {
 				string path = paths[cur.index()];
 
-				foreach (var ext in importer.extensions)
-				{
-					if (path.has_suffix("." + ext))
-					{
+				foreach (var ext in importer.extensions) {
+					if (path.has_suffix("." + ext)) {
 						importables.add(path);
 						cur.remove();
 					}
@@ -576,8 +561,7 @@ public class Project
 		Gtk.FileFilter filter = new Gtk.FileFilter();
 
 		string extensions_comma_separated = "";
-		foreach (var ext in extensions)
-		{
+		foreach (var ext in extensions) {
 			extensions_comma_separated += "*.%s, ".printf(ext);
 			filter.add_pattern("*.%s".printf(ext));
 		}
@@ -613,10 +597,8 @@ public class Project
 	// with the given @a extension.
 	public ImporterData? find_importer_for_path(string path)
 	{
-		foreach (var imp in _importers)
-		{
-			foreach (var ext in imp.extensions)
-			{
+		foreach (var imp in _importers) {
+			foreach (var ext in imp.extensions) {
 				if (path.has_suffix("." + ext))
 					return imp;
 			}
@@ -641,15 +623,13 @@ public class Project
 		src.add_filter(_all_extensions_importer_data._filter);
 		src.set_filter(_all_extensions_importer_data._filter);
 
-		if (src.run() != (int)ResponseType.ACCEPT)
-		{
+		if (src.run() != (int)ResponseType.ACCEPT) {
 			src.destroy();
 			return;
 		}
 
 		string out_dir = "";
-		if (destination_dir == null)
-		{
+		if (destination_dir == null) {
 			Gtk.FileChooserDialog dst = new Gtk.FileChooserDialog("Select destination folder..."
 				, parent_window
 				, FileChooserAction.SELECT_FOLDER
@@ -660,8 +640,7 @@ public class Project
 				);
 			dst.set_current_folder(this.source_dir());
 
-			if (dst.run() != (int)ResponseType.ACCEPT)
-			{
+			if (dst.run() != (int)ResponseType.ACCEPT) {
 				dst.destroy();
 				src.destroy();
 				return;
@@ -669,9 +648,7 @@ public class Project
 
 			out_dir = dst.get_filename();
 			dst.destroy();
-		}
-		else
-		{
+		} else {
 			out_dir = GLib.File.new_for_path(GLib.Path.build_filename(source_dir(), destination_dir)).get_path();
 		}
 
@@ -680,10 +657,8 @@ public class Project
 
 		// Find importer callback
 		unowned ImporterDelegate? importer = null;
-		foreach (var imp in _importers)
-		{
-			if (imp._filter == current_filter)
-			{
+		foreach (var imp in _importers) {
+			if (imp._filter == current_filter) {
 				importer = imp.delegate;
 				break;
 			}
@@ -693,8 +668,7 @@ public class Project
 			importer = _all_extensions_importer_data.delegate;
 
 		// Import
-		if (importer(this, out_dir, filenames) == 0)
-		{
+		if (importer(this, out_dir, filenames) == 0) {
 			_data_compiler.compile.begin(this.data_dir(), this.platform(), (obj, res) => {
 					_data_compiler.compile.end(res);
 				});
@@ -710,8 +684,7 @@ public class Project
 			);
 
 		GLib.FileInfo info = null;
-		while ((info = fe.next_file()) != null)
-		{
+		while ((info = fe.next_file()) != null) {
 			GLib.File subfile = file.resolve_relative_path(info.get_name());
 
 			if (info.get_file_type() == GLib.FileType.DIRECTORY)

+ 26 - 55
tools/level_editor/project_browser.vala

@@ -64,13 +64,10 @@ public class ProjectBrowser : Gtk.Box
 				model.get_value(iter_a, ProjectStore.Column.TYPE, out type_a);
 				model.get_value(iter_b, ProjectStore.Column.TYPE, out type_b);
 
-				if ((string)type_a == "<folder>")
-				{
+				if ((string)type_a == "<folder>") {
 					if ((string)type_b != "<folder>")
 						return -1;
-				}
-				else if ((string)type_b == "<folder>")
-				{
+				} else if ((string)type_b == "<folder>") {
 					if ((string)type_a != "<folder>")
 						return 1;
 				}
@@ -194,8 +191,7 @@ public class ProjectBrowser : Gtk.Box
 			return;
 
 		Gtk.TreePath store_path;
-		if (_project_store.path_for_resource_type_name(out store_path, type, name))
-		{
+		if (_project_store.path_for_resource_type_name(out store_path, type, name)) {
 			Gtk.TreePath filter_path = _tree_filter.convert_child_path_to_path(store_path);
 			if (filter_path == null) // Either the path is not valid or points to a non-visible row in the model.
 				return;
@@ -210,11 +206,9 @@ public class ProjectBrowser : Gtk.Box
 
 	private bool on_button_pressed(Gdk.EventButton ev)
 	{
-		if (ev.button == Gdk.BUTTON_SECONDARY)
-		{
+		if (ev.button == Gdk.BUTTON_SECONDARY) {
 			Gtk.TreePath path;
-			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null))
-			{
+			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null)) {
 				Gtk.TreeIter iter;
 				_tree_view.model.get_iter(out iter, path);
 
@@ -223,8 +217,7 @@ public class ProjectBrowser : Gtk.Box
 				_tree_view.model.get_value(iter, ProjectStore.Column.TYPE, out type);
 				_tree_view.model.get_value(iter, ProjectStore.Column.NAME, out name);
 
-				if (type == "<folder>")
-				{
+				if (type == "<folder>") {
 					Gtk.Menu menu = new Gtk.Menu();
 					Gtk.MenuItem mi;
 
@@ -256,10 +249,8 @@ public class ProjectBrowser : Gtk.Box
 							dg.skip_taskbar_hint = true;
 							dg.show_all();
 
-							if (dg.run() == (int)ResponseType.OK)
-							{
-								if (sb.text.strip() == "")
-								{
+							if (dg.run() == (int)ResponseType.OK) {
+								if (sb.text.strip() == "") {
 									dg.destroy();
 									return;
 								}
@@ -289,10 +280,8 @@ public class ProjectBrowser : Gtk.Box
 							dg.skip_taskbar_hint = true;
 							dg.show_all();
 
-							if (dg.run() == (int)ResponseType.OK)
-							{
-								if (sb.text.strip() == "")
-								{
+							if (dg.run() == (int)ResponseType.OK) {
+								if (sb.text.strip() == "") {
 									dg.destroy();
 									return;
 								}
@@ -325,10 +314,8 @@ public class ProjectBrowser : Gtk.Box
 							dg.skip_taskbar_hint = true;
 							dg.show_all();
 
-							if (dg.run() == (int)ResponseType.OK)
-							{
-								if (sb.text.strip() == "")
-								{
+							if (dg.run() == (int)ResponseType.OK) {
+								if (sb.text.strip() == "") {
 									dg.destroy();
 									return;
 								}
@@ -361,21 +348,17 @@ public class ProjectBrowser : Gtk.Box
 							dg.skip_taskbar_hint = true;
 							dg.show_all();
 
-							if (dg.run() == (int)ResponseType.OK)
-							{
-								if (sb.text.strip() == "")
-								{
+							if (dg.run() == (int)ResponseType.OK) {
+								if (sb.text.strip() == "") {
 									dg.destroy();
 									return;
 								}
 
 								GLib.File file = GLib.File.new_for_path(GLib.Path.build_filename(_project.source_dir(), (string)name, sb.text));
-								try
-								{
+								try {
 									file.make_directory();
 								}
-								catch (Error e)
-								{
+								catch (Error e) {
 									loge(e.message);
 								}
 							}
@@ -384,8 +367,7 @@ public class ProjectBrowser : Gtk.Box
 						});
 					menu.add(mi);
 
-					if ((string)name != ProjectStore.ROOT_FOLDER)
-					{
+					if ((string)name != ProjectStore.ROOT_FOLDER) {
 						mi = new Gtk.MenuItem.with_label("Delete Folder");
 						mi.activate.connect(() => {
 								Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)this.get_toplevel()
@@ -404,12 +386,10 @@ public class ProjectBrowser : Gtk.Box
 									return;
 
 								GLib.File file = GLib.File.new_for_path(GLib.Path.build_filename(_project.source_dir(), (string)name));
-								try
-								{
+								try {
 									_project.delete_tree(file);
 								}
-								catch (Error e)
-								{
+								catch (Error e) {
 									loge(e.message);
 								}
 							});
@@ -418,9 +398,7 @@ public class ProjectBrowser : Gtk.Box
 
 					menu.show_all();
 					menu.popup(null, null, null, ev.button, ev.time);
-				}
-				else // If file
-				{
+				} else { // If file
 					Gtk.Menu menu = new Gtk.Menu();
 					Gtk.MenuItem mi;
 
@@ -434,8 +412,7 @@ public class ProjectBrowser : Gtk.Box
 					mi = new Gtk.MenuItem.with_label("Open Containing Folder...");
 					mi.activate.connect(() => {
 							Gtk.TreeIter parent;
-							if (_tree_view.model.iter_parent(out parent, iter))
-							{
+							if (_tree_view.model.iter_parent(out parent, iter)) {
 								Value parent_name;
 								_tree_view.model.get_value(parent, ProjectStore.Column.NAME, out parent_name);
 
@@ -449,14 +426,10 @@ public class ProjectBrowser : Gtk.Box
 					menu.popup(null, null, null, ev.button, ev.time);
 				}
 			}
-		}
-		else if (ev.button == Gdk.BUTTON_PRIMARY)
-		{
-			if (ev.type == Gdk.EventType.@2BUTTON_PRESS)
-			{
+		} else if (ev.button == Gdk.BUTTON_PRIMARY) {
+			if (ev.type == Gdk.EventType.@2BUTTON_PRESS) {
 				Gtk.TreePath path;
-				if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null))
-				{
+				if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null)) {
 					Gtk.TreeIter iter;
 					_tree_view.model.get_iter(out iter, path);
 
@@ -479,11 +452,9 @@ public class ProjectBrowser : Gtk.Box
 
 	private bool on_button_released(Gdk.EventButton ev)
 	{
-		if (ev.button == Gdk.BUTTON_PRIMARY)
-		{
+		if (ev.button == Gdk.BUTTON_PRIMARY) {
 			Gtk.TreePath path;
-			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null))
-			{
+			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null)) {
 				Gtk.TreeIter iter;
 				_tree_view.model.get_iter(out iter, path);
 

+ 16 - 34
tools/level_editor/project_store.vala

@@ -79,24 +79,20 @@ public class ProjectStore
 	public bool path_for_resource_type_name(out Gtk.TreePath path, string type, string name)
 	{
 		string f = folder(name);
-		if (_folders.has_key(f))
-		{
+		if (_folders.has_key(f)) {
 			// Find the name inside the folder.
 			Gtk.TreeIter parent_iter;
 			_tree_store.get_iter(out parent_iter, _folders[f].get_path());
 
 			Gtk.TreeIter child;
-			if (_tree_store.iter_children(out child, parent_iter))
-			{
+			if (_tree_store.iter_children(out child, parent_iter)) {
 				Value iter_name;
 				Value iter_type;
 
-				while (true)
-				{
+				while (true) {
 					_tree_store.get_value(child, Column.NAME, out iter_name);
 					_tree_store.get_value(child, Column.TYPE, out iter_type);
-					if ((string)iter_name == name && (string)iter_type == type)
-					{
+					if ((string)iter_name == name && (string)iter_type == type) {
 						path = _tree_store.get_path(child);
 						return true;
 					}
@@ -118,8 +114,7 @@ public class ProjectStore
 		// "folder", one word
 		// "folder/another_folder", any number of words concatenated by '/'
 		int first_slash = folder.index_of_char('/', start_index);
-		if (first_slash == -1)
-		{
+		if (first_slash == -1) {
 			Gtk.TreeIter parent_iter;
 			_tree_store.get_iter(out parent_iter, parent.get_path());
 			Gtk.TreeIter iter;
@@ -137,15 +132,10 @@ public class ProjectStore
 
 			_folders[folder] = new Gtk.TreeRowReference(_tree_store, _tree_store.get_path(iter));
 			return iter;
-		}
-		else
-		{
-			if (_folders.has_key(folder.substring(0, first_slash)))
-			{
+		} else {
+			if (_folders.has_key(folder.substring(0, first_slash))) {
 				return make_tree_internal(folder, first_slash + 1, _folders[folder.substring(0, first_slash)]);
-			}
-			else
-			{
+			} else {
 				Gtk.TreeIter parent_iter;
 				_tree_store.get_iter(out parent_iter, parent.get_path());
 				Gtk.TreeIter iter;
@@ -171,8 +161,7 @@ public class ProjectStore
 
 	private Gtk.TreeIter make_tree(string folder)
 	{
-		if (_folders.has_key(folder))
-		{
+		if (_folders.has_key(folder)) {
 			Gtk.TreeIter iter;
 			_tree_store.get_iter(out iter, _folders[folder].get_path());
 			return iter;
@@ -218,17 +207,14 @@ public class ProjectStore
 		Gtk.TreeIter parent_iter;
 		_tree_store.get_iter(out parent_iter, _folders[f].get_path());
 		Gtk.TreeIter child;
-		if (_tree_store.iter_children(out child, parent_iter))
-		{
+		if (_tree_store.iter_children(out child, parent_iter)) {
 			Value iter_name;
 			Value iter_type;
 
-			while (true)
-			{
+			while (true) {
 				_tree_store.get_value(child, Column.NAME, out iter_name);
 				_tree_store.get_value(child, Column.TYPE, out iter_type);
-				if ((string)iter_name == name && (string)iter_type == type)
-				{
+				if ((string)iter_name == name && (string)iter_type == type) {
 					_tree_store.remove(ref child);
 					break;
 				}
@@ -239,17 +225,14 @@ public class ProjectStore
 		}
 
 		// Remove from list store
-		if (_list_store.iter_children(out child, null))
-		{
+		if (_list_store.iter_children(out child, null)) {
 			Value iter_name;
 			Value iter_type;
 
-			while (true)
-			{
+			while (true) {
 				_list_store.get_value(child, Column.NAME, out iter_name);
 				_list_store.get_value(child, Column.TYPE, out iter_type);
-				if ((string)iter_name == name && (string)iter_type == type)
-				{
+				if ((string)iter_name == name && (string)iter_type == type) {
 					_list_store.remove(ref child);
 					break;
 				}
@@ -280,8 +263,7 @@ public class ProjectStore
 
 		// Remove any stale TreeRowRerefence
 		var it = _folders.map_iterator();
-		for (var has_next = it.next(); has_next; has_next = it.next())
-		{
+		for (var has_next = it.next(); has_next; has_next = it.next()) {
 			string ff = it.get_key();
 			if (ff.has_prefix(name + "/"))
 				it.unset();

+ 12 - 28
tools/level_editor/properties_view.vala

@@ -384,8 +384,7 @@ public class ColliderPropertyGrid : PropertyGrid
 
 	private void on_value_changed()
 	{
-		if (_source.text == "mesh")
-		{
+		if (_source.text == "mesh") {
 			_level.set_collider(_id
 				, _component_id
 				, _shape.text
@@ -400,25 +399,19 @@ public class ColliderPropertyGrid : PropertyGrid
 		Unit unit = new Unit(_level._db, _id);
 
 		Value? source = unit.get_component_property(_component_id, "data.source");
-		if (source != null)
-		{
-			if ((string)source == "inline")
-			{
+		if (source != null) {
+			if ((string)source == "inline") {
 				_source.text = "inline";
 				_shape.text  = "";
 				_scene.value = "";
 				_name.text   = "";
-			}
-			else
-			{
+			} else {
 				_source.text = "mesh";
 				_shape.text  = unit.get_component_property_string(_component_id, "data.shape");
 				_scene.value = unit.get_component_property_string(_component_id, "data.scene");
 				_name.text   = unit.get_component_property_string(_component_id, "data.name");
 			}
-		}
-		else
-		{
+		} else {
 			_source.text = "mesh";
 			_shape.text  = unit.get_component_property_string(_component_id, "data.shape");
 			_scene.value = unit.get_component_property_string(_component_id, "data.scene");
@@ -761,22 +754,18 @@ public class PropertiesView : Gtk.Bin
 	{
 		_stack.set_visible_child(_scrolled_window);
 
-		foreach (var entry in _entries)
-		{
+		foreach (var entry in _entries) {
 			Gtk.Expander expander = _expanders[entry.type];
 
 			Unit unit = new Unit(_db, id);
 			Guid component_id;
-			if (unit.has_component(out component_id, entry.type) || entry.type == "name")
-			{
+			if (unit.has_component(out component_id, entry.type) || entry.type == "name") {
 				PropertyGrid cv = _objects[entry.type];
 				cv._id = id;
 				cv._component_id = component_id;
 				cv.update();
 				expander.show_all();
-			}
-			else
-			{
+			} else {
 				expander.hide();
 			}
 		}
@@ -786,19 +775,15 @@ public class PropertiesView : Gtk.Bin
 	{
 		_stack.set_visible_child(_scrolled_window);
 
-		foreach (var entry in _entries)
-		{
+		foreach (var entry in _entries) {
 			Gtk.Expander expander = _expanders[entry.type];
 
-			if (entry.type == "sound_transform" || entry.type == "sound_properties")
-			{
+			if (entry.type == "sound_transform" || entry.type == "sound_properties") {
 				PropertyGrid cv = _objects[entry.type];
 				cv._id = id;
 				cv.update();
 				expander.show_all();
-			}
-			else
-			{
+			} else {
 				expander.hide();
 			}
 		}
@@ -806,8 +791,7 @@ public class PropertiesView : Gtk.Bin
 
 	public void on_selection_changed(Gee.ArrayList<Guid?> selection)
 	{
-		if (selection.size != 1)
-		{
+		if (selection.size != 1) {
 			_stack.set_visible_child(_nothing_to_show);
 			return;
 		}

+ 19 - 40
tools/level_editor/resource_chooser.vala

@@ -157,8 +157,7 @@ public class ResourceChooser : Gtk.Box
 		Gtk.TreePath filter_path = _tree_sort.convert_path_to_child_path(path);
 		Gtk.TreePath child_path = _tree_filter.convert_path_to_child_path(filter_path);
 		Gtk.TreeIter iter;
-		if (_list_store.get_iter(out iter, child_path))
-		{
+		if (_list_store.get_iter(out iter, child_path)) {
 			Value name;
 			Value type;
 			_list_store.get_value(iter, ProjectStore.Column.NAME, out name);
@@ -170,18 +169,14 @@ public class ResourceChooser : Gtk.Box
 
 	private bool on_button_released(Gdk.EventButton ev)
 	{
-		if (ev.button == Gdk.BUTTON_PRIMARY)
-		{
+		if (ev.button == Gdk.BUTTON_PRIMARY) {
 			Gtk.TreePath path;
-			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null))
-			{
-				if (_tree_view.get_selection().path_is_selected(path))
-				{
+			if (_tree_view.get_path_at_pos((int)ev.x, (int)ev.y, out path, null, null, null)) {
+				if (_tree_view.get_selection().path_is_selected(path)) {
 					Gtk.TreePath filter_path = _tree_sort.convert_path_to_child_path(path);
 					Gtk.TreePath child_path = _tree_filter.convert_path_to_child_path(filter_path);
 					Gtk.TreeIter iter;
-					if (_list_store.get_iter(out iter, child_path))
-					{
+					if (_list_store.get_iter(out iter, child_path)) {
 						Value name;
 						Value type;
 						_list_store.get_value(iter, ProjectStore.Column.NAME, out name);
@@ -231,12 +226,10 @@ public class ResourceChooser : Gtk.Box
 		};
 		GLib.SubprocessLauncher sl = new GLib.SubprocessLauncher(SubprocessFlags.NONE);
 		sl.set_cwd(ENGINE_DIR);
-		try
-		{
+		try {
 			_editor_process = sl.spawnv(args);
 		}
-		catch (Error e)
-		{
+		catch (Error e) {
 			loge(e.message);
 		}
 
@@ -250,8 +243,7 @@ public class ResourceChooser : Gtk.Box
 			, EDITOR_CONNECTION_TRIES
 			, EDITOR_CONNECTION_INTERVAL
 			);
-		if (tries == EDITOR_CONNECTION_TRIES)
-		{
+		if (tries == EDITOR_CONNECTION_TRIES) {
 			loge("Cannot connect to unit_preview.");
 			return;
 		}
@@ -264,8 +256,7 @@ public class ResourceChooser : Gtk.Box
 		if (!_preview)
 			return;
 
-		if (_editor != null)
-		{
+		if (_editor != null) {
 			// Reset "disconnected" signal.
 			_editor.disconnected.disconnect(on_editor_disconnected);
 			_editor.disconnected.disconnect(on_editor_disconnected_unexpected);
@@ -273,8 +264,7 @@ public class ResourceChooser : Gtk.Box
 			// Explicit call to this function should not produce error messages.
 			_editor.disconnected.connect(on_editor_disconnected);
 
-			if (_editor.is_connected())
-			{
+			if (_editor.is_connected()) {
 				_stop_editor_callback = stop_editor.callback;
 				_editor.send_script("Device.quit()");
 				yield; // Wait for ConsoleClient to disconnect.
@@ -295,8 +285,7 @@ public class ResourceChooser : Gtk.Box
 
 		yield stop_editor();
 
-		if (_editor_view != null)
-		{
+		if (_editor_view != null) {
 			_editor_stack.remove(_editor_view);
 			_editor_view = null;
 		}
@@ -361,30 +350,22 @@ public class ResourceChooser : Gtk.Box
 		Gtk.TreeIter iter;
 		bool selected = _tree_selection.get_selected(out model, out iter);
 
-		if (ev.keyval == Gdk.Key.Down)
-		{
-			if (selected && model.iter_next(ref iter))
-			{
+		if (ev.keyval == Gdk.Key.Down) {
+			if (selected && model.iter_next(ref iter)) {
 				_tree_selection.select_iter(iter);
 				_tree_view.scroll_to_cell(model.get_path(iter), null, true, 1.0f, 0.0f);
 			}
 
 			return Gdk.EVENT_STOP;
-		}
-		else if (ev.keyval == Gdk.Key.Up)
-		{
-			if (selected && model.iter_previous(ref iter))
-			{
+		} else if (ev.keyval == Gdk.Key.Up) {
+			if (selected && model.iter_previous(ref iter)) {
 				_tree_selection.select_iter(iter);
 				_tree_view.scroll_to_cell(model.get_path(iter), null, true, 1.0f, 0.0f);
 			}
 
 			return Gdk.EVENT_STOP;
-		}
-		else if (ev.keyval == Gdk.Key.Return)
-		{
-			if (selected)
-			{
+		} else if (ev.keyval == Gdk.Key.Return) {
+			if (selected) {
 				Value name;
 				Value type;
 				model.get_value(iter, ProjectStore.Column.NAME, out name);
@@ -401,12 +382,10 @@ public class ResourceChooser : Gtk.Box
 
 	private void on_tree_selection_changed()
 	{
-		if (_preview)
-		{
+		if (_preview) {
 			Gtk.TreeModel model;
 			Gtk.TreeIter iter;
-			if (_tree_selection.get_selected(out model, out iter))
-			{
+			if (_tree_selection.get_selected(out model, out iter)) {
 				Value name;
 				Value type;
 				model.get_value(iter, ProjectStore.Column.NAME, out name);

+ 6 - 12
tools/level_editor/sprite_import_dialog.vala

@@ -34,8 +34,7 @@ Vector2 sprite_cell_pivot_xy(int cell_w, int cell_h, int pivot)
 	int pivot_x = 0;
 	int pivot_y = 0;
 
-	switch (pivot)
-	{
+	switch (pivot) {
 	case Pivot.TOP_LEFT:
 		pivot_x = 0;
 		pivot_y = 0;
@@ -132,12 +131,10 @@ public class SpriteImportDialog : Gtk.Dialog
 		this.title = "Import Sprite...";
 		this.set_icon_name(CROWN_ICON_NAME);
 
-		try
-		{
+		try {
 			_pixbuf = new Gdk.Pixbuf.from_file(png);
 		}
-		catch (GLib.Error e)
-		{
+		catch (GLib.Error e) {
 			loge(e.message);
 		}
 
@@ -185,10 +182,8 @@ public class SpriteImportDialog : Gtk.Dialog
 				int num_v = (int)cells.value.y;
 				int num_h = (int)cells.value.x;
 
-				for (int h = 0; h < num_v; ++h)
-				{
-					for (int w = 0; w < num_h; ++w)
-					{
+				for (int h = 0; h < num_v; ++h) {
+					for (int w = 0; w < num_h; ++w) {
 						Vector2 sc = sprite_cell_xy(h
 							, w
 							, (int)offset.value.x
@@ -499,8 +494,7 @@ public class SpriteImportDialog : Gtk.Dialog
 
 	private void on_response(Gtk.Dialog source, int response_id)
 	{
-		switch (response_id)
-		{
+		switch (response_id) {
 		case Gtk.ResponseType.OK:
 			break;
 

+ 1 - 2
tools/level_editor/statusbar.vala

@@ -46,8 +46,7 @@ public class Statusbar : Gtk.Box
 	{
 		_temporary_message.set_label("; " + message);
 
-		if (_timer_id > 0)
-		{
+		if (_timer_id > 0) {
 			GLib.Source.remove(_timer_id);
 			_timer_id = 0;
 		}

+ 12 - 24
tools/level_editor/unit.vala

@@ -24,8 +24,7 @@ public class Unit
 
 		// Search in components
 		val = _db.get_property(_id, "components");
-		if (val != null)
-		{
+		if (val != null) {
 			if (((HashSet<Guid?>)val).contains(component_id))
 				return _db.get_property(component_id, key);
 		}
@@ -37,8 +36,7 @@ public class Unit
 
 		// Search in prefab
 		val = _db.get_property(_id, "prefab");
-		if (val != null)
-		{
+		if (val != null) {
 			// Convert prefab path to object ID.
 			string prefab = (string)val;
 			Guid prefab_id = _db.get_property_guid(GUID_ZERO, prefab + ".unit");
@@ -84,8 +82,7 @@ public class Unit
 	{
 		// Search in components
 		Value? components = _db.get_property(_id, "components");
-		if (components != null && ((HashSet<Guid?>)components).contains(component_id))
-		{
+		if (components != null && ((HashSet<Guid?>)components).contains(component_id)) {
 			_db.set_property_bool(component_id, key, val);
 			return;
 		}
@@ -97,8 +94,7 @@ public class Unit
 	{
 		// Search in components
 		Value? components = _db.get_property(_id, "components");
-		if (components != null && ((HashSet<Guid?>)components).contains(component_id))
-		{
+		if (components != null && ((HashSet<Guid?>)components).contains(component_id)) {
 			_db.set_property_double(component_id, key, val);
 			return;
 		}
@@ -110,8 +106,7 @@ public class Unit
 	{
 		// Search in components
 		Value? components = _db.get_property(_id, "components");
-		if (components != null && ((HashSet<Guid?>)components).contains(component_id))
-		{
+		if (components != null && ((HashSet<Guid?>)components).contains(component_id)) {
 			_db.set_property_string(component_id, key, val);
 			return;
 		}
@@ -123,8 +118,7 @@ public class Unit
 	{
 		// Search in components
 		Value? components = _db.get_property(_id, "components");
-		if (components != null && ((HashSet<Guid?>)components).contains(component_id))
-		{
+		if (components != null && ((HashSet<Guid?>)components).contains(component_id)) {
 			_db.set_property_guid(component_id, key, val);
 			return;
 		}
@@ -136,8 +130,7 @@ public class Unit
 	{
 		// Search in components
 		Value? components = _db.get_property(_id, "components");
-		if (components != null && ((HashSet<Guid?>)components).contains(component_id))
-		{
+		if (components != null && ((HashSet<Guid?>)components).contains(component_id)) {
 			_db.set_property_vector3(component_id, key, val);
 			return;
 		}
@@ -149,8 +142,7 @@ public class Unit
 	{
 		// Search in components
 		Value? components = _db.get_property(_id, "components");
-		if (components != null && ((HashSet<Guid?>)components).contains(component_id))
-		{
+		if (components != null && ((HashSet<Guid?>)components).contains(component_id)) {
 			_db.set_property_quaternion(component_id, key, val);
 			return;
 		}
@@ -169,12 +161,9 @@ public class Unit
 		// If the component type is found inside the "components" array, the unit has the component
 		// and it owns it.
 		val = db.get_property(unit_id, "components");
-		if (val != null)
-		{
-			foreach (Guid id in (HashSet<Guid?>)val)
-			{
-				if ((string)db.get_property(id, "type") == component_type)
-				{
+		if (val != null) {
+			foreach (Guid id in (HashSet<Guid?>)val) {
+				if ((string)db.get_property(id, "type") == component_type) {
 					component_id = id;
 					owner_id = unit_id;
 					return true;
@@ -184,8 +173,7 @@ public class Unit
 
 		// Otherwise, search if any prefab has the component.
 		val = db.get_property(unit_id, "prefab");
-		if (val != null)
-		{
+		if (val != null) {
 			// Convert prefab path to object ID.
 			string prefab = (string)val;
 			Guid prefab_id = db.get_property_guid(GUID_ZERO, prefab + ".unit");

+ 12 - 26
tools/level_editor/user.vala

@@ -26,11 +26,9 @@ public class User
 		_data = sjson;
 
 		_data.foreach((ee) => {
-				if (ee.key == "recent_projects")
-				{
+				if (ee.key == "recent_projects") {
 					var recent_projects = ee.value as ArrayList<Value?>;
-					for (int ii = 0; ii < recent_projects.size; ++ii)
-					{
+					for (int ii = 0; ii < recent_projects.size; ++ii) {
 						Hashtable rp = recent_projects[ii] as Hashtable;
 
 						recent_project_added((string)rp["source_dir"]
@@ -38,9 +36,7 @@ public class User
 							, (string)rp["mtime"]
 							);
 					}
-				}
-				else
-				{
+				} else {
 					logw("Unknown key: `%s`".printf(ee.key));
 				}
 
@@ -70,15 +66,12 @@ public class User
 		Hashtable? project = null;
 
 		_data.foreach ((ee) => {
-				if (ee.key == "recent_projects")
-				{
+				if (ee.key == "recent_projects") {
 					recent_projects = ee.value as ArrayList<Value?>;
-					for (int ii = 0; ii < recent_projects.size; ++ii)
-					{
+					for (int ii = 0; ii < recent_projects.size; ++ii) {
 						Hashtable rp = recent_projects[ii] as Hashtable;
 
-						if ((string)rp["source_dir"] == source_dir)
-						{
+						if ((string)rp["source_dir"] == source_dir) {
 							project = rp;
 							return false; // break
 						}
@@ -88,25 +81,21 @@ public class User
 				return true;
 			});
 
-		if (recent_projects == null)
-		{
+		if (recent_projects == null) {
 			recent_projects = new ArrayList<Value?>();
 			_data["recent_projects"] = recent_projects;
 		}
 
 		string mtime = new GLib.DateTime.now_utc().to_unix().to_string();
 
-		if (project == null)
-		{
+		if (project == null) {
 			project = new Hashtable();
 			project["name"]       = source_dir; // FIXME: store project name somewhere inside project directory
 			project["source_dir"] = source_dir;
 			project["mtime"]      = mtime;
 			recent_projects.add(project);
 			recent_project_added(source_dir, source_dir, mtime);
-		}
-		else
-		{
+		} else {
 			project["mtime"] = mtime;
 			recent_project_touched(source_dir, mtime);
 		}
@@ -115,15 +104,12 @@ public class User
 	public void remove_recent_project(string source_dir)
 	{
 		_data.foreach((ee) => {
-				if (ee.key == "recent_projects")
-				{
+				if (ee.key == "recent_projects") {
 					var recent_projects = ee.value as ArrayList<Value?>;
 					var it = recent_projects.iterator();
-					for (var has_next = it.next(); has_next; has_next = it.next())
-					{
+					for (var has_next = it.next(); has_next; has_next = it.next()) {
 						Hashtable rp = it.get() as Hashtable;
-						if ((string)rp["source_dir"] == source_dir)
-						{
+						if ((string)rp["source_dir"] == source_dir) {
 							it.remove();
 							recent_project_removed(source_dir);
 							return false; // break

+ 17 - 36
tools/resource/mesh_resource.vala

@@ -22,8 +22,7 @@ public class MeshResource
 		// Create transform
 		{
 			Guid component_id;
-			if (!unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM))
-			{
+			if (!unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM)) {
 				component_id = Guid.new_guid();
 				db.create(component_id, OBJECT_TYPE_TRANSFORM);
 				db.add_to_set(unit_id, "components", component_id);
@@ -37,8 +36,7 @@ public class MeshResource
 		// Create mesh_renderer
 		{
 			Guid component_id;
-			if (!unit.has_component(out component_id, OBJECT_TYPE_MESH_RENDERER))
-			{
+			if (!unit.has_component(out component_id, OBJECT_TYPE_MESH_RENDERER)) {
 				component_id = Guid.new_guid();
 				db.create(component_id, OBJECT_TYPE_MESH_RENDERER);
 				db.add_to_set(unit_id, "components", component_id);
@@ -53,8 +51,7 @@ public class MeshResource
 		// Create collider
 		{
 			Guid component_id;
-			if (!unit.has_component(out component_id, OBJECT_TYPE_COLLIDER))
-			{
+			if (!unit.has_component(out component_id, OBJECT_TYPE_COLLIDER)) {
 				component_id = Guid.new_guid();
 				db.create(component_id, OBJECT_TYPE_COLLIDER);
 				db.add_to_set(unit_id, "components", component_id);
@@ -68,8 +65,7 @@ public class MeshResource
 		// Create actor
 		{
 			Guid component_id;
-			if (!unit.has_component(out component_id, OBJECT_TYPE_ACTOR))
-			{
+			if (!unit.has_component(out component_id, OBJECT_TYPE_ACTOR)) {
 				component_id = Guid.new_guid();
 				db.create(component_id, OBJECT_TYPE_ACTOR);
 				db.add_to_set(unit_id, "components", component_id);
@@ -84,11 +80,9 @@ public class MeshResource
 		if (parent_unit_id != unit_id)
 			db.add_to_set(parent_unit_id, "children", unit_id);
 
-		if (node.has_key("children"))
-		{
+		if (node.has_key("children")) {
 			Hashtable children = (Hashtable)node["children"];
-			foreach (var child in children.entries)
-			{
+			foreach (var child in children.entries) {
 				Guid new_unit_id = Guid.new_guid();
 				db.create(new_unit_id, OBJECT_TYPE_UNIT);
 				create_components(db, unit_id, new_unit_id, material_name, resource_name, child.key, (Hashtable)child.value);
@@ -98,8 +92,7 @@ public class MeshResource
 
 	public static int import(Project project, string destination_dir, SList<string> filenames)
 	{
-		foreach (unowned string filename_i in filenames)
-		{
+		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()));
 
@@ -124,13 +117,10 @@ public class MeshResource
 			mtl.add_filter(fltr);
 
 			string material_path = resource_path;
-			if (mtl.run() == (int)ResponseType.ACCEPT)
-			{
+			if (mtl.run() == (int)ResponseType.ACCEPT) {
 				material_path = project._source_dir.get_relative_path(File.new_for_path(mtl.get_filename()));
 				material_path = material_path.substring(0, material_path.last_index_of_char('.'));
-			}
-			else
-			{
+			} else {
 				Hashtable material = new Hashtable();
 				material["shader"]   = "mesh+DIFFUSE_MAP";
 				material["textures"] = new Hashtable();
@@ -140,12 +130,10 @@ public class MeshResource
 			mtl.destroy();
 			string material_name = project.resource_path_to_resource_name(material_path);
 
-			try
-			{
+			try {
 				file_src.copy(file_dst, FileCopyFlags.OVERWRITE);
 			}
-			catch (Error e)
-			{
+			catch (Error e) {
 				loge(e.message);
 			}
 
@@ -155,12 +143,9 @@ public class MeshResource
 			Guid unit_id;
 			Database db = project._database;
 
-			if (db.has_property(GUID_ZERO, resource_name + ".unit"))
-			{
+			if (db.has_property(GUID_ZERO, resource_name + ".unit")) {
 				unit_id = db.get_property_guid(GUID_ZERO, resource_name + ".unit");
-			}
-			else
-			{
+			} else {
 				db = new Database();
 				unit_id = Guid.new_guid();
 				db.create(unit_id, OBJECT_TYPE_UNIT);
@@ -169,16 +154,14 @@ public class MeshResource
 			Hashtable mesh = SJSON.load_from_path(filename_i);
 			Hashtable mesh_nodes = (Hashtable)mesh["nodes"];
 
-			if (mesh_nodes.size > 1)
-			{
+			if (mesh_nodes.size > 1) {
 				// Create an extra "root" unit to accommodate multiple root objects. This
 				// "root" unit will only have a transform centered at origin to allow other
 				// objects to be linked to it via the SceneGraph.
 				Unit unit = new Unit(db, unit_id);
 
 				Guid component_id;
-				if (!unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM))
-				{
+				if (!unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM)) {
 					component_id = Guid.new_guid();
 					db.create(component_id, OBJECT_TYPE_TRANSFORM);
 					db.add_to_set(unit_id, "components", component_id);
@@ -190,10 +173,8 @@ public class MeshResource
 			}
 
 			Guid new_unit_id = unit_id;
-			foreach (var entry in mesh_nodes.entries)
-			{
-				if (mesh_nodes.size > 1)
-				{
+			foreach (var entry in mesh_nodes.entries) {
+				if (mesh_nodes.size > 1) {
 					// If the mesh contains multiple root objects, create a new unit for each
 					// one of those, otherwise put the components inside the base unit.
 					new_unit_id = Guid.new_guid();

+ 3 - 6
tools/resource/sound_resource.vala

@@ -11,20 +11,17 @@ public class SoundResource
 {
 	public static int import(Project project, string destination_dir, SList<string> filenames)
 	{
-		foreach (unowned string filename_i in filenames)
-		{
+		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._source_dir.get_relative_path(file_dst);
 			string resource_path     = resource_filename.substring(0, resource_filename.last_index_of_char('.'));
 
-			try
-			{
+			try {
 				file_src.copy(file_dst, FileCopyFlags.OVERWRITE);
 			}
-			catch (Error e)
-			{
+			catch (Error e) {
 				loge(e.message);
 			}
 

+ 21 - 47
tools/resource/sprite_resource.vala

@@ -26,18 +26,14 @@ public class SpriteResource
 		SpriteImportDialog sid = new SpriteImportDialog(filenames.nth_data(0));
 		sid.show_all();
 
-		if (File.new_for_path(importer_settings_path).query_exists())
-		{
+		if (File.new_for_path(importer_settings_path).query_exists()) {
 			importer_settings = SJSON.load_from_path(importer_settings_path);
 			sid.load(importer_settings);
-		}
-		else
-		{
+		} else {
 			importer_settings = new Hashtable();
 		}
 
-		if (sid.run() != Gtk.ResponseType.OK)
-		{
+		if (sid.run() != Gtk.ResponseType.OK) {
 			sid.destroy();
 			return 1;
 		}
@@ -78,8 +74,7 @@ public class SpriteResource
 
 		sid.destroy();
 
-		foreach (unowned string filename_i in filenames)
-		{
+		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()));
 
@@ -105,12 +100,10 @@ public class SpriteResource
 			material["uniforms"] = uniforms;
 			SJSON.save(material, Path.build_filename(project.source_dir(), resource_path) + ".material");
 
-			try
-			{
+			try {
 				file_src.copy(file_dst, FileCopyFlags.OVERWRITE);
 			}
-			catch (Error e)
-			{
+			catch (Error e) {
 				loge(e.message);
 			}
 
@@ -125,10 +118,8 @@ public class SpriteResource
 			sprite["height"] = height;
 
 			ArrayList<Value?> frames = new ArrayList<Value?>();
-			for (int r = 0; r < num_v; ++r)
-			{
-				for (int c = 0; c < num_h; ++c)
-				{
+			for (int r = 0; r < num_v; ++r) {
+				for (int c = 0; c < num_h; ++c) {
 					Vector2 cell_xy = sprite_cell_xy(r
 						, c
 						, offset_x
@@ -160,12 +151,9 @@ public class SpriteResource
 			Guid unit_id;
 			Database db = project._database;
 
-			if (db.has_property(GUID_ZERO, resource_name + ".unit"))
-			{
+			if (db.has_property(GUID_ZERO, resource_name + ".unit")) {
 				unit_id = db.get_property_guid(GUID_ZERO, resource_name + ".unit");
-			}
-			else
-			{
+			} else {
 				db = new Database();
 				unit_id = Guid.new_guid();
 				db.create(unit_id, OBJECT_TYPE_UNIT);
@@ -176,8 +164,7 @@ public class SpriteResource
 			// Create transform
 			{
 				Guid component_id;
-				if (!unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM))
-				{
+				if (!unit.has_component(out component_id, OBJECT_TYPE_TRANSFORM)) {
 					component_id = Guid.new_guid();
 					db.create(component_id, OBJECT_TYPE_TRANSFORM);
 					db.add_to_set(unit_id, "components", component_id);
@@ -191,8 +178,7 @@ public class SpriteResource
 			// Create sprite_renderer
 			{
 				Guid component_id;
-				if (!unit.has_component(out component_id, OBJECT_TYPE_SPRITE_RENDERER))
-				{
+				if (!unit.has_component(out component_id, OBJECT_TYPE_SPRITE_RENDERER)) {
 					component_id = Guid.new_guid();
 					db.create(component_id, OBJECT_TYPE_SPRITE_RENDERER);
 					db.add_to_set(unit_id, "components", component_id);
@@ -205,24 +191,21 @@ public class SpriteResource
 				unit.set_component_property_bool  (component_id, "data.visible", true);
 			}
 
-			if (collision_enabled)
-			{
+			if (collision_enabled) {
 				// Create collider
 				double PIXELS_PER_METER = 32.0;
 				{
 					Quaternion rotation = QUATERNION_IDENTITY;
 
 					Guid component_id;
-					if (!unit.has_component(out component_id, OBJECT_TYPE_COLLIDER))
-					{
+					if (!unit.has_component(out component_id, OBJECT_TYPE_COLLIDER)) {
 						component_id = Guid.new_guid();
 						db.create(component_id, OBJECT_TYPE_COLLIDER);
 						db.add_to_set(unit_id, "components", component_id);
 					}
 
 					unit.set_component_property_string(component_id, "data.source", "inline");
-					if (shape_active_name == "square_collider")
-					{
+					if (shape_active_name == "square_collider") {
 						double pos_x =  (collision_x + collision_w/2.0 - pivot_xy.x) / PIXELS_PER_METER;
 						double pos_y = -(collision_y + collision_h/2.0 - pivot_xy.y) / PIXELS_PER_METER;
 						Vector3 position = Vector3(pos_x, 0, pos_y);
@@ -231,9 +214,7 @@ public class SpriteResource
 						unit.set_component_property_quaternion(component_id, "data.collider_data.rotation", rotation);
 						unit.set_component_property_string    (component_id, "data.shape", "box");
 						unit.set_component_property_vector3   (component_id, "data.collider_data.half_extents", half_extents);
-					}
-					else if (shape_active_name == "circle_collider")
-					{
+					} else if (shape_active_name == "circle_collider") {
 						double pos_x =  (circle_collision_center_x - pivot_xy.x) / PIXELS_PER_METER;
 						double pos_y = -(circle_collision_center_y - pivot_xy.y) / PIXELS_PER_METER;
 						Vector3 position = Vector3(pos_x, 0, pos_y);
@@ -242,9 +223,7 @@ public class SpriteResource
 						unit.set_component_property_quaternion(component_id, "data.collider_data.rotation", rotation);
 						unit.set_component_property_string    (component_id, "data.shape", "sphere");
 						unit.set_component_property_double    (component_id, "data.collider_data.radius", radius);
-					}
-					else if (shape_active_name == "capsule_collider")
-					{
+					} else if (shape_active_name == "capsule_collider") {
 						double pos_x =  (capsule_collision_center_x - pivot_xy.x) / PIXELS_PER_METER;
 						double pos_y = -(capsule_collision_center_y - pivot_xy.y) / PIXELS_PER_METER;
 						Vector3 position = Vector3(pos_x, 0, pos_y);
@@ -261,8 +240,7 @@ public class SpriteResource
 				// Create actor
 				{
 					Guid component_id;
-					if (!unit.has_component(out component_id, OBJECT_TYPE_ACTOR))
-					{
+					if (!unit.has_component(out component_id, OBJECT_TYPE_ACTOR)) {
 						component_id = Guid.new_guid();
 						db.create(component_id, OBJECT_TYPE_ACTOR);
 						db.add_to_set(unit_id, "components", component_id);
@@ -279,18 +257,14 @@ public class SpriteResource
 					unit.set_component_property_double(component_id, "data.mass", mass);
 					unit.set_component_property_string(component_id, "data.material", "default");
 				}
-			}
-			else /* if (collision_enabled) */
-			{
+			} else { /* if (collision_enabled) */
 				// Destroy collider and actor if any
 				Guid component_id;
-				if (unit.has_component(out component_id, OBJECT_TYPE_COLLIDER))
-				{
+				if (unit.has_component(out component_id, OBJECT_TYPE_COLLIDER)) {
 					db.remove_from_set(unit_id, "components", component_id);
 					db.destroy(component_id);
 				}
-				if (unit.has_component(out component_id, OBJECT_TYPE_ACTOR))
-				{
+				if (unit.has_component(out component_id, OBJECT_TYPE_ACTOR)) {
 					db.remove_from_set(unit_id, "components", component_id);
 					db.destroy(component_id);
 				}

+ 3 - 6
tools/resource/texture_resource.vala

@@ -11,20 +11,17 @@ public class TextureResource
 {
 	public static int import(Project project, string destination_dir, SList<string> filenames)
 	{
-		foreach (unowned string filename_i in filenames)
-		{
+		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._source_dir.get_relative_path(file_dst);
 			string resource_path     = resource_filename.substring(0, resource_filename.last_index_of_char('.'));
 
-			try
-			{
+			try {
 				file_src.copy(file_dst, FileCopyFlags.OVERWRITE);
 			}
-			catch (Error e)
-			{
+			catch (Error e) {
 				loge(e.message);
 			}
 

+ 5 - 10
tools/widgets/app_chooser_button.vala

@@ -35,14 +35,12 @@ public class AppChooserButton : Gtk.AppChooserButton
 	/// to set the predefined app based @a app_id.
 	public void set_app(string app_name, string? app_id)
 	{
-		if (app_name != APP_PREDEFINED)
-		{
+		if (app_name != APP_PREDEFINED) {
 			this.set_active_custom_item(app_name);
 			return;
 		}
 
-		if (app_id == null)
-		{
+		if (app_id == null) {
 			this.set_active_custom_item(APP_DEFAULT);
 			return;
 		}
@@ -52,8 +50,7 @@ public class AppChooserButton : Gtk.AppChooserButton
 				model.get_value(iter, ModelColumn.APP_INFO, out val);
 
 				GLib.AppInfo app_info = (GLib.AppInfo)val;
-				if (app_info != null && app_info.get_id() == app_id)
-				{
+				if (app_info != null && app_info.get_id() == app_id) {
 					this.set_active_iter(iter);
 					return true;
 				}
@@ -69,8 +66,7 @@ public class AppChooserButton : Gtk.AppChooserButton
 		app_id = null;
 
 		Gtk.TreeIter iter;
-		if (this.get_active_iter(out iter))
-		{
+		if (this.get_active_iter(out iter)) {
 			Value val;
 			this.model.get_value(iter, ModelColumn.NAME, out val);
 			string name = (string)val;
@@ -78,8 +74,7 @@ public class AppChooserButton : Gtk.AppChooserButton
 				return name;
 
 			GLib.AppInfo app_info = this.get_app_info();
-			if (app_info != null)
-			{
+			if (app_info != null) {
 				app_id = app_info.get_id();
 				return AppChooserButton.APP_PREDEFINED;
 			}

+ 2 - 4
tools/widgets/combo_box_map.vala

@@ -34,10 +34,8 @@ public class ComboBoxMap : Gtk.ComboBoxText
 		// Data
 		_stop_emit = false;
 
-		if (labels != null)
-		{
-			for (int ii = 0; ii < ids.length; ++ii)
-			{
+		if (labels != null) {
+			for (int ii = 0; ii < ids.length; ++ii) {
 				unowned string? id = ids != null ? ids[ii] : null;
 				this.append(id, labels[ii]);
 			}

+ 26 - 55
tools/widgets/console_view.vala

@@ -158,30 +158,23 @@ public class ConsoleView : Gtk.Box
 		string text = _entry.text;
 		text = text.strip();
 
-		if (text.length > 0)
-		{
+		if (text.length > 0) {
 			_entry_history.push(text);
 			_distance = 0;
 
 			Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
 			ConsoleClient? client = ((LevelEditorApplication)app).current_selected_client();
 
-			if (text[0] == ':')
-			{
-				string[] args = text[1:text.length].split(" ");
-				if (args.length > 0)
-				{
-					if (client != null)
-					{
+			if (text[0] == ':') {
+				string[] args = text[1 : text.length].split(" ");
+				if (args.length > 0) {
+					if (client != null) {
 						client.send(DeviceApi.command(args));
 						client.send(DeviceApi.frame());
 					}
 				}
-			}
-			else
-			{
-				if (client != null)
-				{
+			} else {
+				if (client != null) {
 					logi("> %s".printf(text));
 					client.send_script(text);
 					client.send(DeviceApi.frame());
@@ -194,25 +187,18 @@ public class ConsoleView : Gtk.Box
 
 	private bool on_entry_key_pressed(Gdk.EventKey ev)
 	{
-		if (ev.keyval == Gdk.Key.Down)
-		{
-			if (_distance > 1)
-			{
+		if (ev.keyval == Gdk.Key.Down) {
+			if (_distance > 1) {
 				--_distance;
 				_entry.text = _entry_history.element(_distance);
-			}
-			else
-			{
+			} else {
 				_entry.text = "";
 			}
 
 			_entry.set_position(_entry.text.length);
 			return Gdk.EVENT_STOP;
-		}
-		else if (ev.keyval == Gdk.Key.Up)
-		{
-			if (_distance < _entry_history._size)
-			{
+		} else if (ev.keyval == Gdk.Key.Up) {
+			if (_distance < _entry_history._size) {
 				++_distance;
 				_entry.text = _entry_history.element(_distance);
 			}
@@ -231,8 +217,7 @@ public class ConsoleView : Gtk.Box
 
 	private bool on_button_released(Gdk.EventButton ev)
 	{
-		if (ev.button == Gdk.BUTTON_PRIMARY)
-		{
+		if (ev.button == Gdk.BUTTON_PRIMARY) {
 			// Do not handle click if some text is selected.
 			Gtk.TextIter dummy_iter;
 			if (_text_view.buffer.get_selection_bounds(out dummy_iter, out dummy_iter))
@@ -248,15 +233,12 @@ public class ConsoleView : Gtk.Box
 				);
 
 			Gtk.TextIter iter;
-			if (_text_view.get_iter_at_location(out iter, buffer_x, buffer_y))
-			{
+			if (_text_view.get_iter_at_location(out iter, buffer_x, buffer_y)) {
 				// Check whether the text under the mouse pointer has a link tag.
 				GLib.SList<unowned TextTag> tags = iter.get_tags();
-				foreach (var item in tags)
-				{
+				foreach (var item in tags) {
 					string resource_name = item.get_data<string>("resource_name");
-					if (resource_name != null)
-					{
+					if (resource_name != null) {
 						Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
 						app.activate_action("open-resource", new GLib.Variant.string(resource_name));
 					}
@@ -281,22 +263,18 @@ public class ConsoleView : Gtk.Box
 			);
 
 		Gtk.TextIter iter;
-		if (_text_view.get_iter_at_location(out iter, buffer_x, buffer_y))
-		{
+		if (_text_view.get_iter_at_location(out iter, buffer_x, buffer_y)) {
 			// Check whether the text under the mouse pointer has a link tag.
 			GLib.SList<unowned TextTag> tags = iter.get_tags();
-			foreach (var item in tags)
-			{
+			foreach (var item in tags) {
 				string resource_name = item.get_data<string>("resource_name");
-				if (resource_name != null)
-				{
+				if (resource_name != null) {
 					hovering = true;
 				}
 			}
 		}
 
-		if (_cursor_is_hovering_link != hovering)
-		{
+		if (_cursor_is_hovering_link != hovering) {
 			_cursor_is_hovering_link = hovering;
 
 			if (_cursor_is_hovering_link)
@@ -314,8 +292,7 @@ public class ConsoleView : Gtk.Box
 
 		// Limit number of lines recorded.
 		int max_lines = (int)_preferences_dialog._console_max_lines.value;
-		if (buffer.get_line_count() - 1 >= max_lines)
-		{
+		if (buffer.get_line_count() - 1 >= max_lines) {
 			Gtk.TextIter start_of_first_line;
 			buffer.get_iter_at_line(out start_of_first_line, 0);
 			Gtk.TextIter end_of_first_line = start_of_first_line;
@@ -328,13 +305,11 @@ public class ConsoleView : Gtk.Box
 
 		// Replace all IDs with corresponding human-readable names.
 		int id_index = 0;
-		do
-		{
+		do {
 			// Search for occurrences of the ID string.
 			int id_index_orig = id_index;
 			id_index = message.index_of("#ID(", id_index);
-			if (id_index != -1)
-			{
+			if (id_index != -1) {
 				// If an occurrenct is found, insert the preceding text as usual.
 				string line_chunk = message.substring(id_index_orig, id_index - id_index_orig);
 				buffer.insert_with_tags(ref end_iter
@@ -346,8 +321,7 @@ public class ConsoleView : Gtk.Box
 
 				// Try to extract the ID from the ID string.
 				int id_closing_parentheses = message.index_of(")", id_index + 4);
-				if (id_closing_parentheses == -1)
-				{
+				if (id_closing_parentheses == -1) {
 					// If the ID is malformed, insert the whole line as-is.
 					buffer.insert_with_tags(ref end_iter
 						, message.substring(id_index)
@@ -376,9 +350,7 @@ public class ConsoleView : Gtk.Box
 					);
 				id_index += 4 + resource_id.length;
 				continue;
-			}
-			else
-			{
+			} else {
 				buffer.insert_with_tags(ref end_iter
 					, message.substring(id_index_orig)
 					, -1
@@ -386,8 +358,7 @@ public class ConsoleView : Gtk.Box
 					, null
 					);
 			}
-		}
-		while (id_index++ >= 0);
+		} while (id_index++ >= 0);
 
 		// Scroll to bottom.
 		// See: gtk3-demo "Automatic Scrolling".

+ 2 - 4
tools/widgets/entry_double.vala

@@ -63,8 +63,7 @@ public class EntryDouble : Gtk.Entry
 
 	private bool on_button_release(Gdk.EventButton ev)
 	{
-		if (ev.button == Gdk.BUTTON_PRIMARY && this.has_focus)
-		{
+		if (ev.button == Gdk.BUTTON_PRIMARY && this.has_focus) {
 			this.text = _edit_fmt.printf(_value);
 			this.set_position(-1);
 			this.select_region(0, -1);
@@ -113,8 +112,7 @@ public class EntryDouble : Gtk.Entry
 		this.text = _preview_fmt.printf(clamped);
 
 		// Notify value changed
-		if (_value != clamped)
-		{
+		if (_value != clamped) {
 			_value = clamped;
 			if (!_stop_emit)
 				value_changed();

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików