2
0
ncannasse 9 жил өмнө
parent
commit
553d2c01bc

+ 2 - 1
hxd/net/Macros.hx

@@ -24,7 +24,8 @@ enum RpcMode {
 	Server;
 	/*
 		When called on the client: will forward the call to the server if not the owner, or else execute locally.
-		When called on the server: will forward the call to the owner
+		When called on the server: will forward the call to the owner.
+		Will fail if there is no owner.
 	*/
 	Owner;
 }

+ 8 - 4
hxd/net/Serializer.hx

@@ -30,6 +30,8 @@ class Convert {
 			var c = new ConvertField(oldT, newT);
 			if( newT != null && sameType(oldT, newT) )
 				c.same = true;
+			else
+				c.defaultValue = getDefault(newT);
 			c.index = read.length;
 			read.push(c);
 			map.set(schema.fieldsNames[i], c);
@@ -569,8 +571,12 @@ class Serializer {
 				v = w.defaultValue;
 			else {
 				v = values[w.index];
-				if( !w.same )
-					v = convertValue(v, w.from, w.to);
+				if( !w.same ) {
+					if( v == null )
+						v = w.defaultValue;
+					else
+						v = convertValue(v, w.from, w.to);
+				}
 			}
 			writeValue(v, w.to);
 		}
@@ -591,8 +597,6 @@ class Serializer {
 	}
 
 	function convertValue( v : Dynamic, from : Schema.FieldType, to : Schema.FieldType ) : Dynamic {
-		if( v == null && isNullable(to) )
-			return null;
 		throw "Cannot convert " + v + " from " + from + " to " + to;
 	}