Jelajahi Sumber

better db save

Nicolas Cannasse 8 tahun lalu
induk
melakukan
666829caef
1 mengubah file dengan 8 tambahan dan 7 penghapusan
  1. 8 7
      h3d/mat/MaterialDatabase.hx

+ 8 - 7
h3d/mat/MaterialDatabase.hx

@@ -22,13 +22,14 @@ class MaterialDatabase {
 	}
 	}
 
 
 	function save() {
 	function save() {
-		#if sys
-		var path = haxe.macro.Compiler.getDefine("resourcesPath");
-		if( path == null ) path = "res";
-		sys.io.File.saveContent(path + "/" + file, haxe.Json.stringify(db, "\t"));
-		#else
-		throw "Can't save material props database " + file;
+		#if (sys || nodejs)
+		var fs = Std.instance(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
+		if( fs != null ) {
+			sys.io.File.saveContent(fs.baseDir + "/" + file, haxe.Json.stringify(db, "\t"));
+			return;
+		}
 		#end
 		#end
+		throw "Can't save material props database " + file;
 	}
 	}
 
 
 	public function loadProps( material : Material, setup : MaterialSetup ) {
 	public function loadProps( material : Material, setup : MaterialSetup ) {
@@ -62,7 +63,7 @@ class MaterialDatabase {
 
 
 		var currentProps = material.props;
 		var currentProps = material.props;
 		setup.initModelMaterial(material); // reset to default
 		setup.initModelMaterial(material); // reset to default
-		if( Std.string(material.props) == Std.string(currentProps) ) {
+		if( currentProps == null || Std.string(material.props) == Std.string(currentProps) ) {
 			// cleanup
 			// cleanup
 			while( path.length > 0 ) {
 			while( path.length > 0 ) {
 				var name = path.pop();
 				var name = path.pop();