Browse Source

[filebrowser] Customise render props for thumbnail generation

Clément Espeute 2 months ago
parent
commit
0d4733dc1c
2 changed files with 21 additions and 7 deletions
  1. 9 1
      hide/Config.hx
  2. 12 6
      hide/tools/ThumbnailGenerator.hx

+ 9 - 1
hide/Config.hx

@@ -56,6 +56,7 @@ class Config {
 	var ide : Ide;
 	var parent : Config;
 	public var path(default,null) : String;
+	var lastPathMTime : Float = 0;
 	public var source(default, null) : ConfigDef = cast {};
 	public var current : ConfigDef = cast {};
 
@@ -65,6 +66,10 @@ class Config {
 		sync();
 	}
 
+	public function getMTime() : Float {
+		return parent != null ? hxd.Math.max(parent.getMTime(), lastPathMTime) : lastPathMTime;
+	}
+
 	public function isLocal() {
 		if( path == null && parent != null ) return parent.isLocal();
 		return path == null || StringTools.startsWith(path, ide.projectDir);
@@ -73,8 +78,11 @@ class Config {
 	public function load( path : String ) {
 		this.path = path;
 		var fullPath = ide.getPath(path);
-		if( sys.FileSystem.exists(fullPath) )
+		if( sys.FileSystem.exists(fullPath) ) {
+			var stat = js.node.Fs.statSync(fullPath);
+			lastPathMTime = stat.mtime.getTime();
 			source = try ide.parseJSON(sys.io.File.getContent(fullPath)) catch( e : Dynamic ) throw e+" (in "+fullPath+")";
+		}
 		else
 			source = cast {};
 		sync();

+ 12 - 6
hide/tools/ThumbnailGenerator.hx

@@ -126,11 +126,6 @@ class ThumbnailGenerator {
 
 			renderCanvas.errorHandler = (e) -> null;
 
-			var renderPropsList = hide.comp.ScenePreview.listRenderPropsStatic(hide.Ide.inst.config.current);
-			if (renderPropsList.length > 0) {
-				renderPropsPath =  renderPropsList[0].value;
-			}
-
 			haxe.Timer.delay(() -> {
 				this.ready = true;
 
@@ -156,7 +151,8 @@ class ThumbnailGenerator {
 					if (!Ide.inst.ideConfig.filebrowserDebugIgnoreThumbnailCache && sys.FileSystem.exists(thumbPath)) {
 						var thumbStat = sys.FileSystem.stat(thumbPath);
 						var fileStat = sys.FileSystem.stat(message.path);
-						if (thumbStat.mtime.getTime() > fileStat.mtime.getTime()) {
+						var config = Config.loadForFile(Ide.inst, message.path);
+						if (thumbStat.mtime.getTime() > fileStat.mtime.getTime() && thumbStat.mtime.getTime() > config.getMTime()) {
 							shouldGenerate = false;
 							sendSuccess(message.path, thumbPath);
 						}
@@ -203,6 +199,16 @@ class ThumbnailGenerator {
 		renderCanvas.engine.setCurrent();
 
 		renderCanvas.s3d.removeChildren();
+
+		var config = Config.loadForFile(Ide.inst, toRender.path);
+		renderPropsPath = config.getLocal("thumbnail.renderProps");
+		if (renderPropsPath == null) {
+			var renderPropsList = hide.comp.ScenePreview.listRenderPropsStatic(config);
+			if (renderPropsList.length > 0) {
+				renderPropsPath =  renderPropsList[0].value;
+			}
+		}
+
 		if (renderPropsPath != null)
 			renderCanvas.setRenderProps(renderPropsPath);