Browse Source

[prefab] Ignore hbson when loading prefab in editor

Clément Espeute 3 months ago
parent
commit
c3abb0a0fb
2 changed files with 9 additions and 1 deletions
  1. 1 1
      hide/view/Prefab.hx
  2. 8 0
      hrt/prefab/Resource.hx

+ 1 - 1
hide/view/Prefab.hx

@@ -442,7 +442,7 @@ class Prefab extends hide.view.FileView {
 	}
 
 	public function onSceneReady() {
-		data = hxd.res.Loader.currentInstance.load(state.path).toPrefab().load().clone();
+		data = hxd.res.Loader.currentInstance.load(state.path).toPrefab().loadBypassCache();
 		sceneEditor.setPrefab(cast data);
 
 		refreshSceneFilters();

+ 8 - 0
hrt/prefab/Resource.hx

@@ -27,8 +27,16 @@ class Resource extends hxd.res.Resource {
 	}
 
 	function loadData() {
+		#if editor
+		// Force loading the original prefab data from disc to avoid sync errors between
+		// original data and bson
+		var localEntry = Std.downcast(entry, hxd.fs.LocalFileSystem.LocalEntry);
+		@:privateAccess var path = localEntry.originalFile ?? localEntry.file;
+		return  haxe.Json.parse(sys.io.File.getContent(path));
+		#else
 		var isBSON = entry.fetchBytes(0,1).get(0) == 'H'.code;
 		return isBSON ? new hxd.fmt.hbson.Reader(entry.getBytes(),false).read() : haxe.Json.parse(entry.getText());
+		#end
 	}
 
 	public function loadBypassCache() {