Browse Source

fixed prefab structural changes

Nicolas Cannasse 4 years ago
parent
commit
f454b640c1
3 changed files with 33 additions and 19 deletions
  1. 10 6
      hide/comp/cdb/DataFiles.hx
  2. 17 10
      hide/comp/cdb/ObjEditor.hx
  3. 6 3
      hide/view/FileView.hx

+ 10 - 6
hide/comp/cdb/DataFiles.hx

@@ -31,16 +31,20 @@ class DataFiles {
 		haxe.Timer.delay(function() {
 			if( !changed ) return;
 			changed = false;
-			for( s in base.sheets )
-				if( s.props.dataFiles != null ) @:privateAccess {
-					s.sheet.lines = null;
-					s.sheet.linesData = null;
-				}
-			load();
+			reload();
 			Editor.refreshAll(true);
 		},0);
 	}
 
+	static function reload() {
+		for( s in base.sheets )
+			if( s.props.dataFiles != null ) @:privateAccess {
+				s.sheet.lines = null;
+				s.sheet.linesData = null;
+			}
+		load();
+	}
+
 	static function loadSheet( sheet : cdb.Sheet ) {
 		var ide = Ide.inst;
 		var lines : Array<Dynamic> = [];

+ 17 - 10
hide/comp/cdb/ObjEditor.hx

@@ -33,14 +33,7 @@ class ObjEditor extends Editor {
 			copy : function() return ((makeStructSign() + haxe.Json.stringify(obj)) : Any),
 			save : function() {
 				// allow save in case structure was changed
-				ide.saveDatabase(true);
-				if( structureWasChanged ) {
-					structureWasChanged = false;
-					haxe.Timer.delay(function() {
-						fileView.modified = false; // prevent message prompt
-						@:privateAccess fileView.onFileChanged(false);
-					},0);
-				}
+				ide.saveDatabase();
 			}
 		};
 		super(props, api);
@@ -54,13 +47,27 @@ class ObjEditor extends Editor {
 				We are about to change structure, but our prefab will not see its data changed...
 				Let's save first our file and reload it in DataFiles so the changes gets applied to it
 			*/
-			fileView.save();
-			DataFiles.load();
+			if( fileView.modified ) {
+				fileView.save();
+				@:privateAccess DataFiles.reload();
+			}
 			structureWasChanged = true;
 		}
 		super.beginChanges(structure);
 	}
 
+	override function endChanges() {
+		super.endChanges();
+		if( structureWasChanged && changesDepth == 0 ) {
+			structureWasChanged = false;
+			// force reload if was changed on disk because of structural change
+			@:privateAccess if( fileView.currentSign == null || fileView.currentSign != fileView.makeSign() ) {
+				fileView.modified = false;
+				fileView.onFileChanged(false);
+			}
+		}
+	}
+
 	override function show(sheet:cdb.Sheet, ?parent:Element) {
 		super.show(sheet, parent);
 		element.addClass("cdb-obj-editor");

+ 6 - 3
hide/view/FileView.hx

@@ -33,12 +33,15 @@ class FileView extends hide.ui.View<{ path : String }> {
 		super.onRebuild();
 	}
 
+	function makeSign() {
+		var content = sys.io.File.getContent(getPath());
+		return haxe.crypto.Md5.encode(content);
+	}
+
 	function onFileChanged( wasDeleted : Bool, rebuildView = true ) {
 		if( !wasDeleted && currentSign != null ) {
 			// double check if content has changed
-			var content = sys.io.File.getContent(getPath());
-			var sign = haxe.crypto.Md5.encode(content);
-			if( sign == currentSign )
+			if( makeSign() == currentSign )
 				return;
 		}
 		if( wasDeleted ) {