ncannasse 9 years ago
parent
commit
a6cbbec0de
1 changed files with 24 additions and 20 deletions
  1. 24 20
      hxd/inspect/Inspector.hx

+ 24 - 20
hxd/inspect/Inspector.hx

@@ -208,26 +208,7 @@ class Inspector {
 					inspect.setPathPropValue(s, state.get(s).original);
 					inspect.setPathPropValue(s, state.get(s).original);
 				state = new Map();
 				state = new Map();
 
 
-				var o : Dynamic = haxe.Json.parse(bytes.toString());
-				function browseRec( path : Array<String>, v : Dynamic ) {
-					switch( Type.typeof(v) ) {
-					case TNull, TInt, TFloat, TBool, TClass(_):
-						var path = path.join(".");
-						state.set(path, { original : null, current : v });
-					case TUnknown, TFunction, TEnum(_):
-						throw "Invalid value " + v;
-					case TObject:
-						for( f in Reflect.fields(v) ) {
-							var fv = Reflect.field(v, f);
-							path.push(f);
-							browseRec(path, fv);
-							path.pop();
-						}
-					}
-				}
-				browseRec([], o);
-				for( s in state.keys() )
-					inspect.setPathPropValue(s, state.get(s).current);
+				loadProps(bytes.toString());
 			});
 			});
 
 
 		},{ defaultPath : savedFile, fileTypes : [ { name:"Scene Props", extensions:["js"] } ] } );
 		},{ defaultPath : savedFile, fileTypes : [ { name:"Scene Props", extensions:["js"] } ] } );
@@ -236,6 +217,29 @@ class Inspector {
 		}
 		}
 	}
 	}
 
 
+	public function loadProps( props : String ) {
+		var o : Dynamic = haxe.Json.parse(props);
+		function browseRec( path : Array<String>, v : Dynamic ) {
+			switch( Type.typeof(v) ) {
+			case TNull, TInt, TFloat, TBool, TClass(_):
+				var path = path.join(".");
+				state.set(path, { original : null, current : v });
+			case TUnknown, TFunction, TEnum(_):
+				throw "Invalid value " + v;
+			case TObject:
+				for( f in Reflect.fields(v) ) {
+					var fv = Reflect.field(v, f);
+					path.push(f);
+					browseRec(path, fv);
+					path.pop();
+				}
+			}
+		}
+		browseRec([], o);
+		for( s in state.keys() )
+			inspect.setPathPropValue(s, state.get(s).current);
+	}
+
 	function save() {
 	function save() {
 		var o : Dynamic = { };
 		var o : Dynamic = { };
 		for( s in state.keys() ) {
 		for( s in state.keys() ) {