Browse Source

added "remove" convert, added multiple extensions "a,b,c" and wildcart support in props.json

Nicolas Cannasse 5 năm trước cách đây
mục cha
commit
44a76a7ef0

+ 4 - 1
hxd/fmt/pak/Build.hx

@@ -41,11 +41,14 @@ class Build {
 				var s = buildRec(fpath);
 				var s = buildRec(fpath);
 				if( s != null ) f.content.push(s);
 				if( s != null ) f.content.push(s);
 			}
 			}
+			if( f.content.length == 0 && path != "" )
+				return null;
 		} else {
 		} else {
 			var ext = path.split("/").pop().split(".").pop().toLowerCase();
 			var ext = path.split("/").pop().split(".").pop().toLowerCase();
 			if( excludedExt.indexOf(ext) >= 0 )
 			if( excludedExt.indexOf(ext) >= 0 )
 				return null;
 				return null;
-			var filePath = fs.getAbsolutePath(fs.get(path));
+			var entry = try fs.get(path) catch( e : hxd.res.NotFound ) return null;
+			var filePath = fs.getAbsolutePath(entry);
 			var data = sys.io.File.getBytes(filePath);
 			var data = sys.io.File.getBytes(filePath);
 
 
 			switch( ext ) {
 			switch( ext ) {

+ 4 - 1
hxd/fs/Convert.hx

@@ -220,6 +220,9 @@ class DummyConvert extends Convert {
 		save(haxe.io.Bytes.alloc(0));
 		save(haxe.io.Bytes.alloc(0));
 	}
 	}
 
 
-	static var _ = Convert.register(new DummyConvert(null,"dummy"));
+	static var _ = [
+		Convert.register(new DummyConvert(null,"dummy")),
+		Convert.register(new DummyConvert(null,"remove"))
+	];
 
 
 }
 }

+ 19 - 3
hxd/fs/FileConverter.hx

@@ -13,6 +13,8 @@ enum ConvertPattern {
 	Filename( name : String );
 	Filename( name : String );
 	Regexp( r : EReg );
 	Regexp( r : EReg );
 	Ext( e : String );
 	Ext( e : String );
+	Exts( e : Array<String> );
+	Wildcard;
 }
 }
 
 
 typedef ConvertCommand = {
 typedef ConvertCommand = {
@@ -39,8 +41,8 @@ class FileConverter {
 		// this is the default converts config, it can be override in per-directory props.json
 		// this is the default converts config, it can be override in per-directory props.json
 		defaultConfig = makeConfig({
 		defaultConfig = makeConfig({
 			"fs.convert" : {
 			"fs.convert" : {
-				"fbx" : "hmd",
-				"fnt" : "bfnt",
+				"fbx" : { "convert" : "hmd", "priority" : -1 },
+				"fnt" : { "convert" : "bfnt", "priority" : -1 }
 			}
 			}
 		});
 		});
 	}
 	}
@@ -58,7 +60,15 @@ class FileConverter {
 		var merge = mergeRec(def, conf);
 		var merge = mergeRec(def, conf);
 		for( f in Reflect.fields(merge) ) {
 		for( f in Reflect.fields(merge) ) {
 			var cmd = makeCommmand(Reflect.field(merge,f));
 			var cmd = makeCommmand(Reflect.field(merge,f));
-			var pt = if( f.charCodeAt(0) == "^".code ) Regexp(new EReg(f,"")) else if( ~/^[a-zA-Z0-9]+$/.match(f) ) Ext(f.toLowerCase()) else Filename(f);
+			var pt = if( f.charCodeAt(0) == "^".code )
+				Regexp(new EReg(f,""));
+			else if( ~/^[a-zA-Z0-9,]+$/.match(f) ) {
+				var el = f.toLowerCase().split(",");
+				el.length == 1 ? Ext(el[0]) : Exts(el);
+			} else if( f == "*" )
+				Wildcard;
+			else
+				Filename(f);
 			cfg.rules.push({ pt : pt, cmd : cmd.cmd, priority : cmd.priority });
 			cfg.rules.push({ pt : pt, cmd : cmd.cmd, priority : cmd.priority });
 		}
 		}
 		cfg.rules.sort(sortByRulePiority);
 		cfg.rules.sort(sortByRulePiority);
@@ -157,6 +167,8 @@ class FileConverter {
 			case Filename(f): if( name == f ) return r;
 			case Filename(f): if( name == f ) return r;
 			case Regexp(reg): if( reg.match(name) || reg.match(path) ) return r;
 			case Regexp(reg): if( reg.match(name) || reg.match(path) ) return r;
 			case Ext(e): if( ext == e ) return r;
 			case Ext(e): if( ext == e ) return r;
+			case Exts(el): if( el.indexOf(ext) >= 0 ) return r;
+			case Wildcard: return r;
 			}
 			}
 		return null;
 		return null;
 	}
 	}
@@ -196,6 +208,10 @@ class FileConverter {
 				sys.io.File.saveContent(e.file,"");
 				sys.io.File.saveContent(e.file,"");
 			return;
 			return;
 		}
 		}
+		if( conv.destExt == "remove" ) {
+			e.file = null;
+			return;
+		}
 		outFile += "."+conv.destExt;
 		outFile += "."+conv.destExt;
 		convertAndCache(e, outFile, conv, cmd.params);
 		convertAndCache(e, outFile, conv, cmd.params);
 		if( cmd.then != null ) {
 		if( cmd.then != null ) {

+ 1 - 0
hxd/fs/LocalFileSystem.hx

@@ -267,6 +267,7 @@ class LocalFileSystem implements FileSystem {
 		if( !check || ((!isWindows || (isWindows && f == baseDir + path)) && sys.FileSystem.exists(f) && checkPath(f)) ) {
 		if( !check || ((!isWindows || (isWindows && f == baseDir + path)) && sys.FileSystem.exists(f) && checkPath(f)) ) {
 			e = new LocalEntry(this, path.split("/").pop(), path, f);
 			e = new LocalEntry(this, path.split("/").pop(), path, f);
 			convert.run(e);
 			convert.run(e);
+			if( e.file == null ) e = null;
 		}
 		}
 		fileCache.set(path, {r:e});
 		fileCache.set(path, {r:e});
 		return e;
 		return e;

+ 1 - 1
hxd/res/FileTree.hx

@@ -153,7 +153,7 @@ class FileTree {
 			if( !StringTools.startsWith(file.fullPath, basePath) )
 			if( !StringTools.startsWith(file.fullPath, basePath) )
 				continue;
 				continue;
 			var name = "R_" + invalidChars.replace(file.relPath, "_");
 			var name = "R_" + invalidChars.replace(file.relPath, "_");
-			var f = fs.get(file.relPath); // convert
+			var f = try fs.get(file.relPath) catch( e : hxd.res.NotFound ) continue; // convert and filter
 			var fullPath = fs.getAbsolutePath(f);
 			var fullPath = fs.getAbsolutePath(f);
 
 
 			switch( file.ext ) {
 			switch( file.ext ) {